[pve-devel] [WIP v2 pve-network 04/10] dhcp: subnet: add DHCP options to subnet configuration
Stefan Hanreich
s.hanreich at proxmox.com
Tue Oct 17 15:55:01 CEST 2023
Parse the dhcp-ranges when getting the configuration via the Subnet
class.
Signed-off-by: Stefan Hanreich <s.hanreich at proxmox.com>
---
src/PVE/Network/SDN/SubnetPlugin.pm | 32 +++++++++++++++++++++++++++++
src/PVE/Network/SDN/Subnets.pm | 18 ++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/src/PVE/Network/SDN/SubnetPlugin.pm b/src/PVE/Network/SDN/SubnetPlugin.pm
index 15b370f..47b8406 100644
--- a/src/PVE/Network/SDN/SubnetPlugin.pm
+++ b/src/PVE/Network/SDN/SubnetPlugin.pm
@@ -61,6 +61,23 @@ sub private {
return $defaultData;
}
+my $dhcp_range_fmt = {
+ server => {
+ type => 'pve-configid',
+ description => 'ID of the DHCP server responsible for managing this range',
+ },
+ 'start-address' => {
+ type => 'ip',
+ description => 'Start address for the DHCP IP range',
+ },
+ 'end-address' => {
+ type => 'ip',
+ description => 'End address for the DHCP IP range',
+ },
+};
+
+PVE::JSONSchema::register_format('pve-sdn-dhcp-range', $dhcp_range_fmt);
+
sub properties {
return {
vnet => {
@@ -84,6 +101,19 @@ sub properties {
type => 'string', format => 'dns-name',
description => "dns domain zone prefix ex: 'adm' -> <hostname>.adm.mydomain.com",
},
+ 'dhcp-range' => {
+ type => 'array',
+ description => 'A list of DHCP ranges for this subnet',
+ items => {
+ type => 'string',
+ format => 'pve-sdn-dhcp-range',
+ }
+ },
+ 'dhcp-dns-server' => {
+ type => 'ip',
+ description => 'IP address for the DNS server',
+ optional => 1,
+ },
};
}
@@ -94,6 +124,8 @@ sub options {
# routes => { optional => 1 },
snat => { optional => 1 },
dnszoneprefix => { optional => 1 },
+ 'dhcp-range' => { optional => 1 },
+ 'dhcp-dns-server' => { optional => 1 },
};
}
diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm
index f654d3a..dd9e697 100644
--- a/src/PVE/Network/SDN/Subnets.pm
+++ b/src/PVE/Network/SDN/Subnets.pm
@@ -8,6 +8,7 @@ use Net::IP;
use NetAddr::IP qw(:lower);
use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
+use PVE::JSONSchema qw(parse_property_string);
use PVE::Network::SDN::Dns;
use PVE::Network::SDN::Ipams;
@@ -31,6 +32,23 @@ sub sdn_subnets_config {
$scfg->{zone} = $zone;
$scfg->{network} = $network;
$scfg->{mask} = $mask;
+
+ if ($scfg->{'dhcp-range'}) {
+ my @dhcp_ranges;
+
+ foreach my $element (@{$scfg->{'dhcp-range'}}) {
+ my $dhcp_range = eval { parse_property_string('pve-sdn-dhcp-range', $element) };
+
+ if ($@ || !$dhcp_range) {
+ warn "Unable to parse dhcp-range string: $element\n";
+ warn "$@\n" if $@;
+ next;
+ }
+
+ push @dhcp_ranges, $dhcp_range;
+ }
+ $scfg->{'dhcp-range'} = \@dhcp_ranges;
+ }
}
return $scfg;
--
2.39.2
More information about the pve-devel
mailing list