[pve-devel] [RFC pve-network 6/9] vnets: rename del|add|update_cidr to ip
Alexandre Derumier
aderumier at odiso.com
Mon Nov 13 11:04:16 CET 2023
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
src/PVE/Network/SDN/Subnets.pm | 4 +---
src/PVE/Network/SDN/Vnets.pm | 27 ++++++++++++---------------
2 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm
index b2125a1..905ec77 100644
--- a/src/PVE/Network/SDN/Subnets.pm
+++ b/src/PVE/Network/SDN/Subnets.pm
@@ -93,14 +93,12 @@ sub get_subnet {
}
sub find_ip_subnet {
- my ($ip, $mask, $subnets) = @_;
+ my ($ip, $subnets) = @_;
my $subnet = undef;
my $subnetid = undef;
foreach my $id (sort keys %{$subnets}) {
-
- next if $mask ne $subnets->{$id}->{mask};
my $cidr = $subnets->{$id}->{cidr};
my $subnet_matcher = subnet_matcher($cidr);
next if !$subnet_matcher->($ip);
diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm
index 9ba1a1e..2f42da6 100644
--- a/src/PVE/Network/SDN/Vnets.pm
+++ b/src/PVE/Network/SDN/Vnets.pm
@@ -80,18 +80,15 @@ sub get_subnets {
return $subnets;
}
-sub get_subnet_from_vnet_cidr {
- my ($vnetid, $cidr) = @_;
+sub get_subnet_from_vnet_ip {
+ my ($vnetid, $ip) = @_;
my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid, 1);
my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid);
my $zoneid = $vnet->{zone};
my $zone = PVE::Network::SDN::Zones::get_zone($zoneid);
- my ($ip, $mask) = split(/\//, $cidr);
- die "ip address is not in cidr format" if !$mask;
-
- my ($subnetid, $subnet) = PVE::Network::SDN::Subnets::find_ip_subnet($ip, $mask, $subnets);
+ my ($subnetid, $subnet) = PVE::Network::SDN::Subnets::find_ip_subnet($ip, $subnets);
return ($zone, $subnetid, $subnet, $ip);
}
@@ -128,30 +125,30 @@ sub add_next_free_cidr {
}
}
-sub add_cidr {
- my ($vnetid, $cidr, $hostname, $mac, $description, $skipdns) = @_;
+sub add_ip {
+ my ($vnetid, $ip, $hostname, $mac, $description, $skipdns) = @_;
return if !$vnetid;
- my ($zone, $subnetid, $subnet, $ip) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_cidr($vnetid, $cidr);
+ my ($zone, $subnetid, $subnet) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_ip($vnetid, $ip);
PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description, undef, $skipdns);
}
-sub update_cidr {
- my ($vnetid, $cidr, $hostname, $oldhostname, $mac, $description, $skipdns) = @_;
+sub update_ip {
+ my ($vnetid, $ip, $hostname, $oldhostname, $mac, $description, $skipdns) = @_;
return if !$vnetid;
- my ($zone, $subnetid, $subnet, $ip) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_cidr($vnetid, $cidr);
+ my ($zone, $subnetid, $subnet) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_ip($vnetid, $ip);
PVE::Network::SDN::Subnets::update_ip($zone, $subnetid, $subnet, $ip, $hostname, $oldhostname, $mac, $description, $skipdns);
}
-sub del_cidr {
- my ($vnetid, $cidr, $hostname, $skipdns) = @_;
+sub del_ip {
+ my ($vnetid, $ip, $hostname, $skipdns) = @_;
return if !$vnetid;
- my ($zone, $subnetid, $subnet, $ip) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_cidr($vnetid, $cidr);
+ my ($zone, $subnetid, $subnet) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_ip($vnetid, $ip);
PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip, $hostname, $skipdns);
}
--
2.39.2
More information about the pve-devel
mailing list