Commit d065cd5a authored by Dietmar Maurer's avatar Dietmar Maurer

fix bug 178: correctly verify if VMID is already used

parent 33d02079
......@@ -7,6 +7,7 @@ use XML::Parser;
use PVE::SafeSyslog;
use PVE::Tools qw(extract_param);
use PVE::Exception qw(raise_param_exc);
use PVE::INotify;
use PVE::Cluster qw(cfs_register_file cfs_lock_file cfs_read_file cfs_write_file);
use PVE::Storage;
......@@ -16,6 +17,7 @@ use PVE::API2::HAConfig;
use JSON;
use PVE::RESTHandler;
use PVE::RPCEnvironment;
use PVE::JSONSchema qw(get_standard_option);
use base qw(PVE::RESTHandler);
......@@ -70,6 +72,7 @@ __PACKAGE__->register_method ({
{ name => 'backup' },
{ name => 'ha' },
{ name => 'status' },
{ name => 'nextid' },
];
return $result;
......@@ -480,4 +483,38 @@ __PACKAGE__->register_method({
}
}});
__PACKAGE__->register_method({
name => 'nextid',
path => 'nextid',
method => 'GET',
description => "Get next free VMID. If you pass an VMID it will raise an error if the ID is already used.",
permissions => { user => 'all' },
parameters => {
additionalProperties => 0,
properties => {
vmid => get_standard_option('pve-vmid', {optional => 1}),
},
},
returns => {
type => 'integer',
description => "The next free VMID.",
},
code => sub {
my ($param) = @_;
my $vmlist = PVE::Cluster::get_vmlist() || {};
my $idlist = $vmlist->{ids} || {};
if (my $vmid = $param->{vmid}) {
return $vmid if !defined($idlist->{$vmid});
raise_param_exc({ vmid => "VM $vmid already exists" });
}
for (my $i = 100; $i < 10000; $i++) {
return $i if !defined($idlist->{$i});
}
die "unable to get any free VMID\n";
}});
1;
pve-manager (2.1-16) unstable; urgency=low
* vzrestore: allow --storage option
* fix bug 178: correctly verify if VMID is already used
-- Proxmox Support Team <support@proxmox.com> Wed, 05 Sep 2012 08:04:28 +0200
......
......@@ -10,31 +10,33 @@ Ext.define('PVE.form.VMIDSelector', {
validateExists: undefined,
validator: function(value) {
/*jslint confusion: true */
var me = this;
if (!Ext.isDefined(me.validateExists)) {
return true;
}
if (PVE.data.ResourceStore.findVMID(value)) {
if (me.validateExists === true) {
return true;
}
return "This VM ID is already in use.";
} else {
if (me.validateExists === false) {
return true;
}
return "This VM ID does not exists.";
}
},
initComponent: function() {
var me = this;
Ext.applyIf(me, {
fieldLabel: 'VM ID'
fieldLabel: 'VM ID',
listeners: {
'change': function(field, newValue, oldValue) {
if (!Ext.isDefined(me.validateExists)) {
return;
}
PVE.Utils.API2Request({
params: { vmid: newValue },
url: '/cluster/nextid',
method: 'GET',
success: function(response, opts) {
if (me.validateExists === true) {
me.markInvalid("This VM ID does not exists.");
}
},
failure: function(response, opts) {
if (me.validateExists === false) {
me.markInvalid("This VM ID is already in use.");
}
}
});
}
}
});
me.callParent();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment