* [pve-devel] [PATCH widget-toolkit v7 1/4] fix #3892: network: add bridge vids field for bridge_vids
2024-11-15 16:57 [pve-devel] [PATCH widget-toolkit v7 0/4] fix #3893: make bridge vids configurable Aaron Lauterer
@ 2024-11-15 16:57 ` Aaron Lauterer
2024-11-15 16:57 ` [pve-devel] [PATCH widget-toolkit v7 2/4] network: make bridge vids label wider to avoid line break Aaron Lauterer
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Aaron Lauterer @ 2024-11-15 16:57 UTC (permalink / raw)
To: pve-devel
The new optional bridge_vids field allows to set that property via the
GUI. Since the backend needs to support it, the field needs to be
explicitly enabled.
For now, Proxmox VE (PVE) is the use case.
Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
I dropped the T-B and R-B tags as these last changes do change the
overall appearance.
changes since
v6:
* revert label to "Bridge VLAN IDs"
* add info when to use it into the tooltip
v5: change label to "VLAN IDs"
v4: none
v3:
* switched regex to one with non-capturing group
* reworked valid VLAN check according to the suggestion
v2:
* added validation code following how it is implemented in the API
src/node/NetworkEdit.js | 65 +++++++++++++++++++++++++++++++++++++++++
src/node/NetworkView.js | 5 ++++
2 files changed, 70 insertions(+)
diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
index 27c1baf..e4fe2db 100644
--- a/src/node/NetworkEdit.js
+++ b/src/node/NetworkEdit.js
@@ -2,6 +2,9 @@ Ext.define('Proxmox.node.NetworkEdit', {
extend: 'Proxmox.window.Edit',
alias: ['widget.proxmoxNodeNetworkEdit'],
+ // Enable to show the VLAN ID field
+ bridge_set_vids: false,
+
initComponent: function() {
let me = this;
@@ -57,11 +60,70 @@ Ext.define('Proxmox.node.NetworkEdit', {
}
if (me.iftype === 'bridge') {
+ let vids = Ext.create('Ext.form.field.Text', {
+ fieldLabel: gettext('Bridge VLAN IDs'),
+ name: 'bridge_vids',
+ emptyText: '2-4094',
+ disabled: true,
+ autoEl: {
+ tag: 'div',
+ 'data-qtip': gettext("Space-separated list of VLANs offloaded to the hardware. Useful for NICs with restricted VLAN offloading support. Single VLAN IDs and ranges. For example: '2 4 100-200'"),
+ },
+ validator: function(value) {
+ if (!value) { // empty
+ return true;
+ }
+
+ let vid_list = value.split(' ');
+
+ let invalidVid = function(tag) {
+ if (!isNaN(tag) && (tag < 2 || tag > 4094)) {
+ return `not a valid VLAN ID '${tag}'`;
+ }
+
+ return false;
+ };
+
+ for (const vid of vid_list) {
+ if (!vid) {
+ continue;
+ }
+ let res = vid.match(/^(\d+)(?:-(\d+))?$/);
+ if (!res) {
+ return `not a valid VLAN configuration '${vid}'`;
+ }
+ let start = Number(res[1]);
+ let end = Number(res[2]);
+
+ res = invalidVid(start);
+ if (res) {
+ return res;
+ }
+
+ res = invalidVid(end);
+ if (res) {
+ return res;
+ }
+
+ if (start >= end) {
+ return `VID range must go from lower to higher tag: '${vid}'`;
+ }
+ }
+ return true;
+ },
+ });
column2.push({
xtype: 'proxmoxcheckbox',
fieldLabel: gettext('VLAN aware'),
name: 'bridge_vlan_aware',
deleteEmpty: !me.isCreate,
+ listeners: {
+ change: function(f, newVal) {
+ if (me.bridge_set_vids) {
+ vids.setDisabled(!newVal);
+ }
+ },
+ },
});
column2.push({
xtype: 'textfield',
@@ -72,6 +134,9 @@ Ext.define('Proxmox.node.NetworkEdit', {
'data-qtip': gettext('Space-separated list of interfaces, for example: enp0s0 enp1s0'),
},
});
+ if (me.bridge_set_vids) {
+ advancedColumn2.push(vids);
+ }
} else if (me.iftype === 'OVSBridge') {
column2.push({
xtype: 'textfield',
diff --git a/src/node/NetworkView.js b/src/node/NetworkView.js
index 1d67ac8..c08cbfa 100644
--- a/src/node/NetworkView.js
+++ b/src/node/NetworkView.js
@@ -33,6 +33,9 @@ Ext.define('Proxmox.node.NetworkView', {
showApplyBtn: false,
+ // decides if VLAN IDs field for bridges is shown, depends on the product if needed
+ bridge_set_vids: false,
+
initComponent: function() {
let me = this;
@@ -100,6 +103,7 @@ Ext.define('Proxmox.node.NetworkView', {
nodename: me.nodename,
iface: rec.data.iface,
iftype: rec.data.type,
+ bridge_set_vids: me.bridge_set_vids,
listeners: {
destroy: () => reload(),
},
@@ -170,6 +174,7 @@ Ext.define('Proxmox.node.NetworkView', {
nodename: me.nodename,
iftype: iType,
iface_default: findNextFreeInterfaceId(iDefault ?? iType),
+ bridge_set_vids: me.bridge_set_vids,
onlineHelp: 'sysadmin_network_configuration',
listeners: {
destroy: () => reload(),
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] [PATCH widget-toolkit v7 2/4] network: make bridge vids label wider to avoid line break
2024-11-15 16:57 [pve-devel] [PATCH widget-toolkit v7 0/4] fix #3893: make bridge vids configurable Aaron Lauterer
2024-11-15 16:57 ` [pve-devel] [PATCH widget-toolkit v7 1/4] fix #3892: network: add bridge vids field for bridge_vids Aaron Lauterer
@ 2024-11-15 16:57 ` Aaron Lauterer
2024-11-15 16:57 ` [pve-devel] [PATCH manager v7 3/4] fix #3893: api: network: add bridge_vids parameter Aaron Lauterer
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Aaron Lauterer @ 2024-11-15 16:57 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
new in v7, kept as a separate patch so it is easier to decide if we want
that or not.
src/node/NetworkEdit.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/node/NetworkEdit.js b/src/node/NetworkEdit.js
index e4fe2db..ece3e02 100644
--- a/src/node/NetworkEdit.js
+++ b/src/node/NetworkEdit.js
@@ -62,6 +62,7 @@ Ext.define('Proxmox.node.NetworkEdit', {
if (me.iftype === 'bridge') {
let vids = Ext.create('Ext.form.field.Text', {
fieldLabel: gettext('Bridge VLAN IDs'),
+ labelWidth: 120,
name: 'bridge_vids',
emptyText: '2-4094',
disabled: true,
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] [PATCH manager v7 3/4] fix #3893: api: network: add bridge_vids parameter
2024-11-15 16:57 [pve-devel] [PATCH widget-toolkit v7 0/4] fix #3893: make bridge vids configurable Aaron Lauterer
2024-11-15 16:57 ` [pve-devel] [PATCH widget-toolkit v7 1/4] fix #3892: network: add bridge vids field for bridge_vids Aaron Lauterer
2024-11-15 16:57 ` [pve-devel] [PATCH widget-toolkit v7 2/4] network: make bridge vids label wider to avoid line break Aaron Lauterer
@ 2024-11-15 16:57 ` Aaron Lauterer
2024-11-15 16:57 ` [pve-devel] [PATCH manager v7 4/4] fix #3893: ui: network: enable bridge_vids field Aaron Lauterer
2024-11-16 15:41 ` [pve-devel] partially-applied: [PATCH widget-toolkit v7 0/4] fix #3893: make bridge vids configurable Thomas Lamprecht
4 siblings, 0 replies; 7+ messages in thread
From: Aaron Lauterer @ 2024-11-15 16:57 UTC (permalink / raw)
To: pve-devel
The API itself allows several list separators. The network configuration
for bridge_vids expects a space separated list. We therefore convert it
initially to a space separated list.
Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
I opted for a comment before the step where we split and reassemble the
list with spaces as separators as this step might be a bit obscure if
one is not aware of the reason (interfaces syntax).
Feel free to drop the comments if you think they are unnessecary
changes since
v6: none
v5:
* drop PVE::Tools::list_is_empty and check for empty lists directly
v4:
* use the list_is_empty function, therefore avoiding negative matches
* recreate the list with spaces as separators
v3:
* changed "vlans" to "VLANs" in description
v2:
* added checks to handle empty lists
PVE/API2/Network.pm | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/PVE/API2/Network.pm b/PVE/API2/Network.pm
index f39f04f5..b9db9b27 100644
--- a/PVE/API2/Network.pm
+++ b/PVE/API2/Network.pm
@@ -66,6 +66,11 @@ my $confdesc = {
type => 'boolean',
optional => 1,
},
+ bridge_vids => {
+ description => "Specify the allowed VLANs. For example: '2 4 100-200'. Only used if the bridge is VLAN aware.",
+ optional => 1,
+ type => 'string', format => 'pve-vlan-id-or-range-list',
+ },
bridge_ports => {
description => "Specify the interfaces you want to add to your bridge.",
optional => 1,
@@ -469,6 +474,14 @@ __PACKAGE__->register_method({
if ! grep { $_ eq $iface } @ports;
}
+ if ($param->{bridge_vids} && scalar(PVE::Tools::split_list($param->{bridge_vids}) == 0)) {
+ raise_param_exc({ bridge_vids => "VLAN list items are empty" });
+ }
+ # make sure the list is space separated! other separators will cause problems in the
+ # network configuration
+ $param->{bridge_vids} = join(" ", PVE::Tools::split_list($param->{bridge_vids}))
+ if $param->{bridge_vids};
+
$ifaces->{$iface} = $param;
PVE::INotify::write_file('interfaces', $config);
@@ -558,7 +571,15 @@ __PACKAGE__->register_method({
foreach my $k (keys %$param) {
$ifaces->{$iface}->{$k} = $param->{$k};
}
-
+
+ if ($param->{bridge_vids} && scalar(PVE::Tools::split_list($param->{bridge_vids}) == 0)) {
+ raise_param_exc({ bridge_vids => "VLAN list items are empty" });
+ }
+ # make sure the list is space separated! other separators will cause problems in the
+ # network configuration
+ $param->{bridge_vids} = join(" ", PVE::Tools::split_list($param->{bridge_vids}))
+ if $param->{bridge_vids};
+
PVE::INotify::write_file('interfaces', $config);
};
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] [PATCH manager v7 4/4] fix #3893: ui: network: enable bridge_vids field
2024-11-15 16:57 [pve-devel] [PATCH widget-toolkit v7 0/4] fix #3893: make bridge vids configurable Aaron Lauterer
` (2 preceding siblings ...)
2024-11-15 16:57 ` [pve-devel] [PATCH manager v7 3/4] fix #3893: api: network: add bridge_vids parameter Aaron Lauterer
@ 2024-11-15 16:57 ` Aaron Lauterer
2024-11-16 15:41 ` [pve-devel] partially-applied: [PATCH widget-toolkit v7 0/4] fix #3893: make bridge vids configurable Thomas Lamprecht
4 siblings, 0 replies; 7+ messages in thread
From: Aaron Lauterer @ 2024-11-15 16:57 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
changes since
v6: none
v5: none
v4: none
v3: none
v2: none
www/manager6/node/Config.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/www/manager6/node/Config.js b/www/manager6/node/Config.js
index d27592ce..7bdfb6d9 100644
--- a/www/manager6/node/Config.js
+++ b/www/manager6/node/Config.js
@@ -194,6 +194,7 @@ Ext.define('PVE.node.Config', {
showApplyBtn: true,
groups: ['services'],
nodename: nodename,
+ bridge_set_vids: true,
onlineHelp: 'sysadmin_network_configuration',
},
{
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* [pve-devel] partially-applied: [PATCH widget-toolkit v7 0/4] fix #3893: make bridge vids configurable
2024-11-15 16:57 [pve-devel] [PATCH widget-toolkit v7 0/4] fix #3893: make bridge vids configurable Aaron Lauterer
` (3 preceding siblings ...)
2024-11-15 16:57 ` [pve-devel] [PATCH manager v7 4/4] fix #3893: ui: network: enable bridge_vids field Aaron Lauterer
@ 2024-11-16 15:41 ` Thomas Lamprecht
2024-11-18 9:23 ` Aaron Lauterer
4 siblings, 1 reply; 7+ messages in thread
From: Thomas Lamprecht @ 2024-11-16 15:41 UTC (permalink / raw)
To: Proxmox VE development discussion, Aaron Lauterer
Am 15.11.24 um 17:57 schrieb Aaron Lauterer:
> After some back and forth on v5 regarding the UI label and extra
> textinfo, another series.
>
> I dropped the T-B and R-B tags for this series, as the last non-trivial
> patch that had them changed the appearance of the UI field considerably.
>
> this version reworks a few parts since
> v6:
> * drop extra explanation field for bridge VIDS and move the info into
> the tooltip
> * Revert UI Label
> * increase label width to avoid linebreak
>
> v5:
> * drop PVE::Tools::list_is_empty completely and run the empty check
> directly in the two call sites
> * Change UI label and description text
> * Put UI description text into a gettext
>
> v4: incorporated @fionas suggestions, besides some style nits:
> * rename check_list_empty to list_is_empty and adapt the return values
> * renamed $check_vid to $valid_vid with return values for each case
> * switch list separators to spaces in the API call, instead of when
> writing the file
> * rework small logical error in the check if the end VLAN ID is larger
> than the start and $noerr is set.
>
> v3: incorporated @shannons recommendations, in detail:
> * improve regex with non-capturing group
> * reworked check if valid VLAN config in UI field check
> * small code style and spelling things
> * reworded UI explanation text for bridge vids
>
> v2:
> * renamed format in JSONSchema to a more generic `pve-vlan-id-or-range`
> * explicitly use spaces when writing interfaces file. This is one
> possible approach to deal with the fact, that the generic `-list`
> format will accept quite a few delimiters and we need spaces.
> * code style improvements such as naming the regex results.
> * add parameter verification to the web ui
>
> widget-toolkit: Aaron Lauterer (2):
> fix #3892: network: add bridge vids field for bridge_vids
> network: make bridge vids label wider to avoid line break
>
> src/node/NetworkEdit.js | 66 +++++++++++++++++++++++++++++++++++++++++
> src/node/NetworkView.js | 5 ++++
> 2 files changed, 71 insertions(+)
>
> manager: Aaron Lauterer (2):
> fix #3893: api: network: add bridge_vids parameter
> fix #3893: ui: network: enable bridge_vids field
>
> PVE/API2/Network.pm | 23 ++++++++++++++++++++++-
> www/manager6/node/Config.js | 1 +
> 2 files changed, 23 insertions(+), 1 deletion(-)
>
applied the widget toolkit with a few follow-ups to reduce code size and
(try to) improve UX, maybe check them out to ensure nothing is off, thanks!
The manager I also applied and adapted to my wtk changes, but FWICT you seem
missing the backend validation for VIDs? So please add something similar to
the UI checks there, if I did not overlook the checks happening in some other
part of the call chain that is.
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 7+ messages in thread