X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PVE%2FNetwork%2FSDN%2FIpams%2FNetboxPlugin.pm;h=3c9921865b5177c2331b452c7a303652f1709d2e;hb=e9365ab0da0baf1111d0d41185efaaf831c89483;hp=01f82f2201f576547285e6984dabc33d69ad4831;hpb=70b035064290a014759ce62e0093df00cd7d62fe;p=pve-network.git diff --git a/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/PVE/Network/SDN/Ipams/NetboxPlugin.pm index 01f82f2..3c99218 100644 --- a/PVE/Network/SDN/Ipams/NetboxPlugin.pm +++ b/PVE/Network/SDN/Ipams/NetboxPlugin.pm @@ -30,7 +30,7 @@ sub options { sub add_subnet { my ($class, $plugin_config, $subnetid, $subnet) = @_; - my $cidr = $subnetid =~ s/-/\//r; + my $cidr = $subnet->{cidr}; my $gateway = $subnet->{gateway}; my $url = $plugin_config->{url}; my $token = $plugin_config->{token}; @@ -40,13 +40,11 @@ sub add_subnet { #create subnet if (!$internalid) { - my ($network, $mask) = split(/-/, $subnetid); my $params = { prefix => $cidr }; eval { my $result = PVE::Network::SDN::Ipams::Plugin::api_request("POST", "$url/ipam/prefixes/", $headers, $params); - $subnet->{ipamid} = $result->{id} if defined($result->{id}); }; if ($@) { die "error add subnet to ipam: $@"; @@ -58,7 +56,7 @@ sub add_subnet { sub del_subnet { my ($class, $plugin_config, $subnetid, $subnet) = @_; - my $cidr = $subnetid =~ s/-/\//r; + my $cidr = $subnet->{cidr}; my $url = $plugin_config->{url}; my $token = $plugin_config->{token}; my $gateway = $subnet->{gateway}; @@ -66,9 +64,8 @@ sub del_subnet { my $internalid = get_prefix_id($url, $cidr, $headers); return if !$internalid; - #fixme: check that prefix is empty exluding gateway, before delete - PVE::Network::SDN::Ipams::NetboxPlugin::del_ip($class, $plugin_config, $subnetid, $gateway) if $gateway; + return; #fixme: check that prefix is empty exluding gateway, before delete eval { PVE::Network::SDN::Ipams::Plugin::api_request("DELETE", "$url/ipam/prefixes/$internalid/", $headers); @@ -80,15 +77,16 @@ sub del_subnet { } sub add_ip { - my ($class, $plugin_config, $subnetid, $ip, $is_gateway) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_; - my ($network, $mask) = split(/-/, $subnetid); + my $mask = $subnet->{mask}; my $url = $plugin_config->{url}; my $token = $plugin_config->{token}; my $section = $plugin_config->{section}; my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Authorization' => "token $token"]; + $description .= " mac:$mac" if $mac && $description; - my $params = { address => "$ip/$mask" }; + my $params = { address => "$ip/$mask", dns_name => $hostname, description => $description }; eval { PVE::Network::SDN::Ipams::Plugin::api_request("POST", "$url/ipam/ip-addresses/", $headers, $params); @@ -100,16 +98,18 @@ sub add_ip { } sub add_next_freeip { - my ($class, $plugin_config, $subnetid, $subnet) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_; + + my $cidr = $subnet->{cidr}; - my $cidr = $subnetid =~ s/-/\//r; my $url = $plugin_config->{url}; my $token = $plugin_config->{token}; my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Authorization' => "token $token"]; my $internalid = get_prefix_id($url, $cidr, $headers); + $description .= " mac:$mac" if $mac && $description; - my $params = {}; + my $params = { dns_name => $hostname, description => $description }; my $ip = undef; eval { @@ -125,7 +125,7 @@ sub add_next_freeip { } sub del_ip { - my ($class, $plugin_config, $subnetid, $ip) = @_; + my ($class, $plugin_config, $subnetid, $subnet, $ip) = @_; return if !$ip;