public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-network] vnet/subnet : add skipdns option
Date: Mon, 12 Jul 2021 00:48:33 +0200	[thread overview]
Message-ID: <20210711224833.66035-1-aderumier@odiso.com> (raw)

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




             reply	other threads:[~2021-07-11 22:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-11 22:48 Alexandre Derumier [this message]
2021-07-13  4:41 ` Thomas Lamprecht
2021-07-13  6:17   ` alexandre derumier
2021-07-13  6:56     ` alexandre derumier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210711224833.66035-1-aderumier@odiso.com \
    --to=aderumier@odiso.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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