Commit 204355df authored by Dietmar Maurer's avatar Dietmar Maurer

allow to filter specific resource types

parent 3a1d95cc
...@@ -112,7 +112,13 @@ __PACKAGE__->register_method({ ...@@ -112,7 +112,13 @@ __PACKAGE__->register_method({
permissions => { user => 'all' }, permissions => { user => 'all' },
parameters => { parameters => {
additionalProperties => 0, additionalProperties => 0,
properties => {}, properties => {
type => {
type => 'string',
optional => 1,
enum => ['vm', 'storage', 'node'],
},
},
}, },
returns => { returns => {
type => 'array', type => 'array',
...@@ -140,82 +146,88 @@ __PACKAGE__->register_method({ ...@@ -140,82 +146,88 @@ __PACKAGE__->register_method({
# we try to generate 'numbers' by using "$X + 0" # we try to generate 'numbers' by using "$X + 0"
foreach my $vmid (keys %$idlist) { if (!$param->{type} || $param->{type} eq 'vm') {
my $data = $idlist->{$vmid}; foreach my $vmid (keys %$idlist) {
my $data = $idlist->{$vmid};
next if !$rpcenv->check($user, "/vms/$vmid", [ 'VM.Audit' ]);
my $entry = { next if !$rpcenv->check($user, "/vms/$vmid", [ 'VM.Audit' ]);
id => "$data->{type}/$vmid",
vmid => $vmid + 0,
node => $data->{node},
type => $data->{type},
};
if (my $d = $rrd->{"pve2-vm/$vmid"}) { my $entry = {
id => "$data->{type}/$vmid",
$entry->{uptime} = ($d->[0] || 0) + 0; vmid => $vmid + 0,
$entry->{name} = $d->[1]; node => $data->{node},
type => $data->{type},
$entry->{maxcpu} = ($d->[3] || 0) + 0; };
$entry->{cpu} = ($d->[4] || 0) + 0;
$entry->{maxmem} = ($d->[5] || 0) + 0;
$entry->{mem} = ($d->[6] || 0) + 0;
$entry->{maxdisk} = ($d->[7] || 0) + 0;
$entry->{disk} = ($d->[8] || 0) + 0;
}
push @$res, $entry;
}
foreach my $node (@$nodelist) { if (my $d = $rrd->{"pve2-vm/$vmid"}) {
my $entry = {
id => "node/$node",
node => $node,
type => "node",
};
if (my $d = $rrd->{"pve2-node/$node"}) {
if (!$members || # no cluster
($members->{$node} && $members->{$node}->{online})) {
$entry->{uptime} = ($d->[0] || 0) + 0; $entry->{uptime} = ($d->[0] || 0) + 0;
$entry->{name} = $d->[1];
$entry->{maxcpu} = ($d->[3] || 0) + 0;
$entry->{cpu} = ($d->[4] || 0) + 0; $entry->{cpu} = ($d->[4] || 0) + 0;
$entry->{mem} = ($d->[7] || 0) + 0; $entry->{maxmem} = ($d->[5] || 0) + 0;
$entry->{disk} = ($d->[11] || 0) + 0; $entry->{mem} = ($d->[6] || 0) + 0;
$entry->{maxdisk} = ($d->[7] || 0) + 0;
$entry->{disk} = ($d->[8] || 0) + 0;
} }
$entry->{maxcpu} = ($d->[3] || 0) + 0; push @$res, $entry;
$entry->{maxmem} = ($d->[6] || 0) + 0;
$entry->{maxdisk} = ($d->[10] || 0) + 0;
} }
push @$res, $entry;
} }
my $cfg = PVE::Storage::config(); if (!$param->{type} || $param->{type} eq 'node') {
my @sids = PVE::Storage::storage_ids ($cfg);
foreach my $storeid (@sids) {
my $scfg = PVE::Storage::storage_config($cfg, $storeid);
next if !$rpcenv->check($user, "/storage/$storeid", [ 'Datastore.Audit' ]);
# we create a entry for each node
foreach my $node (@$nodelist) { foreach my $node (@$nodelist) {
next if !PVE::Storage::storage_check_enabled($cfg, $storeid, $node, 1);
my $entry = { my $entry = {
id => "storage/$node/$storeid", id => "node/$node",
storage => $storeid, node => $node,
node => $node, type => "node",
type => 'storage', };
}; if (my $d = $rrd->{"pve2-node/$node"}) {
if (my $d = $rrd->{"pve2-storage/$node/$storeid"}) { if (!$members || # no cluster
$entry->{maxdisk} = ($d->[1] || 0) + 0; ($members->{$node} && $members->{$node}->{online})) {
$entry->{disk} = ($d->[2] || 0) + 0; $entry->{uptime} = ($d->[0] || 0) + 0;
$entry->{cpu} = ($d->[4] || 0) + 0;
$entry->{mem} = ($d->[7] || 0) + 0;
$entry->{disk} = ($d->[11] || 0) + 0;
}
$entry->{maxcpu} = ($d->[3] || 0) + 0;
$entry->{maxmem} = ($d->[6] || 0) + 0;
$entry->{maxdisk} = ($d->[10] || 0) + 0;
} }
push @$res, $entry; push @$res, $entry;
}
}
if (!$param->{type} || $param->{type} eq 'storage') {
my $cfg = PVE::Storage::config();
my @sids = PVE::Storage::storage_ids ($cfg);
foreach my $storeid (@sids) {
my $scfg = PVE::Storage::storage_config($cfg, $storeid);
next if !$rpcenv->check($user, "/storage/$storeid", [ 'Datastore.Audit' ]);
# we create a entry for each node
foreach my $node (@$nodelist) {
next if !PVE::Storage::storage_check_enabled($cfg, $storeid, $node, 1);
my $entry = {
id => "storage/$node/$storeid",
storage => $storeid,
node => $node,
type => 'storage',
};
if (my $d = $rrd->{"pve2-storage/$node/$storeid"}) {
$entry->{maxdisk} = ($d->[1] || 0) + 0;
$entry->{disk} = ($d->[2] || 0) + 0;
}
push @$res, $entry;
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment