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);
+use PVE::JSONSchema qw(get_standard_option);
+
+use PVE::SectionConfig;
+use base qw(PVE::SectionConfig);
PVE::Cluster::cfs_register_file('sdn/vnets.cfg',
sub { __PACKAGE__->parse_config(@_); },
alias => {
type => 'string',
description => "alias name of the vnet",
+ pattern => qr/[\(\)-_.\w\d\s]{0,256}/i,
+ maxLength => 256,
optional => 1,
},
- mac => {
- type => 'string',
- description => "Anycast router mac address",
- optional => 1, format => 'mac-addr'
- }
};
}
zone => { optional => 0},
tag => { optional => 1},
alias => { optional => 1 },
- mac => { optional => 1 },
vlanaware => { optional => 1 },
};
}
#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;
+ raise_param_exc({ vnet => "Can't delete vnet if subnets exists"}) if $subnets;
}
sub on_update_hook {
- my ($class, $vnetid, $vnet_cfg, $subnet_cfg) = @_;
-
- #fixme : don't allow change zone if subnets are defined
- #fixme : don't vlanaware change if subnets are defined
-# my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid);
-
- # verify that tag is not already defined in another vnet
- 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};
- }
- }
+ my ($class, $vnetid, $vnet_cfg) = @_;
+
+ my $vnet = $vnet_cfg->{ids}->{$vnetid};
+ my $tag = $vnet->{tag};
+ my $vlanaware = $vnet->{vlanaware};
+
+ #don't allow vlanaware change if subnets are defined
+ if($vnet->{vlanaware}) {
+ my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid);
+ raise_param_exc({ vlanaware => "vlanaware vnet is not compatible with subnets"}) if $subnets;
}
}