[pve-devel] [PATCH 1/3] add nic hotplug to update_vm

Derumier Alexandre aderumier at odiso.com
Sat Jan 28 11:02:27 CET 2012


Signed-off-by: Derumier Alexandre <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index adb19ff..48b99d1 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -563,12 +563,24 @@ __PACKAGE__->register_method({
 		    }
 		}
 		#nics
+		my $net = undef;
 		if ($opt =~ m/^net(\d+)$/) {
-		    my $net = PVE::QemuServer::parse_net($param->{$opt});
+		    $net = PVE::QemuServer::parse_net($param->{$opt});
 		    $param->{$opt} = PVE::QemuServer::print_net($net);
+		    #if online update, then unplug first
+		    die "error hot-unplug $opt for update" if $conf->{$opt} && !PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
 		}
 
 		PVE::QemuServer::change_config_nolock($vmid, { $opt => $param->{$opt} }, {}, 1);
+
+		#nic hotplug after config write as we need it for pve-bridge script
+		if (defined ($net)) {
+		    if(!PVE::QemuServer::vm_deviceplug($storecfg, $conf, $vmid, $opt, $net)) {
+		    #rewrite conf to remove nic if hotplug fail
+		    PVE::QemuServer::change_config_nolock($vmid, {}, { $opt => 1 }, 1);
+		    die "error hotplug $opt";
+		    }
+		}
 	    }
 	};
 
-- 
1.7.2.5




More information about the pve-devel mailing list