]> git.proxmox.com Git - pve-network.git/commitdiff
ipams: add mac address
authorAlexandre Derumier <aderumier@odiso.com>
Tue, 5 Jan 2021 09:35:23 +0000 (10:35 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 6 Feb 2021 13:50:44 +0000 (14:50 +0100)
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/Network/SDN/Ipams/NetboxPlugin.pm
PVE/Network/SDN/Ipams/PVEPlugin.pm
PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
PVE/Network/SDN/Ipams/Plugin.pm
PVE/Network/SDN/SubnetPlugin.pm
PVE/Network/SDN/Subnets.pm
PVE/Network/SDN/Vnets.pm

index 298634d32657d86f2b8ee79ae7d64f0b1da78be5..3c9921865b5177c2331b452c7a303652f1709d2e 100644 (file)
@@ -77,13 +77,14 @@ sub del_subnet {
 }
 
 sub add_ip {
-    my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $description, $is_gateway) = @_;
+    my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_;
 
     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", dns_name => $hostname, description => $description };
 
@@ -97,7 +98,7 @@ sub add_ip {
 }
 
 sub add_next_freeip {
-    my ($class, $plugin_config, $subnetid, $subnet, $hostname, $description) = @_;
+    my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_;
 
     my $cidr = $subnet->{cidr};
 
@@ -106,6 +107,7 @@ sub add_next_freeip {
     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 = { dns_name => $hostname, description => $description };
 
index 49252745230c08ce032a5b860a0c49abacaae0e2..c02b6dba74981132a5200a1a768bd4f0601058cc 100644 (file)
@@ -82,7 +82,7 @@ sub del_subnet {
 }
 
 sub add_ip {
-    my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $description, $is_gateway) = @_;
+    my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_;
 
     my $cidr = $subnet->{cidr};
     my $zone = $subnet->{zone};
@@ -106,7 +106,7 @@ sub add_ip {
 }
 
 sub add_next_freeip {
-    my ($class, $plugin_config, $subnetid, $subnet, $hostname, $description) = @_;
+    my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_;
 
     my $cidr = $subnet->{cidr};
     my $network = $subnet->{network};
index 6261764ffb5cb9d7b2bc865704ac74663790d860..ab06f7b5d80970fcb351290140a5e26530c14e49 100644 (file)
@@ -95,7 +95,7 @@ sub del_subnet {
 }
 
 sub add_ip {
-    my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $description, $is_gateway) = @_;
+    my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_;
 
     my $cidr = $subnet->{cidr};
     my $url = $plugin_config->{url};
@@ -111,6 +111,7 @@ sub add_ip {
                   hostname => $hostname,
                   description => $description,
                  };
+    $params->{mac} = $mac if $mac;
 
     eval {
        PVE::Network::SDN::Ipams::Plugin::api_request("POST", "$url/addresses/", $headers, $params);
@@ -122,7 +123,7 @@ sub add_ip {
 }
 
 sub add_next_freeip {
-    my ($class, $plugin_config, $subnetid, $subnet, $hostname, $description) = @_;
+    my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_;
 
     my $cidr = $subnet->{cidr};  
     my $mask = $subnet->{mask};  
@@ -137,6 +138,8 @@ sub add_next_freeip {
                   description => $description,
                  };
 
+    $params->{mac} = $mac if $mac;
+
     my $ip = undef;
     eval {
        my $result = PVE::Network::SDN::Ipams::Plugin::api_request("POST", "$url/addresses/first_free/$internalid/", $headers, $params);
index 065225cfcd55eca8daad944d5261fbada271f836..10e52126e4526b4c9f244ad4c237a9401eb28ad9 100644 (file)
@@ -75,12 +75,12 @@ sub del_subnet {
 }
 
 sub add_ip {
-    my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $description, $is_gateway) = @_;
+    my ($class, $plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description, $is_gateway) = @_;
 
 }
 
 sub add_next_freeip {
-    my ($class, $plugin_config, $subnetid, $subnet) = @_;
+    my ($class, $plugin_config, $subnetid, $subnet, $hostname, $mac, $description) = @_;
 }
 
 sub del_ip {
index 2d6d8082a59b26729b5cb15117b6566c3411fb4f..68efeb66654c5b1bd3d74f4fde7d6036825f3907 100644 (file)
@@ -113,11 +113,13 @@ sub on_update_hook {
     my $reversedns = $zone->{reversedns};
 
     my $old_gateway = $old_subnet->{gateway} if $old_subnet;
+    my $mac = undef;
 
     if($vnetid) {
        my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid);
        raise_param_exc({ vnet => "$vnetid don't exist"}) if !$vnet;
        raise_param_exc({ vnet => "you can't add a subnet on a vlanaware vnet"}) if $vnet->{vlanaware};
+       $mac = $vnet->{mac};
     }
 
     my $pointopoint = 1 if Net::IP::ip_is_ipv4($gateway) && $mask == 32;
@@ -145,7 +147,7 @@ sub on_update_hook {
         if(!$old_gateway || $gateway && $gateway ne $old_gateway) {
            my $hostname = "$vnetid-gw";
            my $description = "$vnetid gw";
-           PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $gateway, $hostname, $description, 1);
+           PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $gateway, $hostname, $mac, $description, 1);
        }
 
        #delete old gateway after update
index 81970a1a54caba87eff8be6be200296825c9a816..b752e2c3e08ba0d2d74a4cfbe700d10d80009807 100644 (file)
@@ -162,7 +162,7 @@ my $del_dns_ptr_record = sub {
 };
 
 sub next_free_ip {
-    my ($zone, $subnetid, $subnet, $hostname, $description) = @_;
+    my ($zone, $subnetid, $subnet, $hostname, $mac, $description) = @_;
 
     my $cidr = undef;
     my $ip = undef;
@@ -184,7 +184,7 @@ sub next_free_ip {
        my $plugin_config = $ipam_cfg->{ids}->{$ipamid};
        my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type});
        eval {
-           $cidr = $plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $description);
+           $cidr = $plugin->add_next_freeip($plugin_config, $subnetid, $subnet, $hostname, $mac, $description);
            ($ip, undef) = split(/\//, $cidr);
        };
        die $@ if $@;
@@ -210,7 +210,7 @@ sub next_free_ip {
 }
 
 sub add_ip {
-    my ($zone, $subnetid, $subnet, $ip, $hostname, $description) = @_;
+    my ($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description) = @_;
 
     return if !$subnet || !$ip; 
 
@@ -235,7 +235,7 @@ sub add_ip {
        my $plugin_config = $ipam_cfg->{ids}->{$ipamid};
        my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type});
        eval {
-           $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $description);
+           $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $description);
        };
        die $@ if $@;
     }
index 1da1d5778e7bd5bae7a934c0f37fef4f7fcee192..d68ffab7d592ecbd01f242b58ae6492a9face104 100644 (file)
@@ -80,7 +80,7 @@ sub get_subnets {
 }
 
 sub get_next_free_cidr {
-    my ($vnetid, $hostname, $description, $ipversion) = @_;
+    my ($vnetid, $hostname, $mac, $description, $ipversion) = @_;
 
     my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid);
     my $zoneid = $vnet->{zone};
@@ -99,7 +99,7 @@ sub get_next_free_cidr {
        $subnetcount++;
        if ($zone->{ipam}) {
            eval {
-               $ip = PVE::Network::SDN::Subnets::next_free_ip($zone, $subnetid, $subnet, $hostname, $description);
+               $ip = PVE::Network::SDN::Subnets::next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $description);
            };
            warn $@ if $@;
        }
@@ -111,7 +111,7 @@ sub get_next_free_cidr {
 }
 
 sub add_cidr {
-    my ($vnetid, $cidr, $hostname, $description) = @_;
+    my ($vnetid, $cidr, $hostname, $mac, $description) = @_;
 
     my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid, 1);
     my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid);
@@ -122,7 +122,7 @@ sub add_cidr {
     die "ip address is not in cidr format" if !$mask;
     my ($subnetid, $subnet) = PVE::Network::SDN::Subnets::find_ip_subnet($ip, $mask, $subnets);
 
-    PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $description);
+    PVE::Network::SDN::Subnets::add_ip($zone, $subnetid, $subnet, $ip, $hostname, $mac, $description);
 }
 
 sub del_cidr {