[pve-devel] applied: [pve-container] vmstatus: define return propertries
Dietmar Maurer
dietmar at proxmox.com
Wed Aug 1 12:39:11 CEST 2018
applied
> On August 1, 2018 at 12:17 PM Dietmar Maurer <dietmar at proxmox.com> wrote:
>
>
> We can use the same properties in vmlist and vmstatus.
>
> Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
> ---
> src/PVE/API2/LXC.pm | 44 +----------------------------------------
> src/PVE/API2/LXC/Status.pm | 11 ++++++++++-
> src/PVE/LXC.pm | 49
> ++++++++++++++++++++++++++++++++++++++++++++--
> 3 files changed, 58 insertions(+), 46 deletions(-)
>
> diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
> index b65143e..cbcc393 100644
> --- a/src/PVE/API2/LXC.pm
> +++ b/src/PVE/API2/LXC.pm
> @@ -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;
> }
>
> diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm
> index b98dc24..95775fe 100644
> --- a/src/PVE/API2/LXC/Status.pm
> +++ b/src/PVE/API2/LXC/Status.pm
> @@ -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) = @_;
>
> diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
> index bc03792..1504bd0 100644
> --- a/src/PVE/LXC.pm
> +++ b/src/PVE/LXC.pm
> @@ -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();
>
> --
> 2.11.0
>
>
More information about the pve-devel
mailing list