[pve-devel] [PATCH v2 manager 1/2] lxc: show dynamically assigned IPs in network tab

DERUMIER, Alexandre alexandre.derumier at groupe-cyllene.com
Wed Nov 15 21:51:13 CET 2023


-------- Message initial --------
De: Leo Nunner <l.nunner at proxmox.com<mailto:Leo%20Nunner%20%3cl.nunner at proxmox.com%3e>>
Répondre à: Proxmox VE development discussion <pve-devel at lists.proxmox.com<mailto:Proxmox%20VE%20development%20discussion%20%3cpve-devel at lists.proxmox.com%3e>>
À: pve-devel at lists.proxmox.com<mailto:pve-devel at lists.proxmox.com>
Objet: [pve-devel] [PATCH v2 manager 1/2] lxc: show dynamically assigned IPs in network tab
Date: 15/06/2023 11:43:32

adds a call to /nodes/{node}/lxc/{vmid}/interfaces and merges the
returned data with the existing configuration. This will update the
IPv4 and IPv6 address, as well as the interface name (in case the
container changed it).

Signed-off-by: Leo Nunner <l.nunner at proxmox.com<mailto:l.nunner at proxmox.com>>
---
 www/manager6/lxc/Network.js | 57 +++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 15 deletions(-)

diff --git a/www/manager6/lxc/Network.js b/www/manager6/lxc/Network.js
index b2cd94109..41de72f43 100644
--- a/www/manager6/lxc/Network.js
+++ b/www/manager6/lxc/Network.js
@@ -356,25 +356,52 @@ Ext.define('PVE.lxc.NetworkView', {

  Proxmox.Utils.setErrorMask(me, true);

+ let nodename = me.pveSelNode.data.node;
+ let vmid = me.pveSelNode.data.vmid;
+
  Proxmox.Utils.API2Request({
-     url: me.url,
+     url: `/nodes/${nodename}/lxc/${vmid}/interfaces`,
+     method: 'GET',
      failure: function(response, opts) {
  Proxmox.Utils.setErrorMask(me, gettext('Error') + ': ' + response.htmlStatus);
      },
-     success: function(response, opts) {
- Proxmox.Utils.setErrorMask(me, false);
- let result = Ext.decode(response.responseText);
- me.dataCache = result.data || {};
- let records = [];
- for (const [key, value] of Object.entries(me.dataCache)) {
-     if (key.match(/^net\d+/)) {
- let net = PVE.Parser.parseLxcNetwork(value);
- net.id = key;
- records.push(net);
-     }
- }
- me.store.loadData(records);
- me.down('button[name=addButton]').setDisabled(records.length >= 32);
+     success: function(ifResponse, ifOpts) {
+ Proxmox.Utils.API2Request({
+     url: me.url,
+     failure: function(response, opts) {
+ Proxmox.Utils.setErrorMask(me, gettext('Error') + ': ' + response.htmlStatus);
+     },
+     success: function(confResponse, confOpts) {
+ Proxmox.Utils.setErrorMask(me, false);
+
+ let interfaces = [];
+ for (const [, iface] of Object.entries(ifResponse?.result?.data || {})) {
+     interfaces[iface.hwaddr] = iface;
+ }
+
+ let result = Ext.decode(confResponse.responseText);
+ me.dataCache = result.data || {};
+ let records = [];
+ for (const [key, value] of Object.entries(me.dataCache)) {
+     if (key.match(/^net\d+/)) {
+ let net = PVE.Parser.parseLxcNetwork(value);
+ net.id = key;
+
+ let iface;
+ if ((iface = interfaces[net.hwaddr.toLowerCase()])) {
+     net.name = iface.name;
+     net.ip = iface.inet;
+     net.ip6 = iface.inet6;
+ }
+
+ records.push(net);
+     }
+ }
+
+ me.store.loadData(records);
+ me.down('button[name=addButton]').setDisabled(records.length >= 32);
+     },
+ });
      },
  });
     },



More information about the pve-devel mailing list