[pve-devel] [RFC container] allow automatic VMID selection on create

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Oct 17 17:44:35 CEST 2016


Using a dot (.) as a VMID will automatically select an available one,
this can be helpful for mass CT creation or may be simply just
convenient.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/API2/LXC.pm | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 15ebb87..7a0b97a 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -109,7 +109,7 @@ __PACKAGE__->register_method({
     	additionalProperties => 0,
 	properties => PVE::LXC::Config->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-optional', { completion => \&PVE::Cluster::complete_next_vmid }),
 	    ostemplate => {
 		description => "The OS template or backup file.",
 		type => 'string',
@@ -170,6 +170,11 @@ __PACKAGE__->register_method({
 
 	my $vmid = extract_param($param, 'vmid');
 
+	if ($vmid eq '.') {
+	    $vmid = PVE::Cluster::next_unused_vmid(100, 100000, 1);
+	    print "creating CT with VMID '$vmid'\n" if $rpcenv->{type} eq 'cli';
+	}
+
 	my $ignore_unpack_errors = extract_param($param, 'ignore-unpack-errors');
 
 	my $basecfg_fn = PVE::LXC::Config->config_file($vmid);
-- 
2.1.4





More information about the pve-devel mailing list