From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 96FD81FF165 for ; Thu, 22 May 2025 18:20:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CC272A703; Thu, 22 May 2025 18:18:04 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Thu, 22 May 2025 18:17:02 +0200 Message-Id: <20250522161731.537011-47-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250522161731.537011-1-s.hanreich@proxmox.com> References: <20250522161731.537011-1-s.hanreich@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.224 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 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pve-devel] [PATCH pve-network v3 13/21] fabrics: add jsonschema for fabrics and nodes 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" Provide a JSONSchema for the new two entity types, fabric and node. While both are stored in the same configuration file, there are two separate API submodules for fabrics and nodes, so we need to separate the schema definitions as well. The schemas are equivalent to the API types defined in Rust. In the future it should be possible to generate the JSONSchema directly from those types, but for now we have to duplicate the schema here. Co-authored-by: Gabriel Goller Signed-off-by: Stefan Hanreich --- src/PVE/Network/SDN/Fabrics.pm | 206 +++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) diff --git a/src/PVE/Network/SDN/Fabrics.pm b/src/PVE/Network/SDN/Fabrics.pm index 3ac01cd..4d499ce 100644 --- a/src/PVE/Network/SDN/Fabrics.pm +++ b/src/PVE/Network/SDN/Fabrics.pm @@ -8,6 +8,35 @@ use PVE::JSONSchema qw(get_standard_option); use PVE::INotify; use PVE::RS::SDN::Fabrics; +PVE::JSONSchema::register_format('pve-sdn-fabric-id', sub { + my ($id, $noerr) = @_; + + if ($id !~ m/^[a-zA-Z0-9][a-zA-Z0-9-]{0,6}[a-zA-Z0-9]?$/i) { + return undef if $noerr; + die "Fabric ID '$id' contains illegal characters\n"; + } + + return $id; +}); + +PVE::JSONSchema::register_standard_option('pve-sdn-fabric-id', { + description => "Identifier for SDN fabrics", + type => 'string', + format => 'pve-sdn-fabric-id', +}); + +PVE::JSONSchema::register_standard_option('pve-sdn-fabric-node-id', { + description => "Identifier for nodes in an SDN fabric", + type => 'string', + format => 'pve-node', +}); + +PVE::JSONSchema::register_standard_option('pve-sdn-fabric-protocol', { + description => "Type of configuration entry in an SDN Fabric section config", + type => 'string', + enum => ['openfabric', 'ospf'], +}); + cfs_register_file( 'sdn/fabrics.cfg', \&parse_fabrics_config, @@ -81,4 +110,181 @@ sub generate_etc_network_config { return $fabric_config->get_interfaces_etc_network_config($nodename); } +sub node_properties { + my ($update) = @_; + + my $properties = { + fabric_id => get_standard_option('pve-sdn-fabric-id'), + node_id => get_standard_option('pve-sdn-fabric-node-id'), + protocol => get_standard_option('pve-sdn-fabric-protocol'), + digest => get_standard_option('pve-config-digest'), + ip => { + type => 'string', + format => 'ipv4', + description => 'IPv4 address for this node', + optional => 1, + }, + ip6 => { + type => 'string', + format => 'ipv6', + description => 'IPv6 address for this node', + optional => 1, + }, + interfaces => { + # coerce this value into an array before parsing (oneOf workaround) + type => 'array', + 'type-property' => 'protocol', + oneOf => [ + { + type => 'array', + 'instance-types' => ['openfabric'], + items => { + type => 'string', + format => { + name => { + type => 'string', + format => 'pve-iface', + description => 'Name of the network interface', + }, + hello_multiplier => { + type => 'integer', + description => 'The hello_multiplier property of the interface', + optional => 1, + minimum => 2, + maximum => 100, + }, + ip => { + type => 'string', + format => 'CIDRv4', + description => 'IPv4 address for this node', + optional => 1, + }, + ip6 => { + type => 'string', + format => 'CIDRv6', + description => 'IPv6 address for this node', + optional => 1, + }, + }, + }, + description => 'OpenFabric network interface', + optional => 1, + }, + { + type => 'array', + 'instance-types' => ['ospf'], + items => { + type => 'string', + format => { + name => { + type => 'string', + format => 'pve-iface', + description => 'Name of the network interface', + }, + ip => { + type => 'string', + format => 'CIDRv4', + description => 'IPv4 address for this node', + optional => 1, + }, + }, + }, + description => 'OSPF network interface', + optional => 1, + }, + ] + } + }; + + if ($update) { + $properties->{delete} = { + type => 'array', + items => { + type => 'string', + enum => ['interfaces', 'ip', 'ip6'], + }, + optional => 1, + } + } + + return $properties; +} + +sub fabric_properties { + my ($update) = @_; + + my $properties = { + id => get_standard_option('pve-sdn-fabric-id'), + protocol => get_standard_option('pve-sdn-fabric-protocol'), + digest => get_standard_option('pve-config-digest'), + ip_prefix => { + type => 'string', + format => 'CIDR', + description => 'The IP prefix for Node IPs', + optional => 1, + }, + ip6_prefix => { + type => 'string', + format => 'CIDR', + description => 'The IP prefix for Node IPs', + optional => 1, + }, + hello_interval => { + type => 'number', + 'type-property' => 'protocol', + 'instance-types' => ['openfabric'], + description => 'The hello_interval property for Openfabric', + optional => 1, + minimum => 1, + maximum => 600, + }, + csnp_interval => { + type => 'number', + 'type-property' => 'protocol', + 'instance-types' => ['openfabric'], + description => 'The csnp_interval property for Openfabric', + optional => 1, + minimum => 1, + maximum => 600, + }, + area => { + type => 'string', + 'type-property' => 'protocol', + 'instance-types' => ['ospf'], + description => 'OSPF area. Either a IPv4 address or a 32-bit number. Gets validated in rust.', + optional => 1, + }, + }; + + if ($update) { + $properties->{delete} = { + # coerce this value into an array before parsing (oneOf workaround) + type => 'array', + 'type-property' => 'protocol', + oneOf => [ + { + type => 'array', + 'instance-types' => ['openfabric'], + items => { + type => 'string', + enum => ['hello_interval', 'csnp_interval'], + }, + optional => 1, + }, + { + type => 'array', + 'instance-types' => ['ospf'], + items => { + type => 'string', + enum => ['area'], + }, + optional => 1, + }, + ] + } + } + + return $properties; +} + 1; -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel