From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v2 1/3] lxc: show dynamically assigned IPs in network tab
Date: Tue, 10 Dec 2024 16:11:28 +0100 [thread overview]
Message-ID: <20241210151130.321984-2-g.goller@proxmox.com> (raw)
In-Reply-To: <20241210151130.321984-1-g.goller@proxmox.com>
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).
Originally-by: Leo Nunner <l.nunner@proxmox.com>
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
www/manager6/lxc/Network.js | 85 ++++++++++++++++++++++++++-----------
1 file changed, 60 insertions(+), 25 deletions(-)
diff --git a/www/manager6/lxc/Network.js b/www/manager6/lxc/Network.js
index b2cd94109485..d50274739400 100644
--- a/www/manager6/lxc/Network.js
+++ b/www/manager6/lxc/Network.js
@@ -356,25 +356,66 @@ 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['hardware-address']] = iface;
+ }
+
+ me.dataCache = confResponse.result.data || {};
+ let records = [];
+ for (const [key, value] of Object.entries(me.dataCache)) {
+ if (key.match(/^net\d+/)) {
+ 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 = [];
+ 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 {
+ net.ip.push(`${ip_with_prefix} (dhcp)`);
+ }
+ } else if (i['ip-address-type'] === "inet6") {
+ if (config.ip6 === ip_with_prefix) {
+ net.ip.push(`${ip_with_prefix} (static)`);
+ } else {
+ net.ip.push(`${ip_with_prefix} (dhcp)`);
+ }
+ }
+ }
+ }
+ records.push(net);
+ }
+ }
+
+ me.store.loadData(records);
+ me.down('button[name=addButton]').setDisabled(records.length >= 32);
+ },
+ });
},
});
},
@@ -504,7 +545,7 @@ Ext.define('PVE.lxc.NetworkView', {
},
{
header: gettext('VLAN Tag'),
- width: 80,
+ width: 70,
dataIndex: 'tag',
},
{
@@ -514,16 +555,10 @@ Ext.define('PVE.lxc.NetworkView', {
},
{
header: gettext('IP address'),
- width: 150,
+ width: 200,
dataIndex: 'ip',
- renderer: function(value, metaData, rec) {
- if (rec.data.ip && rec.data.ip6) {
- return rec.data.ip + "<br>" + rec.data.ip6;
- } else if (rec.data.ip6) {
- return rec.data.ip6;
- } else {
- return rec.data.ip;
- }
+ renderer: function(_value, _metaData, rec) {
+ return rec.data.ip.join("<br>");
},
},
{
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2024-12-10 15:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 15:11 [pve-devel] [PATCH container/manager v2 0/3] Show container ip in summary and " Gabriel Goller
2024-12-10 15:11 ` Gabriel Goller [this message]
2024-12-10 15:11 ` [pve-devel] [PATCH manager v2 2/3] guest: refactor and reuse AgentIPView for containers Gabriel Goller
2024-12-10 15:11 ` [pve-devel] [PATCH container v2 3/3] api: return all addresses of an interface Gabriel Goller
2024-12-10 17:58 ` Thomas Lamprecht
2024-12-11 14:57 ` Maximiliano Sandoval
2024-12-12 8:02 ` [pve-devel] [PATCH container/manager v2 0/3] Show container ip in summary and network tab Fabian Grünbichler
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=20241210151130.321984-2-g.goller@proxmox.com \
--to=g.goller@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