From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C529C9A389 for ; Fri, 17 Nov 2023 12:40:49 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9DD5B30AB4 for ; Fri, 17 Nov 2023 12:40:19 +0100 (CET) Received: from lana.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP for ; Fri, 17 Nov 2023 12:40:18 +0100 (CET) Received: by lana.proxmox.com (Postfix, from userid 10043) id 0F6B62C20F4; Fri, 17 Nov 2023 12:40:18 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Fri, 17 Nov 2023 12:39:40 +0100 Message-Id: <20231117114011.834002-3-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231117114011.834002-1-s.hanreich@proxmox.com> References: <20231117114011.834002-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.511 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 T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [subnets.pm, vnets.pm, zones.pm] Subject: [pve-devel] [PATCH v4 pve-network 02/33] sdn: preparations for DHCP plugin 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: , X-List-Received-Date: Fri, 17 Nov 2023 11:40:49 -0000 Add the option to retrieve the running configuration instead of only the pending configuration via the config methods. Refactor methods using the running config to utilize the new parameter. Add helper methods and return additional attributes from the getter functions that are needed by the dhcp plugins. Signed-off-by: Stefan Hanreich --- src/PVE/Network/SDN/Subnets.pm | 25 +++++++++++++------------ src/PVE/Network/SDN/Vnets.pm | 27 +++++++++++++-------------- src/PVE/Network/SDN/Zones.pm | 34 +++++++++++++++++++++++++--------- 3 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm index 6bb42e5..f654d3a 100644 --- a/src/PVE/Network/SDN/Subnets.pm +++ b/src/PVE/Network/SDN/Subnets.pm @@ -23,7 +23,9 @@ sub sdn_subnets_config { my $scfg = $cfg->{ids}->{$id}; die "sdn subnet '$id' does not exist\n" if (!$noerr && !$scfg); - if($scfg) { + if ($scfg) { + $scfg->{id} = $id; + my ($zone, $network, $mask) = split(/-/, $id); $scfg->{cidr} = "$network/$mask"; $scfg->{zone} = $zone; @@ -35,7 +37,14 @@ sub sdn_subnets_config { } sub config { - my $config = cfs_read_file("sdn/subnets.cfg"); + my ($running) = @_; + + if ($running) { + my $cfg = PVE::Network::SDN::running_config(); + return $cfg->{subnets}; + } + + return cfs_read_file("sdn/subnets.cfg"); } sub write_config { @@ -61,16 +70,8 @@ sub complete_sdn_subnet { sub get_subnet { my ($subnetid, $running) = @_; - my $cfg = {}; - if($running) { - my $cfg = PVE::Network::SDN::running_config(); - $cfg = $cfg->{subnets}; - } else { - $cfg = PVE::Network::SDN::Subnets::config(); - } - - my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $subnetid, 1); - return $subnet; + my $cfg = PVE::Network::SDN::Subnets::config($running); + return PVE::Network::SDN::Subnets::sdn_subnets_config($cfg, $subnetid, 1); } sub find_ip_subnet { diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm index 1106c9f..39bdda0 100644 --- a/src/PVE/Network/SDN/Vnets.pm +++ b/src/PVE/Network/SDN/Vnets.pm @@ -26,6 +26,13 @@ sub sdn_vnets_config { } sub config { + my ($running) = @_; + + if ($running) { + my $cfg = PVE::Network::SDN::running_config(); + return $cfg->{vnets}; + } + return cfs_read_file("sdn/vnets.cfg"); } @@ -54,31 +61,23 @@ sub get_vnet { return if !$vnetid; - my $scfg = {}; - if($running) { - my $cfg = PVE::Network::SDN::running_config(); - $scfg = $cfg->{vnets}; - } else { - $scfg = PVE::Network::SDN::Vnets::config(); - } - - my $vnet = PVE::Network::SDN::Vnets::sdn_vnets_config($scfg, $vnetid, 1); - - return $vnet; + my $cfg = PVE::Network::SDN::Vnets::config($running); + return PVE::Network::SDN::Vnets::sdn_vnets_config($cfg, $vnetid, 1); } sub get_subnets { - my ($vnetid) = @_; + my ($vnetid, $running) = @_; my $subnets = undef; - my $subnets_cfg = PVE::Network::SDN::Subnets::config(); + my $subnets_cfg = PVE::Network::SDN::Subnets::config($running); + foreach my $subnetid (sort keys %{$subnets_cfg->{ids}}) { my $subnet = PVE::Network::SDN::Subnets::sdn_subnets_config($subnets_cfg, $subnetid); next if !$subnet->{vnet} || ($vnetid && $subnet->{vnet} ne $vnetid); $subnets->{$subnetid} = $subnet; } - return $subnets; + return $subnets; } sub get_subnet_from_vnet_cidr { diff --git a/src/PVE/Network/SDN/Zones.pm b/src/PVE/Network/SDN/Zones.pm index 4ad4e4d..5bd3536 100644 --- a/src/PVE/Network/SDN/Zones.pm +++ b/src/PVE/Network/SDN/Zones.pm @@ -40,8 +40,14 @@ sub sdn_zones_config { } sub config { - my $config = cfs_read_file("sdn/zones.cfg"); - return $config; + my ($running) = @_; + + if ($running) { + my $cfg = PVE::Network::SDN::running_config(); + return $cfg->{zones}; + } + + return cfs_read_file("sdn/zones.cfg"); } sub get_plugin_config { @@ -74,19 +80,29 @@ sub complete_sdn_zone { sub get_zone { my ($zoneid, $running) = @_; - my $cfg = {}; - if($running) { - my $cfg = PVE::Network::SDN::running_config(); - $cfg = $cfg->{vnets}; - } else { - $cfg = PVE::Network::SDN::Zones::config(); - } + my $cfg = PVE::Network::SDN::Zones::config($running); my $zone = PVE::Network::SDN::Zones::sdn_zones_config($cfg, $zoneid, 1); return $zone; } +sub get_vnets { + my ($zoneid, $running) = @_; + + return if !$zoneid; + + my $vnets_config = PVE::Network::SDN::Vnets::config($running); + my $vnets = undef; + + for my $vnetid (keys %{$vnets_config->{ids}}) { + my $vnet = PVE::Network::SDN::Vnets::sdn_vnets_config($vnets_config, $vnetid); + next if !$vnet->{zone} || $vnet->{zone} ne $zoneid; + $vnets->{$vnetid} = $vnet; + } + + return $vnets; +} sub generate_etc_network_config { -- 2.39.2