]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/Network.js
88c6e561020c477c4e5b31ad7be882a081fe0e66
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
) {
61 throw "no dataCache specified";
66 throw "no interface name specified";
68 if (!me
.dataCache
[me
.ifname
]) {
69 throw "no such interface '" + me
.ifname
+ "'";
72 cdata
= PVE
.Parser
.parseLxcNetwork(me
.dataCache
[me
.ifname
]);
76 for (i
= 0; i
< 10; i
++) {
77 if (me
.isCreate
&& !me
.dataCache
['net'+i
.toString()]) {
78 me
.ifname
= 'net' + i
.toString();
94 fieldLabel
: gettext('Name'),
95 emptyText
: '(e.g., eth0)',
98 validator: function(value
) {
100 Ext
.Object
.each(me
.dataCache
, function(key
, netstr
) {
101 if (!key
.match(/^net\d+/) || key
=== me
.ifname
) {
104 var net
= PVE
.Parser
.parseLxcNetwork(netstr
);
105 if (net
.name
=== value
) {
106 result
= "interface name already in use";
113 // validator can return bool/string
114 /*jslint confusion:true*/
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 checked
: 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]').setDisabled(!value
);
194 me
.down('field[name=gw]').setDisabled(!value
);
200 boxLabel
: 'DHCP', // do not localize
211 vtype
: 'IPCIDRAddress',
214 fieldLabel
: 'IPv4/CIDR' // do not localize
222 fieldLabel
: gettext('Gateway') + ' (IPv4)',
223 margin
: '0 0 3 0' // override bottom margin to account for the menuseparator
226 xtype
: 'menuseparator',
240 text
: 'IPv6:' // do not localize
244 boxLabel
: gettext('Static'),
246 inputValue
: 'static',
247 checked
: !(auto6
|| dhcp6
),
250 change: function(cb
, value
) {
251 me
.down('field[name=ip6]').setDisabled(!value
);
252 me
.down('field[name=gw6]').setDisabled(!value
);
258 boxLabel
: 'DHCP', // do not localize
266 boxLabel
: 'SLAAC', // do not localize
278 vtype
: 'IP6CIDRAddress',
279 disabled
: (dhcp6
|| auto6
),
280 fieldLabel
: 'IPv6/CIDR' // do not localize
287 disabled
: (dhcp6
|| auto6
),
288 fieldLabel
: gettext('Gateway') + ' (IPv6)'
297 Ext
.define('PVE.lxc.NetworkEdit', {
298 extend
: 'Proxmox.window.Edit',
302 initComponent : function() {
306 throw "no dataCache specified";
310 throw "no node name specified";
313 var ipanel
= Ext
.create('PVE.lxc.NetworkInputPanel', {
315 nodename
: me
.nodename
,
316 dataCache
: me
.dataCache
,
317 isCreate
: me
.isCreate
321 subject
: gettext('Network Device') + ' (veth)',
322 digest
: me
.dataCache
.digest
,
330 Ext
.define('PVE.lxc.NetworkView', {
331 extend
: 'Ext.grid.GridPanel',
332 alias
: 'widget.pveLxcNetworkView',
334 onlineHelp
: 'pct_container_network',
336 dataCache
: {}, // used to store result of last load
339 stateId
: 'grid-lxc-network',
344 Proxmox
.Utils
.setErrorMask(me
, true);
346 Proxmox
.Utils
.API2Request({
348 failure: function(response
, opts
) {
349 Proxmox
.Utils
.setErrorMask(me
, gettext('Error') + ': ' + response
.htmlStatus
);
351 success: function(response
, opts
) {
352 Proxmox
.Utils
.setErrorMask(me
, false);
353 var result
= Ext
.decode(response
.responseText
);
354 var data
= result
.data
|| {};
357 Ext
.Object
.each(data
, function(key
, value
) {
358 if (!key
.match(/^net\d+/)) {
361 var net
= PVE
.Parser
.parseLxcNetwork(value
);
365 me
.store
.loadData(records
);
366 me
.down('button[name=addButton]').setDisabled((records
.length
>= 10));
371 initComponent : function() {
374 var nodename
= me
.pveSelNode
.data
.node
;
376 throw "no node name specified";
379 var vmid
= me
.pveSelNode
.data
.vmid
;
381 throw "no VM ID specified";
384 var caps
= Ext
.state
.Manager
.get('GuiCap');
386 me
.url
= '/nodes/' + nodename
+ '/lxc/' + vmid
+ '/config';
388 var store
= new Ext
.data
.Store({
389 model
: 'pve-lxc-network',
398 var sm
= Ext
.create('Ext.selection.RowModel', {});
400 var remove_btn
= new Proxmox
.button
.Button({
401 text
: gettext('Remove'),
404 enableFn: function(rec
) {
405 return !!caps
.vms
['VM.Config.Network'];
407 confirmMsg: function (rec
) {
408 return Ext
.String
.format(gettext('Are you sure you want to remove entry {0}'),
409 "'" + rec
.data
.id
+ "'");
411 handler: function(btn
, event
, rec
) {
412 Proxmox
.Utils
.API2Request({
416 params
: { 'delete': rec
.data
.id
, digest
: me
.dataCache
.digest
},
417 callback: function() {
420 failure: function (response
, opts
) {
421 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
427 var run_editor = function() {
428 var rec
= sm
.getSelection()[0];
433 if (!caps
.vms
['VM.Config.Network']) {
437 var win
= Ext
.create('PVE.lxc.NetworkEdit', {
440 dataCache
: me
.dataCache
,
443 win
.on('destroy', me
.load
, me
);
447 var edit_btn
= new Proxmox
.button
.Button({
448 text
: gettext('Edit'),
451 enableFn: function(rec
) {
452 if (!caps
.vms
['VM.Config.Network']) {
465 text
: gettext('Add'),
467 disabled
: !caps
.vms
['VM.Config.Network'],
468 handler: function() {
469 var win
= Ext
.create('PVE.lxc.NetworkEdit', {
473 dataCache
: me
.dataCache
475 win
.on('destroy', me
.load
, me
);
489 header
: gettext('Name'),
494 header
: gettext('Bridge'),
499 header
: gettext('Firewall'),
501 dataIndex
: 'firewall',
502 renderer
: Proxmox
.Utils
.format_boolean
505 header
: gettext('VLAN Tag'),
510 header
: gettext('MAC address'),
515 header
: gettext('IP address'),
518 renderer: function(value
, metaData
, rec
) {
519 if (rec
.data
.ip
&& rec
.data
.ip6
) {
520 return rec
.data
.ip
+ "<br>" + rec
.data
.ip6
;
521 } else if (rec
.data
.ip6
) {
529 header
: gettext('Gateway'),
532 renderer: function(value
, metaData
, rec
) {
533 if (rec
.data
.gw
&& rec
.data
.gw6
) {
534 return rec
.data
.gw
+ "<br>" + rec
.data
.gw6
;
535 } else if (rec
.data
.gw6
) {
545 itemdblclick
: run_editor
553 Ext
.define('pve-lxc-network', {
554 extend
: "Ext.data.Model",
555 proxy
: { type
: 'memory' },
556 fields
: [ 'id', 'name', 'hwaddr', 'bridge',
557 'ip', 'gw', 'ip6', 'gw6', 'tag', 'firewall' ]