78 lines
2.4 KiB
JavaScript
78 lines
2.4 KiB
JavaScript
/*
|
|
* Proxmox VE - VLAN Trunks UI Plugin
|
|
* Adds a "Trunks" field to the QEMU VM Network Device editor.
|
|
*
|
|
* The PVE network parser/printer (PVE.Parser) already understands the
|
|
* `trunks=` option; only the UI field is missing. This override adds it.
|
|
*
|
|
* Install: place in /usr/share/pve-manager/js/ and load it after
|
|
* pvemanagerlib.js via the index template (see install.sh).
|
|
*/
|
|
|
|
Ext.define('PVE.patch.QemuNetworkTrunks', {
|
|
override: 'PVE.qemu.NetworkInputPanel',
|
|
|
|
// Keep in sync with the parser regex in pvemanagerlib.js (print/parse_net).
|
|
trunksRegex: /^\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*$/,
|
|
|
|
// The original onGetValues builds `me.network` and serializes it with
|
|
// PVE.Parser.printQemuNetwork(), which appends `,trunks=` when set.
|
|
// So we just maintain me.network.trunks and let the parent serialize.
|
|
onGetValues: function (values) {
|
|
var me = this;
|
|
|
|
if (values.trunks) {
|
|
me.network.trunks = values.trunks;
|
|
} else {
|
|
delete me.network.trunks;
|
|
}
|
|
delete values.trunks; // not a real form field for the parent
|
|
|
|
return me.callParent([values]);
|
|
},
|
|
|
|
initComponent: function () {
|
|
var me = this;
|
|
|
|
me.callParent(arguments);
|
|
|
|
me.addTrunksField();
|
|
},
|
|
|
|
// Insert the Trunks field right after MTU in the advanced column.
|
|
addTrunksField: function () {
|
|
var me = this;
|
|
|
|
if (me.down('[name=trunks]')) {
|
|
return; // already added
|
|
}
|
|
|
|
var mtuField = me.down('[name=mtu]');
|
|
var container = mtuField && mtuField.ownerCt;
|
|
if (!container) {
|
|
return; // layout changed in this PVE version; fail safe
|
|
}
|
|
|
|
container.add({
|
|
xtype: 'textfield',
|
|
name: 'trunks',
|
|
fieldLabel: 'Trunks',
|
|
emptyText: 'e.g. 100;200;300-400',
|
|
allowBlank: true,
|
|
regex: me.trunksRegex,
|
|
regexText: 'VLAN IDs separated by semicolons, e.g. 100;200;300-400',
|
|
});
|
|
|
|
// In the wizard, disable Trunks together with "No network device".
|
|
var noNetworkCb = me.down('[name=nonetwork]');
|
|
if (noNetworkCb) {
|
|
noNetworkCb.on('change', function (cb, value) {
|
|
var trunksField = me.down('[name=trunks]');
|
|
if (trunksField) {
|
|
trunksField.setDisabled(value);
|
|
}
|
|
});
|
|
}
|
|
},
|
|
});
|