]> git.proxmox.com Git - pve-network.git/commitdiff
vnet: update_hook: verify if tag already exist in another vnet
authorAlexandre Derumier <aderumier@odiso.com>
Fri, 3 May 2019 09:00:17 +0000 (11:00 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 6 May 2019 05:56:57 +0000 (07:56 +0200)
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/API2/Network/Network.pm
PVE/Network/Network/VnetPlugin.pm

index 6ea8fe2468f38b83461138d637ea39b01c6f563f..d1992341b08cbbf5d80e306bd28119146c658c32 100644 (file)
@@ -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);
 
index b2080e11222f4a7a52b98bd88bcc972588f11b67..593e475e4fd79c7aced8b99990481f1a8659f1d7 100644 (file)
@@ -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 {