[pve-devel] [PATCH pve-network 12/17] api: fabrics: add common helpers

Gabriel Goller g.goller at proxmox.com
Fri Mar 28 18:13:27 CET 2025


From: Stefan Hanreich <s.hanreich at proxmox.com>

Since the perlmod API for both the openfabric and ospf are the same,
add helpers for all CRUD operations that will be supported by the
openfabric and ospf endpoints, so they can share the same code.

Signed-off-by: Stefan Hanreich <s.hanreich at proxmox.com>
Co-authored-by: Gabriel Goller <g.goller at proxmox.com>
Signed-off-by: Gabriel Goller <g.goller at proxmox.com>
---
 src/PVE/API2/Network/SDN/Fabrics/Common.pm | 80 ++++++++++++++++++++++
 src/PVE/API2/Network/SDN/Fabrics/Makefile  |  9 +++
 2 files changed, 89 insertions(+)
 create mode 100644 src/PVE/API2/Network/SDN/Fabrics/Common.pm
 create mode 100644 src/PVE/API2/Network/SDN/Fabrics/Makefile

diff --git a/src/PVE/API2/Network/SDN/Fabrics/Common.pm b/src/PVE/API2/Network/SDN/Fabrics/Common.pm
new file mode 100644
index 000000000000..9d68264f6252
--- /dev/null
+++ b/src/PVE/API2/Network/SDN/Fabrics/Common.pm
@@ -0,0 +1,80 @@
+package PVE::API2::Network::SDN::Fabrics::Common;
+
+use strict;
+use warnings;
+
+use PVE::Network::SDN::Fabrics;
+
+sub delete_fabric {
+    my ($type, $param) = @_;
+
+    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
+    $fabrics->delete_fabric($param);
+    PVE::Network::SDN::Fabrics::write_config($fabrics);
+    return undef;
+}
+
+sub delete_node {
+    my ($type, $param) = @_;
+
+    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
+    $fabrics->delete_node($param);
+    PVE::Network::SDN::Fabrics::write_config($fabrics);
+    return undef;
+}
+
+sub add_node {
+    my ($type, $param) = @_;
+
+    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
+    $fabrics->add_node($param);
+    PVE::Network::SDN::Fabrics::write_config($fabrics);
+
+    return undef;
+}
+
+sub add_fabric {
+    my ($type, $param) = @_;
+
+    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
+    $fabrics->add_fabric($param);
+    PVE::Network::SDN::Fabrics::write_config($fabrics);
+
+    return undef;
+}
+
+sub get_fabric {
+    my ($type, $param) = @_;
+
+    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
+    my $return_value = $fabrics->get_fabric($param->{fabric});
+    return $return_value;
+}
+
+sub get_node {
+    my ($type, $param) = @_;
+
+    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
+    my $return_value = $fabrics->get_node($param->{fabric}, $param->{node});
+    return $return_value;
+}
+
+sub edit_fabric {
+    my ($type, $param) = @_;
+
+    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
+    $fabrics->edit_fabric($param);
+    PVE::Network::SDN::Fabrics::write_config($fabrics);
+    return undef;
+}
+
+sub edit_node {
+    my ($type, $param) = @_;
+
+    my $fabrics = PVE::Network::SDN::Fabrics::config_for_protocol($type);
+    $fabrics->edit_node($param);
+    PVE::Network::SDN::Fabrics::write_config($fabrics);
+    return undef;
+}
+
+1;
diff --git a/src/PVE/API2/Network/SDN/Fabrics/Makefile b/src/PVE/API2/Network/SDN/Fabrics/Makefile
new file mode 100644
index 000000000000..e433f2e7d0a6
--- /dev/null
+++ b/src/PVE/API2/Network/SDN/Fabrics/Makefile
@@ -0,0 +1,9 @@
+SOURCES=OpenFabric.pm Ospf.pm Common.pm
+
+
+PERL5DIR=${DESTDIR}/usr/share/perl5
+
+.PHONY: install
+install:
+	for i in ${SOURCES}; do install -D -m 0644 $$i ${PERL5DIR}/PVE/API2/Network/SDN/Fabrics/$$i; done
+
-- 
2.39.5





More information about the pve-devel mailing list