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({
permissions => { user => 'all' },
parameters => {
additionalProperties => 0,
properties => {},
properties => {
type => {
type => 'string',
optional => 1,
enum => ['vm', 'storage', 'node'],
},
},
},
returns => {
type => 'array',
......@@ -140,82 +146,88 @@ __PACKAGE__->register_method({
# we try to generate 'numbers' by using "$X + 0"
foreach my $vmid (keys %$idlist) {
my $data = $idlist->{$vmid};
if (!$param->{type} || $param->{type} eq 'vm') {
foreach my $vmid (keys %$idlist) {
my $data = $idlist->{$vmid};
next if !$rpcenv->check($user, "/vms/$vmid", [ 'VM.Audit' ]);
my $entry = {
id => "$data->{type}/$vmid",
vmid => $vmid + 0,
node => $data->{node},
type => $data->{type},
};
next if !$rpcenv->check($user, "/vms/$vmid", [ 'VM.Audit' ]);
if (my $d = $rrd->{"pve2-vm/$vmid"}) {
$entry->{uptime} = ($d->[0] || 0) + 0;
$entry->{name} = $d->[1];
$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;
}
my $entry = {
id => "$data->{type}/$vmid",
vmid => $vmid + 0,
node => $data->{node},
type => $data->{type},
};
foreach my $node (@$nodelist) {
my $entry = {
id => "node/$node",
node => $node,
type => "node",
};
if (my $d = $rrd->{"pve2-node/$node"}) {
if (my $d = $rrd->{"pve2-vm/$vmid"}) {
if (!$members || # no cluster
($members->{$node} && $members->{$node}->{online})) {
$entry->{uptime} = ($d->[0] || 0) + 0;
$entry->{name} = $d->[1];
$entry->{maxcpu} = ($d->[3] || 0) + 0;
$entry->{cpu} = ($d->[4] || 0) + 0;
$entry->{mem} = ($d->[7] || 0) + 0;
$entry->{disk} = ($d->[11] || 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;
}
$entry->{maxcpu} = ($d->[3] || 0) + 0;
$entry->{maxmem} = ($d->[6] || 0) + 0;
$entry->{maxdisk} = ($d->[10] || 0) + 0;
push @$res, $entry;
}
push @$res, $entry;
}
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
if (!$param->{type} || $param->{type} eq '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;
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->{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;
}
}
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