]> git.proxmox.com Git - pve-network.git/blobdiff - PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
ipam: add update_ip
[pve-network.git] / PVE / Network / SDN / Ipams / PhpIpamPlugin.pm
index ab06f7b5d80970fcb351290140a5e26530c14e49..b5ff38cd372fad5106a45a348757a5bec61b777e 100644 (file)
@@ -122,6 +122,34 @@ sub add_ip {
     }
 }
 
+sub update_ip {
+    my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_;
+
+    my $cidr = $subnet->{cidr};
+    my $url = $plugin_config->{url};
+    my $token = $plugin_config->{token};
+    my $section = $plugin_config->{section};
+    my $headers = ['Content-Type' => 'application/json; charset=UTF-8', 'Token' => $token];
+
+    my $ip_id = get_ip_id($url, $ip, $headers);
+    die "can't find ip addresse in ipam" if !$ip_id;
+
+    my $params = { 
+                  is_gateway => $is_gateway,
+                  hostname => $hostname,
+                  description => $description,
+                 };
+    $params->{mac} = $mac if $mac;
+
+    eval {
+       PVE::Network::SDN::Ipams::Plugin::api_request("PATCH", "$url/addresses/$ip_id", $headers, $params);
+    };
+
+    if ($@) {
+       die "ipam: error update subnet ip $ip: $@";
+    }
+}
+
 sub add_next_freeip {
     my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_;