From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id C6E981FF16F
	for <inbox@lore.proxmox.com>; Tue, 27 May 2025 16:06:02 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id C273716A6A;
	Tue, 27 May 2025 16:06:11 +0200 (CEST)
From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 27 May 2025 16:04:46 +0200
Message-Id: <20250527140446.365983-3-g.goller@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250527140446.365983-1-g.goller@proxmox.com>
References: <20250527140446.365983-1-g.goller@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.021 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH pve-manager v5 2/2] guest: refactor and reuse
 AgentIPView for containers
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Refactor AgentIPView to be generic over container and vms. Reuse it in
the Container Summary to show the ip addresses of the container. Also
make the GuestSummary scrollable, as it can potentially be bigger
(because of the ip-addresses that can be shown) than 300 (which is the
size of the RRD graphs).

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 www/manager6/Makefile                         |   2 +-
 www/manager6/panel/GuestStatusView.js         | 140 +++++++++++++++++-
 www/manager6/panel/GuestSummary.js            |   1 +
 .../{qemu/AgentIPView.js => panel/IPView.js}  |  79 ++--------
 4 files changed, 151 insertions(+), 71 deletions(-)
 rename www/manager6/{qemu/AgentIPView.js => panel/IPView.js} (58%)

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index fdf0e8165969..cf4a4f803da4 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -103,6 +103,7 @@ JSSRC= 							\
 	panel/BackupJobPrune.js				\
 	panel/HealthWidget.js				\
 	panel/IPSet.js					\
+	panel/IPView.js					\
 	panel/RunningChart.js				\
 	panel/StatusPanel.js				\
 	panel/GuestStatusView.js			\
@@ -234,7 +235,6 @@ JSSRC= 							\
 	pool/Config.js					\
 	pool/StatusView.js				\
 	pool/Summary.js					\
-	qemu/AgentIPView.js				\
 	qemu/AudioEdit.js				\
 	qemu/BootOrderEdit.js				\
 	qemu/CDEdit.js					\
