[pve-devel] [PATCH v2 pve-network 08/15] add nodes option to zones

Alexandre Derumier aderumier at odiso.com
Tue Nov 26 10:00:23 CET 2019


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Network/SDN/Zones.pm         |  4 ++++
 PVE/Network/SDN/Zones.pm              |  8 ++++++++
 PVE/Network/SDN/Zones/EvpnPlugin.pm   |  1 +
 PVE/Network/SDN/Zones/FaucetPlugin.pm |  1 +
 PVE/Network/SDN/Zones/Plugin.pm       | 29 +++++++++++++++++++++++++++
 PVE/Network/SDN/Zones/QinQPlugin.pm   |  1 +
 PVE/Network/SDN/Zones/VlanPlugin.pm   |  1 +
 PVE/Network/SDN/Zones/VxlanPlugin.pm  |  1 +
 8 files changed, 46 insertions(+)

diff --git a/PVE/API2/Network/SDN/Zones.pm b/PVE/API2/Network/SDN/Zones.pm
index ce99bd8..16c90cc 100644
--- a/PVE/API2/Network/SDN/Zones.pm
+++ b/PVE/API2/Network/SDN/Zones.pm
@@ -32,6 +32,10 @@ my $api_sdn_zones_config = sub {
     $scfg->{zone} = $id;
     $scfg->{digest} = $cfg->{digest};
 
+    if ($scfg->{nodes}) {
+        $scfg->{nodes} = PVE::Storage::Plugin->encode_value($scfg->{type}, 'nodes', $scfg->{nodes});
+    }
+
     return $scfg;
 };
 
