From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
Oguz Bektas <o.bektas@proxmox.com>
Subject: Re: [pve-devel] [PATCH container] vmstatus: include detected IP address of running containers
Date: Tue, 27 Jul 2021 16:03:17 +0200 [thread overview]
Message-ID: <166e8460-05ff-5791-6103-7e2a5fc796d4@proxmox.com> (raw)
In-Reply-To: <20210727133709.1311314-1-o.bektas@proxmox.com>
On 27.07.21 15:37, Oguz Bektas wrote:
> 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
>
what about multiple, you only print the last match which is quite confusing...
And why use `lxc-info`, this is called very often and we know about setups with
1500+ CTs on a single host, so it'd be good to check if adding 1000s forks every
status call could be avoided.
> Signed-off-by: Oguz Bektas <o.bektas@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);
You forgot to add this to the API/CLI return schema in $PVE::LXC::vmstatus_return_properties,
which may highly probably actually want to be an array...
> +
> 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;
as said above, needs to be an array..
> +
> + 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 {
>
next prev parent reply other threads:[~2021-07-27 14:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-27 13:37 Oguz Bektas
2021-07-27 14:03 ` Thomas Lamprecht [this message]
2021-07-27 14:17 ` Oguz Bektas
2021-07-27 15:02 ` Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=166e8460-05ff-5791-6103-7e2a5fc796d4@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=o.bektas@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.