From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-manager v5 15/18] ui: lxc: network view: convert to pending grid
Date: Mon, 16 Nov 2026 17:30:40 +0100 [thread overview]
Message-ID: <20261116163138.343821-16-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261116163138.343821-1-d.csapak@proxmox.com>
so that pending changes of the nics are shown, and can be reverted with
the new revert button. This is also preparation for showing the nics in
the resource view.
Instead of loading the config once, the grid now uses an ObjectStore
for the pending api call. That one can also be given from outside, so
it can be shared with a PendingObjectGrid. If it's not given, the grid
creates its own. In both cases 'load' still loads the interfaces first
and then triggers a load of that store.
The code that built the records moves mostly unchanged into the
'recordParser'. Since that overwrites the name and addresses with the
ones from inside the container, the parsed config is saved in the
record too. That way the renderers can show the configured values for
a pending change that modifies them, otherwise it could not be seen.
The 'dataCache' for the edit window (and the digest) is now filled from
the store on each update.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
www/manager6/lxc/Network.js | 181 +++++++++++++++++++++++++-----------
1 file changed, 127 insertions(+), 54 deletions(-)
diff --git a/www/manager6/lxc/Network.js b/www/manager6/lxc/Network.js
index b2737471..f18a984f 100644
--- a/www/manager6/lxc/Network.js
+++ b/www/manager6/lxc/Network.js
@@ -349,16 +349,39 @@ Ext.define('PVE.lxc.NetworkEdit', {
Ext.define(
'PVE.lxc.NetworkView',
{
- extend: 'Ext.grid.GridPanel',
+ extend: 'PVE.grid.PendingGrid',
alias: 'widget.pveLxcNetworkView',
onlineHelp: 'pct_container_network',
dataCache: {}, // used to store result of last load
+ // interfaces as seen inside the container, indexed by mac address
+ interfaces: undefined,
+
stateful: true,
stateId: 'grid-lxc-network',
+ storeFilter: (rec) => PVE.Utils.keyIsNic(rec.data.key),
+
+ statics: {
+ // the record data to show for the current or pending config
+ //
+ // the name and addresses from inside the container are also used for the pending
+ // config, except when it changes them
+ displayData: function (rec, pending) {
+ if (!pending) {
+ return rec.data;
+ }
+ let current = rec.data.config ?? {};
+ let config = rec.data.pending?.config ?? {};
+ let changed = ['hwaddr', 'name', 'ip', 'ip6'].some(
+ (key) => config[key] !== current[key],
+ );
+ return changed ? config : rec.data;
+ },
+ },
+
load: async function () {
let me = this;
@@ -372,9 +395,6 @@ Ext.define(
url: `/nodes/${nodename}/lxc/${vmid}/interfaces`,
method: 'GET',
});
- let confResponse = await Proxmox.Async.api2({
- url: me.url,
- });
Proxmox.Utils.setErrorMask(me, false);
let interfaces = [];
@@ -382,48 +402,67 @@ Ext.define(
interfaces[iface['hardware-address']] = iface;
}
- let records = [];
- me.dataCache = confResponse.result.data || {};
- for (const [key, value] of Object.entries(confResponse.result.data)) {
- if (!PVE.Utils.keyIsNic(key)) {
- continue;
- }
- let config = PVE.Parser.parseLxcNetwork(value);
- let net = structuredClone(config);
- net.id = key;
-
- let iface = interfaces[config.hwaddr.toLowerCase()];
- if (iface) {
- net.name = iface.name;
- net.ip = [];
- net.ip6 = [];
- for (const i of iface['ip-addresses']) {
- let ip_with_prefix = `${i['ip-address']}/${i.prefix}`;
- if (i['ip-address-type'] === 'inet') {
- if (config.ip === ip_with_prefix) {
- net.ip.push(`${ip_with_prefix} (static)`);
- } else {
- // this could be dhcp, but also a static address set directly on the container
- net.ip.push(`${ip_with_prefix} (dynamic)`);
- }
- } else if (i['ip-address-type'] === 'inet6') {
- if (config.ip6 === ip_with_prefix) {
- net.ip6.push(`${ip_with_prefix} (static)`);
- } else {
- // this could be dhcp, slaac, but also a static address set directly on the container
- net.ip6.push(`${ip_with_prefix} (dynamic)`);
- }
- }
+ me.interfaces = interfaces;
+ me.rstore.load();
+ } catch (error) {
+ Proxmox.Utils.setErrorMask(me, gettext('Error') + ': ' + error);
+ }
+ },
+
+ recordParser: function (key, value) {
+ let me = this;
+
+ let config = PVE.Parser.parseLxcNetwork(value);
+ if (!config) {
+ return undefined;
+ }
+ let net = structuredClone(config);
+ net.id = key;
+ // the values below get overwritten, but they are needed for pending changes
+ net.config = config;
+
+ let iface = me.interfaces?.[config.hwaddr.toLowerCase()];
+ if (iface) {
+ net.name = iface.name;
+ net.ip = [];
+ net.ip6 = [];
+ for (const i of iface['ip-addresses']) {
+ let ip_with_prefix = `${i['ip-address']}/${i.prefix}`;
+ if (i['ip-address-type'] === 'inet') {
+ if (config.ip === ip_with_prefix) {
+ net.ip.push(`${ip_with_prefix} (static)`);
+ } else {
+ // this could be dhcp, but also a static address set directly on the container
+ net.ip.push(`${ip_with_prefix} (dynamic)`);
+ }
+ } else if (i['ip-address-type'] === 'inet6') {
+ if (config.ip6 === ip_with_prefix) {
+ net.ip6.push(`${ip_with_prefix} (static)`);
+ } else {
+ // this could be dhcp, slaac, but also a static address set directly on the container
+ net.ip6.push(`${ip_with_prefix} (dynamic)`);
}
}
- records.push(net);
}
-
- me.store.loadData(records);
- me.down('button[name=addButton]').setDisabled(records.length >= 32);
- } catch (error) {
- Proxmox.Utils.setErrorMask(me, gettext('Error') + ': ' + error);
}
+ return net;
+ },
+
+ updateData: function () {
+ let me = this;
+
+ me.callParent();
+
+ let records = me.store.getRange();
+ me.dataCache = {};
+ let data = me.rstore.getData();
+ // like the config api call, this includes the pending changes
+ (data.getSource() ?? data).each(function (rec) {
+ if (!rec.data.delete) {
+ me.dataCache[rec.data.key] = rec.data.pending ?? rec.data.value;
+ }
+ });
+ me.down('button[name=addButton]').setDisabled(records.length >= 32);
},
initComponent: function () {
@@ -443,6 +482,16 @@ Ext.define(
me.url = `/nodes/${nodename}/lxc/${vmid}/config`;
+ // can be given from outside to share it, e.g. with a PendingObjectGrid
+ let ownRstore = !me.rstore;
+ if (ownRstore) {
+ me.rstore = Ext.create('Proxmox.data.ObjectStore', {
+ model: 'KeyValuePendingDelete',
+ readArray: true,
+ url: `/api2/json/nodes/${nodename}/lxc/${vmid}/pending`,
+ });
+ }
+
let store = new Ext.data.Store({
model: 'pve-lxc-network',
sorters: [
@@ -457,7 +506,7 @@ Ext.define(
let run_editor = function () {
let rec = sm.getSelection()[0];
- if (!rec || !caps.vms['VM.Config.Network']) {
+ if (!rec || !!rec.data.deleted || !caps.vms['VM.Config.Network']) {
return false; // disable default-propagation when triggered by grid dblclick
}
Ext.create('PVE.lxc.NetworkEdit', {
@@ -500,7 +549,7 @@ Ext.define(
disabled: true,
selModel: sm,
enableFn: function (rec) {
- return !!caps.vms['VM.Config.Network'];
+ return !!caps.vms['VM.Config.Network'] && !rec.data.deleted;
},
confirmMsg: ({ data }) =>
Ext.String.format(
@@ -527,9 +576,17 @@ Ext.define(
text: gettext('Edit'),
selModel: sm,
disabled: true,
- enableFn: (rec) => !!caps.vms['VM.Config.Network'],
+ enableFn: (rec) => !!caps.vms['VM.Config.Network'] && !rec.data.deleted,
handler: run_editor,
},
+ {
+ xtype: 'pvePendingRevertButton',
+ apiurl: `/api2/extjs${me.url}`,
+ parentXType: 'pvePendingGrid',
+ selModel: sm,
+ enableFn: (rec) => !!rec.data.deleted || !!rec.data.pending,
+ reloadCallback: () => me.load(),
+ },
],
columns: [
{
@@ -541,6 +598,8 @@ Ext.define(
header: gettext('Name'),
width: 80,
dataIndex: 'name',
+ renderer: (_value, _metaData, rec, _rI, _cI, _store, _view, pending) =>
+ Ext.htmlEncode(PVE.lxc.NetworkView.displayData(rec, pending).name),
},
{
header: gettext('Bridge'),
@@ -567,7 +626,7 @@ Ext.define(
header: gettext('IP address'),
width: 300,
dataIndex: 'ip',
- renderer: function (_value, _metaData, rec) {
+ renderer: function (_value, _metaData, rec, _ri, _ci, _s, _v, pending) {
const formatIpValue = (value, prefix) => {
if (Array.isArray(value) && value.length > 0) {
// multiple addresses (usually from the api)
@@ -587,9 +646,9 @@ Ext.define(
return '';
};
+ let data = PVE.lxc.NetworkView.displayData(rec, pending);
return (
- formatIpValue(rec.data.ip, 'ip: ') +
- formatIpValue(rec.data.ip6, 'ip6: ')
+ formatIpValue(data.ip, 'ip: ') + formatIpValue(data.ip6, 'ip6: ')
);
},
},
@@ -597,13 +656,14 @@ Ext.define(
header: gettext('Gateway'),
width: 150,
dataIndex: 'gw',
- renderer: function (value, metaData, rec) {
- if (rec.data.gw && rec.data.gw6) {
- return rec.data.gw + '<br>' + rec.data.gw6;
- } else if (rec.data.gw6) {
- return rec.data.gw6;
+ renderer: function (value, metaData, rec, _ri, _ci, _s, _v, pending) {
+ let data = (pending ? rec.data.pending : rec.data) ?? {};
+ if (data.gw && data.gw6) {
+ return data.gw + '<br>' + data.gw6;
+ } else if (data.gw6) {
+ return data.gw6;
} else {
- return rec.data.gw;
+ return data.gw;
}
},
},
@@ -626,6 +686,19 @@ Ext.define(
});
me.callParent();
+
+ if (ownRstore) {
+ Proxmox.Utils.monStoreErrors(me, me.rstore);
+ }
+
+ // the buttons only evaluate their enableFn on selection changes, but the data of a
+ // selected record can change on a reload too
+ me.mon(me.store, 'refresh', function () {
+ let selection = sm.getSelection();
+ if (selection.length) {
+ sm.fireEvent('selectionchange', sm, selection);
+ }
+ });
},
},
function () {
--
2.47.3
next prev parent reply other threads:[~2026-11-16 16:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 16:30 [PATCH pve-manager v5 00/18] ui: split out disks and nics into grids Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 01/18] ui: utils: factor out 'media=cdrom' check Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 02/18] ui: parser: qemu drive: allow '-' in key name Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 03/18] ui: factor out the guest key nic regex check Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 04/18] ui: add pending grid Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 05/18] ui: revert button: add parentXType and reloadCallback Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 06/18] ui: button: add config remove button Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 07/18] ui: qemu: hardware: wrap in container Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 08/18] ui: qemu: introduce hardware disk grid Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 09/18] ui: qemu: introduce hardware net grid Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 10/18] ui: qemu: hardware view: separate disks into own grid Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 11/18] ui: qemu: hardware view: separate nics " Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 12/18] ui: qemu: hardware view: inline edit/remove/revert button in general grid Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 13/18] ui: qemu: hardware view: inline 'add efi' menuitem Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 14/18] ui: utils: factor out volume size renderer Dominik Csapak
2026-11-16 16:30 ` Dominik Csapak [this message]
2026-11-16 16:30 ` [PATCH pve-manager v5 16/18] ui: lxc: introduce resource volume grid Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 17/18] ui: lxc: resources: separate volumes into own grid Dominik Csapak
2026-11-16 16:30 ` [PATCH pve-manager v5 18/18] ui: lxc: resources: integrate network view Dominik Csapak
2026-11-19 10:01 ` superseded: [PATCH pve-manager v5 00/18] ui: split out disks and nics into grids Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116163138.343821-16-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox