From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-network 02/15] ipams: add mac address
Date: Tue, 5 Jan 2021 10:35:23 +0100 [thread overview]
Message-ID: <20210105093536.1727641-3-aderumier@odiso.com> (raw)
In-Reply-To: <20210105093536.1727641-1-aderumier@odiso.com>
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
PVE/Network/SDN/Ipams/NetboxPlugin.pm | 6 ++++--
PVE/Network/SDN/Ipams/PVEPlugin.pm | 4 ++--
PVE/Network/SDN/Ipams/PhpIpamPlugin.pm | 7 +++++--
PVE/Network/SDN/Ipams/Plugin.pm | 4 ++--
PVE/Network/SDN/SubnetPlugin.pm | 4 +++-
PVE/Network/SDN/Subnets.pm | 8 ++++----
PVE/Network/SDN/Vnets.pm | 8 ++++----
7 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/PVE/Network/SDN/Ipams/NetboxPlugin.pm b/PVE/Network/SDN/Ipams/NetboxPlugin.pm
index 298634d..3c99218 100644
--- a/PVE/Network/SDN/Ipams/NetboxPlugin.pm
+++ b/PVE/Network/SDN/Ipams/NetboxPlugin.pm
@@ -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 };
diff --git a/PVE/Network/SDN/Ipams/PVEPlugin.pm b/PVE/Network/SDN/Ipams/PVEPlugin.pm
index 4925274..c02b6db 100644
--- a/PVE/Network/SDN/Ipams/PVEPlugin.pm
+++ b/PVE/Network/SDN/Ipams/PVEPlugin.pm
@@ -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};
diff --git a/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm b/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
index 6261764..ab06f7b 100644
--- a/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
+++ b/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm
@@ -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);
diff --git a/PVE/Network/SDN/Ipams/Plugin.pm b/PVE/Network/SDN/Ipams/Plugin.pm
index 065225c..10e5212 100644
--- a/PVE/Network/SDN/Ipams/Plugin.pm
+++ b/PVE/Network/SDN/Ipams/Plugin.pm
@@ -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 {
diff --git a/PVE/Network/SDN/SubnetPlugin.pm b/PVE/Network/SDN/SubnetPlugin.pm
index 2d6d808..68efeb6 100644
--- a/PVE/Network/SDN/SubnetPlugin.pm
+++ b/PVE/Network/SDN/SubnetPlugin.pm
@@ -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
diff --git a/PVE/Network/SDN/Subnets.pm b/PVE/Network/SDN/Subnets.pm
index 81970a1..b752e2c 100644
--- a/PVE/Network/SDN/Subnets.pm
+++ b/PVE/Network/SDN/Subnets.pm
@@ -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 $@;
}
diff --git a/PVE/Network/SDN/Vnets.pm b/PVE/Network/SDN/Vnets.pm
index 1da1d57..d68ffab 100644
--- a/PVE/Network/SDN/Vnets.pm
+++ b/PVE/Network/SDN/Vnets.pm
@@ -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 {
--
2.20.1
next prev parent reply other threads:[~2021-01-05 9:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-05 9:35 [pve-devel] [PATCH pve-network 00/15] bugfix && unit tests Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 01/15] sdn: pending_config: initialize empty pending key Alexandre Derumier
2021-01-05 9:35 ` Alexandre Derumier [this message]
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 03/15] ipam: add update_ip Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 04/15] dns/ipam : move api_request helper to sdn module Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 05/15] subnets: fix del_ip rollback Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 06/15] dns: add update record && fix powerdns Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 07/15] ipam: phpipam: rename get_internal to get_prefix_id (like netbox) Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 08/15] ipams: add noerr param Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 09/15] tests: add ipams tests Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 10/15] dns: add noerr param Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 11/15] tests: add dns tests Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 12/15] subnets: convert dns private function to public sub Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 13/15] subnets: add add_subnet/del_subnet Alexandre Derumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 14/15] tests: add subnets tests Alexandre Derumier
2021-02-06 13:56 ` Thomas Lamprecht
2021-02-07 14:09 ` aderumier
2021-01-05 9:35 ` [pve-devel] [PATCH pve-network 15/15] fix coding style NetAddr::IP->new Alexandre Derumier
2021-02-06 13:57 ` [pve-devel] [PATCH pve-network 00/15] bugfix && unit tests Thomas Lamprecht
2021-02-07 14:26 ` aderumier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210105093536.1727641-3-aderumier@odiso.com \
--to=aderumier@odiso.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox