--- Begin Message ---
Signed-off-by: lou lecrivain <lou.lecriv...@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



--- End Message ---
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to