[pve-devel] [PATCH pve-network 2/3] controllers: add generate_controller_rawconfig

Alexandre Derumier aderumier at odiso.com
Wed Dec 9 16:11:18 CET 2020


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Network/SDN/Controllers.pm            | 19 ++++++++++++++++++-
 PVE/Network/SDN/Controllers/BgpPlugin.pm  |  5 +++++
 PVE/Network/SDN/Controllers/EvpnPlugin.pm | 10 +++++++++-
 PVE/Network/SDN/Controllers/Plugin.pm     |  6 ++++++
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/PVE/Network/SDN/Controllers.pm b/PVE/Network/SDN/Controllers.pm
index 9937755..ba67d75 100644
--- a/PVE/Network/SDN/Controllers.pm
+++ b/PVE/Network/SDN/Controllers.pm
@@ -147,10 +147,27 @@ sub reload_controller {
     }
 }
 
+sub generate_controller_rawconfig {
+    my ($config) = @_;
+
+    my $cfg = PVE::Network::SDN::config();
+    my $controller_cfg = $cfg->{controllers};
+    return if !$controller_cfg;
+
+    my $rawconfig = "";
+    foreach my $id (keys %{$controller_cfg->{ids}}) {
+	my $plugin_config = $controller_cfg->{ids}->{$id};
+	my $plugin = PVE::Network::SDN::Controllers::Plugin->lookup($plugin_config->{type});
+	$rawconfig .= $plugin->generate_controller_rawconfig($plugin_config, $config);
+    }
+    return $rawconfig;
+}
+
 sub write_controller_config {
     my ($config) = @_;
 
-    my $controller_cfg = PVE::Cluster::cfs_read_file('sdn/controllers.cfg');
+    my $cfg = PVE::Network::SDN::config();
+    my $controller_cfg = $cfg->{controllers};
     return if !$controller_cfg;
 
     foreach my $id (keys %{$controller_cfg->{ids}}) {
diff --git a/PVE/Network/SDN/Controllers/BgpPlugin.pm b/PVE/Network/SDN/Controllers/BgpPlugin.pm
index ccc06a8..e5d8490 100644
--- a/PVE/Network/SDN/Controllers/BgpPlugin.pm
+++ b/PVE/Network/SDN/Controllers/BgpPlugin.pm
@@ -138,6 +138,11 @@ sub on_update_hook {
     }
 }
 
+sub generate_controller_rawconfig {
+    my ($class, $plugin_config, $config) = @_;
+    return "";
+}
+
 sub write_controller_config {
     my ($class, $plugin_config, $config) = @_;
     return;
diff --git a/PVE/Network/SDN/Controllers/EvpnPlugin.pm b/PVE/Network/SDN/Controllers/EvpnPlugin.pm
index 6927921..55828ef 100644
--- a/PVE/Network/SDN/Controllers/EvpnPlugin.pm
+++ b/PVE/Network/SDN/Controllers/EvpnPlugin.pm
@@ -280,7 +280,7 @@ sub generate_frr_recurse{
     }
 }
 
-sub write_controller_config {
+sub generate_controller_rawconfig {
     my ($class, $plugin_config, $config) = @_;
 
     my $nodename = PVE::INotify::nodename();
@@ -311,6 +311,14 @@ sub write_controller_config {
 
     my $rawconfig = join("\n", @{$final_config});
 
+    return if !$rawconfig;
+    return $rawconfig;
+}
+
+sub write_controller_config {
+    my ($class, $plugin_config, $config) = @_;
+
+    my $rawconfig = $class->generate_controller_rawconfig($plugin_config, $config);
     return if !$rawconfig;
     return if !-d "/etc/frr";
 
diff --git a/PVE/Network/SDN/Controllers/Plugin.pm b/PVE/Network/SDN/Controllers/Plugin.pm
index 0c92b17..8b5bd4f 100644
--- a/PVE/Network/SDN/Controllers/Plugin.pm
+++ b/PVE/Network/SDN/Controllers/Plugin.pm
@@ -87,6 +87,12 @@ sub generate_controller_vnet_config {
 
 }
 
+sub generate_controller_rawconfig {
+    my ($class, $plugin_config, $config) = @_;
+
+    die "please implement inside plugin";
+}
+
 sub write_controller_config {
     my ($class, $plugin_config, $config) = @_;
 
-- 
2.20.1





More information about the pve-devel mailing list