diff --git a/www/manager6/panel/GuestStatusView.js b/www/manager6/panel/GuestStatusView.js
index 6401811c73bb..6c06141fd9f3 100644
--- a/www/manager6/panel/GuestStatusView.js
+++ b/www/manager6/panel/GuestStatusView.js
@@ -146,14 +146,150 @@ Ext.define('PVE.panel.GuestStatusView', {
 	    height: 15,
 	},
 	{
-	    itemId: 'ips',
-	    xtype: 'pveAgentIPView',
+	    itemId: 'agentIPs',
+	    xtype: 'pveIPView',
 	    cbind: {
 		rstore: '{rstore}',
 		pveSelNode: '{pveSelNode}',
 		hidden: '{isLxc}',
 		disabled: '{isLxc}',
 	    },
+	    createUpdateStoreCallback: function(ipview, nodename, vmid) {
+		ipview.ipStore = Ext.create('Proxmox.data.UpdateStore', {
+		    interval: 10000,
+		    storeid: 'pve-qemu-agent-' + vmid,
+		    method: 'POST',
+		    proxy: {
+			type: 'proxmox',
+			url: '/api2/json/nodes/' + nodename + '/qemu/' + vmid + '/agent/network-get-interfaces',
+		    },
+		});
+		ipview.callParent();
+
+		ipview.mon(ipview.ipStore, 'load', function(_store, records, success) {
+		    if (records && records.length) {
+			ipview.nics = records[0].data.result;
+		    } else {
+			ipview.nics = undefined;
+		    }
+		    ipview.updateStatus(!success);
+		});
+	    },
+	    updateStatusCallback: function(ipview, unsuccessful, defaulttext) {
+		var text = defaulttext || gettext('No network information');
+		var more = false;
+		if (unsuccessful) {
+		    text = gettext('Guest Agent not running');
+		} else if (ipview.agent && ipview.running) {
+		    if (Ext.isArray(ipview.nics) && ipview.nics.length) {
+			more = true;
+			var ips = ipview.getDefaultIps(ipview.nics);
+			if (ips.length !== 0) {
+			    text = ips.join('<br>');
+			}
+		    } else if (ipview.nics && ipview.nics.error) {
+			let msg = gettext('Cannot get info from Guest Agent<br>Error: {0}');
+			text = Ext.String.format(msg, Ext.htmlEncode(ipview.nics.error.desc));
+		    }
+		} else if (ipview.agent) {
+		    text = gettext('Guest Agent not running');
+		} else {
+		    text = gettext('No Guest Agent configured');
+		}
+
+		var ipBox = ipview.down('#ipBox');
+		ipBox.update(text);
+
+		var moreBtn = ipview.down('#moreBtn');
+		moreBtn.setVisible(more);
+	    },
+	    startIPStoreCallback: function(ipview, store) {
+		let agentRec = store.getById('agent');
+		let state = store.getById('status');
+
+		ipview.agent = agentRec && agentRec.data.value === 1;
+		ipview.running = state && state.data.value === 'running';
+
+		var caps = Ext.state.Manager.get('GuiCap');
+
+		if (!caps.vms['VM.Monitor']) {
+		    var errorText = gettext("Requires '{0}' Privileges");
+		    ipview.updateStatus(false, Ext.String.format(errorText, 'VM.Monitor'));
+		    return;
+		}
+
+		if (ipview.agent && ipview.running && ipview.ipStore.isStopped) {
+		    ipview.ipStore.startUpdate();
+		} else if (ipview.ipStore.isStopped) {
+		    ipview.updateStatus();
+		}
+	    },
+	},
+	{
+	    itemId: 'ctIPS',
+	    xtype: 'pveIPView',
+	    cbind: {
+		rstore: '{rstore}',
+		pveSelNode: '{pveSelNode}',
+		hidden: '{!isLxc}',
+		disabled: '{!isLxc}',
+	    },
+	    createUpdateStoreCallback: function(ipview, nodename, vmid) {
+		ipview.ipStore = Ext.create('Proxmox.data.UpdateStore', {
+		    interval: 10000,
+		    storeid: 'lxc-interfaces-' + vmid,
+		    method: 'GET',
+		    proxy: {
+			type: 'proxmox',
+			url: '/api2/json/nodes/' + nodename + '/lxc/' + vmid + '/interfaces',
+		    },
+		});
+		ipview.callParent();
+
+		ipview.mon(ipview.ipStore, 'load', function(_store, records, success) {
+		    if (records && records.length) {
+			ipview.nics = records.map(r => r.data);
+		    } else {
+			ipview.nics = undefined;
+		    }
+		    ipview.updateStatus(!success);
+		});
+	    },
+	    updateStatusCallback: function(ipview, _unsuccessful, defaulttext) {
+		var text = defaulttext || gettext('No network information');
+		var more = false;
+		if (Ext.isArray(ipview.nics) && ipview.nics.length) {
+		    more = true;
+		    var ips = ipview.getDefaultIps(ipview.nics);
+		    if (ips.length !== 0) {
+			text = ips.join('<br>');
+		    }
+		}
+		var ipBox = ipview.down('#ipBox');
+		ipBox.update(text);
+
+		var moreBtn = ipview.down('#moreBtn');
+		moreBtn.setVisible(more);
+	    },
+	    startIPStoreCallback: function(ipview, store) {
+		let state = store.getById('status');
+
+		ipview.running = state && state.data.value === 'running';
+
+		var caps = Ext.state.Manager.get('GuiCap');
+
+		if (!caps.vms['VM.Audit']) {
+		    var errorText = gettext("Requires '{0}' Privileges");
+		    ipview.updateStatus(false, Ext.String.format(errorText, 'VM.Audit'));
+		    return;
+		}
+
+		if (ipview.running && ipview.ipStore.isStopped) {
+		    ipview.ipStore.startUpdate();
+		} else if (ipview.ipStore.isStopped) {
+		    ipview.updateStatus();
+		}
+	    },
 	},
     ],
 
