use API call to get next free VMID

We cant use the ResourceStore, because it only contains VM accessable for
actual user.
This commit is contained in:
Dietmar Maurer 2012-09-27 08:13:51 +02:00
parent 9128a8c82c
commit 2aabf72c92
5 changed files with 18 additions and 18 deletions

View File

@ -2,23 +2,12 @@ Ext.define('PVE.data.ResourceStore', {
extend: 'PVE.data.UpdateStore',
singleton: true,
findNextVMID: function() {
var me = this, i;
for (i = 100; i < 10000; i++) {
if (me.findExact('vmid', i) < 0) {
return i;
}
}
},
findVMID: function(vmid) {
var me = this, i;
return (me.findExact('vmid', parseInt(vmid, 10)) >= 0);
},
constructor: function(config) {
// fixme: how to avoid those warnings
/*jslint confusion: true */

View File

@ -10,6 +10,8 @@ Ext.define('PVE.form.VMIDSelector', {
validateExists: undefined,
loadNextFreeVMID: false,
initComponent: function() {
var me = this;
@ -40,5 +42,15 @@ Ext.define('PVE.form.VMIDSelector', {
});
me.callParent();
if (me.loadNextFreeVMID) {
PVE.Utils.API2Request({
url: '/cluster/nextid',
method: 'GET',
success: function(response, opts) {
me.setRawValue(response.result.data);
}
});
}
}
});

View File

@ -5,8 +5,6 @@ Ext.define('PVE.openvz.CreateWizard', {
initComponent: function() {
var me = this;
var nextvmid = PVE.data.ResourceStore.findNextVMID();
var summarystore = Ext.create('Ext.data.Store', {
model: 'KeyValue',
sorters: [
@ -79,7 +77,8 @@ Ext.define('PVE.openvz.CreateWizard', {
{
xtype: 'pveVMIDSelector',
name: 'vmid',
value: nextvmid,
value: '',
loadNextFreeVMID: true,
validateExists: false
},
{

View File

@ -6,8 +6,6 @@ Ext.define('PVE.qemu.CreateWizard', {
initComponent: function() {
var me = this;
var nextvmid = PVE.data.ResourceStore.findNextVMID();
var summarystore = Ext.create('Ext.data.Store', {
model: 'KeyValue',
sorters: [
@ -59,7 +57,8 @@ Ext.define('PVE.qemu.CreateWizard', {
{
xtype: 'pveVMIDSelector',
name: 'vmid',
value: nextvmid,
value: '',
loadNextFreeVMID: true,
validateExists: false
},
{

View File

@ -45,7 +45,8 @@ Ext.define('PVE.window.Restore', {
xtype: me.vmid ? 'displayfield' : 'pveVMIDSelector',
name: 'vmid',
fieldLabel: 'VM ID',
value: me.vmid || PVE.data.ResourceStore.findNextVMID(),
value: me.vmid,
loadNextFreeVMID: me.vmid ? false: true,
validateExists: false
}
]