On 3/24/20 8:27 AM, Alexandre Derumier wrote:
> Signed-off-by: Alexandre Derumier <aderum...@odiso.com>
> ---
>  PVE/API2/Network.pm | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/PVE/API2/Network.pm b/PVE/API2/Network.pm
> index 4c691879..d727a2fc 100644
> --- a/PVE/API2/Network.pm
> +++ b/PVE/API2/Network.pm
> @@ -18,6 +18,7 @@ use base qw(PVE::RESTHandler);
>  
>  my $have_sdn;
>  eval {
> +    require PVE::Network::SDN::Vnets;
>      require PVE::Network::SDN::Zones;
>      require PVE::Network::SDN::Controllers;
>      $have_sdn = 1;
> @@ -246,6 +247,30 @@ __PACKAGE__->register_method({
>                   ($type eq 'bridge' || $type eq 'OVSBridge'));
>               delete $ifaces->{$k} if !$match;
>           }
> +
> +         if ($have_sdn && $param->{type} eq 'any_bridge') {
> +             my $vnets_cfg = PVE::Network::SDN::Vnets::config();
> +             my $zones_cfg = PVE::Network::SDN::Zones::config();
> +             my @vnetids = 
> PVE::Network::SDN::Vnets::sdn_vnets_ids($vnets_cfg);
> +             my $authuser = $rpcenv->get_user();
> +             my $nodename = PVE::INotify::nodename();
> +
> +
> +             foreach my $vnetid (@vnetids) {
> +
> +                my $vnet = 
> PVE::Network::SDN::Vnets::sdn_vnets_config($vnets_cfg, $vnetid);
> +                my $zoneid = $vnet->{zone};
> +                next if !$zoneid;
> +                my $zone_config = 
> PVE::Network::SDN::Zones::sdn_zones_config($zones_cfg, $zoneid);
> +
> +                 my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
> +                 next if !$rpcenv->check_any($authuser, 
> "/sdn/vnets/$vnetid", $privs, 1);
> +                 next if defined($zone_config->{nodes}) && 
> !$zone_config->{nodes}->{$nodename};
> +
> +                 my $iface = { type => 'vnet', active => '1' };
> +                 $ifaces->{$vnetid} = $iface;
> +             }
> +         }

hmm, isn't there any "get vnets" function in pve-network? If not, should there 
be
one? this code seems besides the $rpcenv (which can be get in the pve-network 
too)
not be suited to "clutter" this API call, a simple:

my $vnets = PVE::Network::SDN::Vnets::get_user_vnets();
map {
    $iface->{$_} = $vnets->{$_};
} keys %$vnets;

(or "foreach" instead of "map") would make this easier to read.

>       }
>  
>       return PVE::RESTHandler::hash_to_array($ifaces, 'iface');
> 


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to