[pve-devel] [PATCH pve-network v3 16/21] api: fabrics: add node submodule
Stefan Hanreich
s.hanreich at proxmox.com
Thu May 22 18:17:05 CEST 2025
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 | 7 ++
src/PVE/API2/Network/SDN/Fabrics/Makefile | 2 +-
src/PVE/API2/Network/SDN/Fabrics/Node.pm | 107 ++++++++++++++++++++++
3 files changed, 115 insertions(+), 1 deletion(-)
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 4ec9b79..dd50aab 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 => '',
@@ -44,6 +50,7 @@ __PACKAGE__->register_method ({
my $res = [
{ subdir => 'fabric' },
+ { subdir => 'node' },
{ subdir => 'all' },
];
diff --git a/src/PVE/API2/Network/SDN/Fabrics/Makefile b/src/PVE/API2/Network/SDN/Fabrics/Makefile
index bd644f7..169ebbe 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 0000000..958d387
--- /dev/null
+++ b/src/PVE/API2/Network/SDN/Fabrics/Node.pm
@@ -0,0 +1,107 @@
+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