* [pve-devel] SPAM: [PATCH pve-network 01/16] ipam: nautobot support initial commit
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 02/16] ipam: add Nautobot plugin sources to Makefile Lou Lecrivain via pve-devel
` (14 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 6101 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 01/16] ipam: nautobot support initial commit
Date: Wed, 27 Nov 2024 17:17:48 +0100
Message-ID: <20241127161803.8866-2-lou.lecrivain@wdz.de>
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/API2/Network/SDN/Ipams.pm | 1 +
src/PVE/Network/SDN/Ipams.pm | 3 ++
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 37 +++++++++++++++++++++
3 files changed, 41 insertions(+)
create mode 100644 src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
diff --git a/src/PVE/API2/Network/SDN/Ipams.pm b/src/PVE/API2/Network/SDN/Ipams.pm
index 27ead02..8074512 100644
--- a/src/PVE/API2/Network/SDN/Ipams.pm
+++ b/src/PVE/API2/Network/SDN/Ipams.pm
@@ -12,6 +12,7 @@ use PVE::Network::SDN::Ipams::Plugin;
use PVE::Network::SDN::Ipams::PVEPlugin;
use PVE::Network::SDN::Ipams::PhpIpamPlugin;
use PVE::Network::SDN::Ipams::NetboxPlugin;
+use PVE::Network::SDN::Ipams::NautobotPlugin;
use PVE::Network::SDN::Dhcp;
use PVE::Network::SDN::Vnets;
use PVE::Network::SDN::Zones;
diff --git a/src/PVE/Network/SDN/Ipams.pm b/src/PVE/Network/SDN/Ipams.pm
index c689b8f..2ecb75e 100644
--- a/src/PVE/Network/SDN/Ipams.pm
+++ b/src/PVE/Network/SDN/Ipams.pm
@@ -12,11 +12,14 @@ use PVE::Network;
use PVE::Network::SDN::Ipams::PVEPlugin;
use PVE::Network::SDN::Ipams::NetboxPlugin;
+use PVE::Network::SDN::Ipams::NautobotPlugin;
use PVE::Network::SDN::Ipams::PhpIpamPlugin;
use PVE::Network::SDN::Ipams::Plugin;
+
PVE::Network::SDN::Ipams::PVEPlugin->register();
PVE::Network::SDN::Ipams::NetboxPlugin->register();
+PVE::Network::SDN::Ipams::NautobotPlugin->register();
PVE::Network::SDN::Ipams::PhpIpamPlugin->register();
PVE::Network::SDN::Ipams::Plugin->init();
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
new file mode 100644
index 0000000..03bd3de
--- /dev/null
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -0,0 +1,37 @@
+package PVE::Network::SDN::Ipams::NautobotPlugin;
+
+use strict;
+use warnings;
+use PVE::INotify;
+use PVE::Cluster;
+use PVE::Tools;
+
+use base('PVE::Network::SDN::Ipams::NetboxPlugin');
+
+sub type {
+ return 'nautobot';
+}
+
+sub verify_api {
+ my ($class, $plugin_config) = @_;
+
+ my $url = $plugin_config->{url};
+ my $token = $plugin_config->{token};
+ my $headers = [ 'Authorization' => "token $token", 'Accept' => "application/json; indent=4" ];
+
+ eval {
+ PVE::Network::SDN::api_request("GET", "$url/ipam/namespaces", $headers);
+ };
+ if ($@) {
+ die "Can't connect to nautobot api: $@";
+ }
+}
+
+# helpers
+sub on_update_hook {
+ my ($class, $plugin_config) = @_;
+
+ PVE::Network::SDN::Ipams::NautobotPlugin::verify_api($class, $plugin_config);
+}
+
+1;
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 02/16] ipam: add Nautobot plugin sources to Makefile
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 01/16] ipam: nautobot support initial commit Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 03/16] ipam: change verify URL (now common to Nautobot and Netbox) Lou Lecrivain via pve-devel
` (13 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 4072 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 02/16] ipam: add Nautobot plugin sources to Makefile
Date: Wed, 27 Nov 2024 17:17:49 +0100
Message-ID: <20241127161803.8866-3-lou.lecrivain@wdz.de>
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/PVE/Network/SDN/Ipams/Makefile b/src/PVE/Network/SDN/Ipams/Makefile
index 4e7d65f..75e5b9a 100644
--- a/src/PVE/Network/SDN/Ipams/Makefile
+++ b/src/PVE/Network/SDN/Ipams/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Plugin.pm PhpIpamPlugin.pm NetboxPlugin.pm PVEPlugin.pm
+SOURCES=Plugin.pm PhpIpamPlugin.pm NetboxPlugin.pm PVEPlugin.pm NautobotPlugin.pm
PERL5DIR=${DESTDIR}/usr/share/perl5
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 03/16] ipam: change verify URL (now common to Nautobot and Netbox)
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 01/16] ipam: nautobot support initial commit Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 02/16] ipam: add Nautobot plugin sources to Makefile Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 04/16] ipam: nautobot: add verification for ipam namespace plugin parameter Lou Lecrivain via pve-devel
` (12 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 5148 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 03/16] ipam: change verify URL (now common to Nautobot and Netbox)
Date: Wed, 27 Nov 2024 17:17:50 +0100
Message-ID: <20241127161803.8866-4-lou.lecrivain@wdz.de>
+ minimal module
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 22 ---------------------
src/PVE/Network/SDN/Ipams/NetboxPlugin.pm | 2 +-
2 files changed, 1 insertion(+), 23 deletions(-)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index 03bd3de..6597bfe 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -12,26 +12,4 @@ sub type {
return 'nautobot';
}
-sub verify_api {
- my ($class, $plugin_config) = @_;
-
- my $url = $plugin_config->{url};
- my $token = $plugin_config->{token};
- my $headers = [ 'Authorization' => "token $token", 'Accept' => "application/json; indent=4" ];
-
- eval {
- PVE::Network::SDN::api_request("GET", "$url/ipam/namespaces", $headers);
- };
- if ($@) {
- die "Can't connect to nautobot api: $@";
- }
-}
-
-# helpers
-sub on_update_hook {
- my ($class, $plugin_config) = @_;
-
- PVE::Network::SDN::Ipams::NautobotPlugin::verify_api($class, $plugin_config);
-}
-
1;
diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index d923269..7efccaf 100644
--- a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
@@ -240,7 +240,7 @@ sub verify_api {
eval {
- PVE::Network::SDN::api_request("GET", "$url/ipam/aggregates/", $headers);
+ PVE::Network::SDN::api_request("GET", "$url/ipam/prefixes/", $headers);
};
if ($@) {
die "Can't connect to netbox api: $@";
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 04/16] ipam: nautobot: add verification for ipam namespace plugin parameter
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (2 preceding siblings ...)
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 03/16] ipam: change verify URL (now common to Nautobot and Netbox) Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 05/16] ipam: nautobot: fix on_update_hook for NautobotPlugin Lou Lecrivain via pve-devel
` (11 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 5134 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 04/16] ipam: nautobot: add verification for ipam namespace plugin parameter
Date: Wed, 27 Nov 2024 17:17:51 +0100
Message-ID: <20241127161803.8866-5-lou.lecrivain@wdz.de>
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 45 +++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index 6597bfe..ebdc07b 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -12,4 +12,49 @@ sub type {
return 'nautobot';
}
+sub properties {
+ return {
+ namespace => {
+ type => 'string',
+ },
+ };
+}
+
+sub options {
+ return {
+ url => { optional => 0 },
+ token => { optional => 0 },
+ namespace => { optional => 0 },
+ };
+}
+
+# implem
+sub verify_api {
+ my ($class, $plugin_config) = @_;
+
+ my $url = $plugin_config->{url};
+ my $token = $plugin_config->{token};
+ my $namespace = $plugin_config->{namespace};
+ my $headers = [ 'Authorization' => "token $token", 'Accept' => "application/json; indent=4" ];
+
+ # check that the namespace exists AND that we have
+ # indeed API access
+ eval {
+ PVE::Network::SDN::Ipams::NautobotPlugin::get_namespace_id($url, $namespace, $headers) // die "namespace $namespace does not exist";
+ };
+ if ($@) {
+ die "Can't connect to nautobot api: $@";
+ }
+}
+
+# helpers
+sub get_namespace_id {
+ my ($url, $namespace, $headers) = @_;
+
+ my $result = PVE::Network::SDN::api_request("GET", "$url/ipam/namespaces/?q=$namespace", $headers);
+ my $data = @{$result->{results}}[0];
+ my $internalid = $data->{id};
+ return $internalid;
+}
+
1;
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 05/16] ipam: nautobot: fix on_update_hook for NautobotPlugin
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (3 preceding siblings ...)
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 04/16] ipam: nautobot: add verification for ipam namespace plugin parameter Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 06/16] ipam: nautobot: add default active status check Lou Lecrivain via pve-devel
` (10 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 4192 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 05/16] ipam: nautobot: fix on_update_hook for NautobotPlugin
Date: Wed, 27 Nov 2024 17:17:52 +0100
Message-ID: <20241127161803.8866-6-lou.lecrivain@wdz.de>
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index ebdc07b..083ab20 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -47,6 +47,12 @@ sub verify_api {
}
}
+sub on_update_hook {
+ my ($class, $plugin_config) = @_;
+
+ PVE::Network::SDN::Ipams::NautobotPlugin::verify_api($class, $plugin_config);
+}
+
# helpers
sub get_namespace_id {
my ($url, $namespace, $headers) = @_;
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 06/16] ipam: nautobot: add default active status check
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (4 preceding siblings ...)
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 05/16] ipam: nautobot: fix on_update_hook for NautobotPlugin Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 07/16] ipam: nautobot: fix typo Lou Lecrivain via pve-devel
` (9 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 5266 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 06/16] ipam: nautobot: add default active status check
Date: Wed, 27 Nov 2024 17:17:53 +0100
Message-ID: <20241127161803.8866-7-lou.lecrivain@wdz.de>
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index 083ab20..53190bc 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -28,7 +28,12 @@ sub options {
};
}
+sub default_ip_status {
+ return 'Active';
+}
+
# implem
+
sub verify_api {
my ($class, $plugin_config) = @_;
@@ -37,13 +42,14 @@ sub verify_api {
my $namespace = $plugin_config->{namespace};
my $headers = [ 'Authorization' => "token $token", 'Accept' => "application/json; indent=4" ];
- # check that the namespace exists AND that we have
- # indeed API access
+ # check that the namespace exists AND that default IP active status
+ # exists AND that we have indeed API access
eval {
PVE::Network::SDN::Ipams::NautobotPlugin::get_namespace_id($url, $namespace, $headers) // die "namespace $namespace does not exist";
+ PVE::Network::SDN::Ipams::NautobotPlugin::get_status_id($url, default_ip_status(), $headers) // die "default IP status ". default_ip_status() . " not found";
};
if ($@) {
- die "Can't connect to nautobot api: $@";
+ die "Can't use nautobot api: $@";
}
}
@@ -63,4 +69,13 @@ sub get_namespace_id {
return $internalid;
}
+sub get_status_id {
+ my ($url, $status, $headers) = @_;
+
+ my $result = PVE::Network::SDN::api_request("GET", "$url/extra/statuses/?q=$status", $headers);
+ my $data = @{$result->{results}}[0];
+ my $internalid = $data->{id};
+ return $internalid;
+}
+
1;
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 07/16] ipam: nautobot: fix typo
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (5 preceding siblings ...)
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 06/16] ipam: nautobot: add default active status check Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 08/16] ipam: nautobot: 1st working "add subnet" and "add ip" Lou Lecrivain via pve-devel
` (8 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 4300 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 07/16] ipam: nautobot: fix typo
Date: Wed, 27 Nov 2024 17:17:54 +0100
Message-ID: <20241127161803.8866-8-lou.lecrivain@wdz.de>
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index 53190bc..ee0ad49 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -72,7 +72,7 @@ sub get_namespace_id {
sub get_status_id {
my ($url, $status, $headers) = @_;
- my $result = PVE::Network::SDN::api_request("GET", "$url/extra/statuses/?q=$status", $headers);
+ my $result = PVE::Network::SDN::api_request("GET", "$url/extras/statuses/?q=$status", $headers);
my $data = @{$result->{results}}[0];
my $internalid = $data->{id};
return $internalid;
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 08/16] ipam: nautobot: 1st working "add subnet" and "add ip"
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (6 preceding siblings ...)
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 07/16] ipam: nautobot: fix typo Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 09/16] ipam: nautobot: simplify query Lou Lecrivain via pve-devel
` (7 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 7430 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 08/16] ipam: nautobot: 1st working "add subnet" and "add ip"
Date: Wed, 27 Nov 2024 17:17:55 +0100
Message-ID: <20241127161803.8866-9-lou.lecrivain@wdz.de>
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 69 ++++++++++++++++++++-
1 file changed, 66 insertions(+), 3 deletions(-)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index ee0ad49..6675ba4 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -34,19 +34,82 @@ sub default_ip_status {
# implem
+sub add_subnet {
+ my ($class, $plugin_config, $subnetid, $subnet, $noerr) = @_;
+
+ my $cidr = $subnet->{cidr};
+ my $gateway = $subnet->{gateway};
+ my $url = $plugin_config->{url};
+ my $token = $plugin_config->{token};
+ my $namespace = $plugin_config->{namespace};
+ my $headers = ['Content-Type' => "application/json", 'Authorization' => "token $token", 'Accept' => "application/json"];
+
+ my $internalid = PVE::Network::SDN::Ipams::NetboxPlugin::get_prefix_id($url, $cidr, $headers);
+
+ #create subnet
+ if (!$internalid) {
+ my $namespace_id = get_namespace_id($url, $namespace, $headers);
+ my $status_id = get_status_id($url, default_ip_status(), $headers);
+
+ my $params = { prefix => $cidr, namespace => { id => $namespace_id}, status => { id => $status_id}};
+
+ eval {
+ my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/prefixes/", $headers, $params);
+ };
+ if ($@) {
+ die "error adding subnet to ipam: $@" if !$noerr;
+ }
+ }
+}
+
+sub add_ip {
+ my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $vmid, $is_gateway, $noerr) = @_;
+
+ my $mask = $subnet->{mask};
+ my $url = $plugin_config->{url};
+ my $token = $plugin_config->{token};
+ my $namespace = $plugin_config->{namespace};
+ my $headers = ['Content-Type' => "application/json", 'Authorization' => "token $token", 'Accept' => "application/json"];
+
+ my $namespace_id = get_namespace_id($url, $namespace, $headers);
+ my $status_id = get_status_id($url, default_ip_status(), $headers);
+
+ my $description = undef;
+ if ($is_gateway) {
+ $description = 'gateway'
+ } elsif ($mac) {
+ $description = "mac:$mac";
+ }
+
+ my $params = { address => "$ip/$mask", type => "dhcp", dns_name => $hostname, description => $description, namespace => { id => $namespace_id }, status => { id => $status_id }};
+
+ eval {
+ PVE::Network::SDN::api_request("POST", "$url/ipam/ip-addresses/", $headers, $params);
+ };
+
+ if ($@) {
+ if($is_gateway) {
+ die "error adding subnet ip to ipam: ip $ip already exists: $@" if !PVE::Network::SDN::Ipams::NetboxPlugin::is_ip_gateway($url, $ip, $headers) && !$noerr;
+ } else {
+ die "error adding subnet ip to ipam: ip $ip already exists: $@" if !$noerr;
+ }
+ }
+}
+
+
sub verify_api {
my ($class, $plugin_config) = @_;
my $url = $plugin_config->{url};
my $token = $plugin_config->{token};
my $namespace = $plugin_config->{namespace};
- my $headers = [ 'Authorization' => "token $token", 'Accept' => "application/json; indent=4" ];
+ my $headers = ['Content-Type' => "application/json", 'Authorization' => "token $token", 'Accept' => "application/json"];
# check that the namespace exists AND that default IP active status
# exists AND that we have indeed API access
eval {
- PVE::Network::SDN::Ipams::NautobotPlugin::get_namespace_id($url, $namespace, $headers) // die "namespace $namespace does not exist";
- PVE::Network::SDN::Ipams::NautobotPlugin::get_status_id($url, default_ip_status(), $headers) // die "default IP status ". default_ip_status() . " not found";
+ get_namespace_id($url, $namespace, $headers) // die "namespace $namespace does not exist";
+ get_status_id($url, default_ip_status(), $headers) // die "default IP status ". default_ip_status() . " not found";
};
if ($@) {
die "Can't use nautobot api: $@";
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 09/16] ipam: nautobot: simplify query
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (7 preceding siblings ...)
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 08/16] ipam: nautobot: 1st working "add subnet" and "add ip" Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 10/16] ipam: nautobot: api endpoint change no longer needed Lou Lecrivain via pve-devel
` (6 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 5430 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 09/16] ipam: nautobot: simplify query
Date: Wed, 27 Nov 2024 17:17:56 +0100
Message-ID: <20241127161803.8866-10-lou.lecrivain@wdz.de>
Nautobot can infer object IDs itself
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index 6675ba4..c6581f9 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -48,10 +48,7 @@ sub add_subnet {
#create subnet
if (!$internalid) {
- my $namespace_id = get_namespace_id($url, $namespace, $headers);
- my $status_id = get_status_id($url, default_ip_status(), $headers);
-
- my $params = { prefix => $cidr, namespace => { id => $namespace_id}, status => { id => $status_id}};
+ my $params = { prefix => $cidr, namespace => $namespace, status => default_ip_status()};
eval {
my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/prefixes/", $headers, $params);
@@ -71,9 +68,6 @@ sub add_ip {
my $namespace = $plugin_config->{namespace};
my $headers = ['Content-Type' => "application/json", 'Authorization' => "token $token", 'Accept' => "application/json"];
- my $namespace_id = get_namespace_id($url, $namespace, $headers);
- my $status_id = get_status_id($url, default_ip_status(), $headers);
-
my $description = undef;
if ($is_gateway) {
$description = 'gateway'
@@ -81,7 +75,7 @@ sub add_ip {
$description = "mac:$mac";
}
- my $params = { address => "$ip/$mask", type => "dhcp", dns_name => $hostname, description => $description, namespace => { id => $namespace_id }, status => { id => $status_id }};
+ my $params = { address => "$ip/$mask", type => "dhcp", dns_name => $hostname, description => $description, namespace => $namespace, status => default_ip_status()};
eval {
PVE::Network::SDN::api_request("POST", "$url/ipam/ip-addresses/", $headers, $params);
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 10/16] ipam: nautobot: api endpoint change no longer needed
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (8 preceding siblings ...)
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 09/16] ipam: nautobot: simplify query Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 11/16] ipam: nautobot: add update_ip sub Lou Lecrivain via pve-devel
` (5 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 4177 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 10/16] ipam: nautobot: api endpoint change no longer needed
Date: Wed, 27 Nov 2024 17:17:57 +0100
Message-ID: <20241127161803.8866-11-lou.lecrivain@wdz.de>
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NetboxPlugin.pm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index 7efccaf..d923269 100644
--- a/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NetboxPlugin.pm
@@ -240,7 +240,7 @@ sub verify_api {
eval {
- PVE::Network::SDN::api_request("GET", "$url/ipam/prefixes/", $headers);
+ PVE::Network::SDN::api_request("GET", "$url/ipam/aggregates/", $headers);
};
if ($@) {
die "Can't connect to netbox api: $@";
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 11/16] ipam: nautobot: add update_ip sub
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (9 preceding siblings ...)
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 10/16] ipam: nautobot: api endpoint change no longer needed Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 12/16] ipam: nautobot: add get ips for mac function Lou Lecrivain via pve-devel
` (4 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 6720 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 11/16] ipam: nautobot: add update_ip sub
Date: Wed, 27 Nov 2024 17:17:58 +0100
Message-ID: <20241127161803.8866-12-lou.lecrivain@wdz.de>
+ use default_headers to avoid code repetition
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 45 ++++++++++++++++++---
1 file changed, 39 insertions(+), 6 deletions(-)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index c6581f9..e328c9f 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -32,6 +32,13 @@ sub default_ip_status {
return 'Active';
}
+sub default_headers {
+ my ($plugin_config) = @_;
+ my $token = $plugin_config->{token};
+
+ return ['Content-Type' => "application/json", 'Authorization' => "token $token", 'Accept' => "application/json"];
+}
+
# implem
sub add_subnet {
@@ -40,9 +47,8 @@ sub add_subnet {
my $cidr = $subnet->{cidr};
my $gateway = $subnet->{gateway};
my $url = $plugin_config->{url};
- my $token = $plugin_config->{token};
my $namespace = $plugin_config->{namespace};
- my $headers = ['Content-Type' => "application/json", 'Authorization' => "token $token", 'Accept' => "application/json"];
+ my $headers = default_headers($plugin_config);
my $internalid = PVE::Network::SDN::Ipams::NetboxPlugin::get_prefix_id($url, $cidr, $headers);
@@ -64,9 +70,8 @@ sub add_ip {
my $mask = $subnet->{mask};
my $url = $plugin_config->{url};
- my $token = $plugin_config->{token};
my $namespace = $plugin_config->{namespace};
- my $headers = ['Content-Type' => "application/json", 'Authorization' => "token $token", 'Accept' => "application/json"];
+ my $headers = default_headers($plugin_config);
my $description = undef;
if ($is_gateway) {
@@ -91,13 +96,41 @@ sub add_ip {
}
+sub update_ip {
+ my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $vmid, $is_gateway, $noerr) = @_;
+
+ my $mask = $subnet->{mask};
+ my $url = $plugin_config->{url};
+ my $namespace = $plugin_config->{namespace};
+ my $headers = default_headers($plugin_config);
+
+ my $description = undef;
+ if ($is_gateway) {
+ $description = 'gateway'
+ } elsif ($mac) {
+ $description = "mac:$mac";
+ }
+
+ my $params = { address => "$ip/$mask", type => "dhcp", dns_name => $hostname, description => $description, namespace => $namespace, status => default_ip_status()};
+
+ my $ip_id = PVE::Network::SDN::Ipams::NetboxPlugin::get_ip_id($url, $ip, $headers);
+ die "can't find ip $ip in ipam" if !$ip_id;
+
+ eval {
+ PVE::Network::SDN::api_request("PATCH", "$url/ipam/ip-addresses/$ip_id/", $headers, $params);
+ };
+ if ($@) {
+ die "error updating ip $ip: $@" if !$noerr;
+ }
+}
+
+
sub verify_api {
my ($class, $plugin_config) = @_;
my $url = $plugin_config->{url};
- my $token = $plugin_config->{token};
my $namespace = $plugin_config->{namespace};
- my $headers = ['Content-Type' => "application/json", 'Authorization' => "token $token", 'Accept' => "application/json"];
+ my $headers = default_headers($plugin_config);
# check that the namespace exists AND that default IP active status
# exists AND that we have indeed API access
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 12/16] ipam: nautobot: add get ips for mac function
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (10 preceding siblings ...)
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 11/16] ipam: nautobot: add update_ip sub Lou Lecrivain via pve-devel
@ 2024-11-27 16:17 ` Lou Lecrivain via pve-devel
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 13/16] ipam: nautobot: 1st draft for allocating ip in dhcp range Lou Lecrivain via pve-devel
` (3 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:17 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 4673 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 12/16] ipam: nautobot: add get ips for mac function
Date: Wed, 27 Nov 2024 17:17:59 +0100
Message-ID: <20241127161803.8866-13-lou.lecrivain@wdz.de>
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 24 +++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index e328c9f..69e7897 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -143,6 +143,30 @@ sub verify_api {
}
}
+sub get_ips_from_mac {
+ my ($class, $plugin_config, $mac, $zoneid) = @_;
+
+ my $url = $plugin_config->{url};
+ my $namespace = $plugin_config->{namespace};
+ my $headers = default_headers($plugin_config);
+
+ my $ip4 = undef;
+ my $ip6 = undef;
+
+ my $data = PVE::Network::SDN::api_request("GET", "$url/ipam/ip-addresses/?q=$mac", $headers);
+ for my $ip (@{$data->{results}}) {
+ if ($ip->{ip_version} == 4 && !$ip4) {
+ ($ip4, undef) = split(/\//, $ip->{address});
+ }
+
+ if ($ip->{ip_version} == 6 && !$ip6) {
+ ($ip6, undef) = split(/\//, $ip->{address});
+ }
+ }
+
+ return ($ip4, $ip6);
+}
+
sub on_update_hook {
my ($class, $plugin_config) = @_;
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 13/16] ipam: nautobot: 1st draft for allocating ip in dhcp range
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (11 preceding siblings ...)
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 12/16] ipam: nautobot: add get ips for mac function Lou Lecrivain via pve-devel
@ 2024-11-27 16:18 ` Lou Lecrivain via pve-devel
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 14/16] ipam: nautobot: hacky ip range support Lou Lecrivain via pve-devel
` (2 subsequent siblings)
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:18 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 5329 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 13/16] ipam: nautobot: 1st draft for allocating ip in dhcp range
Date: Wed, 27 Nov 2024 17:18:00 +0100
Message-ID: <20241127161803.8866-14-lou.lecrivain@wdz.de>
offset has to be fixed - we can't guarantee correct start
if IPs outside range have been boked
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 25 +++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index 69e7897..bf9d34a 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -5,6 +5,7 @@ use warnings;
use PVE::INotify;
use PVE::Cluster;
use PVE::Tools;
+use NetAddr::IP;
use base('PVE::Network::SDN::Ipams::NetboxPlugin');
@@ -95,6 +96,30 @@ sub add_ip {
}
}
+sub add_range_next_freeip {
+ my ($class, $plugin_config, $subnet, $range, $data, $noerr) = @_;
+
+ my $url = $plugin_config->{url};
+ my $namespace = $plugin_config->{namespace};
+ my $headers = default_headers($plugin_config);
+ my $cidr = $subnet->{cidr};
+
+ my $range_offset = NetAddr::IP->new($range->{'start-address'}) - NetAddr::IP->new($cidr);
+ my $internalid = PVE::Network::SDN::Ipams::NetboxPlugin::get_prefix_id($url, $cidr, $headers);
+ my $params = { offset => $range_offset };
+
+ eval {
+ my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/prefixes/$internalid/available-ips/", $headers, $params);
+ my ($ip, undef) = split(/\//, @{$result}[0]->{address});
+ print "found free ip $ip in range $range->{'start-address'}-$range->{'end-address'}\n" if $ip;
+ return $ip
+ };
+
+ if ($@) {
+ die "can't find free ip in range $range->{'start-address'}-$range->{'end-address'}: $@" if !$noerr;
+ }
+}
+
sub update_ip {
my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $vmid, $is_gateway, $noerr) = @_;
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 14/16] ipam: nautobot: hacky ip range support
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (12 preceding siblings ...)
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 13/16] ipam: nautobot: 1st draft for allocating ip in dhcp range Lou Lecrivain via pve-devel
@ 2024-11-27 16:18 ` Lou Lecrivain via pve-devel
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 15/16] ipam: nautobot: implement plain prefix allocation (without ranges) Lou Lecrivain via pve-devel
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 16/16] ipam: nautobot: add word of warning for dhcp range support Lou Lecrivain via pve-devel
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:18 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 5864 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 14/16] ipam: nautobot: hacky ip range support
Date: Wed, 27 Nov 2024 17:18:01 +0100
Message-ID: <20241127161803.8866-15-lou.lecrivain@wdz.de>
since nautobot lacks support for IP ranges,
this feature could be dropped / marked unsupported
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 26 ++++++++++++++++-----
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index bf9d34a..95e749c 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -104,15 +104,22 @@ sub add_range_next_freeip {
my $headers = default_headers($plugin_config);
my $cidr = $subnet->{cidr};
- my $range_offset = NetAddr::IP->new($range->{'start-address'}) - NetAddr::IP->new($cidr);
+ my $minimal_size = NetAddr::IP->new($range->{'start-address'}) - NetAddr::IP->new($cidr);
my $internalid = PVE::Network::SDN::Ipams::NetboxPlugin::get_prefix_id($url, $cidr, $headers);
- my $params = { offset => $range_offset };
eval {
- my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/prefixes/$internalid/available-ips/", $headers, $params);
- my ($ip, undef) = split(/\//, @{$result}[0]->{address});
- print "found free ip $ip in range $range->{'start-address'}-$range->{'end-address'}\n" if $ip;
- return $ip
+ my $result = PVE::Network::SDN::api_request("GET", "$url/ipam/prefixes/$internalid/available-ips/?limit=$minimal_size", $headers);
+ # v important for NetAddr::IP comparison!
+ my @ips = map((split(/\//,$_->{address}))[0], @{$result});
+ # get 1st result
+ my $ip = (get_ips_within_range($range->{'start-address'}, $range->{'end-address'}, @ips))[0];
+
+ if ($ip) {
+ print "found free ip $ip in range $range->{'start-address'}-$range->{'end-address'}\n"
+ } else { die "prefix out of space in range"; }
+
+ $class->add_ip($plugin_config, undef, $subnet, $ip, $data->{hostname}, $data->{mac}, undef, 0, 0);
+ return $ip;
};
if ($@) {
@@ -199,6 +206,13 @@ sub on_update_hook {
}
# helpers
+sub get_ips_within_range {
+ my ($start_address, $end_address, @list) = @_;
+ $start_address = NetAddr::IP->new($start_address);
+ $end_address = NetAddr::IP->new($end_address);
+ return grep($start_address <= NetAddr::IP->new($_) <= $end_address, @list);
+}
+
sub get_namespace_id {
my ($url, $namespace, $headers) = @_;
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 15/16] ipam: nautobot: implement plain prefix allocation (without ranges)
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (13 preceding siblings ...)
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 14/16] ipam: nautobot: hacky ip range support Lou Lecrivain via pve-devel
@ 2024-11-27 16:18 ` Lou Lecrivain via pve-devel
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 16/16] ipam: nautobot: add word of warning for dhcp range support Lou Lecrivain via pve-devel
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:18 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 6480 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 15/16] ipam: nautobot: implement plain prefix allocation (without ranges)
Date: Wed, 27 Nov 2024 17:18:02 +0100
Message-ID: <20241127161803.8866-16-lou.lecrivain@wdz.de>
+ bugfix (return from eval was garbage-collected, callers got undef)
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 30 ++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index 95e749c..e3ba57c 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -96,6 +96,33 @@ sub add_ip {
}
}
+sub add_next_freeip {
+ my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $vmid, $noerr) = @_;
+
+ my $cidr = $subnet->{cidr};
+
+ my $url = $plugin_config->{url};
+ my $namespace = $plugin_config->{namespace};
+ my $headers = default_headers($plugin_config);
+
+ my $internalid = PVE::Network::SDN::Ipams::NetboxPlugin::get_prefix_id($url, $cidr, $headers);
+
+ my $description = "mac:$mac" if $mac;
+
+ my $params = { type => "dhcp", dns_name => $hostname, description => $description, namespace => $namespace, status => default_ip_status() };
+
+ my $ip = eval {
+ my $result = PVE::Network::SDN::api_request("POST", "$url/ipam/prefixes/$internalid/available-ips/", $headers, $params);
+ my ($ip, undef) = split(/\//, $result->{address});
+ return $ip;
+ };
+
+ if ($@) {
+ die "can't find free ip in subnet $cidr: $@" if !$noerr;
+ }
+ return $ip;
+}
+
sub add_range_next_freeip {
my ($class, $plugin_config, $subnet, $range, $data, $noerr) = @_;
@@ -107,7 +134,7 @@ sub add_range_next_freeip {
my $minimal_size = NetAddr::IP->new($range->{'start-address'}) - NetAddr::IP->new($cidr);
my $internalid = PVE::Network::SDN::Ipams::NetboxPlugin::get_prefix_id($url, $cidr, $headers);
- eval {
+ my $ip = eval {
my $result = PVE::Network::SDN::api_request("GET", "$url/ipam/prefixes/$internalid/available-ips/?limit=$minimal_size", $headers);
# v important for NetAddr::IP comparison!
my @ips = map((split(/\//,$_->{address}))[0], @{$result});
@@ -125,6 +152,7 @@ sub add_range_next_freeip {
if ($@) {
die "can't find free ip in range $range->{'start-address'}-$range->{'end-address'}: $@" if !$noerr;
}
+ return $ip;
}
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* [pve-devel] SPAM: [PATCH pve-network 16/16] ipam: nautobot: add word of warning for dhcp range support
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
` (14 preceding siblings ...)
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 15/16] ipam: nautobot: implement plain prefix allocation (without ranges) Lou Lecrivain via pve-devel
@ 2024-11-27 16:18 ` Lou Lecrivain via pve-devel
15 siblings, 0 replies; 16+ messages in thread
From: Lou Lecrivain via pve-devel @ 2024-11-27 16:18 UTC (permalink / raw)
To: pve-devel; +Cc: Lou Lecrivain
[-- Attachment #1: Type: message/rfc822, Size: 4342 bytes --]
From: Lou Lecrivain <lou.lecrivain@wdz.de>
To: pve-devel@lists.proxmox.com
Subject: SPAM: [PATCH pve-network 16/16] ipam: nautobot: add word of warning for dhcp range support
Date: Wed, 27 Nov 2024 17:18:03 +0100
Message-ID: <20241127161803.8866-17-lou.lecrivain@wdz.de>
Signed-off-by: lou lecrivain <lou.lecrivain@wdz.de>
---
src/PVE/Network/SDN/Ipams/NautobotPlugin.pm | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
index e3ba57c..22867df 100644
--- a/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
+++ b/src/PVE/Network/SDN/Ipams/NautobotPlugin.pm
@@ -131,6 +131,7 @@ sub add_range_next_freeip {
my $headers = default_headers($plugin_config);
my $cidr = $subnet->{cidr};
+ # 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 = PVE::Network::SDN::Ipams::NetboxPlugin::get_prefix_id($url, $cidr, $headers);
--
2.39.5
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2024-11-27 16:28 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20241127161803.8866-1-lou.lecrivain@wdz.de>
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 01/16] ipam: nautobot support initial commit Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 02/16] ipam: add Nautobot plugin sources to Makefile Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 03/16] ipam: change verify URL (now common to Nautobot and Netbox) Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 04/16] ipam: nautobot: add verification for ipam namespace plugin parameter Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 05/16] ipam: nautobot: fix on_update_hook for NautobotPlugin Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 06/16] ipam: nautobot: add default active status check Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 07/16] ipam: nautobot: fix typo Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 08/16] ipam: nautobot: 1st working "add subnet" and "add ip" Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 09/16] ipam: nautobot: simplify query Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 10/16] ipam: nautobot: api endpoint change no longer needed Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 11/16] ipam: nautobot: add update_ip sub Lou Lecrivain via pve-devel
2024-11-27 16:17 ` [pve-devel] SPAM: [PATCH pve-network 12/16] ipam: nautobot: add get ips for mac function Lou Lecrivain via pve-devel
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 13/16] ipam: nautobot: 1st draft for allocating ip in dhcp range Lou Lecrivain via pve-devel
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 14/16] ipam: nautobot: hacky ip range support Lou Lecrivain via pve-devel
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 15/16] ipam: nautobot: implement plain prefix allocation (without ranges) Lou Lecrivain via pve-devel
2024-11-27 16:18 ` [pve-devel] SPAM: [PATCH pve-network 16/16] ipam: nautobot: add word of warning for dhcp range support Lou Lecrivain via pve-devel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal