From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 5497269811 for ; Tue, 27 Jul 2021 15:37:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 471AD1A551 for ; Tue, 27 Jul 2021 15:37:41 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 9CACC1A548 for ; Tue, 27 Jul 2021 15:37:40 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 635334220B for ; Tue, 27 Jul 2021 15:37:40 +0200 (CEST) From: Oguz Bektas To: pve-devel@lists.proxmox.com Date: Tue, 27 Jul 2021 15:37:09 +0200 Message-Id: <20210727133709.1311314-1-o.bektas@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 1.381 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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: [pve-devel] [PATCH container] vmstatus: include detected IP address of running containers 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: , X-List-Received-Date: Tue, 27 Jul 2021 13:37:41 -0000 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 --- 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