public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-network] vnet/subnet : add skipdns option
@ 2021-07-11 22:48 Alexandre Derumier
  2021-07-13  4:41 ` Thomas Lamprecht
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Derumier @ 2021-07-11 22:48 UTC (permalink / raw)
  To: pve-devel

allow to register ip to ipam without dns registration.
can be used for temp/pending ip for example

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 PVE/Network/SDN/Subnets.pm | 70 ++++++++++++++++++++++----------------
 PVE/Network/SDN/Vnets.pm   | 16 ++++-----
 2 files changed, 49 insertions(+), 37 deletions(-)

diff --git a/PVE/Network/SDN/Subnets.pm b/PVE/Network/SDN/Subnets.pm
index 0231822..6bb42e5 100644
--- a/PVE/Network/SDN/Subnets.pm
+++ b/PVE/Network/SDN/Subnets.pm
@@ -184,7 +184,7 @@ sub del_subnet {
 }
 
 sub next_free_ip {
-    my ($zone, $subnetid, $subnet, $hostname, $mac, $description) = @_;
+    my ($zone, $subnetid, $subnet, $hostname, $mac, $description, $skipdns) = @_;
 
     my $cidr = undef;
     my $ip = undef;
@@ -199,7 +199,7 @@ sub next_free_ip {
     $hostname .= ".$dnszoneprefix" if $dnszoneprefix;
 
     #verify dns zones before ipam
-    verify_dns_zone($dnszone, $dns);
+    verify_dns_zone($dnszone, $dns) if !$skipdns;
 
     if($ipamid) {
 	my $ipam_cfg = PVE::Network::SDN::Ipams::config();
@@ -215,10 +215,12 @@ sub next_free_ip {
     eval {
 	my $reversednszone = get_reversedns_zone($subnetid, $subnet, $reversedns, $ip);
 
-	#add dns
-	add_dns_record($dnszone, $dns, $hostname, $ip);
-	#add reverse dns
-	add_dns_ptr_record($reversednszone, $dnszone, $reversedns, $hostname, $ip);
+	if(!$skipdns) {
+	    #add dns
+	    add_dns_record($dnszone, $dns, $hostname, $ip);
+	    #add reverse dns
+	    add_dns_ptr_record($reversednszone, $dnszone, $reversedns, $hostname, $ip);
+	}
     };
     if ($@) {
 	#rollback
@@ -232,7 +234,7 @@ sub next_free_ip {
 }
 
 sub add_ip {
-    my ($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_;
+    my ($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway, $skipdns) = @_;
 
     return if !$subnet || !$ip; 
 
@@ -249,8 +251,10 @@ sub add_ip {
     $hostname .= ".$dnszoneprefix" if $dnszoneprefix;
 
     #verify dns zones before ipam
-    verify_dns_zone($dnszone, $dns);
-    verify_dns_zone($reversednszone, $reversedns);
+    if(!$skipdns) {
+	verify_dns_zone($dnszone, $dns);
+	verify_dns_zone($reversednszone, $reversedns);
+    }
 
     if ($ipamid) {
 
@@ -265,10 +269,12 @@ sub add_ip {
     }
 
     eval {
-	#add dns
-	add_dns_record($dnszone, $dns, $hostname, $ip);
-	#add reverse dns
-	add_dns_ptr_record($reversednszone, $dnszone, $reversedns, $hostname, $ip);
+	if(!$skipdns) {
+	    #add dns
+	    add_dns_record($dnszone, $dns, $hostname, $ip);
+	    #add reverse dns
+	    add_dns_ptr_record($reversednszone, $dnszone, $reversedns, $hostname, $ip);
+	}
     };
     if ($@) {
 	#rollback
@@ -281,7 +287,7 @@ sub add_ip {
 }
 
 sub update_ip {
-    my ($zone, $subnetid, $subnet, $ip, $hostname, $oldhostname, $mac, $description) = @_;
+    my ($zone, $subnetid, $subnet, $ip, $hostname, $oldhostname, $mac, $description, $skipdns) = @_;
 
     return if !$subnet || !$ip; 
 
@@ -298,8 +304,10 @@ sub update_ip {
     $hostname .= ".$dnszoneprefix" if $dnszoneprefix;
 
     #verify dns zones before ipam
-    verify_dns_zone($dnszone, $dns);
-    verify_dns_zone($reversednszone, $reversedns);
+    if(!$skipdns) {
+	verify_dns_zone($dnszone, $dns);
+	verify_dns_zone($reversednszone, $reversedns);
+    }
 
     if ($ipamid) {
 	my $ipam_cfg = PVE::Network::SDN::Ipams::config();
@@ -314,18 +322,19 @@ sub update_ip {
     return if $hostname eq $oldhostname;
 
     eval {
-	#add dns
-	
-	del_dns_record($dnszone, $dns, $oldhostname, $ip);
-	add_dns_record($dnszone, $dns, $hostname, $ip);
-	#add reverse dns
-	del_dns_ptr_record($reversednszone, $reversedns, $ip);
-	add_dns_ptr_record($reversednszone, $dnszone, $reversedns, $hostname, $ip);
+	if(!$skipdns) {
+	    #add dns
+	    del_dns_record($dnszone, $dns, $oldhostname, $ip);
+	    add_dns_record($dnszone, $dns, $hostname, $ip);
+	    #add reverse dns
+	    del_dns_ptr_record($reversednszone, $reversedns, $ip);
+	    add_dns_ptr_record($reversednszone, $dnszone, $reversedns, $hostname, $ip);
+	}
     };
 }
 
 sub del_ip {
-    my ($zone, $subnetid, $subnet, $ip, $hostname) = @_;
+    my ($zone, $subnetid, $subnet, $ip, $hostname, $skipdns) = @_;
 
     return if !$subnet || !$ip;
 
@@ -340,9 +349,10 @@ sub del_ip {
     my $dnszoneprefix = $subnet->{dnszoneprefix};
     $hostname .= ".$dnszoneprefix" if $dnszoneprefix;
 
-
-    verify_dns_zone($dnszone, $dns);
-    verify_dns_zone($reversednszone, $reversedns);
+    if(!$skipdns) {
+	verify_dns_zone($dnszone, $dns);
+	verify_dns_zone($reversednszone, $reversedns);
+    }
 
     if ($ipamid) {
 	my $ipam_cfg = PVE::Network::SDN::Ipams::config();
@@ -352,8 +362,10 @@ sub del_ip {
     }
 
     eval {
-	del_dns_record($dnszone, $dns, $hostname, $ip);
-	del_dns_ptr_record($reversednszone, $reversedns, $ip);
+	if(!$skipdns) {
+	    del_dns_record($dnszone, $dns, $hostname, $ip);
+	    del_dns_ptr_record($reversednszone, $reversedns, $ip);
+	}
     };
     if ($@) {
 	warn $@;
diff --git a/PVE/Network/SDN/Vnets.pm b/PVE/Network/SDN/Vnets.pm
index 86967a3..caa6bfc 100644
--- a/PVE/Network/SDN/Vnets.pm
+++ b/PVE/Network/SDN/Vnets.pm
@@ -100,7 +100,7 @@ sub get_subnet_from_vnet_cidr {
 }
 
 sub get_next_free_cidr {
-    my ($vnetid, $hostname, $mac, $description, $ipversion) = @_;
+    my ($vnetid, $hostname, $mac, $description, $ipversion, $skipdns) = @_;
 
     my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid);
     my $zoneid = $vnet->{zone};
@@ -121,7 +121,7 @@ sub get_next_free_cidr {
 	$subnetcount++;
 
 	eval {
-	    $ip = PVE::Network::SDN::Subnets::next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $description);
+	    $ip = PVE::Network::SDN::Subnets::next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $description, $skipdns);
 	};
 	warn $@ if $@;
 	last if $ip;
@@ -132,30 +132,30 @@ sub get_next_free_cidr {
 }
 
 sub add_cidr {
-    my ($vnetid, $cidr, $hostname, $mac, $description) = @_;
+    my ($vnetid, $cidr, $hostname, $mac, $description, $skipdns) = @_;
 
     return if !$vnetid;
     
     my ($zone, $subnetid, $subnet, $ip) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_cidr($vnetid, $cidr);
-    PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description);
+    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) = @_;
+    my ($vnetid, $cidr, $hostname, $oldhostname, $mac, $description, $skipdns) = @_;
 
     return if !$vnetid;
 
     my ($zone, $subnetid, $subnet, $ip) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_cidr($vnetid, $cidr);
-    PVE::Network::SDN::Subnets::update_ip($zone, $subnetid, $subnet, $ip, $hostname, $oldhostname, $mac, $description);
+    PVE::Network::SDN::Subnets::update_ip($zone, $subnetid, $subnet, $ip, $hostname, $oldhostname, $mac, $description, $skipdns);
 }
 
 sub del_cidr {
-    my ($vnetid, $cidr, $hostname) = @_;
+    my ($vnetid, $cidr, $hostname, $skipdns) = @_;
 
     return if !$vnetid;
 
     my ($zone, $subnetid, $subnet, $ip) = PVE::Network::SDN::Vnets::get_subnet_from_vnet_cidr($vnetid, $cidr);
-    PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip, $hostname);
+    PVE::Network::SDN::Subnets::del_ip($zone, $subnetid, $subnet, $ip, $hostname, $skipdns);
 }
 
 
-- 
2.30.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-13  6:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-11 22:48 [pve-devel] [PATCH pve-network] vnet/subnet : add skipdns option Alexandre Derumier
2021-07-13  4:41 ` Thomas Lamprecht
2021-07-13  6:17   ` alexandre derumier
2021-07-13  6:56     ` alexandre derumier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal