]> git.proxmox.com Git - pve-network.git/commitdiff
zone: add vnet_update_hook
authorAlexandre Derumier <aderumier@odiso.com>
Mon, 5 Oct 2020 15:08:42 +0000 (17:08 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 6 Oct 2020 15:30:04 +0000 (17:30 +0200)
move verify_tag code in this hook
add mac address generation for simple && evpn plugin

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/API2/Network/SDN/Vnets.pm
PVE/Network/SDN/Zones/EvpnPlugin.pm
PVE/Network/SDN/Zones/Plugin.pm
PVE/Network/SDN/Zones/QinQPlugin.pm
PVE/Network/SDN/Zones/SimplePlugin.pm
PVE/Network/SDN/Zones/VlanPlugin.pm
PVE/Network/SDN/Zones/VxlanPlugin.pm

index 23bc8bb6bd744d6864a12d3070687da346ffb17d..58ec21f58012770cd06fafcdcb70a18e361fd92f 100644 (file)
@@ -131,7 +131,7 @@ __PACKAGE__->register_method ({
            my $zoneid = $cfg->{ids}->{$id}->{zone};
            my $plugin_config = $zone_cfg->{ids}->{$zoneid};
            my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
-           $plugin->verify_tag($opts->{tag});
+            $plugin->vnet_update_hook($cfg->{ids}->{$id});
 
            my $subnet_cfg = PVE::Network::SDN::Subnets::config();
 
@@ -174,7 +174,7 @@ __PACKAGE__->register_method ({
            my $zoneid = $cfg->{ids}->{$id}->{zone};
            my $plugin_config = $zone_cfg->{ids}->{$zoneid};
            my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
-           $plugin->verify_tag($opts->{tag});
+           $plugin->vnet_update_hook($cfg->{ids}->{$id});
 
            my $subnet_cfg = PVE::Network::SDN::Subnets::config();
 
index 83ceb3aec459b7fd0ad1f66d4ff5ef6bd68a48e4..0ebe13e7af7d8c86b2e92ce1ab48202bbfe5c9d7 100644 (file)
@@ -5,6 +5,9 @@ use warnings;
 use PVE::Network::SDN::Zones::VxlanPlugin;
 use PVE::Tools qw($IPV4RE);
 use PVE::INotify;
+use PVE::Cluster;
+use PVE::Tools;
+
 use PVE::Network::SDN::Controllers::EvpnPlugin;
 
 use base('PVE::Network::SDN::Zones::VxlanPlugin');
@@ -143,15 +146,23 @@ sub on_update_hook {
        die "vrf-vxlan $vrfvxlan is already declared in $id"
                if (defined($zone_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $zone_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
     }
+
 }
 
-sub verify_tag {
-    my ($class, $tag) = @_;
 
-    raise_param_exc({ tag => "missing vxlan tag"}) if !defined($tag);
-    raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $tag > 16777216;
+sub vnet_update_hook {
+    my ($class, $vnet) = @_;
+
+    raise_param_exc({ tag => "missing vxlan tag"}) if !defined($vnet->{tag});
+    raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $vnet->{tag} > 16777216;
+
+    if (!defined($vnet->{mac})) {
+       my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
+       $vnet->{mac} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
+    }
 }
 
+
 1;
 
 
index 451699f95e24f8ef747861ee22c462ab20d186f5..7f6db0e95aca35ce65717dbd6683921256e8f66e 100644 (file)
@@ -139,8 +139,9 @@ sub on_update_hook {
     # do nothing by default
 }
 
-sub verify_tag {
-    my ($class, $tag) = @_;
+sub vnet_update_hook {
+    my ($class, $vnet) = @_;
+
     # do nothing by default
 }
 
index 5fffd15e10f4be40fadc9d84e0915183086ddde0..c828af432509f592a531d9fb94755afcbbb4be63 100644 (file)
@@ -211,11 +211,11 @@ sub status {
     return $err_msg;
 }
 
-sub verify_tag {
-    my ($class, $tag) = @_;
+sub vnet_update_hook {
+    my ($class, $vnet) = @_;
 
-    raise_param_exc({ tag => "missing vlan tag"}) if !defined($tag);
-    raise_param_exc({ tag => "vlan tag max value is 4096"}) if $tag > 4096;
+    raise_param_exc({ tag => "missing vlan tag"}) if !defined($vnet->{tag});
+    raise_param_exc({ tag => "vlan tag max value is 4096"}) if $vnet->{tag} > 4096;
 }
 
 1;
index 312dcbf0e2d965a8a90f2235e7adca419e831755..7006b133d9900e8e601d7f32d82be186d4b8fdc2 100644 (file)
@@ -4,6 +4,8 @@ use strict;
 use warnings;
 use PVE::Network::SDN::Zones::Plugin;
 use PVE::Exception qw(raise raise_param_exc);
+use PVE::Cluster;
+use PVE::Tools;
 
 use base('PVE::Network::SDN::Zones::Plugin');
 
@@ -71,10 +73,16 @@ sub status {
     return $err_msg;
 }
 
-sub verify_tag {
-    my ($class, $tag) = @_;
 
-    raise_param_exc({ tag => "vlan tag is not allowed on simple bridge"}) if defined($tag);
+sub vnet_update_hook {
+    my ($class, $vnet) = @_;
+
+    raise_param_exc({ tag => "vlan tag is not allowed on simple bridge"}) if defined($vnet->{tag});
+
+    if (!defined($vnet->{mac})) {
+        my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
+        $vnet->{mac} = PVE::Tools::random_ether_addr($dc->{mac_prefix});
+    }
 }
 
 1;
index 8485ae192ea76c5e5e3599661643bf6d98ed762a..7f90d312ab0efd3d8a0007abb70f5309e9eb0396 100644 (file)
@@ -170,11 +170,11 @@ sub status {
     return $err_msg;
 }
 
-sub verify_tag {
-    my ($class, $tag) = @_;
+sub vnet_update_hook {
+    my ($class, $vnet) = @_;
 
-    raise_param_exc({ tag => "missing vlan tag"}) if !defined($tag);
-    raise_param_exc({ tag => "vlan tag max value is 4096"}) if $tag > 4096;
+    raise_param_exc({ tag => "missing vlan tag"}) if !defined($vnet->{tag});
+    raise_param_exc({ tag => "vlan tag max value is 4096"}) if $vnet->{tag} > 4096;
 }
 
 1;
index 8386c43110ab0d7f3b3424c0b4e322bbb1d02d06..79af0546eaac3d13456fe7af13505769bdf378bd 100644 (file)
@@ -89,11 +89,11 @@ sub generate_sdn_config {
     return $config;
 }
 
-sub verify_tag {
-    my ($class, $tag) = @_;
+sub vnet_update_hook {
+    my ($class, $vnet) = @_;
 
-    raise_param_exc({ tag => "missing vxlan tag"}) if !defined($tag);
-    raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $tag > 16777216;
+    raise_param_exc({ tag => "missing vxlan tag"}) if !defined($vnet->{tag});
+    raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $vnet->{tag} > 16777216;
 }
 
 1;