]> git.proxmox.com Git - pve-network.git/blobdiff - PVE/Network/SDN/VnetPlugin.pm
zones: evpn : add support for loopback
[pve-network.git] / PVE / Network / SDN / VnetPlugin.pm
index d24a539f41aff4623cb7ef3f1640512d7231048e..34841ae5edb776fb1c71a5c336508f3199fd7e14 100644 (file)
@@ -4,13 +4,13 @@ use strict;
 use warnings;
 
 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
-use base qw(PVE::SectionConfig);
+use PVE::Exception qw(raise raise_param_exc);
 use PVE::JSONSchema qw(get_standard_option);
 
-PVE::Cluster::cfs_register_file('sdn/vnets.cfg',
-                                 sub { __PACKAGE__->parse_config(@_); });
+use PVE::SectionConfig;
+use base qw(PVE::SectionConfig);
 
-PVE::Cluster::cfs_register_file('sdn/vnets.cfg.new',
+PVE::Cluster::cfs_register_file('sdn/vnets.cfg',
                                  sub { __PACKAGE__->parse_config(@_); },
                                  sub { __PACKAGE__->write_config(@_); });
 
@@ -27,7 +27,7 @@ sub parse_sdn_vnet_id {
         return undef if $noerr;
         die "vnet ID '$id' contains illegal characters\n";
     }
-    die "vnet ID '$id' can't be more length than 10 characters\n" if length($id) > 10;
+    die "vnet ID '$id' can't be more length than 8 characters\n" if length($id) > 8;
     return $id;
 }
 
@@ -61,26 +61,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",
@@ -92,33 +81,32 @@ 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, $vnet_cfg) = @_;
+    my ($class, $vnetid, $vnet_cfg) = @_;
 
-    return;
+    #verify if subnets are associated
+    my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid);
+    raise_param_exc({ vnet => "Can't delete vnet if subnets exists"}) if $subnets;
 }
 
 sub on_update_hook {
     my ($class, $vnetid, $vnet_cfg) = @_;
-    # 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})) {
-               die "tag $tag already exist in vnet $id" if $tag eq $vnet->{tag};
-           }
-       }
+
+    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;
     }
 }