]> git.proxmox.com Git - pve-container.git/commitdiff
vmstatus: define return propertries
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 1 Aug 2018 10:14:04 +0000 (12:14 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 1 Aug 2018 10:32:55 +0000 (12:32 +0200)
We can use the same properties in vmlist and vmstatus.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
src/PVE/API2/LXC.pm
src/PVE/API2/LXC/Status.pm
src/PVE/LXC.pm

index b65143e4a1cd195f070d69a1ce4b01cb5d506af0..cbcc3930da7e1f03d6a811eccb2eb949a6595425 100644 (file)
@@ -74,48 +74,7 @@ __PACKAGE__->register_method({
        type => 'array',
        items => {
            type => "object",
-           properties => {
-               vmid => get_standard_option('pve-vmid'),
-               status => {
-                   description => "LXC Container status.",
-                   type => 'string',
-                   enum => ['stopped', 'running'],
-               },
-               maxmem => {
-                   description => "Maximum memory in bytes.",
-                   type => 'integer',
-                   optional => 1,
-                   renderer => 'bytes',
-               },
-               maxswap => {
-                   description => "Maximum SWAP memory in bytes.",
-                   type => 'integer',
-                   optional => 1,
-                   renderer => 'bytes',
-               },
-               maxdisk => {
-                   description => "Root disk size in bytes.",
-                   type => 'integer',
-                   optional => 1,
-                   renderer => 'bytes',
-               },
-               name => {
-                   description => "Container name.",
-                   type => 'string',
-                   optional => 1,
-               },
-               uptime => {
-                   description => "Uptime.",
-                   type => 'integer',
-                   optional => 1,
-                   renderer => 'duration',
-               },
-               cpus => {
-                   description => "Maximum usable CPUs.",
-                   type => 'number',
-                   optional => 1,
-               },
-           },
+           properties => $PVE::LXC::vmstatus_return_properties,
        },
        links => [ { rel => 'child', href => "{vmid}" } ],
     },
@@ -132,7 +91,6 @@ __PACKAGE__->register_method({
            next if !$rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Audit' ], 1);
 
            my $data = $vmstatus->{$vmid};
-           $data->{vmid} = $vmid;
            push @$res, $data;
        }
 
index b98dc246fe4e1590ada88ed13002d21d6b0350d1..95775fee7b4daab2dbcf63bdbdc8d2d910042115 100644 (file)
@@ -87,7 +87,16 @@ __PACKAGE__->register_method({
            vmid => get_standard_option('pve-vmid'),
        },
     },
-    returns => { type => 'object' },
+    returns => {
+       type => 'object',
+       properties => {
+           %$PVE::LXC::vmstatus_return_properties,
+           ha => {
+               description => "HA manager service status.",
+               type => 'object',
+           },
+       },
+    },
     code => sub {
        my ($param) = @_;
 
index bc0379268bd7742a3533848b69ee6bebfb1793eb..1504bd015f9b641bd7f7a2dd73ffee38f90b0d9f 100644 (file)
@@ -18,6 +18,7 @@ use PVE::Exception qw(raise_perm_exc);
 use PVE::Storage;
 use PVE::SafeSyslog;
 use PVE::INotify;
+use PVE::JSONSchema qw(get_standard_option);
 use PVE::Tools qw($IPV6RE $IPV4RE dir_glob_foreach lock_file lock_file_full O_PATH);
 use PVE::CpuSet;
 use PVE::Network;
@@ -25,6 +26,7 @@ use PVE::AccessControl;
 use PVE::ProcFSTools;
 use PVE::Syscall;
 use PVE::LXC::Config;
+
 use Time::HiRes qw (gettimeofday);
 
 my $nodename = PVE::INotify::nodename();
@@ -42,7 +44,7 @@ sub config_list {
        my $d = $ids->{$vmid};
        next if !$d->{node} || $d->{node} ne $nodename;
        next if !$d->{type} || $d->{type} ne 'lxc';
-       $res->{$vmid}->{type} = 'lxc';
+       $res->{$vmid} = { type => 'lxc', vmid => $vmid };
     }
     return $res;
 }
@@ -115,10 +117,53 @@ my $parse_cpuacct_stat = sub {
     return $stat;
 };
 
+our $vmstatus_return_properties = {
+    vmid => get_standard_option('pve-vmid'),
+    status => {
+       description => "LXC Container status.",
+       type => 'string',
+       enum => ['stopped', 'running'],
+    },
+    maxmem => {
+       description => "Maximum memory in bytes.",
+       type => 'integer',
+       optional => 1,
+       renderer => 'bytes',
+    },
+    maxswap => {
+       description => "Maximum SWAP memory in bytes.",
+       type => 'integer',
+       optional => 1,
+       renderer => 'bytes',
+    },
+    maxdisk => {
+       description => "Root disk size in bytes.",
+       type => 'integer',
+       optional => 1,
+       renderer => 'bytes',
+    },
+    name => {
+       description => "Container name.",
+       type => 'string',
+       optional => 1,
+    },
+    uptime => {
+       description => "Uptime.",
+       type => 'integer',
+       optional => 1,
+       renderer => 'duration',
+    },
+    cpus => {
+       description => "Maximum usable CPUs.",
+       type => 'number',
+       optional => 1,
+    },
+};
+
 sub vmstatus {
     my ($opt_vmid) = @_;
 
-    my $list = $opt_vmid ? { $opt_vmid => { type => 'lxc' }} : config_list();
+    my $list = $opt_vmid ? { $opt_vmid => { type => 'lxc', vmid => $opt_vmid }} : config_list();
 
     my $active_hash = list_active_containers();