]> git.proxmox.com Git - pve-container.git/commitdiff
vm status: force int where appropriate
authorFabian Ebner <f.ebner@proxmox.com>
Tue, 1 Jun 2021 06:43:05 +0000 (08:43 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 17 Jun 2021 12:44:18 +0000 (14:44 +0200)
In the case of a running container with cgroupv2, swap would be a string,
causing a
    size.toFixed is not a function
error for the format_size call in the containers's "Summary" page in the UI.

The vmids from config_list() are already integers as the return schema expects,
while the opt_vmid passed from the status/current API call needs to be
converted.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
src/PVE/LXC.pm

index a1f9b719eaefa252d4685645907c99719976d43c..d432fc67fb9c4724325728cd47439609542f4865 100644 (file)
@@ -171,7 +171,7 @@ our $vmstatus_return_properties = {
 sub vmstatus {
     my ($opt_vmid) = @_;
 
-    my $list = $opt_vmid ? { $opt_vmid => { type => 'lxc', vmid => $opt_vmid }} : config_list();
+    my $list = $opt_vmid ? { $opt_vmid => { type => 'lxc', vmid => int($opt_vmid) }} : config_list();
 
     my $active_hash = list_active_containers();
 
@@ -187,7 +187,7 @@ sub vmstatus {
     foreach my $vmid (keys %$list) {
        my $d = $list->{$vmid};
 
-       eval { $d->{pid} = find_lxc_pid($vmid) if defined($active_hash->{$vmid}); };
+       eval { $d->{pid} = int(find_lxc_pid($vmid)) if defined($active_hash->{$vmid}); };
        warn $@ if $@; # ignore errors (consider them stopped)
 
        $d->{status} = $active_hash->{$vmid} ? 'running' : 'stopped';
@@ -207,8 +207,8 @@ sub vmstatus {
 
        if ($d->{pid}) {
            my $res = get_container_disk_usage($vmid, $d->{pid});
-           $d->{disk} = $res->{used};
-           $d->{maxdisk} = $res->{total};
+           $d->{disk} = int($res->{used});
+           $d->{maxdisk} = int($res->{total});
        } else {
            $d->{disk} = 0;
            # use 4GB by default ??
@@ -252,16 +252,16 @@ sub vmstatus {
        my $cgroups = PVE::LXC::CGroup->new($vmid);
 
        if (defined(my $mem = $cgroups->get_memory_stat())) {
-           $d->{mem} = $mem->{mem};
-           $d->{swap} = $mem->{swap};
+           $d->{mem} = int($mem->{mem});
+           $d->{swap} = int($mem->{swap});
        } else {
            $d->{mem} = 0;
            $d->{swap} = 0;
        }
 
        if (defined(my $blkio = $cgroups->get_io_stats())) {
-           $d->{diskread} = $blkio->{diskread};
-           $d->{diskwrite} = $blkio->{diskwrite};
+           $d->{diskread} = int($blkio->{diskread});
+           $d->{diskwrite} = int($blkio->{diskwrite});
        } else {
            $d->{diskread} = 0;
            $d->{diskwrite} = 0;