[pve-devel] [PATCH pve-network v4 16/21] api: fabrics: add node submodule

Gabriel Goller g.goller at proxmox.com
Wed Jul 2 16:50:36 CEST 2025


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

The GET endpoint lists all nodes from all fabrics - for listing the
nodes of a specific fabric or editing nodes another submodule will be
introduced below the node submodule in a future commit.

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

diff --git a/src/PVE/API2/Network/SDN/Fabrics.pm b/src/PVE/API2/Network/SDN/Fabrics.pm
index 18e51a9d471e..5644fbee0fff 100644
--- a/src/PVE/API2/Network/SDN/Fabrics.pm
+++ b/src/PVE/API2/Network/SDN/Fabrics.pm
@@ -9,6 +9,7 @@ use PVE::Network::SDN;
 use PVE::Network::SDN::Fabrics;
 
 use PVE::API2::Network::SDN::Fabrics::Fabric;
+use PVE::API2::Network::SDN::Fabrics::Node;
 
 use PVE::RESTHandler;
 use base qw(PVE::RESTHandler);
@@ -18,6 +19,11 @@ __PACKAGE__->register_method({
     path => 'fabric',
 });
 
+__PACKAGE__->register_method({
+    subclass => "PVE::API2::Network::SDN::Fabrics::Node",
+    path => 'node',
+});
+
 __PACKAGE__->register_method({
     name => 'index',
     path => '',
@@ -43,7 +49,7 @@ __PACKAGE__->register_method({
         my ($param) = @_;
 
         my $res = [
-            { subdir => 'fabric' }, { subdir => 'all' },
+            { subdir => 'fabric' }, { subdir => 'node' }, { subdir => 'all' },
         ];
 
         return $res;
diff --git a/src/PVE/API2/Network/SDN/Fabrics/Makefile b/src/PVE/API2/Network/SDN/Fabrics/Makefile
index bd644f76888e..169ebbed8897 100644
--- a/src/PVE/API2/Network/SDN/Fabrics/Makefile
+++ b/src/PVE/API2/Network/SDN/Fabrics/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Fabric.pm
+SOURCES=Fabric.pm Node.pm
 
 
 PERL5DIR=${DESTDIR}/usr/share/perl5
diff --git a/src/PVE/API2/Network/SDN/Fabrics/Node.pm b/src/PVE/API2/Network/SDN/Fabrics/Node.pm
new file mode 100644
index 000000000000..785e1ec9fbcb
--- /dev/null
+++ b/src/PVE/API2/Network/SDN/Fabrics/Node.pm
@@ -0,0 +1,106 @@
+package PVE::API2::Network::SDN::Fabrics::Node;
+
+use strict;
+use warnings;
+
+use PVE::Tools qw(extract_param);
+
+use PVE::Network::SDN;
+use PVE::Network::SDN::Fabrics;
+
+use PVE::JSONSchema qw(get_standard_option);
+
+use PVE::RESTHandler;
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+    name => 'list_nodes',
+    path => '',
+    method => 'GET',
+    permissions => {
+        description =>
+            "Only list nodes where you have 'SDN.Audit' or 'SDN.Allocate' permissions on\n"
+            . "'/sdn/fabrics/<fabric>' and 'Sys.Audit' or 'Sys.Modify' on /nodes/<node_id>",
+        user => 'all',
+    },
+    description => "SDN Fabrics Index",
+    parameters => {
+        properties => {
+            running => {
+                type => 'boolean',
+                optional => 1,
+                description => "Display running config.",
+            },
+            pending => {
+                type => 'boolean',
+                optional => 1,
+                description => "Display pending config.",
+            },
+        },
+    },
+    returns => {
+        type => 'array',
+        items => {
+            type => "object",
+            properties => PVE::Network::SDN::Fabrics::node_properties(0),
+        },
+        links => [{ rel => 'child', href => "{fabric_id}" }],
+    },
+    code => sub {
+        my ($param) = @_;
+
+        my $pending = extract_param($param, 'pending');
+        my $running = extract_param($param, 'running');
+
+        my $digest;
+        my $nodes;
+
+        if ($pending) {
+            my $current_config = PVE::Network::SDN::Fabrics::config();
+            my $running_config = PVE::Network::SDN::Fabrics::config(1);
+
+            my $running_nodes = $running_config->list_nodes();
+
+            my $current_nodes = $current_config->list_nodes();
+
+            my $pending_nodes = PVE::Network::SDN::pending_config(
+                { nodes => { ids => $running_nodes } },
+                { ids => $current_nodes },
+                'nodes',
+            );
+
+            $digest = $current_config->digest();
+            $nodes = $pending_nodes->{ids};
+        } elsif ($running) {
+            $nodes = PVE::Network::SDN::Fabrics::config(1)->list_nodes();
+        } else {
+            my $current_config = PVE::Network::SDN::Fabrics::config();
+
+            $digest = $current_config->digest();
+            $nodes = $current_config->list_nodes();
+        }
+
+        my $rpcenv = PVE::RPCEnvironment::get();
+        my $authuser = $rpcenv->get_user();
+        my $fabric_privs = ['SDN.Audit', 'SDN.Allocate'];
+        my $node_privs = ['Sys.Audit', 'Sys.Modify'];
+
+        my @res;
+
+        for my $node_id (keys %$nodes) {
+            my $node = $nodes->{$node_id};
+            my $fabric_id = $node->{fabric_id};
+
+            next if !$rpcenv->check_any($authuser, "/sdn/fabrics/$fabric_id", $fabric_privs, 1);
+            next if !$rpcenv->check_any($authuser, "/nodes/$node_id", $node_privs, 1);
+
+            $node->{digest} = $digest if $digest;
+
+            push @res, $node;
+        }
+
+        return \@res;
+    },
+});
+
+1;
-- 
2.39.5





More information about the pve-devel mailing list