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 922D21FF183 for ; Wed, 2 Jul 2025 16:52:38 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BA7BD1E9C1; Wed, 2 Jul 2025 16:51:39 +0200 (CEST) From: Gabriel Goller To: pve-devel@lists.proxmox.com Date: Wed, 2 Jul 2025 16:50:33 +0200 Message-Id: <20250702145101.894299-49-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.018 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 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 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" From: Stefan Hanreich 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 | 219 +++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) diff --git a/src/PVE/Network/SDN/Fabrics.pm b/src/PVE/Network/SDN/Fabrics.pm index 5ef4606710f8..796d14978cfe 100644 --- a/src/PVE/Network/SDN/Fabrics.pm +++ b/src/PVE/Network/SDN/Fabrics.pm @@ -8,6 +8,47 @@ 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, \&write_fabrics_config, ); @@ -79,4 +120,182 @@ 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