[PATCH pve-container 2/2] fix #5339: api: lxc: ip: add 'all' option so that all addresses can be returned.
Johannes Cornelis Draaijer
jcdra1 at gmail.com
Thu Apr 18 22:49:33 CEST 2024
Signed-off-by: Johannes Cornelis Draaijer <jcdra1 at gmail.com>
---
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',
+ }
},
},
returns => {
@@ -2552,12 +2558,14 @@ __PACKAGE__->register_method({
},
inet => {
type => 'string',
- description => 'The IPv4 address of the interface',
+ format => 'CIDRv4-list',
+ 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',
+ 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;
- 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) {
+ push(@{$obj->{$ip->{family}}}, $cidr);
+ } else {
+ $obj->{$ip->{family}} = $cidr;
+ }
}
$obj->{hwaddr} = $interface->{address};
push @$res, $obj
--
2.34.1
More information about the pve-devel
mailing list