[pve-devel] [PATCH pve-network 4/7] vnet: update_hook: verify if tag already exist in another vnet
Alexandre Derumier
aderumier at odiso.com
Fri May 3 11:00:17 CEST 2019
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Network/Network.pm | 4 ++--
PVE/Network/Network/VnetPlugin.pm | 14 +++++++++++---
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/PVE/API2/Network/Network.pm b/PVE/API2/Network/Network.pm
index 6ea8fe2..d199234 100644
--- a/PVE/API2/Network/Network.pm
+++ b/PVE/API2/Network/Network.pm
@@ -137,7 +137,7 @@ __PACKAGE__->register_method ({
}
$cfg->{ids}->{$networkid} = $opts;
- $plugin->on_update_hook($networkid, $scfg);
+ $plugin->on_update_hook($networkid, $cfg);
PVE::Network::Network::write_config($cfg);
@@ -179,7 +179,7 @@ __PACKAGE__->register_method ({
$scfg->{$k} = $opts->{$k};
}
- $plugin->on_update_hook($networkid, $scfg);
+ $plugin->on_update_hook($networkid, $cfg);
PVE::Network::Network::write_config($cfg);
diff --git a/PVE/Network/Network/VnetPlugin.pm b/PVE/Network/Network/VnetPlugin.pm
index b2080e1..593e475 100644
--- a/PVE/Network/Network/VnetPlugin.pm
+++ b/PVE/Network/Network/VnetPlugin.pm
@@ -107,10 +107,18 @@ sub on_delete_hook {
}
sub on_update_hook {
- my ($class, $networkid, $scfg) = @_;
-
+ my ($class, $networkid, $network_cfg) = @_;
# verify that tag is not already defined in another vnet
-
+ if (defined($network_cfg->{ids}->{$networkid}->{tag})) {
+ my $tag = $network_cfg->{ids}->{$networkid}->{tag};
+ foreach my $id (keys %{$network_cfg->{ids}}) {
+ next if $id eq $networkid;
+ my $network = $network_cfg->{ids}->{$id};
+ if ($network->{type} eq 'vnet' && defined($network->{tag})) {
+ die "tag $tag already exist in vnet $id" if $tag eq $network->{tag};
+ }
+ }
+ }
}
sub read_cluster_vm_config {
--
2.11.0
More information about the pve-devel
mailing list