Add a new basic Fabrics module that can be used for reading and writing the fabrics configuration file.
Co-authored-by: Gabriel Goller <g.gol...@proxmox.com> Signed-off-by: Stefan Hanreich <s.hanre...@proxmox.com> --- src/PVE/Network/SDN/Fabrics.pm | 49 ++++++++++++++++++++++++++++++++++ src/PVE/Network/SDN/Makefile | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/PVE/Network/SDN/Fabrics.pm diff --git a/src/PVE/Network/SDN/Fabrics.pm b/src/PVE/Network/SDN/Fabrics.pm new file mode 100644 index 0000000..77da6ae --- /dev/null +++ b/src/PVE/Network/SDN/Fabrics.pm @@ -0,0 +1,49 @@ +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::JSONSchema qw(get_standard_option); +use PVE::INotify; +use PVE::RS::SDN::Fabrics; + +cfs_register_file( + 'sdn/fabrics.cfg', + \&parse_fabrics_config, + \&write_fabrics_config, +); + +sub parse_fabrics_config { + my ($filename, $raw) = @_; + return $raw // ''; +} + +sub write_fabrics_config { + my ($filename, $config) = @_; + return $config // ''; +} + +sub config { + my ($running) = @_; + + if ($running) { + my $running_config = PVE::Network::SDN::running_config(); + + # if the config hasn't yet been applied after the introduction of + # fabrics then the key does not exist in the running config so we + # default to an empty hash + my $fabrics_config = $running_config->{fabrics}->{ids} // {}; + return PVE::RS::SDN::Fabrics->running_config($fabrics_config); + } + + my $fabrics_config = cfs_read_file("sdn/fabrics.cfg"); + return PVE::RS::SDN::Fabrics->config($fabrics_config); +} + +sub write_config { + my ($config) = @_; + cfs_write_file("sdn/fabrics.cfg", $config->to_raw(), 1); +} + +1; diff --git a/src/PVE/Network/SDN/Makefile b/src/PVE/Network/SDN/Makefile index 3e6e5fb..a256642 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