X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PVE%2FNetwork%2FSDN%2FVnetPlugin.pm;h=47fd4d4b619fc40b513d3b624e57b31ddfcfd896;hb=e612faf6ba28c0ba52446236067b4cbeeae1a5fa;hp=28a7b59f19caa0f5bb390ff6b37bcd4efa60b23d;hpb=f5eabba018956d5599edbc1578365bb15615ee26;p=pve-network.git diff --git a/PVE/Network/SDN/VnetPlugin.pm b/PVE/Network/SDN/VnetPlugin.pm index 28a7b59..47fd4d4 100644 --- a/PVE/Network/SDN/VnetPlugin.pm +++ b/PVE/Network/SDN/VnetPlugin.pm @@ -6,11 +6,9 @@ use warnings; use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file); use base qw(PVE::SectionConfig); use PVE::JSONSchema qw(get_standard_option); +use PVE::Exception qw(raise raise_param_exc); PVE::Cluster::cfs_register_file('sdn/vnets.cfg', - sub { __PACKAGE__->parse_config(@_); }); - -PVE::Cluster::cfs_register_file('sdn/vnets.cfg.new', sub { __PACKAGE__->parse_config(@_); }, sub { __PACKAGE__->write_config(@_); }); @@ -23,10 +21,11 @@ PVE::JSONSchema::register_format('pve-sdn-vnet-id', \&parse_sdn_vnet_id); sub parse_sdn_vnet_id { my ($id, $noerr) = @_; - if ($id !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) { + if ($id !~ m/^[a-z][a-z0-9]*[a-z0-9]$/i) { return undef if $noerr; - die "SDN object vnet ID '$id' contains illegal characters\n"; + die "vnet ID '$id' contains illegal characters\n"; } + die "vnet ID '$id' can't be more length than 8 characters\n" if length($id) > 8; return $id; } @@ -60,26 +59,15 @@ sub properties { type => 'integer', description => "vlan or vxlan id", }, + vlanaware => { + type => 'boolean', + description => 'Allow vm VLANs to pass through this vnet.', + }, alias => { type => 'string', description => "alias name of the vnet", optional => 1, }, - mtu => { - type => 'integer', - description => "mtu", - optional => 1, - }, - ipv4 => { - description => "Anycast router ipv4 address.", - type => 'string', format => 'CIDRv4', - optional => 1, - }, - ipv6 => { - description => "Anycast router ipv6 address.", - type => 'string', format => 'CIDRv6', - optional => 1, - }, mac => { type => 'string', description => "Anycast router mac address", @@ -91,31 +79,35 @@ sub properties { sub options { return { zone => { optional => 0}, - tag => { optional => 0}, + tag => { optional => 1}, alias => { optional => 1 }, - ipv4 => { optional => 1 }, - ipv6 => { optional => 1 }, - mtu => { optional => 1 }, mac => { optional => 1 }, + vlanaware => { optional => 1 }, }; } sub on_delete_hook { - my ($class, $sdnid, $sdn_cfg) = @_; + my ($class, $vnetid, $vnet_cfg) = @_; - return; + #verify if subnets are associated + my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid); + my @subnetlist = (); + foreach my $subnetid (sort keys %{$subnets}) { + push @subnetlist, $subnetid; + } + raise_param_exc({ vnet => "Vnet is attached to following subnets:". join(',', @subnetlist)}) if @subnetlist > 0; } sub on_update_hook { - my ($class, $sdnid, $sdn_cfg) = @_; + my ($class, $vnetid, $vnet_cfg, $subnet_cfg) = @_; # verify that tag is not already defined in another vnet - if (defined($sdn_cfg->{ids}->{$sdnid}->{tag})) { - my $tag = $sdn_cfg->{ids}->{$sdnid}->{tag}; - foreach my $id (keys %{$sdn_cfg->{ids}}) { - next if $id eq $sdnid; - my $sdn = $sdn_cfg->{ids}->{$id}; - if ($sdn->{type} eq 'vnet' && defined($sdn->{tag})) { - die "tag $tag already exist in vnet $id" if $tag eq $sdn->{tag}; + if (defined($vnet_cfg->{ids}->{$vnetid}->{tag})) { + my $tag = $vnet_cfg->{ids}->{$vnetid}->{tag}; + foreach my $id (keys %{$vnet_cfg->{ids}}) { + next if $id eq $vnetid; + my $vnet = $vnet_cfg->{ids}->{$id}; + if ($vnet->{type} eq 'vnet' && defined($vnet->{tag})) { + raise_param_exc({ tag => "tag $tag already exist in vnet $id"}) if $tag eq $vnet->{tag}; } } }