[pve-devel] [PATCH v2 pve-network 10/15] fix zones on_update_hook
Alexandre Derumier
aderumier at odiso.com
Tue Nov 26 10:00:25 CET 2019
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Network/SDN/Zones.pm | 22 +++++-----
PVE/Network/SDN/Zones/EvpnPlugin.pm | 63 ++++++++++-----------------
PVE/Network/SDN/Zones/FaucetPlugin.pm | 6 ---
PVE/Network/SDN/Zones/Plugin.pm | 2 +-
4 files changed, 37 insertions(+), 56 deletions(-)
diff --git a/PVE/API2/Network/SDN/Zones.pm b/PVE/API2/Network/SDN/Zones.pm
index 16c90cc..00380dc 100644
--- a/PVE/API2/Network/SDN/Zones.pm
+++ b/PVE/API2/Network/SDN/Zones.pm
@@ -142,17 +142,18 @@ __PACKAGE__->register_method ({
PVE::Network::SDN::Zones::lock_sdn_zones_config(
sub {
- my $cfg = PVE::Network::SDN::Zones::config();
+ my $zone_cfg = PVE::Network::SDN::Zones::config();
+ my $controller_cfg = PVE::Network::SDN::Controllers::config();
my $scfg = undef;
- if ($scfg = PVE::Network::SDN::Zones::sdn_zones_config($cfg, $id, 1)) {
+ if ($scfg = PVE::Network::SDN::Zones::sdn_zones_config($zone_cfg, $id, 1)) {
die "sdn zone object ID '$id' already defined\n";
}
- $cfg->{ids}->{$id} = $opts;
- $plugin->on_update_hook($id, $cfg);
+ $zone_cfg->{ids}->{$id} = $opts;
+ $plugin->on_update_hook($id, $zone_cfg, $controller_cfg);
- PVE::Network::SDN::Zones::write_config($cfg);
+ PVE::Network::SDN::Zones::write_config($zone_cfg);
}, "create sdn zone object failed");
@@ -201,11 +202,12 @@ __PACKAGE__->register_method ({
PVE::Network::SDN::Zones::lock_sdn_zones_config(
sub {
- my $cfg = PVE::Network::SDN::Zones::config();
+ my $zone_cfg = PVE::Network::SDN::Zones::config();
+ my $controller_cfg = PVE::Network::SDN::Controllers::config();
- PVE::SectionConfig::assert_if_modified($cfg, $digest);
+ PVE::SectionConfig::assert_if_modified($zone_cfg, $digest);
- my $scfg = PVE::Network::SDN::Zones::sdn_zones_config($cfg, $id);
+ my $scfg = PVE::Network::SDN::Zones::sdn_zones_config($zone_cfg, $id);
my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($scfg->{type});
my $opts = $plugin->check_config($id, $param, 0, 1);
@@ -214,9 +216,9 @@ __PACKAGE__->register_method ({
$scfg->{$k} = $opts->{$k};
}
- $plugin->on_update_hook($id, $cfg);
+ $plugin->on_update_hook($id, $zone_cfg, $controller_cfg);
- PVE::Network::SDN::Zones::write_config($cfg);
+ PVE::Network::SDN::Zones::write_config($zone_cfg);
}, "update sdn zone object failed");
diff --git a/PVE/Network/SDN/Zones/EvpnPlugin.pm b/PVE/Network/SDN/Zones/EvpnPlugin.pm
index 012274f..1119226 100644
--- a/PVE/Network/SDN/Zones/EvpnPlugin.pm
+++ b/PVE/Network/SDN/Zones/EvpnPlugin.pm
@@ -12,12 +12,6 @@ sub type {
return 'evpn';
}
-sub plugindata {
- return {
- role => 'transport',
- };
-}
-
sub properties {
return {
'vrf' => {
@@ -133,41 +127,32 @@ sub generate_sdn_config {
}
sub on_update_hook {
- my ($class, $transportid, $sdn_cfg) = @_;
-
- # verify that router exist
- if (defined($sdn_cfg->{ids}->{$transportid}->{controller})) {
- my $controller = $sdn_cfg->{ids}->{$transportid}->{controller};
- if (!defined($sdn_cfg->{ids}->{$controller})) {
- die "controller $controller don't exist";
- } else {
- die "$controller is not a evpn controller type" if $sdn_cfg->{ids}->{$controller}->{type} ne 'evpn';
- }
+ my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_;
+
+ # verify that controller exist
+ my $controller = $zone_cfg->{ids}->{$zoneid}->{controller};
+ if (!defined($controller_cfg->{ids}->{$controller})) {
+ die "controller $controller don't exist";
+ } else {
+ die "$controller is not a evpn controller type" if $controller_cfg->{ids}->{$controller}->{type} ne 'evpn';
+ }
- #vrf && vrf-vxlan need to be defined with controller
- my $vrf = $sdn_cfg->{ids}->{$transportid}->{vrf};
- if (!defined($vrf)) {
- die "missing vrf option";
- } else {
- # verify that vrf is not already declared in another transport
- foreach my $id (keys %{$sdn_cfg->{ids}}) {
- next if $id eq $transportid;
- die "vrf $vrf is already declared in $id"
- if (defined($sdn_cfg->{ids}->{$id}->{vrf}) && $sdn_cfg->{ids}->{$id}->{vrf} eq $vrf);
- }
- }
+ #vrf && vrf-vxlan need to be defined
+ my $vrf = $zone_cfg->{ids}->{$zoneid}->{vrf};
- my $vrfvxlan = $sdn_cfg->{ids}->{$transportid}->{'vrf-vxlan'};
- if (!defined($vrfvxlan)) {
- die "missing vrf-vxlan option";
- } else {
- # verify that vrf-vxlan is not already declared in another transport
- foreach my $id (keys %{$sdn_cfg->{ids}}) {
- next if $id eq $transportid;
- die "vrf-vxlan $vrfvxlan is already declared in $id"
- if (defined($sdn_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $sdn_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
- }
- }
+ # verify that vrf is not already declared in another zone
+ foreach my $id (keys %{$zone_cfg->{ids}}) {
+ next if $id eq $zoneid;
+ die "vrf $vrf is already declared in $id"
+ if (defined($zone_cfg->{ids}->{$id}->{vrf}) && $zone_cfg->{ids}->{$id}->{vrf} eq $vrf);
+ }
+
+ my $vrfvxlan = $zone_cfg->{ids}->{$zoneid}->{'vrf-vxlan'};
+ # verify that vrf-vxlan is not already declared in another zone
+ foreach my $id (keys %{$zone_cfg->{ids}}) {
+ next if $id eq $zoneid;
+ 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);
}
}
diff --git a/PVE/Network/SDN/Zones/FaucetPlugin.pm b/PVE/Network/SDN/Zones/FaucetPlugin.pm
index 2a196bd..bece4e4 100644
--- a/PVE/Network/SDN/Zones/FaucetPlugin.pm
+++ b/PVE/Network/SDN/Zones/FaucetPlugin.pm
@@ -10,12 +10,6 @@ sub type {
return 'faucet';
}
-sub plugindata {
- return {
- role => 'transport',
- };
-}
-
sub properties {
return {
'dp-id' => {
diff --git a/PVE/Network/SDN/Zones/Plugin.pm b/PVE/Network/SDN/Zones/Plugin.pm
index 62db9cd..c252dfc 100644
--- a/PVE/Network/SDN/Zones/Plugin.pm
+++ b/PVE/Network/SDN/Zones/Plugin.pm
@@ -130,7 +130,7 @@ sub on_delete_hook {
}
sub on_update_hook {
- my ($class, $sdnid, $scfg) = @_;
+ my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_;
# do nothing by default
}
--
2.20.1
More information about the pve-devel
mailing list