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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 58F0C9B384 for ; Tue, 17 Oct 2023 15:55:12 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 43E2E34327 for ; Tue, 17 Oct 2023 15:55:12 +0200 (CEST) Received: from lana.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP for ; Tue, 17 Oct 2023 15:55:10 +0200 (CEST) Received: by lana.proxmox.com (Postfix, from userid 10043) id DA7FD2C211F; Tue, 17 Oct 2023 15:55:09 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Tue, 17 Oct 2023 15:54:59 +0200 Message-Id: <20231017135507.2220948-3-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231017135507.2220948-1-s.hanreich@proxmox.com> References: <20231017135507.2220948-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.488 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 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] Subject: [pve-devel] [WIP v2 pve-network 02/10] subnets: vnets: preparations for DHCP plugins 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: Tue, 17 Oct 2023 13:55:12 -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. Additionally include the id for subnets, since it is needed later by some of the DHCP plugins. Signed-off-by: Stefan Hanreich --- src/PVE/Network/SDN/Subnets.pm | 25 +++++++++++++------------ src/PVE/Network/SDN/Vnets.pm | 27 +++++++++++++-------------- 2 files changed, 26 insertions(+), 26 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 { -- 2.39.2