]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
add vlan interface support
authorAlexandre Derumier <aderumier@odiso.com>
Tue, 28 Jan 2020 10:24:45 +0000 (11:24 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 30 Jan 2020 15:14:30 +0000 (16:14 +0100)
vlan-raw-device && vlan-id field are only
enabled if interface name is different than interfaceX.Y

I have added a listener on iface,
to enable them live if user want a custom name for vlan interface

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
Toolkit.js
Utils.js
node/NetworkEdit.js
node/NetworkView.js

index 538db3af28a1b86d6518dafe0ccb176c2865c091..d8378905c493d5281e5325e9baad4315fc72a98f 100644 (file)
@@ -83,6 +83,14 @@ Ext.apply(Ext.form.field.VTypes, {
     BridgeName: function(v) {
         return (/^vmbr\d{1,4}$/).test(v);
     },
+    VlanName: function(v) {
+       if (Proxmox.Utils.VlanInterface_match.test(v)) {
+         return true;
+       } else if (Proxmox.Utils.Vlan_match.test(v)) {
+         return true;
+       }
+       return true;
+    },
     BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
 
     BondName: function(v) {
index 6d1b24c7079080cf04c393f6d64064999899489f..e9dcd798bc75f5e00dc92071d78d3ee9777c37f2 100644 (file)
--- a/Utils.js
+++ b/Utils.js
@@ -696,5 +696,7 @@ Ext.define('Proxmox.Utils', { utilities: {
        me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
        me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
        me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
+        me.Vlan_match = new RegExp('^vlan(\\d+)');
+        me.VlanInterface_match = new RegExp('(\\w+)\\.(\\d+)');
     }
 });
index ce7e7aee627129e8bf8b5af6d1453ae57e843008..33fee75c841cb558ff2c2d6fa4eb0628116ae61f 100644 (file)
@@ -23,8 +23,8 @@ Ext.define('Proxmox.node.NetworkEdit', {
            iface_vtype = 'BondName';
        } else if (me.iftype === 'eth' && !me.isCreate) {
            iface_vtype = 'InterfaceName';
-       } else if (me.iftype === 'vlan' && !me.isCreate) {
-           iface_vtype = 'InterfaceName';
+       } else if (me.iftype === 'vlan') {
+           iface_vtype = 'VlanName';
        } else if (me.iftype === 'OVSBridge') {
            iface_vtype = 'BridgeName';
        } else if (me.iftype === 'OVSBond') {
@@ -96,6 +96,49 @@ Ext.define('Proxmox.node.NetworkEdit', {
                fieldLabel: gettext('OVS options'),
                name: 'ovs_options'
            });
+       } else if (me.iftype === 'vlan') {
+
+           if(!me.isCreate) {
+
+                me.disablevlanid = false;
+                me.disablevlanrawdevice = false;
+                me.vlanrawdevicevalue = '';
+                me.vlanidvalue = '';
+
+                if (Proxmox.Utils.VlanInterface_match.test(me.iface)) {
+                   me.disablevlanid = true;
+                   me.disablevlanrawdevice = true;
+                   var arr = Proxmox.Utils.VlanInterface_match.exec(me.iface);
+                   me.vlanrawdevicevalue = arr[1];
+                   me.vlanidvalue = arr[2];
+
+                } else if (Proxmox.Utils.Vlan_match.test(me.iface)) {
+                   me.disablevlanid = true;
+                   var arr = Proxmox.Utils.Vlan_match.exec(me.iface);
+                   me.vlanidvalue = arr[1];
+                }
+           } else {
+
+                me.disablevlanid = true;
+                me.disablevlanrawdevice = true;
+           }
+
+           column2.push({
+               xtype: 'textfield',
+               fieldLabel: gettext('Vlan raw device'),
+               name: 'vlan-raw-device',
+                value: me.vlanrawdevicevalue,
+               disabled: me.disablevlanrawdevice
+           });
+
+           column2.push({
+               xtype: 'pveVlanField',
+               name: 'vlan-id',
+                value: me.vlanidvalue,
+               disabled: me.disablevlanid
+
+           });
+
        } else if (me.iftype === 'bond') {
            column2.push({
                xtype: 'textfield',
@@ -200,7 +243,25 @@ Ext.define('Proxmox.node.NetworkEdit', {
                name: 'iface',
                value: me.iface,
                vtype: iface_vtype,
-               allowBlank: false
+               allowBlank: false,
+                listeners: {
+                    change: function(f, value) {
+                        if (me.isCreate && iface_vtype === 'VlanName') {
+                           var vlanidField = me.down('field[name=vlan-id]');
+                           var vlanrawdeviceField = me.down('field[name=vlan-raw-device]');
+                           if (Proxmox.Utils.VlanInterface_match.test(value)) {
+                               vlanidField.setDisabled(true);
+                               vlanrawdeviceField.setDisabled(true);
+                           } else if (Proxmox.Utils.Vlan_match.test(value)) {
+                               vlanidField.setDisabled(true);
+                               vlanrawdeviceField.setDisabled(false);
+                           } else {
+                               vlanidField.setDisabled(false);
+                               vlanrawdeviceField.setDisabled(false);
+                           }
+                        }
+                    }
+                }
            }
        ];
 
index 9b3845d307f8d9886ca00d254bae3fa896f7a0c3..92d7eb8139046fd58f3e809c0424f3ea7700fdfd 100644 (file)
@@ -18,7 +18,7 @@ Ext.define('Proxmox.node.NetworkView', {
 
     // defines what types of network devices we want to create
     // order is always the same
-    types: ['bridge', 'bond', 'ovs'],
+    types: ['bridge', 'bond', 'vlan', 'ovs'],
 
     showApplyBtn: false,
 
@@ -216,6 +216,21 @@ Ext.define('Proxmox.node.NetworkView', {
            });
        }
 
+       if (me.types.indexOf('vlan') !== -1) {
+           menu_items.push({
+               text: Proxmox.Utils.render_network_iface_type('vlan'),
+               handler: function() {
+                   var win = Ext.create('Proxmox.node.NetworkEdit', {
+                       nodename: me.nodename,
+                       iftype: 'vlan',
+                       iface_default: 'interfaceX.1'
+                   });
+                   win.on('destroy', reload);
+                   win.show();
+               }
+           });
+       }
+
        if (me.types.indexOf('ovs') !== -1) {
            if (menu_items.length > 0) {
                menu_items.push({ xtype: 'menuseparator' });