--- Begin Message ---
this is needed in order to not accidentally use another
subnet or IP which might be in another namespace.
Signed-off-by: lou lecrivain <lou.lecriv...@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 40 +++++++++++++--------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index 3d60265..f69119e 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -52,7 +52,7 @@ sub add_subnet {
my $namespace = $plugin_config->{namespace};
my $headers = default_headers($plugin_config);
- my $internalid = get_prefix_id($url, $cidr, $headers, $noerr);
+ my $internalid = get_prefix_id($plugin_config, $cidr, $noerr);
#create subnet if it doesn't already exists
if (!$internalid) {
@@ -74,7 +74,7 @@ sub del_subnet {
my $url = $plugin_config->{url};
my $headers = default_headers($plugin_config);
- my $internalid = get_prefix_id($url, $cidr, $headers, $noerr);
+ my $internalid = get_prefix_id($plugin_config, $cidr, $noerr);
return if !$internalid;
if (!subnet_is_deletable($class, $plugin_config, $subnetid, $subnet,
$internalid, $noerr)) {
@@ -115,7 +115,7 @@ sub add_ip {
if ($@) {
if($is_gateway) {
- die "error adding subnet ip to ipam: ip $ip already exists: $@" if
!$noerr && !is_ip_gateway($url, $ip, $headers, $noerr);
+ die "error adding subnet ip to ipam: ip $ip already exists: $@" if
!$noerr && !is_ip_gateway($plugin_config, $ip, $noerr);
} else {
die "error adding subnet ip to ipam: ip $ip already exists: $@" if
!$noerr;
}
@@ -131,7 +131,7 @@ sub add_next_freeip {
my $namespace = $plugin_config->{namespace};
my $headers = default_headers($plugin_config);
- my $internalid = get_prefix_id($url, $cidr, $headers, $noerr);
+ my $internalid = get_prefix_id($plugin_config, $cidr, $noerr);
die "cannot find prefix $cidr in Nautobot" if !$internalid;
my $description = "mac:$mac" if $mac;
@@ -160,7 +160,7 @@ sub add_range_next_freeip {
# ranges are not supported natively in nautobot, hence why we have to get
a little hacky.
my $minimal_size = NetAddr::IP->new($range->{'start-address'}) -
NetAddr::IP->new($cidr);
- my $internalid = get_prefix_id($url, $cidr, $headers, $noerr);
+ my $internalid = get_prefix_id($plugin_config, $cidr, $noerr);
my $ip = eval {
my $result = PVE::Network::SDN::api_request("GET",
"$url/ipam/prefixes/$internalid/available-ips/?limit=$minimal_size", $headers);
@@ -201,7 +201,7 @@ sub update_ip {
my $params = { address => "$ip/$mask", type => "dhcp", dns_name =>
$hostname, description => $description, namespace => $namespace, status =>
default_ip_status()};
- my $ip_id = get_ip_id($url, $ip, $headers, $noerr);
+ my $ip_id = get_ip_id($plugin_config, $ip, $noerr);
die "can't find ip $ip in ipam" if !$noerr && !$ip_id;
eval {
@@ -221,7 +221,7 @@ sub del_ip {
my $url = $plugin_config->{url};
my $headers = default_headers($plugin_config);
- my $ip_id = get_ip_id($url, $ip, $headers, $noerr);
+ my $ip_id = get_ip_id($plugin_config, $ip, $noerr);
die "can't find ip $ip in ipam" if !$ip_id && !$noerr;
eval {
@@ -274,7 +274,7 @@ sub subnet_is_deletable {
} elsif (
!(all {$_ == 1} (
map {
- is_ip_gateway($url, $_->{host}, $headers, $noerr)
+ is_ip_gateway($plugin_config, $_->{host}, $noerr)
} $response->{results}->@*
))) {
# some remaining IPs are not gateway, nok
@@ -342,10 +342,14 @@ sub get_ips_within_range {
}
sub get_ip_id {
- my ($url, $ip, $headers, $noerr) = @_;
+ my ($plugin_config, $ip, $noerr) = @_;
+
+ my $url = $plugin_config->{url};
+ my $namespace = $plugin_config->{namespace};
+ my $headers = default_headers($plugin_config);
my $result = eval {
- return PVE::Network::SDN::api_request("GET",
"$url/ipam/ip-addresses/?q=$ip", $headers);
+ return PVE::Network::SDN::api_request("GET",
"$url/ipam/ip-addresses/?q=$ip&namespace=$namespace", $headers);
};
if ($@) {
die "error while querying for ip $ip id: $@" if !$noerr;
@@ -357,10 +361,14 @@ sub get_ip_id {
}
sub get_prefix_id {
- my ($url, $cidr, $headers, $noerr) = @_;
+ my ($plugin_config, $cidr, $noerr) = @_;
+
+ my $url = $plugin_config->{url};
+ my $namespace = $plugin_config->{namespace};
+ my $headers = default_headers($plugin_config);
my $result = eval {
- return PVE::Network::SDN::api_request("GET",
"$url/ipam/prefixes/?q=$cidr", $headers);
+ return PVE::Network::SDN::api_request("GET",
"$url/ipam/prefixes/?q=$cidr&namespace=$namespace", $headers);
};
if ($@) {
die "error while querying for cidr $cidr prefix id: $@" if !$noerr;
@@ -402,10 +410,14 @@ sub get_status_id {
}
sub is_ip_gateway {
- my ($url, $ip, $headers, $noerr) = @_;
+ my ($plugin_config, $ip, $noerr) = @_;
+
+ my $url = $plugin_config->{url};
+ my $namespace = $plugin_config->{namespace};
+ my $headers = default_headers($plugin_config);
my $result = eval {
- return PVE::Network::SDN::api_request("GET",
"$url/ipam/ip-addresses/?q=$ip", $headers);
+ return PVE::Network::SDN::api_request("GET",
"$url/ipam/ip-addresses/?q=$ip&namespace=$namespace", $headers);
};
if ($@) {
die "error while checking if $ip is a gateway" if !$noerr;
--
2.39.5
--- End Message ---