From: Dominik Csapak Date: Fri, 3 May 2019 07:28:53 +0000 (+0200) Subject: add new parameters cidr(6) to the network api X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=1e94d06239fb4e9a3bf9ce1cdfe93d8e62b56b98;p=pmg-api.git add new parameters cidr(6) to the network api to also allow to set it directly and not only via address/netmask Signed-off-by: Dominik Csapak --- diff --git a/PMG/API2/Network.pm b/PMG/API2/Network.pm index 6636553..b6a58da 100644 --- a/PMG/API2/Network.pm +++ b/PMG/API2/Network.pm @@ -124,6 +124,11 @@ my $confdesc = { optional => 1, requires => 'netmask', }, + cidr => { + description => 'IPv4 CIDR.', + type => 'string', format => 'CIDRv4', + optional => 1, + }, gateway6 => { description => 'Default ipv6 gateway address.', type => 'string', format => 'ipv6', @@ -140,7 +145,12 @@ my $confdesc = { type => 'string', format => 'ipv6', optional => 1, requires => 'netmask6', - } + }, + cidr6 => { + description => 'IPv6 CIDR.', + type => 'string', format => 'CIDRv6', + optional => 1, + }, }; sub json_config_properties { @@ -272,6 +282,34 @@ my $check_ipv6_settings = sub { (defined($type) && $type !~ /^(?:(?:GLOBAL|(?:UNIQUE|LINK)-LOCAL)-UNICAST)$/); }; +my $map_cidr_to_address_netmask = sub { + my ($param) = @_; + + if ($param->{cidr}) { + raise_param_exc({ address => "address conflicts with cidr" }) + if $param->{address}; + raise_param_exc({ netmask => "netmask conflicts with cidr" }) + if $param->{netmask}; + + my ($address, $netmask) = $param->{cidr} =~ m!^(.*)/(\d+)$!; + $param->{address} = $address; + $param->{netmask} = $netmask; + delete $param->{cidr}; + } + + if ($param->{cidr6}) { + raise_param_exc({ address6 => "address6 conflicts with cidr6" }) + if $param->{address6}; + raise_param_exc({ netmask6 => "netmask6 conflicts with cidr6" }) + if $param->{netmask6}; + + my ($address, $netmask) = $param->{cidr6} =~ m!^(.*)/(\d+)$!; + $param->{address6} = $address; + $param->{netmask6} = $netmask; + delete $param->{cidr6}; + } +}; + __PACKAGE__->register_method({ name => 'create_network', path => '', @@ -304,6 +342,8 @@ __PACKAGE__->register_method({ &$check_duplicate_gateway6($ifaces, $iface) if $param->{gateway6}; + $map_cidr_to_address_netmask->($param); + &$check_ipv6_settings($param->{address6}, int($param->{netmask6})) if $param->{address6}; @@ -386,6 +426,8 @@ __PACKAGE__->register_method({ @$families = grep(!/^inet6$/, @$families) if $k eq 'address6'; } + $map_cidr_to_address_netmask->($param); + &$check_duplicate_gateway($ifaces, $iface) if $param->{gateway}; &$check_duplicate_gateway6($ifaces, $iface)