[pve-devel] [PATCH pve-network v2 14/19] api: openfabric: add node endpoints
Gabriel Goller
g.goller at proxmox.com
Fri Apr 4 18:28:50 CEST 2025
From: Stefan Hanreich <s.hanreich at proxmox.com>
Add CRUD endpoints for manipulating OpenFabric nodes. They are
implemented in proxmox-perl-rs.
Signed-off-by: Stefan Hanreich <s.hanreich at proxmox.com>
Signed-off-by: Gabriel Goller <g.goller at proxmox.com>
---
src/PVE/API2/Network/SDN/Fabrics/Makefile | 2 +-
.../Network/SDN/Fabrics/OpenFabricNode.pm | 181 ++++++++++++++++++
2 files changed, 182 insertions(+), 1 deletion(-)
create mode 100644 src/PVE/API2/Network/SDN/Fabrics/OpenFabricNode.pm
diff --git a/src/PVE/API2/Network/SDN/Fabrics/Makefile b/src/PVE/API2/Network/SDN/Fabrics/Makefile
index 9caae13ad963..af733ad013fd 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
+SOURCES=Common.pm OpenFabric.pm OpenFabricNode.pm
PERL5DIR=${DESTDIR}/usr/share/perl5
diff --git a/src/PVE/API2/Network/SDN/Fabrics/OpenFabricNode.pm b/src/PVE/API2/Network/SDN/Fabrics/OpenFabricNode.pm
new file mode 100644
index 000000000000..5e4d4befe7ab
--- /dev/null
+++ b/src/PVE/API2/Network/SDN/Fabrics/OpenFabricNode.pm
@@ -0,0 +1,181 @@
+package PVE::API2::Network::SDN::Fabrics::OpenFabricNode;
+
+use strict;
+use warnings;
+
+use PVE::JSONSchema qw(get_standard_option);
+
+use PVE::API2::Network::SDN::Fabrics::Common;
+
+use PVE::RESTHandler;
+use base qw(PVE::RESTHandler);
+
+our $hello_interval_option = {
+ type => 'number',
+ description => 'The hello_interval property of the interface',
+ optional => 1,
+ minimum => 1,
+ maximum => 600,
+};
+
+my $interface_properties = {
+ name => {
+ type => 'string',
+ format => 'pve-iface',
+ description => 'Name of the network interface',
+ },
+ ip => {
+ type => 'string',
+ format => 'CIDRv4',
+ description => 'The IPv4 address of the interface',
+ optional => 1,
+ },
+ ipv6 => {
+ type => 'string',
+ format => 'CIDRv6',
+ description => 'The IPv6 address of the interface',
+ optional => 1,
+ },
+ passive => {
+ type => 'boolean',
+ description => 'The passive property of the interface',
+ optional => 1,
+ },
+ hello_interval => $hello_interval_option,
+ csnp_interval => {
+ type => 'number',
+ description => 'The csnp_interval property of the interface',
+ optional => 1,
+ minimum => 1,
+ maximum => 600,
+ },
+ hello_multiplier => {
+ type => 'number',
+ description => 'The hello_multiplier property of the interface',
+ optional => 1,
+ minimum => 2,
+ maximum => 600,
+ },
+};
+
+my $node_properties = {
+ digest => get_standard_option('pve-config-digest'),
+ fabric_id => get_standard_option('pve-sdn-fabric-id'),
+ node_id => get_standard_option('pve-sdn-fabric-node-id'),
+ router_id => {
+ type => 'string',
+ format => 'ip',
+ description => 'The Router-ID of this node (will be converted to a real NET later)',
+ },
+ interfaces => {
+ type => 'array',
+ optional => 1,
+ description => 'List of interfaces on this node that are part of the fabric.',
+ items => {
+ type => 'string',
+ description => 'OpenFabric interface configuration.',
+ format => $interface_properties,
+ },
+ },
+};
+
+__PACKAGE__->register_method({
+ name => 'get_node',
+ path => '{node_id}',
+ method => 'GET',
+ description => 'Get the configuration for a node in an OpenFabric fabric',
+ permissions => {
+ check => ['perm', '/sdn/fabrics/openfabric/{fabric_id}', [ 'SDN.Audit', 'SDN.Allocate' ], any => 1],
+ },
+ parameters => {
+ properties => {
+ fabric_id => get_standard_option('pve-sdn-fabric-id'),
+ node_id => get_standard_option('pve-sdn-fabric-node-id'),
+ },
+ },
+ returns => {
+ type => 'object',
+ properties => $node_properties,
+ },
+ code => sub {
+ my ($param) = @_;
+
+ return PVE::API2::Network::SDN::Fabrics::Common::get_node("openfabric", $param);
+ },
+});
+
+__PACKAGE__->register_method({
+ name => 'add_node',
+ path => '/',
+ method => 'POST',
+ description => 'Add a node to an OpenFabric fabric',
+ protected => 1,
+ permissions => {
+ check => ['perm', '/sdn/fabrics/openfabric/{fabric_id}', [ 'SDN.Allocate' ]],
+ },
+ parameters => {
+ properties => $node_properties,
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ PVE::Network::SDN::lock_sdn_config(
+ sub {
+ PVE::API2::Network::SDN::Fabrics::Common::add_node("openfabric", $param);
+ }, "add sdn fabric node failed");
+ },
+});
+
+__PACKAGE__->register_method({
+ name => 'update_node',
+ path => '{node_id}',
+ method => 'PUT',
+ description => 'Update a node in an OpenFabric fabric',
+ protected => 1,
+ permissions => {
+ check => ['perm', '/sdn/fabrics/openfabric/{fabric_id}', [ 'SDN.Allocate' ]],
+ },
+ parameters => {
+ properties => $node_properties,
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+
+ PVE::Network::SDN::lock_sdn_config(
+ sub {
+ PVE::API2::Network::SDN::Fabrics::Common::edit_node("openfabric", $param);
+ }, "edit sdn fabric node failed");
+ },
+});
+
+__PACKAGE__->register_method({
+ name => 'delete_node',
+ path => '{node_id}',
+ method => 'DELETE',
+ description => 'Delete a node from an OpenFabric fabric',
+ protected => 1,
+ permissions => {
+ check => ['perm', '/sdn/fabrics/openfabric/{fabric_id}', [ 'SDN.Allocate' ]],
+ },
+ parameters => {
+ properties => {
+ fabric_id => get_standard_option('pve-sdn-fabric-id'),
+ node_id => get_standard_option('pve-sdn-fabric-node-id'),
+ },
+ },
+ returns => {
+ type => 'null',
+ },
+ code => sub {
+ my ($param) = @_;
+
+ PVE::Network::SDN::lock_sdn_config(
+ sub {
+ PVE::API2::Network::SDN::Fabrics::Common::delete_node("openfabric", $param);
+ }, "delete sdn fabric node failed");
+ },
+});
+
+1;
--
2.39.5
More information about the pve-devel
mailing list