]> git.proxmox.com Git - pve-network.git/blobdiff - PVE/Network/SDN/VnetPlugin.pm
vnets: alias: fix regex
[pve-network.git] / PVE / Network / SDN / VnetPlugin.pm
index 8481f0d16d98a3a81b52f487ab65d30d660bb25a..062904c98d884b606c571c3f7082a6a19e9952c9 100644 (file)
@@ -4,9 +4,11 @@ use strict;
 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(@_); },
@@ -66,13 +68,10 @@ sub properties {
         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'
-        }
     };
 }
 
@@ -81,7 +80,6 @@ sub options {
         zone => { optional => 0},
         tag => { optional => 1},
         alias => { optional => 1 },
-        mac => { optional => 1 },
         vlanaware => { optional => 1 },
     };
 }
@@ -91,30 +89,20 @@ sub on_delete_hook {
 
     #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;
     }
 }