[pve-devel] [PATCH 01/19] qm create : make vmid optionnal

Alexandre Derumier aderumier at odiso.com
Wed Feb 22 14:33:25 CET 2017


if ommit, we generate it with PVE::Cluster::next_vmid

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

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index a077ed7..76bba70 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -375,7 +375,7 @@ __PACKAGE__->register_method({
 	properties => PVE::QemuServer::json_config_properties(
 	    {
 		node => get_standard_option('pve-node'),
-		vmid => get_standard_option('pve-vmid', { completion => \&PVE::Cluster::complete_next_vmid }),
+		vmid => get_standard_option('pve-vmid', { completion => \&PVE::Cluster::complete_next_vmid, optional => 1 }),
 		archive => {
 		    description => "The backup file.",
 		    type => 'string',
@@ -431,12 +431,18 @@ __PACKAGE__->register_method({
 
 	my $pool = extract_param($param, 'pool');
 
-	my $filename = PVE::QemuConfig->config_file($vmid);
-
 	my $storecfg = PVE::Storage::config();
 
 	PVE::Cluster::check_cfs_quorum();
 
+	if (!$vmid) {
+	    my $nextvmid = PVE::Cluster::complete_next_vmid() if !$vmid;
+	    $vmid = @$nextvmid[0];
+	    die "Can't generate a new vmid" if !$vmid;
+	}
+
+	my $filename = PVE::QemuConfig->config_file($vmid);
+
 	if (defined($pool)) {
 	    $rpcenv->check_pool_exist($pool);
 	}
@@ -571,6 +577,8 @@ __PACKAGE__->register_method({
 		    die "create failed - $err";
 		}
 
+		print "vm $vmid created\n";
+
 		PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;
 	    };
 
-- 
2.1.4




More information about the pve-devel mailing list