[pve-devel] [PATCH pve-network 2/7] move status code to zone plugin

Alexandre Derumier aderumier at odiso.com
Mon Feb 10 17:26:05 CET 2020


---
 PVE/Network/SDN/Zones.pm        | 35 +++++++++++----------------------
 PVE/Network/SDN/Zones/Plugin.pm | 27 +++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/PVE/Network/SDN/Zones.pm b/PVE/Network/SDN/Zones.pm
index a76ee11..e3d72e8 100644
--- a/PVE/Network/SDN/Zones.pm
+++ b/PVE/Network/SDN/Zones.pm
@@ -195,35 +195,22 @@ sub status {
     my $zone_cfg = PVE::Cluster::cfs_read_file('sdn/zones.cfg');
     my $nodename = PVE::INotify::nodename();
 
+
     my $vnet_status = {};
     my $zone_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;
-	$zone_status->{$zone}->{status} = 'available' if !defined($zone_status->{$zone}->{status});
-
-	if($err_config) {
-	    $vnet_status->{$id}->{status} = 'pending';
-	    $vnet_status->{$id}->{statusmsg} = $err_config;
-	    $zone_status->{$zone}->{status} = 'pending';
-	} elsif ($status->{$id}->{status} && $status->{$id}->{status} eq 'pass') {
-	    $vnet_status->{$id}->{status} = 'available';
-	    my $bridgeport = $status->{$id}->{config}->{'bridge-ports'};
-
-	    if ($status->{$bridgeport}->{status} && $status->{$bridgeport}->{status} ne 'pass') {
-		$vnet_status->{$id}->{status} = 'error';
-		$vnet_status->{$id}->{statusmsg} = 'configuration not fully applied';
-		$zone_status->{$zone}->{status} = 'error';
-	    }
-	} else {
-	    $vnet_status->{$id}->{status} = 'error';
-	    $vnet_status->{$id}->{statusmsg} = 'missing';
-	    $zone_status->{$zone}->{status} = 'error';
-	}
+        my $vnet = $vnet_cfg->{ids}->{$id};
+        my $zone = $vnet->{zone};
+
+	next if !$zone;
+        my $plugin_config = $zone_cfg->{ids}->{$zone};
+        next if defined($plugin_config->{nodes}) && !$plugin_config->{nodes}->{$nodename};
+
+        my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
+        $plugin->status($plugin_config, $zone, $id, $vnet, $err_config, $status, $vnet_status, $zone_status);
     }
+
     return($zone_status, $vnet_status);
 }
 
diff --git a/PVE/Network/SDN/Zones/Plugin.pm b/PVE/Network/SDN/Zones/Plugin.pm
index f84c1b2..5aeff19 100644
--- a/PVE/Network/SDN/Zones/Plugin.pm
+++ b/PVE/Network/SDN/Zones/Plugin.pm
@@ -179,6 +179,33 @@ sub parse_tag_number_or_range {
     return (scalar(@elements) > 1);
 }
 
+sub status {
+    my ($class, $plugin_config, $zone, $id, $vnet, $err_config, $status, $vnet_status, $zone_status) = @_;
+
+    $vnet_status->{$id}->{zone} = $zone;
+    $zone_status->{$zone}->{status} = 'available' if !defined($zone_status->{$zone}->{status});
+
+    if($err_config) {
+	$vnet_status->{$id}->{status} = 'pending';
+	$vnet_status->{$id}->{statusmsg} = $err_config;
+	$zone_status->{$zone}->{status} = 'pending';
+    } elsif ($status->{$id}->{status} && $status->{$id}->{status} eq 'pass') {
+	$vnet_status->{$id}->{status} = 'available';
+	my $bridgeport = $status->{$id}->{config}->{'bridge-ports'};
+
+	if ($bridgeport && $status->{$bridgeport}->{status} && $status->{$bridgeport}->{status} ne 'pass') {
+	    $vnet_status->{$id}->{status} = 'error';
+	    $vnet_status->{$id}->{statusmsg} = 'configuration not fully applied';
+	    $zone_status->{$zone}->{status} = 'error';
+	}
+
+    } else {
+	$vnet_status->{$id}->{status} = 'error';
+	$vnet_status->{$id}->{statusmsg} = 'missing';
+	$zone_status->{$zone}->{status} = 'error';
+    }
+}
+
 #helper
 
 sub get_uplink_iface {
-- 
2.20.1



More information about the pve-devel mailing list