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 7BDF01FF161
	for <inbox@lore.proxmox.com>; Wed,  4 Dec 2024 10:18:22 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 25F0A372A;
	Wed,  4 Dec 2024 10:18:21 +0100 (CET)
Message-ID: <a804fc51-23cf-4a27-b04b-3af8b115e9af@proxmox.com>
Date: Wed, 4 Dec 2024 10:17:46 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird Beta
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Gabriel Goller <g.goller@proxmox.com>
References: <20241202104626.166056-1-g.goller@proxmox.com>
 <20241202104626.166056-2-g.goller@proxmox.com>
Content-Language: en-US
From: Dominik Csapak <d.csapak@proxmox.com>
In-Reply-To: <20241202104626.166056-2-g.goller@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.134 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
 POISEN_SPAM_PILL          0.1 Meta: its spam
 POISEN_SPAM_PILL_1        0.1 random spam to be learned in bayes
 POISEN_SPAM_PILL_3        0.1 random spam to be learned in bayes
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH manager 1/2] lxc: show dynamically assigned
 IPs in network tab
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-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

generally looks good but i have one high level comment/question
(and some nits inline)

one thing i'd like to see here is to retain the info what is configured,
so previously the info was either 'dhcp'/'auto' (slaac) or an ip address

now we only show the ip adress

what i mean is something like

'x.y.z.w (dhcp)'

or

'xx00::1 (static)'

etc. so one can still see what mode is configured

On 12/2/24 11:46, Gabriel Goller wrote:
> 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 | 57 +++++++++++++++++++++++++++----------
>   1 file changed, 42 insertions(+), 15 deletions(-)
> 
> diff --git a/www/manager6/lxc/Network.js b/www/manager6/lxc/Network.js
> index b2cd94109485..41de72f43646 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);

i know it's pre-existing, but when touching the code we could directly use
confResponse.result.data, no? AFAICS this is the already decoded info from there
(no clue why that wasn't used before though...)

> +			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;
> +				}

this reads a bit odd with the if condition
i'd rather use something like

let iface = interfaces[net....];
if (iface) {
...
}

this should do the same, but is much easier to read

> +
> +				records.push(net);
> +			    }
> +			}
> +
> +			me.store.loadData(records);
> +			me.down('button[name=addButton]').setDisabled(records.length >= 32);
> +		    },
> +		});
>   	    },
>   	});
>       },



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