From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 076CF1FF183 for ; Wed, 2 Jul 2025 16:52:48 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0DA781EA07; Wed, 2 Jul 2025 16:51:41 +0200 (CEST) From: Gabriel Goller To: pve-devel@lists.proxmox.com Date: Wed, 2 Jul 2025 16:50:36 +0200 Message-Id: <20250702145101.894299-52-g.goller@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250702145101.894299-1-g.goller@proxmox.com> References: <20250702145101.894299-1-g.goller@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.168 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH pve-network v4 16/21] api: fabrics: add node submodule X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" From: Stefan Hanreich 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 Signed-off-by: Stefan Hanreich --- 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/' and 'Sys.Audit' or 'Sys.Modify' on /nodes/", + 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 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel