Add the config file for ospf and openfabric and add common read/write functions. We also add the ospf/openfabric config to the `.running-config` – even though we don't ready from it later.
Signed-off-by: Gabriel Goller <g.gol...@proxmox.com> --- src/PVE/Network/SDN.pm | 8 +++- src/PVE/Network/SDN/Fabrics.pm | 86 ++++++++++++++++++++++++++++++++++ src/PVE/Network/SDN/Makefile | 2 +- 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 src/PVE/Network/SDN/Fabrics.pm diff --git a/src/PVE/Network/SDN.pm b/src/PVE/Network/SDN.pm index c7dccfa89fcf..399435b07cd2 100644 --- a/src/PVE/Network/SDN.pm +++ b/src/PVE/Network/SDN.pm @@ -150,13 +150,19 @@ sub commit_config { my $zones_cfg = PVE::Network::SDN::Zones::config(); my $controllers_cfg = PVE::Network::SDN::Controllers::config(); my $subnets_cfg = PVE::Network::SDN::Subnets::config(); + my $openfabrics_cfg_rust = PVE::Network::SDN::Fabrics::get_config("openfabric"); + my $openfabrics_cfg = $openfabrics_cfg_rust->get_inner(); + my $ospf_config_rust = PVE::Network::SDN::Fabrics::get_config("ospf"); + my $ospf_cfg = $ospf_config_rust->get_inner(); my $vnets = { ids => $vnets_cfg->{ids} }; my $zones = { ids => $zones_cfg->{ids} }; my $controllers = { ids => $controllers_cfg->{ids} }; my $subnets = { ids => $subnets_cfg->{ids} }; + my $openfabric = { ids => $openfabrics_cfg }; + my $ospf = { ids => $ospf_cfg }; - $cfg = { version => $version, vnets => $vnets, zones => $zones, controllers => $controllers, subnets => $subnets }; + $cfg = { version => $version, vnets => $vnets, zones => $zones, controllers => $controllers, subnets => $subnets, openfabric => $openfabric, ospf => $ospf }; cfs_write_file($running_cfg, $cfg); } diff --git a/src/PVE/Network/SDN/Fabrics.pm b/src/PVE/Network/SDN/Fabrics.pm new file mode 100644 index 000000000000..bbd07cf30624 --- /dev/null +++ b/src/PVE/Network/SDN/Fabrics.pm @@ -0,0 +1,86 @@ +package PVE::Network::SDN::Fabrics; + +use strict; +use warnings; + +use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_lock_file cfs_write_file); +use PVE::RS::SDN::Fabrics; +use PVE::RS::SDN::Fabrics::Ospf; +use PVE::RS::SDN::Fabrics::OpenFabric; + +cfs_register_file( + 'sdn/fabrics/openfabric.cfg', + \&parse_fabrics_config, + \&write_fabrics_config, +); + +cfs_register_file( + 'sdn/fabrics/ospf.cfg', + \&parse_fabrics_config, + \&write_fabrics_config, +); + +sub parse_fabrics_config { + my ($filename, $raw) = @_; + + $raw = '' if !defined($raw); + return $raw; +} + +sub write_fabrics_config { + my ($filename, $config) = @_; + return $config; +} + +sub lock_config { + my ($protocol, $code, $timeout) = @_; + + if ($protocol eq "openfabric") { + cfs_lock_file('sdn/fabrics/openfabric.cfg', $timeout, $code); + die $@ if $@; + } elsif ($protocol eq "ospf") { + cfs_lock_file('sdn/fabrics/openfabric.cfg', $timeout, $code); + die $@ if $@; + } else { + die "cannot lock fabric config \"$protocol\": not implemented"; + } +} + +sub get_all_configs { + my $openfabric = cfs_read_file('sdn/fabrics/openfabric.cfg'); + my $ospf = cfs_read_file('sdn/fabrics/ospf.cfg'); + + return PVE::RS::SDN::Fabrics::config($openfabric, $ospf); +} + +sub get_config { + my ($protocol) = @_; + + my $config; + my $fabric_config; + + if ($protocol eq "openfabric") { + $config = cfs_read_file('sdn/fabrics/openfabric.cfg'); + $fabric_config = PVE::RS::SDN::Fabrics::OpenFabric->config($config); + } elsif ($protocol eq "ospf") { + $config = cfs_read_file('sdn/fabrics/ospf.cfg'); + $fabric_config = PVE::RS::SDN::Fabrics::Ospf->config($config); + } else { + die "cannot get fabric config \"$protocol\": not implemented"; + } + + return $fabric_config; +} + +sub write_config { + my ($config) = @_; + + my ($new_config, $protocol) = $config->write(); + + # It is safe to use the protocol in the path here as it comes from rust. There + # the protocol is stored in an enum so we know it is correct. + cfs_write_file("sdn/fabrics/$protocol.cfg", $new_config, 1); +} + +1; + diff --git a/src/PVE/Network/SDN/Makefile b/src/PVE/Network/SDN/Makefile index 3e6e5fb4c6f2..a256642e3044 100644 --- a/src/PVE/Network/SDN/Makefile +++ b/src/PVE/Network/SDN/Makefile @@ -1,4 +1,4 @@ -SOURCES=Vnets.pm VnetPlugin.pm Zones.pm Controllers.pm Subnets.pm SubnetPlugin.pm Ipams.pm Dns.pm Dhcp.pm +SOURCES=Vnets.pm VnetPlugin.pm Zones.pm Controllers.pm Subnets.pm SubnetPlugin.pm Ipams.pm Dns.pm Dhcp.pm Fabrics.pm PERL5DIR=${DESTDIR}/usr/share/perl5 -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel