]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/Network.js
1 Ext
.define('PVE.lxc.NetworkInputPanel', {
2 extend
: 'Proxmox.panel.InputPanel',
3 alias
: 'widget.pveLxcNetworkInputPanel',
7 onlineHelp
: 'pct_container_network',
9 setNodename: function(nodename
) {
12 if (!nodename
|| (me
.nodename
=== nodename
)) {
16 me
.nodename
= nodename
;
18 var bridgesel
= me
.query("[isFormField][name=bridge]")[0];
19 bridgesel
.setNodename(nodename
);
22 onGetValues: function(values
) {
39 if (values
.ipv6mode
!== 'static') {
40 values
.ip6
= values
.ipv6mode
;
42 if (values
.ipv4mode
!== 'static') {
43 values
.ip
= values
.ipv4mode
;
45 newdata
[id
] = PVE
.Parser
.printLxcNetwork(values
);
49 initComponent : function() {
54 if (me
.insideWizard
) {
59 cdata
.firewall
= (me
.insideWizard
|| me
.isCreate
);
62 throw "no dataCache specified";
67 throw "no interface name specified";
69 if (!me
.dataCache
[me
.ifname
]) {
70 throw "no such interface '" + me
.ifname
+ "'";
73 cdata
= PVE
.Parser
.parseLxcNetwork(me
.dataCache
[me
.ifname
]);
77 for (i
= 0; i
< 32; i
++) {
78 if (me
.isCreate
&& !me
.dataCache
['net'+i
.toString()]) {
79 me
.ifname
= 'net' + i
.toString();
95 fieldLabel
: gettext('Name'),
96 emptyText
: '(e.g., eth0)',
99 validator: function(value
) {
101 Ext
.Object
.each(me
.dataCache
, function(key
, netstr
) {
102 if (!key
.match(/^net\d+/) || key
=== me
.ifname
) {
105 var net
= PVE
.Parser
.parseLxcNetwork(netstr
);
106 if (net
.name
=== value
) {
107 result
= "interface name already in use";
114 // validator can return bool/string
121 fieldLabel
: gettext('MAC address'),
128 xtype
: 'PVE.form.BridgeSelector',
130 nodename
: me
.nodename
,
131 fieldLabel
: gettext('Bridge'),
136 xtype
: 'pveVlanField',
141 xtype
: 'numberfield',
143 fieldLabel
: gettext('Rate limit') + ' (MB/s)',
147 emptyText
: 'unlimited',
151 xtype
: 'proxmoxcheckbox',
152 fieldLabel
: gettext('Firewall'),
154 value
: cdata
.firewall
,
158 var dhcp4
= (cdata
.ip
=== 'dhcp');
164 var auto6
= (cdata
.ip6
=== 'auto');
165 var dhcp6
= (cdata
.ip6
=== 'dhcp');
166 if (auto6
|| dhcp6
) {
182 text
: 'IPv4:', // do not localize
186 boxLabel
: gettext('Static'),
188 inputValue
: 'static',
192 change: function(cb
, value
) {
193 me
.down('field[name=ip]').setEmptyText(
194 !!value
? Proxmox
.Utils
.NoneText
: "",
196 me
.down('field[name=ip]').setDisabled(!value
);
197 me
.down('field[name=gw]').setDisabled(!value
);
203 boxLabel
: 'DHCP', // do not localize
214 vtype
: 'IPCIDRAddress',
216 emptyText
: dhcp4
? '' : Proxmox
.Utils
.NoneText
,
218 fieldLabel
: 'IPv4/CIDR', // do not localize
226 fieldLabel
: gettext('Gateway') + ' (IPv4)',
227 margin
: '0 0 3 0', // override bottom margin to account for the menuseparator
230 xtype
: 'menuseparator',
244 text
: 'IPv6:', // do not localize
248 boxLabel
: gettext('Static'),
250 inputValue
: 'static',
251 checked
: !(auto6
|| dhcp6
),
254 change: function(cb
, value
) {
255 me
.down('field[name=ip6]').setEmptyText(
256 !!value
? Proxmox
.Utils
.NoneText
: "",
258 me
.down('field[name=ip6]').setDisabled(!value
);
259 me
.down('field[name=gw6]').setDisabled(!value
);
265 boxLabel
: 'DHCP', // do not localize
273 boxLabel
: 'SLAAC', // do not localize
285 emptyText
: dhcp6
|| auto6
? '' : Proxmox
.Utils
.NoneText
,
286 vtype
: 'IP6CIDRAddress',
287 disabled
: (dhcp6
|| auto6
),
288 fieldLabel
: 'IPv6/CIDR', // do not localize
295 disabled
: (dhcp6
|| auto6
),
296 fieldLabel
: gettext('Gateway') + ' (IPv6)',
304 Ext
.define('PVE.lxc.NetworkEdit', {
305 extend
: 'Proxmox.window.Edit',
309 initComponent : function() {
313 throw "no dataCache specified";
317 throw "no node name specified";
320 var ipanel
= Ext
.create('PVE.lxc.NetworkInputPanel', {
322 nodename
: me
.nodename
,
323 dataCache
: me
.dataCache
,
324 isCreate
: me
.isCreate
,
328 subject
: gettext('Network Device') + ' (veth)',
329 digest
: me
.dataCache
.digest
,
337 Ext
.define('PVE.lxc.NetworkView', {
338 extend
: 'Ext.grid.GridPanel',
339 alias
: 'widget.pveLxcNetworkView',
341 onlineHelp
: 'pct_container_network',
343 dataCache
: {}, // used to store result of last load
346 stateId
: 'grid-lxc-network',
351 Proxmox
.Utils
.setErrorMask(me
, true);
353 Proxmox
.Utils
.API2Request({
355 failure: function(response
, opts
) {
356 Proxmox
.Utils
.setErrorMask(me
, gettext('Error') + ': ' + response
.htmlStatus
);
358 success: function(response
, opts
) {
359 Proxmox
.Utils
.setErrorMask(me
, false);
360 var result
= Ext
.decode(response
.responseText
);
361 var data
= result
.data
|| {};
364 Ext
.Object
.each(data
, function(key
, value
) {
365 if (!key
.match(/^net\d+/)) {
368 var net
= PVE
.Parser
.parseLxcNetwork(value
);
372 me
.store
.loadData(records
);
373 me
.down('button[name=addButton]').setDisabled((records
.length
>= 32));
378 initComponent : function() {
381 var nodename
= me
.pveSelNode
.data
.node
;
383 throw "no node name specified";
386 var vmid
= me
.pveSelNode
.data
.vmid
;
388 throw "no VM ID specified";
391 var caps
= Ext
.state
.Manager
.get('GuiCap');
393 me
.url
= '/nodes/' + nodename
+ '/lxc/' + vmid
+ '/config';
395 var store
= new Ext
.data
.Store({
396 model
: 'pve-lxc-network',
405 var sm
= Ext
.create('Ext.selection.RowModel', {});
407 var remove_btn
= new Proxmox
.button
.Button({
408 text
: gettext('Remove'),
411 enableFn: function(rec
) {
412 return !!caps
.vms
['VM.Config.Network'];
414 confirmMsg: function (rec
) {
415 return Ext
.String
.format(gettext('Are you sure you want to remove entry {0}'),
416 "'" + rec
.data
.id
+ "'");
418 handler: function(btn
, event
, rec
) {
419 Proxmox
.Utils
.API2Request({
423 params
: { 'delete': rec
.data
.id
, digest
: me
.dataCache
.digest
},
424 callback: function() {
427 failure: function (response
, opts
) {
428 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
434 var run_editor = function() {
435 var rec
= sm
.getSelection()[0];
440 if (!caps
.vms
['VM.Config.Network']) {
444 var win
= Ext
.create('PVE.lxc.NetworkEdit', {
447 dataCache
: me
.dataCache
,
450 win
.on('destroy', me
.load
, me
);
454 var edit_btn
= new Proxmox
.button
.Button({
455 text
: gettext('Edit'),
458 enableFn: function(rec
) {
459 if (!caps
.vms
['VM.Config.Network']) {
472 text
: gettext('Add'),
474 disabled
: !caps
.vms
['VM.Config.Network'],
475 handler: function() {
476 var win
= Ext
.create('PVE.lxc.NetworkEdit', {
480 dataCache
: me
.dataCache
,
482 win
.on('destroy', me
.load
, me
);
496 header
: gettext('Name'),
501 header
: gettext('Bridge'),
506 header
: gettext('Firewall'),
508 dataIndex
: 'firewall',
509 renderer
: Proxmox
.Utils
.format_boolean
,
512 header
: gettext('VLAN Tag'),
517 header
: gettext('MAC address'),
522 header
: gettext('IP address'),
525 renderer: function(value
, metaData
, rec
) {
526 if (rec
.data
.ip
&& rec
.data
.ip6
) {
527 return rec
.data
.ip
+ "<br>" + rec
.data
.ip6
;
528 } else if (rec
.data
.ip6
) {
536 header
: gettext('Gateway'),
539 renderer: function(value
, metaData
, rec
) {
540 if (rec
.data
.gw
&& rec
.data
.gw6
) {
541 return rec
.data
.gw
+ "<br>" + rec
.data
.gw6
;
542 } else if (rec
.data
.gw6
) {
552 itemdblclick
: run_editor
,
560 Ext
.define('pve-lxc-network', {
561 extend
: "Ext.data.Model",
562 proxy
: { type
: 'memory' },
563 fields
: [ 'id', 'name', 'hwaddr', 'bridge',
564 'ip', 'gw', 'ip6', 'gw6', 'tag', 'firewall' ],