[pve-devel] [PATCH pve-network] add get_local_vnets()

Alexandre Derumier aderumier at odiso.com
Thu Mar 26 03:06:34 CET 2020


return the vnets of the localnode

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Network/SDN.pm | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/PVE/Network/SDN.pm b/PVE/Network/SDN.pm
index 2e996e9..2b423a7 100644
--- a/PVE/Network/SDN.pm
+++ b/PVE/Network/SDN.pm
@@ -6,6 +6,7 @@ use warnings;
 use Data::Dumper;
 use JSON;
 
+use PVE::Network::SDN::Vnets;
 use PVE::Network::SDN::Zones;
 
 use PVE::Tools qw(extract_param dir_glob_regex run_command);
@@ -45,5 +46,38 @@ sub status {
     return($zone_status, $vnet_status);
 }
 
+sub get_local_vnets {
+
+    my $rpcenv = PVE::RPCEnvironment::get();
+
+    my $authuser = $rpcenv->get_user();
+
+    my $nodename = PVE::INotify::nodename();
+
+    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 $vnets = {};
+
+    foreach my $vnetid (@vnetids) {
+
+	my $vnet = PVE::Network::SDN::Vnets::sdn_vnets_config($vnets_cfg, $vnetid);
+	my $zoneid = $vnet->{zone};
+	my $privs = [ 'SDN.Audit', 'SDN.Allocate' ];
+
+	next if !$zoneid;
+	next if !$rpcenv->check_any($authuser, "/sdn/zones/$zoneid", $privs, 1);
+
+	my $zone_config = PVE::Network::SDN::Zones::sdn_zones_config($zones_cfg, $zoneid);
+
+	next if defined($zone_config->{nodes}) && !$zone_config->{nodes}->{$nodename};
+	$vnets->{$vnetid} = { type => 'vnet', active => '1' };
+    }
+
+    return $vnets;
+}
+
 1;
 
-- 
2.20.1




More information about the pve-devel mailing list