API: add ability to restrict ref list to specified type
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 30 May 2014 07:37:49 +0000 (09:37 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 30 May 2014 07:37:49 +0000 (09:37 +0200)
src/PVE/API2/Firewall/Cluster.pm
src/PVE/API2/Firewall/VM.pm

index 8f1deef..e8b44d2 100644 (file)
@@ -216,7 +216,14 @@ __PACKAGE__->register_method({
     description => "Lists possible IPSet/Alias reference which are allowed in source/dest properties.",
     parameters => {
        additionalProperties => 0,
-       properties => {},
+       properties => {
+           type => {
+               description => "Only list references of specified type.",
+               type => 'string',
+               enum => ['alias', 'ipset'],
+               optional => 1,
+           },
+       },
     },
     returns => {
        type => 'array',
@@ -247,27 +254,31 @@ __PACKAGE__->register_method({
 
        my $res = [];
 
-       foreach my $name (keys %{$conf->{ipset}}) {
-           my $data = {
-               type => 'ipset',
-               name => $name,
-               ref => "+$name",
-           };
-           if (my $comment = $conf->{ipset_comments}->{$name}) {
-               $data->{comment} = $comment;
+       if (!$param->{type} || $param->{type} eq 'ipset') {
+           foreach my $name (keys %{$conf->{ipset}}) {
+               my $data = {
+                   type => 'ipset',
+                   name => $name,
+                   ref => "+$name",
+               };
+               if (my $comment = $conf->{ipset_comments}->{$name}) {
+                   $data->{comment} = $comment;
+               }
+               push @$res, $data;
            }
-           push @$res, $data;
        }
 
-       foreach my $name (keys %{$conf->{aliases}}) {
-           my $e = $conf->{aliases}->{$name};
-           my $data = {
-               type => 'alias',
-               name => $name,
-               ref => $name,
-           };
-           $data->{comment} = $e->{comment} if $e->{comment};
-           push @$res, $data;
+       if (!$param->{type} || $param->{type} eq 'alias') {
+           foreach my $name (keys %{$conf->{aliases}}) {
+               my $e = $conf->{aliases}->{$name};
+               my $data = {
+                   type => 'alias',
+                   name => $name,
+                   ref => $name,
+               };
+               $data->{comment} = $e->{comment} if $e->{comment};
+               push @$res, $data;
+           }
        }
 
        return $res;
index 3e49e88..63d7090 100644 (file)
@@ -246,6 +246,12 @@ sub register_handlers {
            properties => {
                node => get_standard_option('pve-node'),
                vmid => get_standard_option('pve-vmid'),
+               type => {
+                   description => "Only list references of specified type.",
+                   type => 'string',
+                   enum => ['alias', 'ipset'],
+                   optional => 1,
+               },
            },
        },
        returns => {
@@ -278,27 +284,31 @@ sub register_handlers {
 
            foreach my $conf (($cluster_conf, $fw_conf)) {
                next if !$conf;
-               foreach my $name (keys %{$conf->{ipset}}) {
-                   my $data = { 
-                       type => 'ipset',
-                       name => $name,
-                       ref => "+$name",
-                   };
-                   if (my $comment = $conf->{ipset_comments}->{$name}) {
-                       $data->{comment} = $comment;
+               if (!$param->{type} || $param->{type} eq 'ipset') {
+                   foreach my $name (keys %{$conf->{ipset}}) {
+                       my $data = { 
+                           type => 'ipset',
+                           name => $name,
+                           ref => "+$name",
+                       };
+                       if (my $comment = $conf->{ipset_comments}->{$name}) {
+                           $data->{comment} = $comment;
+                       }
+                       $ipsets->{$name} = $data;
                    }
-                   $ipsets->{$name} = $data;
                }
 
-               foreach my $name (keys %{$conf->{aliases}}) {
-                   my $e = $conf->{aliases}->{$name};
-                   my $data = { 
-                       type => 'alias',
-                       name => $name,
-                       ref => $name,
-                   };
-                   $data->{comment} = $e->{comment} if $e->{comment};
-                   $aliases->{$name} = $data;
+               if (!$param->{type} || $param->{type} eq 'alias') {
+                   foreach my $name (keys %{$conf->{aliases}}) {
+                       my $e = $conf->{aliases}->{$name};
+                       my $data = { 
+                           type => 'alias',
+                           name => $name,
+                           ref => $name,
+                       };
+                       $data->{comment} = $e->{comment} if $e->{comment};
+                       $aliases->{$name} = $data;
+                   }
                }
            }