From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 3E42D1FF2A8 for ; Tue, 2 Jul 2024 16:29:14 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EEE7630033; Tue, 2 Jul 2024 16:29:28 +0200 (CEST) Date: Tue, 2 Jul 2024 16:29:25 +0200 (CEST) From: =?UTF-8?Q?Fabian_Gr=C3=BCnbichler?= To: Proxmox VE development discussion Message-ID: <1042471210.2938.1719930565011@webmail.proxmox.com> In-Reply-To: References: <20240418204933.58521-1-jcdra1@gmail.com> MIME-Version: 1.0 X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v7.10.6-Rev65 X-Originating-Client: open-xchange-appsuite X-SPAM-LEVEL: Spam detection results: 0 AWL 0.051 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lxc.pm] Subject: Re: [pve-devel] [PATCH pve-container 2/2] fix #5339: api: lxc: ip: add 'all' option so that all addresses can be returned. X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" apologies again for the long delay! > Johannes Cornelis Draaijer via pve-devel hat am 18.04.2024 22:49 CEST geschrieben: > Signed-off-by: Johannes Cornelis Draaijer > --- > src/PVE/API2/LXC.pm | 16 +++++++++++++--- > src/PVE/LXC.pm | 9 +++++++-- > 2 files changed, 20 insertions(+), 5 deletions(-) > > diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm > index 89ba64c..3561317 100644 > --- a/src/PVE/API2/LXC.pm > +++ b/src/PVE/API2/LXC.pm > @@ -2533,6 +2533,12 @@ __PACKAGE__->register_method({ > properties => { > node => get_standard_option('pve-node'), > vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }), > + all => { > + type => 'boolean', > + default => 0, > + optional => 1, > + description => 'Return all adresses of each interface instead of only one', typo: s/adresses/addresses > + } > }, > }, > returns => { > @@ -2552,12 +2558,14 @@ __PACKAGE__->register_method({ > }, > inet => { > type => 'string', > - description => 'The IPv4 address of the interface', > + format => 'CIDRv4-list', this format here and the code below don't agree. a string type with the -list suffix needs actually be a string with the list elements delimited by either space, ',' or ';'. in this case, comma or semicolon is probably okay. > + description => 'A list of IPv4 CIDRs. This will only contain a single address if \'all\' is not set to true', > optional => 1, > }, > inet6 => { > type => 'string', > - description => 'The IPv6 address of the interface', > + format => 'CIDRv6-list', same here > + description => 'A list of IPv6 CIDRs. This will only contain a single address if \'all\' is not set to true', > optional => 1, > }, > } > @@ -2565,8 +2573,10 @@ __PACKAGE__->register_method({ > }, > code => sub { > my ($param) = @_; > + my $vmid = extract_param($param, 'vmid'); > + my $alladdrs = extract_param($param, 'all') // 0; existing code is not always consistent, but this should be all_addrs > > - return PVE::LXC::get_interfaces($param->{vmid}); > + return PVE::LXC::get_interfaces($vmid, $alladdrs); > }}); > > __PACKAGE__->register_method({ > diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm > index 7883cfb..6d00141 100644 > --- a/src/PVE/LXC.pm > +++ b/src/PVE/LXC.pm > @@ -1088,7 +1088,7 @@ sub hotplug_net { > } > > sub get_interfaces { > - my ($vmid) = @_; > + my ($vmid, $alladdrs) = @_; > > my $pid = eval { find_lxc_pid($vmid); }; > return if $@; > @@ -1104,7 +1104,12 @@ sub get_interfaces { > for my $interface ($config->@*) { > my $obj = { name => $interface->{ifname} }; > for my $ip ($interface->{addr_info}->@*) { > - $obj->{$ip->{family}} = $ip->{local} . "/" . $ip->{prefixlen}; > + my $cidr = $ip->{local} . "/" . $ip->{prefixlen}; > + if ($alladdrs eq 1) { eq is for string comparison, this can just use if ($all_addrs) { but for regular comparison you'd use `==` otherwise :) > + push(@{$obj->{$ip->{family}}}, $cidr); if you do this, then you'd need to `join` this list into a string at the end. or you could just build the string directly here (special casing the first and subsequent addresses), both would work in this case. or you do this here unconditionally, and then after the loop either join (if $all_addr) or just pick the first element, which would be equivalent to the old code here as well. > + } else { > + $obj->{$ip->{family}} = $cidr; > + } > } > $obj->{hwaddr} = $interface->{address}; > push @$res, $obj > -- > 2.34.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel