From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id B3C821FF0DF for ; Thu, 19 Nov 2026 10:32:51 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6173621A24; Thu, 19 Nov 2026 10:29:50 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH pve-manager v6 17/21] ui: lxc: network view: convert to pending grid Date: Thu, 19 Nov 2026 10:28:30 +0100 Message-ID: <20261119092930.830046-18-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119092930.830046-1-d.csapak@proxmox.com> References: <20261119092930.830046-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.277 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: C3ANPXDJ6O6VZMDSZ3YLRAYTR2X76LJN X-Message-ID-Hash: C3ANPXDJ6O6VZMDSZ3YLRAYTR2X76LJN X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- www/manager6/lxc/Network.js | 184 +++++++++++++++++++++++++----------- 1 file changed, 130 insertions(+), 54 deletions(-) diff --git a/www/manager6/lxc/Network.js b/www/manager6/lxc/Network.js index b2737471..87cf7962 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,70 @@ 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; + } + }); + let caps = Ext.state.Manager.get('GuiCap'); + me.down('button[name=addButton]').setDisabled( + !caps.vms['VM.Config.Network'] || records.length >= 32, + ); }, initComponent: function () { @@ -443,6 +485,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 +509,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 +552,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 +579,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 +601,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 +629,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 +649,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 +659,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 + '
' + 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 + '
' + data.gw6; + } else if (data.gw6) { + return data.gw6; } else { - return rec.data.gw; + return data.gw; } }, }, @@ -626,6 +689,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