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,9 +146,11 @@ __PACKAGE__->register_method({ ...@@ -140,9 +146,11 @@ __PACKAGE__->register_method({
# we try to generate 'numbers' by using "$X + 0" # we try to generate 'numbers' by using "$X + 0"
if (!$param->{type} || $param->{type} eq 'vm') {
foreach my $vmid (keys %$idlist) { foreach my $vmid (keys %$idlist) {
my $data = $idlist->{$vmid}; my $data = $idlist->{$vmid};
next if !$rpcenv->check($user, "/vms/$vmid", [ 'VM.Audit' ]); next if !$rpcenv->check($user, "/vms/$vmid", [ 'VM.Audit' ]);
my $entry = { my $entry = {
...@@ -167,7 +175,9 @@ __PACKAGE__->register_method({ ...@@ -167,7 +175,9 @@ __PACKAGE__->register_method({
push @$res, $entry; push @$res, $entry;
} }
}
if (!$param->{type} || $param->{type} eq 'node') {
foreach my $node (@$nodelist) { foreach my $node (@$nodelist) {
my $entry = { my $entry = {
id => "node/$node", id => "node/$node",
...@@ -189,9 +199,11 @@ __PACKAGE__->register_method({ ...@@ -189,9 +199,11 @@ __PACKAGE__->register_method({
$entry->{maxdisk} = ($d->[10] || 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 $cfg = PVE::Storage::config();
my @sids = PVE::Storage::storage_ids ($cfg); my @sids = PVE::Storage::storage_ids ($cfg);
...@@ -215,7 +227,7 @@ __PACKAGE__->register_method({ ...@@ -215,7 +227,7 @@ __PACKAGE__->register_method({
} }
push @$res, $entry; 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