all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-network 06/11] add config file and common read/write methods
Date: Fri, 14 Feb 2025 14:39:46 +0100	[thread overview]
Message-ID: <20250214133951.344500-7-g.goller@proxmox.com> (raw)
In-Reply-To: <20250214133951.344500-1-g.goller@proxmox.com>

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.goller@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

  parent reply	other threads:[~2025-02-14 13:40 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-14 13:39 [pve-devel] [RFC cluster/manager/network/proxmox{-ve-rs, -perl-rs} 00/11] Add SDN Fabrics Gabriel Goller
2025-02-14 13:39 ` [pve-devel] [PATCH proxmox-ve-rs 01/11] add crate with common network types Gabriel Goller
2025-03-03 15:08   ` Stefan Hanreich
2025-03-05  8:28     ` Gabriel Goller
2025-02-14 13:39 ` [pve-devel] [PATCH proxmox-ve-rs 02/11] add proxmox-frr crate with frr types Gabriel Goller
2025-03-03 16:29   ` Stefan Hanreich
2025-03-04 16:28     ` Gabriel Goller
2025-02-14 13:39 ` [pve-devel] [PATCH proxmox-ve-rs 03/11] add intermediate fabric representation Gabriel Goller
2025-02-28 13:57   ` Thomas Lamprecht
2025-02-28 16:19     ` Gabriel Goller
2025-03-04 17:30     ` Gabriel Goller
2025-03-05  9:03       ` Wolfgang Bumiller
2025-03-04  8:45   ` Stefan Hanreich
2025-03-05  9:09     ` Gabriel Goller
2025-02-14 13:39 ` [pve-devel] [PATCH proxmox-perl-rs 04/11] fabrics: add CRUD and generate fabrics methods Gabriel Goller
2025-03-04  9:28   ` Stefan Hanreich
2025-03-05 10:20     ` Gabriel Goller
2025-02-14 13:39 ` [pve-devel] [PATCH pve-cluster 05/11] cluster: add sdn fabrics config files Gabriel Goller
2025-02-28 12:19   ` Thomas Lamprecht
2025-02-28 12:52     ` Gabriel Goller
2025-02-14 13:39 ` Gabriel Goller [this message]
2025-02-14 13:39 ` [pve-devel] [PATCH pve-network 07/11] merge the frr config with the fabrics frr config on apply Gabriel Goller
2025-02-14 13:39 ` [pve-devel] [PATCH pve-network 08/11] add api endpoints for fabrics Gabriel Goller
2025-03-04  9:51   ` Stefan Hanreich
2025-02-14 13:39 ` [pve-devel] [PATCH pve-manager 09/11] sdn: add Fabrics view Gabriel Goller
2025-03-04  9:57   ` Stefan Hanreich
2025-03-07 15:57     ` Gabriel Goller
2025-02-14 13:39 ` [pve-devel] [PATCH pve-manager 10/11] sdn: add fabric edit/delete forms Gabriel Goller
2025-03-04 10:07   ` Stefan Hanreich
2025-03-07 16:04     ` Gabriel Goller
2025-02-14 13:39 ` [pve-devel] [PATCH pve-manager 11/11] network: return loopback interface on network endpoint Gabriel Goller
2025-03-03 16:58 ` [pve-devel] [RFC cluster/manager/network/proxmox{-ve-rs, -perl-rs} 00/11] Add SDN Fabrics Stefan Hanreich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250214133951.344500-7-g.goller@proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal