summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Hanreich <s.hanreich@proxmox.com>2025-07-16 15:08:11 +0200
committerThomas Lamprecht <t.lamprecht@proxmox.com>2025-07-17 00:10:45 +0200
commitfeaf9363e03e2bed4c8b233ecdbc123db5ebefa4 (patch)
treeedca443f180579998cff26ab8475fd1a3282f187 /src
parentc570570f38accb2c11065a92891c3c73a76923d4 (diff)
api: fabrics: add node submodule
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@proxmox.com> Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com> Link: https://lore.proxmox.com/20250716130837.585796-51-g.goller@proxmox.com
Diffstat (limited to 'src')
-rw-r--r--src/PVE/API2/Network/SDN/Fabrics.pm8
-rw-r--r--src/PVE/API2/Network/SDN/Fabrics/Makefile2
-rw-r--r--src/PVE/API2/Network/SDN/Fabrics/Node.pm106
3 files changed, 114 insertions, 2 deletions
diff --git a/src/PVE/API2/Network/SDN/Fabrics.pm b/src/PVE/API2/Network/SDN/Fabrics.pm
index 18e51a9..5644fbe 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);
@@ -19,6 +20,11 @@ __PACKAGE__->register_method({
});
__PACKAGE__->register_method({
+ subclass => "PVE::API2::Network::SDN::Fabrics::Node",
+ path => 'node',
+});
+
+__PACKAGE__->register_method({
name => 'index',
path => '',
method => 'GET',
@@ -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 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..785e1ec
--- /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;