diff --git a/PVE/Network/SDN/Zones.pm b/PVE/Network/SDN/Zones.pm
index d481d5c..d7afba1 100644
--- a/PVE/Network/SDN/Zones.pm
+++ b/PVE/Network/SDN/Zones.pm
@@ -97,6 +97,8 @@ sub generate_etc_network_config {
 
     #generate configuration
     my $config = {};
+    my $nodename = PVE::INotify::nodename();
+
     foreach my $id (keys %{$vnet_cfg->{ids}}) {
 	my $vnet = $vnet_cfg->{ids}->{$id};
 	my $zone = $vnet->{zone};
@@ -113,6 +115,8 @@ sub generate_etc_network_config {
 	    next;
 	}
 
+	next if defined($plugin_config->{nodes}) && !$plugin_config->{nodes}->{$nodename};
+
 	my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
 	$plugin->generate_sdn_config($plugin_config, $zone, $id, $vnet, $uplinks, $config);
     }
@@ -196,12 +200,16 @@ sub status {
     my $status = ifquery_check();
 
     my $vnet_cfg = PVE::Cluster::cfs_read_file('sdn/vnets.cfg');
+    my $zone_cfg = PVE::Cluster::cfs_read_file('sdn/zones.cfg');
+    my $nodename = PVE::INotify::nodename();
 
     my $vnet_status = {};
     my $transport_status = {};
 
     foreach my $id (keys %{$vnet_cfg->{ids}}) {
 	my $zone = $vnet_cfg->{ids}->{$id}->{zone};
+	next if defined($zone_cfg->{ids}->{$zone}->{nodes}) && !$zone_cfg->{ids}->{$zone}->{nodes}->{$nodename};
+
 	$vnet_status->{$id}->{zone} = $zone;
 	$transport_status->{$zone}->{status} = 'available' if !defined($transport_status->{$zone}->{status});
 
diff --git a/PVE/Network/SDN/Zones/EvpnPlugin.pm b/PVE/Network/SDN/Zones/EvpnPlugin.pm
index 2acb9ae..f999847 100644
--- a/PVE/Network/SDN/Zones/EvpnPlugin.pm
+++ b/PVE/Network/SDN/Zones/EvpnPlugin.pm
@@ -38,6 +38,7 @@ sub properties {
 sub options {
 
     return {
+        nodes => { optional => 1},
 	'uplink-id' => { optional => 0 },
         'vrf' => { optional => 0 },
         'vrf-vxlan' => { optional => 0 },
diff --git a/PVE/Network/SDN/Zones/FaucetPlugin.pm b/PVE/Network/SDN/Zones/FaucetPlugin.pm
index e9c07a6..2a196bd 100644
--- a/PVE/Network/SDN/Zones/FaucetPlugin.pm
+++ b/PVE/Network/SDN/Zones/FaucetPlugin.pm
@@ -28,6 +28,7 @@ sub properties {
 sub options {
 
     return {
+        nodes => { optional => 1},
 	'dp-id' => { optional => 0 },
 	'uplink-id' => { optional => 0 },
         'controller' => { optional => 0 },
diff --git a/PVE/Network/SDN/Zones/Plugin.pm b/PVE/Network/SDN/Zones/Plugin.pm
index 7e820cd..62db9cd 100644
--- a/PVE/Network/SDN/Zones/Plugin.pm
+++ b/PVE/Network/SDN/Zones/Plugin.pm
@@ -42,6 +42,7 @@ my $defaultData = {
 	    type => 'string', format => 'pve-configid',
 	    type => 'string',
 	},
+        nodes => get_standard_option('pve-node-list', { optional => 1 }),
         zone => get_standard_option('pve-sdn-zone-id',
             { completion => \&PVE::Network::SDN::Zones::complete_sdn_zone }),
     },
@@ -51,6 +52,34 @@ sub private {
     return $defaultData;
 }
 
+sub decode_value {
+    my ($class, $type, $key, $value) = @_;
+
+    if ($key eq 'nodes') {
+        my $res = {};
+
+        foreach my $node (PVE::Tools::split_list($value)) {
+            if (PVE::JSONSchema::pve_verify_node_name($node)) {
+                $res->{$node} = 1;
+            }
+        }
+
+        return $res;
+    } 
+
+   return $value;
+}
+
+sub encode_value {
+    my ($class, $type, $key, $value) = @_;
+
+    if ($key eq 'nodes') {
+        return join(',', keys(%$value));
+    }
+
+    return $value;
+}
+
 sub parse_section_header {
     my ($class, $line) = @_;
 
diff --git a/PVE/Network/SDN/Zones/QinQPlugin.pm b/PVE/Network/SDN/Zones/QinQPlugin.pm
index 734c56b..c9f522b 100644
--- a/PVE/Network/SDN/Zones/QinQPlugin.pm
+++ b/PVE/Network/SDN/Zones/QinQPlugin.pm
@@ -29,6 +29,7 @@ sub properties {
 sub options {
 
     return {
+        nodes => { optional => 1},
 	'uplink-id' => { optional => 0 },
 	'tag' => { optional => 0 },
 	'vlan-protocol' => { optional => 1 },
diff --git a/PVE/Network/SDN/Zones/VlanPlugin.pm b/PVE/Network/SDN/Zones/VlanPlugin.pm
index 07188f6..39f103e 100644
--- a/PVE/Network/SDN/Zones/VlanPlugin.pm
+++ b/PVE/Network/SDN/Zones/VlanPlugin.pm
@@ -32,6 +32,7 @@ sub properties {
 sub options {
 
     return {
+        nodes => { optional => 1},
 	'uplink-id' => { optional => 0 },
     };
 }
diff --git a/PVE/Network/SDN/Zones/VxlanPlugin.pm b/PVE/Network/SDN/Zones/VxlanPlugin.pm
index 8ae3ce8..e3624ea 100644
--- a/PVE/Network/SDN/Zones/VxlanPlugin.pm
+++ b/PVE/Network/SDN/Zones/VxlanPlugin.pm
@@ -56,6 +56,7 @@ sub properties {
 sub options {
 
     return {
+        nodes => { optional => 1},
 	'uplink-id' => { optional => 0 },
         'multicast-address' => { optional => 1 },
         'unicast-address' => { optional => 1 },
-- 
2.20.1




More information about the pve-devel mailing list