[pve-devel] [PATCH container] vmstatus: include detected IP address of running containers
Oguz Bektas
o.bektas at proxmox.com
Tue Jul 27 15:37:09 CEST 2021
add a helper 'find_lxc_ip_address' to fetch IP address of container from
its network namespace using lxc-info.
for the moment it can be queried with the pct tool:
$ pct status 1000 --verbose
cpu: 0
cpus: 1
disk: 6422528
diskread: 368640
diskwrite: 0
ipaddress: 192.168.31.83 <----
maxdisk: 4294967296
maxmem: 536870912
maxswap: 536870912
mem: 864256
name: CT1000
netin: 3281265
netout: 15794
pid: 34897
status: running
swap: 94208
type: lxc
uptime: 11088
vmid: 1000
Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
---
src/PVE/LXC.pm | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 139f901..e7804e0 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -247,6 +247,8 @@ sub vmstatus {
next if !$pid; # skip stopped CTs
+ $d->{ipaddress} = find_lxc_ip_address($vmid);
+
my $proc_pid_stat = PVE::ProcFSTools::read_proc_pid_stat($pid);
$d->{uptime} = int(($uptime - $proc_pid_stat->{starttime}) / $clock_ticks); # the method lxcfs uses
@@ -397,6 +399,20 @@ sub open_ppid {
return ($ppid, $fd);
}
+sub find_lxc_ip_address {
+ my ($vmid) = @_;
+
+ my $ip = undef;
+
+ my $parser = sub {
+ my $line = shift;
+ $ip = $1 if $line =~ m/^IP:\s+(.*)$/;
+ };
+
+ PVE::Tools::run_command(['lxc-info', '-n', $vmid, '--ips'], outfunc => $parser, errfunc => sub {});
+ return $ip;
+}
+
# Note: we cannot use Net:IP, because that only allows strict
# CIDR networks
sub parse_ipv4_cidr {
--
2.30.2
More information about the pve-devel
mailing list