[pve-devel] [PATCH pve-network v2 15/19] api: ospf: add fabric endpoints
Gabriel Goller
g.goller at proxmox.com
Fri Apr 4 18:28:51 CEST 2025
From: Stefan Hanreich <s.hanreich at proxmox.com>
Add CRUD endpoints for the ospf fabric and node section types. They
are implemented in proxmox-perl-rs.
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/Makefile | 2 +-
src/PVE/API2/Network/SDN/Fabrics/OSPF.pm | 155 ++++++++++++++++++++++
2 files changed, 156 insertions(+), 1 deletion(-)
create mode 100644 src/PVE/API2/Network/SDN/Fabrics/OSPF.pm
diff --git a/src/PVE/API2/Network/SDN/Fabrics/Makefile b/src/PVE/API2/Network/SDN/Fabrics/Makefile
index af733ad013fd..62d794486ebe 100644
--- a/src/PVE/API2/Network/SDN/Fabrics/Makefile
+++ b/src/PVE/API2/Network/SDN/Fabrics/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Common.pm OpenFabric.pm OpenFabricNode.pm
+SOURCES=Common.pm OpenFabric.pm OpenFabricNode.pm OSPF.pm
PERL5DIR=${DESTDIR}/usr/share/perl5
diff --git a/src/PVE/API2/Network/SDN/Fabrics/OSPF.pm b/src/PVE/API2/Network/SDN/Fabrics/OSPF.pm
new file mode 100644
index 000000000000..bb32e785aaff
--- /dev/null
+++ b/src/PVE/API2/Network/SDN/Fabrics/OSPF.pm
@@ -0,0 +1,155 @@
+package PVE::API2::Network::SDN::Fabrics::OSPF;
+
+use strict;
+use warnings;
+
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::Tools qw(extract_param $IPV4RE);
+
+use PVE::API2::Network::SDN::Fabrics::Common;
+use PVE::API2::Network::SDN::Fabrics::OSPFNode;
+
+use PVE::RESTHandler;
+use base qw(PVE::RESTHandler);
+
+# either a 32-bit unsigned integer or an IP address
+sub parse_ospf_area {
+ my ($id, $noerr) = @_;
+
+ if ($id =~ m/\d+/) {
+ if ($id < 0 || $id > 4294967295) {
+ return undef if $noerr;
+ die "$id is a number, but outside of the valid 32-bit unsigned integer range";
+ }
+ } elsif ($id !~ m/^$IPV4RE$/) {
+ return undef if $noerr;
+ die "$id is not a valid IPv4 address nor a number";
+ }
+
+ return $id;
+}
+
+PVE::JSONSchema::register_format('pve-sdn-fabric-ospf-area', \&parse_ospf_area);
+
+my $update_fabric_properties = {
+ digest => get_standard_option('pve-config-digest'),
+ area => {
+ type => 'string',
+ description => 'OSPF Area (either a 32-bit unsigned integer or IPv4 address)',
+ format => 'pve-sdn-fabric-ospf-area',
+ },
+};
+
+our $fabric_properties = {
+ fabric_id => get_standard_option('pve-sdn-fabric-id'),
+ loopback_prefix => get_standard_option('pve-sdn-fabric-loopback-prefix'),
+ %$update_fabric_properties,
+};
+
+__PACKAGE__->register_method ({
+ subclass => "PVE::API2::Network::SDN::Fabrics::OSPFNode",
+ path => '{fabric_id}/node',
+});
+
+__PACKAGE__->register_method({
+ name => 'get_fabric',
+ path => '{fabric_id}',
+ method => 'GET',
+ description => 'Get the configuration for an OSPF fabric',
+ permissions => {
+ check => ['perm', '/sdn/fabrics/ospf/{fabric_id}', [ 'SDN.Audit', 'SDN.Allocate' ], any => 1],
+ },
+ parameters => {
+ properties => {
+ fabric_id => get_standard_option('pve-sdn-fabric-id'),
+ },
+ },
+ returns => {
+ type => 'object',
+ properties => $fabric_properties,
+ },
+ code => sub {
+ my ($param) = @_;
+
+ return PVE::API2::Network::SDN::Fabrics::Common::get_fabric("ospf", $param);
+ },
+});
+
+__PACKAGE__->register_method({
+ name => 'add_fabric',
+ path => '/',
+ method => 'POST',
+ description => 'Add an OSPF fabric',
+ protected => 1,
+ permissions => {
+ check => ['perm', '/sdn/fabrics/ospf', [ 'SDN.Allocate' ]],
+ },
+ parameters => {
+ properties => $fabric_properties,
+ },
+ returns => {
+ type => 'null',
+ },
+ code => sub {
+ my ($param) = @_;
+
+ PVE::Network::SDN::lock_sdn_config(
+ sub {
+ PVE::API2::Network::SDN::Fabrics::Common::add_fabric("ospf", $param);
+ }, "add sdn fabric failed");
+ },
+});
+
+__PACKAGE__->register_method({
+ name => 'update_fabric',
+ path => '{fabric_id}',
+ method => 'PUT',
+ description => 'Update a OSPF fabric',
+ protected => 1,
+ permissions => {
+ check => ['perm', '/sdn/fabrics/ospf/{fabric_id}', [ 'SDN.Allocate' ]],
+ },
+ parameters => {
+ properties => $update_fabric_properties,
+ },
+ returns => {
+ type => 'null',
+ },
+ code => sub {
+ my ($param) = @_;
+
+ PVE::Network::SDN::lock_sdn_config(
+ sub {
+ PVE::API2::Network::SDN::Fabrics::Common::edit_fabric("ospf", $param);
+ }, "edit sdn fabric failed");
+ },
+});
+
+__PACKAGE__->register_method({
+ name => 'delete_fabric',
+ path => '{fabric_id}',
+ method => 'DELETE',
+ description => 'Delete a OSPF fabric',
+ protected => 1,
+ permissions => {
+ check => ['perm', '/sdn/fabrics/ospf/{fabric_id}', [ 'SDN.Allocate' ]],
+ },
+ parameters => {
+ properties => {
+ fabric_id => get_standard_option('pve-sdn-fabric-id'),
+ },
+ },
+ returns => {
+ type => 'null',
+ },
+ code => sub {
+ my ($param) = @_;
+
+ PVE::Network::SDN::lock_sdn_config(
+ sub {
+ PVE::API2::Network::SDN::Fabrics::Common::delete_fabric("ospf", $param);
+ }, "delete sdn fabric failed");
+ },
+});
+
+1;
--
2.39.5
More information about the pve-devel
mailing list