[pve-devel] [PATCH pve-network 5/8] add controller_reload

Alexandre Derumier aderumier at odiso.com
Mon Sep 30 11:03:36 CEST 2019


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Network/SDN.pm              | 17 +++++++++++++++++
 PVE/Network/SDN/FaucetPlugin.pm | 11 +++++++++++
 PVE/Network/SDN/FrrPlugin.pm    | 18 ++++++++++++++++++
 PVE/Network/SDN/Plugin.pm       |  6 ++++++
 4 files changed, 52 insertions(+)

diff --git a/PVE/Network/SDN.pm b/PVE/Network/SDN.pm
index 137f9f9..8e96084 100644
--- a/PVE/Network/SDN.pm
+++ b/PVE/Network/SDN.pm
@@ -230,6 +230,23 @@ sub generate_controller_config {
     return $config;
 }
 
+
+sub reload_controller {
+
+    my $sdn_cfg = PVE::Cluster::cfs_read_file('sdn.cfg');
+    return if !$sdn_cfg;
+
+    foreach my $id (keys %{$sdn_cfg->{ids}}) {
+	my $plugin_config = $sdn_cfg->{ids}->{$id};
+	my $plugin = PVE::Network::SDN::Plugin->lookup($plugin_config->{type});
+	my $pd = $plugin->plugindata();
+	my $role = $pd->{role};
+	if ($role eq 'controller') {
+	    $plugin->reload_controller();
+	}
+    }
+}
+
 sub write_etc_network_config {
     my ($rawconfig) = @_;
 
diff --git a/PVE/Network/SDN/FaucetPlugin.pm b/PVE/Network/SDN/FaucetPlugin.pm
index 9e313c3..fe75efb 100644
--- a/PVE/Network/SDN/FaucetPlugin.pm
+++ b/PVE/Network/SDN/FaucetPlugin.pm
@@ -98,5 +98,16 @@ sub write_controller_config {
     $writefh->close();
 }
 
+sub reload_controller {
+    my ($class) = @_;
+
+    my $conf_file = "/etc/faucet/faucet.yaml";
+    my $bin_path = "/usr/bin/faucet";
+
+    if (-e $conf_file && -e $bin_path) {
+        PVE::Tools::run_command(['systemctl', 'reload', 'faucet']);
+    }
+}
+
 1;
 
diff --git a/PVE/Network/SDN/FrrPlugin.pm b/PVE/Network/SDN/FrrPlugin.pm
index 532247a..3410844 100644
--- a/PVE/Network/SDN/FrrPlugin.pm
+++ b/PVE/Network/SDN/FrrPlugin.pm
@@ -290,6 +290,24 @@ sub write_controller_config {
     $writefh->close();
 }
 
+sub reload_controller {
+    my ($class) = @_;
+
+    my $conf_file = "/etc/frr/frr.conf";
+    my $bin_path = "/usr/bin/vtysh";
+
+    my $err = sub {
+	my $line = shift;
+	if ($line =~ /^line (\S+)/) {
+	    print "$line \n";
+	}
+    };
+
+    if (-e $conf_file && -e $bin_path) {
+	PVE::Tools::run_command([$bin_path, '-m', '-f', $conf_file], outfunc => {}, errfunc => $err);
+    }
+}
+
 1;
 
 
diff --git a/PVE/Network/SDN/Plugin.pm b/PVE/Network/SDN/Plugin.pm
index 605fd06..0c6eaf0 100644
--- a/PVE/Network/SDN/Plugin.pm
+++ b/PVE/Network/SDN/Plugin.pm
@@ -88,6 +88,12 @@ sub write_controller_config {
     die "please implement inside plugin";
 }
 
+sub controller_reload {
+    my ($class) = @_;
+
+    die "please implement inside plugin";
+}
+
 sub on_delete_hook {
     my ($class, $sndid, $scfg) = @_;
 
-- 
2.20.1




More information about the pve-devel mailing list