diff options
| author | Stefan Hanreich <s.hanreich@proxmox.com> | 2025-07-16 15:08:01 +0200 |
|---|---|---|
| committer | Thomas Lamprecht <t.lamprecht@proxmox.com> | 2025-07-17 00:10:36 +0200 |
| commit | a2d808835bd241f82af8c117345899c4162c3cb9 (patch) | |
| tree | 4716b2624f9d6e9bed2749cb623d0d91cf987f6b /src/PVE/Network/SDN/Controllers.pm | |
| parent | ccb1c8c122852992945b27b4fc8fa9ac75ee3a3a (diff) | |
controllers: define new api for frr config generation
With the changes to how we handle the frr config generation,
controllers are now no longer responsible for serializing and writing
the FRR configuration. Instead, we pass the existing frr_config perl
hash to every controller, where controllers append their respective
configuration.
This requires a few changes in the controller API, so that they now
append to a perl hash, instead of directly writing their own
configuration to the file, which is now handled externally by the SDN
module.
We also remove the respective methods in the EvpnPlugin that were
previously responsible for serializing and writing the FRR
configuration, since they have been moved to the Frr helper module
instead.
Co-authored-by: Gabriel Goller <g.goller@proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
Link: https://lore.proxmox.com/20250716130837.585796-41-g.goller@proxmox.com
Diffstat (limited to 'src/PVE/Network/SDN/Controllers.pm')
| -rw-r--r-- | src/PVE/Network/SDN/Controllers.pm | 71 |
1 files changed, 10 insertions, 61 deletions
diff --git a/src/PVE/Network/SDN/Controllers.pm b/src/PVE/Network/SDN/Controllers.pm index 2ffd75e..3c18552 100644 --- a/src/PVE/Network/SDN/Controllers.pm +++ b/src/PVE/Network/SDN/Controllers.pm @@ -80,12 +80,12 @@ sub read_etc_network_interfaces { return $interfaces_config; } -sub generate_controller_config { +sub generate_frr_config { + my ($frr_config, $sdn_config) = @_; - my $cfg = PVE::Network::SDN::running_config(); - my $vnet_cfg = $cfg->{vnets}; - my $zone_cfg = $cfg->{zones}; - my $controller_cfg = $cfg->{controllers}; + my $vnet_cfg = $sdn_config->{vnets}; + my $zone_cfg = $sdn_config->{zones}; + my $controller_cfg = $sdn_config->{controllers}; return if !$vnet_cfg && !$zone_cfg && !$controller_cfg; @@ -103,14 +103,10 @@ sub generate_controller_config { } } - # generate configuration - my $config = {}; - foreach my $id (sort keys %{ $controller_cfg->{ids} }) { my $plugin_config = $controller_cfg->{ids}->{$id}; my $plugin = PVE::Network::SDN::Controllers::Plugin->lookup($plugin_config->{type}); - $plugin->generate_controller_config($plugin_config, $controller_cfg, $id, $uplinks, - $config); + $plugin->generate_frr_config($plugin_config, $controller_cfg, $id, $uplinks, $frr_config); } foreach my $id (sort keys %{ $zone_cfg->{ids} }) { @@ -121,8 +117,8 @@ sub generate_controller_config { if ($controller) { my $controller_plugin = PVE::Network::SDN::Controllers::Plugin->lookup($controller->{type}); - $controller_plugin->generate_controller_zone_config( - $plugin_config, $controller, $controller_cfg, $id, $uplinks, $config, + $controller_plugin->generate_zone_frr_config( + $plugin_config, $controller, $controller_cfg, $id, $uplinks, $frr_config, ); } } @@ -140,58 +136,11 @@ sub generate_controller_config { if ($controller) { my $controller_plugin = PVE::Network::SDN::Controllers::Plugin->lookup($controller->{type}); - $controller_plugin->generate_controller_vnet_config( - $plugin_config, $controller, $zone, $zoneid, $id, $config, + $controller_plugin->generate_vnet_frr_config( + $plugin_config, $controller, $zone, $zoneid, $id, $frr_config, ); } } - - return $config; -} - -sub reload_controller { - - my $cfg = PVE::Network::SDN::running_config(); - my $controller_cfg = $cfg->{controllers}; - - return if !$controller_cfg; - - 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}); - $plugin->reload_controller(); - } -} - -sub generate_controller_rawconfig { - my ($config) = @_; - - my $cfg = PVE::Network::SDN::running_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 $cfg = PVE::Network::SDN::running_config(); - my $controller_cfg = $cfg->{controllers}; - return if !$controller_cfg; - - 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}); - $plugin->write_controller_config($plugin_config, $config); - } } 1; - |