diff --git a/www/manager6/panel/GuestSummary.js b/www/manager6/panel/GuestSummary.js
index 1565db3f658d..baf658714128 100644
--- a/www/manager6/panel/GuestSummary.js
+++ b/www/manager6/panel/GuestSummary.js
@@ -38,6 +38,7 @@ Ext.define('PVE.guest.Summary', {
 		itemId: 'gueststatus',
 		pveSelNode: me.pveSelNode,
 		rstore: rstore,
+		scrollable: 'y',
 	    },
 	    {
 		xtype: 'pmxNotesView',
diff --git a/www/manager6/qemu/AgentIPView.js b/www/manager6/panel/IPView.js
similarity index 58%
rename from www/manager6/qemu/AgentIPView.js
rename to www/manager6/panel/IPView.js
index a554de65f119..f8d1e77d139d 100644
--- a/www/manager6/qemu/AgentIPView.js
+++ b/www/manager6/panel/IPView.js
@@ -1,7 +1,7 @@
 Ext.define('PVE.window.IPInfo', {
     extend: 'Ext.window.Window',
     width: 600,
-    title: gettext('Guest Agent Network Information'),
+    title: gettext('Network Information'),
     height: 300,
     layout: {
 	type: 'fit',
@@ -53,9 +53,9 @@ Ext.define('PVE.window.IPInfo', {
     ],
 });
 
-Ext.define('PVE.qemu.AgentIPView', {
+Ext.define('PVE.IPView', {
     extend: 'Ext.container.Container',
-    xtype: 'pveAgentIPView',
+    xtype: 'pveIPView',
 
     layout: {
 	type: 'hbox',
@@ -63,6 +63,9 @@ Ext.define('PVE.qemu.AgentIPView', {
     },
 
     nics: [],
+    startIPStoreCallback: undefined,
+    updateStatusCallback: undefined,
+    createUpdateStoreCallback: undefined,
 
     items: [
 	{
@@ -92,7 +95,7 @@ Ext.define('PVE.qemu.AgentIPView', {
 		    hidden: true,
 		    ui: 'default-toolbar',
 		    handler: function(btn) {
-			let view = this.up('pveAgentIPView');
+			let view = this.up('pveIPView');
 
 			var win = Ext.create('PVE.window.IPInfo');
 			win.down('grid').getStore().setData(view.nics);
@@ -127,55 +130,14 @@ Ext.define('PVE.qemu.AgentIPView', {
 
     startIPStore: function(store, records, success) {
 	var me = this;
-	let agentRec = store.getById('agent');
-	let state = store.getById('status');
 
-	me.agent = agentRec && agentRec.data.value === 1;
-	me.running = state && state.data.value === 'running';
-
-	var caps = Ext.state.Manager.get('GuiCap');
-
-	if (!caps.vms['VM.Monitor']) {
-	    var errorText = gettext("Requires '{0}' Privileges");
-	    me.updateStatus(false, Ext.String.format(errorText, 'VM.Monitor'));
-	    return;
-	}
-
-	if (me.agent && me.running && me.ipStore.isStopped) {
-	    me.ipStore.startUpdate();
-	} else if (me.ipStore.isStopped) {
-	    me.updateStatus();
-	}
+	me.startIPStoreCallback(me, store);
     },
 
     updateStatus: function(unsuccessful, defaulttext) {
 	var me = this;
-	var text = defaulttext || gettext('No network information');
-	var more = false;
-	if (unsuccessful) {
-	    text = gettext('Guest Agent not running');
-	} else if (me.agent && me.running) {
-	    if (Ext.isArray(me.nics) && me.nics.length) {
-		more = true;
-		var ips = me.getDefaultIps(me.nics);
-		if (ips.length !== 0) {
-		    text = ips.join('<br>');
-		}
-	    } else if (me.nics && me.nics.error) {
-		let msg = gettext('Cannot get info from Guest Agent<br>Error: {0}');
-		text = Ext.String.format(msg, Ext.htmlEncode(me.nics.error.desc));
-	    }
-	} else if (me.agent) {
-	    text = gettext('Guest Agent not running');
-	} else {
-	    text = gettext('No Guest Agent configured');
-	}
-
-	var ipBox = me.down('#ipBox');
-	ipBox.update(text);
 
-	var moreBtn = me.down('#moreBtn');
-	moreBtn.setVisible(more);
+	me.updateStatusCallback(me, unsuccessful, defaulttext);
     },
 
     initComponent: function() {
@@ -192,26 +154,7 @@ Ext.define('PVE.qemu.AgentIPView', {
 	var nodename = me.pveSelNode.data.node;
 	var vmid = me.pveSelNode.data.vmid;
 
-	me.ipStore = Ext.create('Proxmox.data.UpdateStore', {
-	    interval: 10000,
-	    storeid: 'pve-qemu-agent-' + vmid,
-	    method: 'POST',
-	    proxy: {
-		type: 'proxmox',
-		url: '/api2/json/nodes/' + nodename + '/qemu/' + vmid + '/agent/network-get-interfaces',
-	    },
-	});
-
-	me.callParent();
-
-	me.mon(me.ipStore, 'load', function(store, records, success) {
-	    if (records && records.length) {
-		me.nics = records[0].data.result;
-	    } else {
-		me.nics = undefined;
-	    }
-	    me.updateStatus(!success);
-	});
+	me.createUpdateStoreCallback(me, nodename, vmid);
 
 	me.on('destroy', me.ipStore.stopUpdate, me.ipStore);
 
@@ -220,7 +163,7 @@ Ext.define('PVE.qemu.AgentIPView', {
 	    me.startIPStore(me.rstore, me.rstore.getData(), false);
 	}
 
-	// check if the guest agent is there on every statusstore load
 	me.mon(me.rstore, 'load', me.startIPStore, me);
     },
 });
+
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel