public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [pve-network/qemu-server/pve-container/pve-manager] RFC: use ipam without dhcp
@ 2024-01-04 16:27 Alexandre Derumier
  2024-01-04 16:27 ` [pve-devel] [qemu-server 1/1] add_next_free_cidr: remove old dhcprange param Alexandre Derumier
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:27 UTC (permalink / raw)
  To: pve-devel

This patch serie add support to use ipam without dhcp.

Users could want to use ipam to manage cloudinit for example, or firewall rules,.. with
static assignement of ips in vm configuration

a new "ipamreservation" option is defined on zone

- Manual (undefined): user need to do manually the ips reservation
- Static: ip is auto assigned at vm create && removed at vm delete
- Dynamic: ip is auto assigned at vm start && removed at vm stop  (not yet implemented)


pve-network:

Alexandre Derumier (4):
  vnets: use ipam without dhcp
  vnets: add_next_free_cidr : skip if ipamreservation is not defined
  subnets: call add_range_next_freeip only if dhcp is defined
  api2: ipam status: display ipam zones without dhcp flag

 src/PVE/API2/Network/SDN/Ipams.pm |  2 +-
 src/PVE/Network/SDN/Subnets.pm    | 13 +++++++++----
 src/PVE/Network/SDN/Vnets.pm      | 12 ++++++------
 3 files changed, 16 insertions(+), 11 deletions(-)

qemu-server:

Alexandre Derumier (1):
  add_next_free_cidr: remove old dhcprange param

 PVE/QemuServer.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

pve-container:

Alexandre Derumier (1):
  add_next_free_cidr: remove old dhcprange param

 src/PVE/LXC.pm        | 8 ++++----
 src/PVE/LXC/Config.pm | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

pve-manager:

Alexandre Derumier (1):
  sdn: zones: add ipam reservation option.

 www/manager6/sdn/zones/Base.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)

-- 
2.39.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [qemu-server 1/1] add_next_free_cidr: remove old dhcprange param
  2024-01-04 16:27 [pve-devel] [pve-network/qemu-server/pve-container/pve-manager] RFC: use ipam without dhcp Alexandre Derumier
@ 2024-01-04 16:27 ` Alexandre Derumier
  2024-01-04 16:27 ` [pve-devel] [pve-manager 1/1] sdn: zones: add ipam reservation option Alexandre Derumier
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:27 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 PVE/QemuServer.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 600d0a8..a00e09e 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5279,7 +5279,7 @@ sub vmconfig_apply_pending {
 			}
 		   }
 		   #fixme: reuse ip if mac change && same bridge
-		   PVE::Network::SDN::Vnets::add_next_free_cidr($new_net->{bridge}, $conf->{name}, $new_net->{macaddr}, $vmid, undef, 1);
+		   PVE::Network::SDN::Vnets::add_next_free_cidr($new_net->{bridge}, $conf->{name}, $new_net->{macaddr}, $vmid);
 		}
 	    }
 	};
@@ -5349,7 +5349,7 @@ sub vmconfig_update_net {
 		if (safe_string_ne($oldnet->{bridge}, $newnet->{bridge})) {
 		    if ($have_sdn) {
 			PVE::Network::SDN::Vnets::del_ips_from_mac($oldnet->{bridge}, $oldnet->{macaddr}, $conf->{name});
-			PVE::Network::SDN::Vnets::add_next_free_cidr($newnet->{bridge}, $conf->{name}, $newnet->{macaddr}, $vmid, undef, 1);
+			PVE::Network::SDN::Vnets::add_next_free_cidr($newnet->{bridge}, $conf->{name}, $newnet->{macaddr}, $vmid);
 		    }
 		}
 
@@ -5381,7 +5381,7 @@ sub vmconfig_update_net {
 
     if ($hotplug) {
 	if ($have_sdn) {
-	    PVE::Network::SDN::Vnets::add_next_free_cidr($newnet->{bridge}, $conf->{name}, $newnet->{macaddr}, $vmid, undef, 1);
+	    PVE::Network::SDN::Vnets::add_next_free_cidr($newnet->{bridge}, $conf->{name}, $newnet->{macaddr}, $vmid);
 	    PVE::Network::SDN::Vnets::add_dhcp_mapping($newnet->{bridge}, $newnet->{macaddr}, $vmid, $conf->{name});
 	}
 	vm_deviceplug($storecfg, $conf, $vmid, $opt, $newnet, $arch, $machine_type);
@@ -8691,7 +8691,7 @@ sub create_ifaces_ipams_ips {
         if ($opt =~ m/^net(\d+)$/) {
             my $value = $conf->{$opt};
             my $net = PVE::QemuServer::parse_net($value);
-            eval { PVE::Network::SDN::Vnets::add_next_free_cidr($net->{bridge}, $conf->{name}, $net->{macaddr}, $vmid, undef, 1) };
+            eval { PVE::Network::SDN::Vnets::add_next_free_cidr($net->{bridge}, $conf->{name}, $net->{macaddr}, $vmid) };
             warn $@ if $@;
         }
     }
-- 
2.39.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [pve-manager 1/1] sdn: zones: add ipam reservation option.
  2024-01-04 16:27 [pve-devel] [pve-network/qemu-server/pve-container/pve-manager] RFC: use ipam without dhcp Alexandre Derumier
  2024-01-04 16:27 ` [pve-devel] [qemu-server 1/1] add_next_free_cidr: remove old dhcprange param Alexandre Derumier
@ 2024-01-04 16:27 ` Alexandre Derumier
  2024-01-04 16:27 ` [pve-devel] [pve-network 1/4] vnets: use ipam without dhcp Alexandre Derumier
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:27 UTC (permalink / raw)
  To: pve-devel

Manual: user need to manually do reservation
static: ip is auto assign at vm create && remove at vm delete
dynamic: ip is auto assign at vm start && remove at vm stop  (not yet implemented)
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 www/manager6/sdn/zones/Base.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/www/manager6/sdn/zones/Base.js b/www/manager6/sdn/zones/Base.js
index 709129e6..77b57f61 100644
--- a/www/manager6/sdn/zones/Base.js
+++ b/www/manager6/sdn/zones/Base.js
@@ -53,6 +53,18 @@ Ext.define('PVE.panel.SDNZoneBase', {
 		value: me.ipam || 'pve',
 		allowBlank: false,
 	    },
+	    {
+		xtype: 'proxmoxKVComboBox',
+		fieldLabel: gettext('IPAM IP reservation'),
+		name: 'ipamreservation',
+		value: '__default__',
+		deleteEmpty: !me.isCreate,
+		comboItems: [
+			['__default__', 'manual'],
+			['static', 'static (ip remove at vm deleted)'],
+			['dynamic', 'dynamic (ip remove at vm stop)'],
+		],
+	    },
 	);
 
 	me.advancedItems = me.advancedItems ?? [];
-- 
2.39.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [pve-network 1/4] vnets: use ipam without dhcp
  2024-01-04 16:27 [pve-devel] [pve-network/qemu-server/pve-container/pve-manager] RFC: use ipam without dhcp Alexandre Derumier
  2024-01-04 16:27 ` [pve-devel] [qemu-server 1/1] add_next_free_cidr: remove old dhcprange param Alexandre Derumier
  2024-01-04 16:27 ` [pve-devel] [pve-manager 1/1] sdn: zones: add ipam reservation option Alexandre Derumier
@ 2024-01-04 16:27 ` Alexandre Derumier
  2024-01-04 16:27 ` [pve-devel] [pve-network 2/4] vnets: add_next_free_cidr : skip if ipamreservation is not defined Alexandre Derumier
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:27 UTC (permalink / raw)
  To: pve-devel

User should be able to use ipam without need to use dhcp.

(with static configuration for example).

Could be use to firewall rules or other rules based on ipam

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Vnets.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm
index 0dfdfd7..060cb3c 100644
--- a/src/PVE/Network/SDN/Vnets.pm
+++ b/src/PVE/Network/SDN/Vnets.pm
@@ -103,7 +103,7 @@ sub add_next_free_cidr {
     my $zoneid = $vnet->{zone};
     my $zone = PVE::Network::SDN::Zones::get_zone($zoneid);
 
-    return if !$zone->{ipam} || !$zone->{dhcp};
+    return if !$zone->{ipam};
 
     my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid, 1);
 
@@ -170,7 +170,7 @@ sub get_ips_from_mac {
     my $zoneid = $vnet->{zone};
     my $zone = PVE::Network::SDN::Zones::get_zone($zoneid);
 
-    return if !$zone->{ipam} || !$zone->{dhcp};
+    return if !$zone->{ipam};
 
     return PVE::Network::SDN::Ipams::get_ips_from_mac($mac, $zoneid, $zone);
 }
@@ -193,7 +193,7 @@ sub add_dhcp_mapping {
     my $zoneid = $vnet->{zone};
     my $zone = PVE::Network::SDN::Zones::get_zone($zoneid);
 
-    return if !$zone->{ipam} || !$zone->{dhcp};
+    return if !$zone->{ipam};
 
     my ($ip4, $ip6) = PVE::Network::SDN::Vnets::get_ips_from_mac($vnetid, $mac);
     if ( ! ($ip4 || $ip6) ) {
@@ -202,7 +202,7 @@ sub add_dhcp_mapping {
 	($ip4, $ip6) = PVE::Network::SDN::Vnets::get_ips_from_mac($vnetid, $mac);
 	print "got new IP from IPAM: $ip4 $ip6\n";
     }
-    PVE::Network::SDN::Dhcp::add_mapping($vnetid, $mac, $ip4, $ip6) if $ip4 || $ip6;
+    PVE::Network::SDN::Dhcp::add_mapping($vnetid, $mac, $ip4, $ip6) if $zone->{dhcp} && ($ip4 || $ip6);
 }
 
 1;
-- 
2.39.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [pve-network 2/4] vnets: add_next_free_cidr : skip if ipamreservation is not defined
  2024-01-04 16:27 [pve-devel] [pve-network/qemu-server/pve-container/pve-manager] RFC: use ipam without dhcp Alexandre Derumier
                   ` (2 preceding siblings ...)
  2024-01-04 16:27 ` [pve-devel] [pve-network 1/4] vnets: use ipam without dhcp Alexandre Derumier
@ 2024-01-04 16:27 ` Alexandre Derumier
  2024-01-04 16:27 ` [pve-devel] [pve-network 3/4] subnets: call add_range_next_freeip only if dhcp is defined Alexandre Derumier
  2024-01-04 16:27 ` [pve-devel] [pve-network 4/4] api2: ipam status: display ipam zones without dhcp flag Alexandre Derumier
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:27 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Vnets.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm
index 060cb3c..0268684 100644
--- a/src/PVE/Network/SDN/Vnets.pm
+++ b/src/PVE/Network/SDN/Vnets.pm
@@ -103,7 +103,7 @@ sub add_next_free_cidr {
     my $zoneid = $vnet->{zone};
     my $zone = PVE::Network::SDN::Zones::get_zone($zoneid);
 
-    return if !$zone->{ipam};
+    return if !$zone->{ipam} || !$zone->{'ipamreservation'};
 
     my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid, 1);
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [pve-network 3/4] subnets: call add_range_next_freeip only if dhcp is defined
  2024-01-04 16:27 [pve-devel] [pve-network/qemu-server/pve-container/pve-manager] RFC: use ipam without dhcp Alexandre Derumier
                   ` (3 preceding siblings ...)
  2024-01-04 16:27 ` [pve-devel] [pve-network 2/4] vnets: add_next_free_cidr : skip if ipamreservation is not defined Alexandre Derumier
@ 2024-01-04 16:27 ` Alexandre Derumier
  2024-01-04 16:27 ` [pve-devel] [pve-network 4/4] api2: ipam status: display ipam zones without dhcp flag Alexandre Derumier
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:27 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/Network/SDN/Subnets.pm | 13 +++++++++----
 src/PVE/Network/SDN/Vnets.pm   |  4 ++--
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm
index 3b08dcd..4767850 100644
--- a/src/PVE/Network/SDN/Subnets.pm
+++ b/src/PVE/Network/SDN/Subnets.pm
@@ -206,7 +206,7 @@ sub del_subnet {
 }
 
 sub add_next_free_ip {
-    my ($zone, $subnetid, $subnet, $hostname, $mac, $vmid, $skipdns, $dhcprange) = @_;
+    my ($zone, $subnetid, $subnet, $hostname, $mac, $vmid, $skipdns) = @_;
 
     my $cidr = undef;
     my $ip = undef;
@@ -227,15 +227,18 @@ sub add_next_free_ip {
 	my $plugin_config = $ipam_cfg->{ids}->{$ipamid};
 	my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type});
 	eval {
-	    if ($dhcprange) {
+
+	    my $dhcp_ranges = PVE::Network::SDN::Subnets::get_dhcp_ranges($subnet);
+	    if ($zone->{dhcp}) {
+	
+		die "no dhcp_range are defined" if @$dhcp_ranges == 0;
+
 		my $data = {
 		    mac => $mac,
 		    hostname => $hostname,
 		    vmid => $vmid,
 		};
 
-		my $dhcp_ranges = PVE::Network::SDN::Subnets::get_dhcp_ranges($subnet);
-
 		foreach my $range (@$dhcp_ranges) {
 		    $ip = $plugin->add_range_next_freeip($plugin_config, $subnet, $range, $data);
 		    last if $ip;
@@ -247,6 +250,8 @@ sub add_next_free_ip {
 
 	die $@ if $@;
 
+	die "Can't find any free ip" if !$ip;
+
 	eval { PVE::Network::SDN::Ipams::add_cache_mac_ip($mac, $ip); };
 	warn $@ if $@;
     }
diff --git a/src/PVE/Network/SDN/Vnets.pm b/src/PVE/Network/SDN/Vnets.pm
index 0268684..83b79dd 100644
--- a/src/PVE/Network/SDN/Vnets.pm
+++ b/src/PVE/Network/SDN/Vnets.pm
@@ -95,7 +95,7 @@ sub get_subnet_from_vnet_ip {
 }
 
 sub add_next_free_cidr {
-    my ($vnetid, $hostname, $mac, $vmid, $skipdns, $dhcprange) = @_;
+    my ($vnetid, $hostname, $mac, $vmid, $skipdns) = @_;
 
     my $vnet = PVE::Network::SDN::Vnets::get_vnet($vnetid);
     return if !$vnet;
@@ -121,7 +121,7 @@ sub add_next_free_cidr {
 	    $subnetcount++;
 
 	    eval {
-		$ip = PVE::Network::SDN::Subnets::add_next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $vmid, $skipdns, $dhcprange);
+		$ip = PVE::Network::SDN::Subnets::add_next_free_ip($zone, $subnetid, $subnet, $hostname, $mac, $vmid, $skipdns);
 	    };
 	    die $@ if $@;
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pve-devel] [pve-network 4/4] api2: ipam status: display ipam zones without dhcp flag
  2024-01-04 16:27 [pve-devel] [pve-network/qemu-server/pve-container/pve-manager] RFC: use ipam without dhcp Alexandre Derumier
                   ` (4 preceding siblings ...)
  2024-01-04 16:27 ` [pve-devel] [pve-network 3/4] subnets: call add_range_next_freeip only if dhcp is defined Alexandre Derumier
@ 2024-01-04 16:27 ` Alexandre Derumier
  5 siblings, 0 replies; 7+ messages in thread
From: Alexandre Derumier @ 2024-01-04 16:27 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
---
 src/PVE/API2/Network/SDN/Ipams.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/PVE/API2/Network/SDN/Ipams.pm b/src/PVE/API2/Network/SDN/Ipams.pm
index 27ead02..a70a2f3 100644
--- a/src/PVE/API2/Network/SDN/Ipams.pm
+++ b/src/PVE/API2/Network/SDN/Ipams.pm
@@ -293,7 +293,7 @@ __PACKAGE__->register_method ({
 
 	for my $zone_id (keys %{$ipam_db->{zones}}) {
 	    my $zone_config = PVE::Network::SDN::Zones::get_zone($zone_id, 1);
-            next if !$zone_config || $zone_config->{ipam} ne 'pve' || !$zone_config->{dhcp};
+            next if !$zone_config || $zone_config->{ipam} ne 'pve';
 
 	    my $zone = $ipam_db->{zones}->{$zone_id};
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-01-04 16:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-04 16:27 [pve-devel] [pve-network/qemu-server/pve-container/pve-manager] RFC: use ipam without dhcp Alexandre Derumier
2024-01-04 16:27 ` [pve-devel] [qemu-server 1/1] add_next_free_cidr: remove old dhcprange param Alexandre Derumier
2024-01-04 16:27 ` [pve-devel] [pve-manager 1/1] sdn: zones: add ipam reservation option Alexandre Derumier
2024-01-04 16:27 ` [pve-devel] [pve-network 1/4] vnets: use ipam without dhcp Alexandre Derumier
2024-01-04 16:27 ` [pve-devel] [pve-network 2/4] vnets: add_next_free_cidr : skip if ipamreservation is not defined Alexandre Derumier
2024-01-04 16:27 ` [pve-devel] [pve-network 3/4] subnets: call add_range_next_freeip only if dhcp is defined Alexandre Derumier
2024-01-04 16:27 ` [pve-devel] [pve-network 4/4] api2: ipam status: display ipam zones without dhcp flag Alexandre Derumier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal