Commit 2aabf72c authored by Dietmar Maurer's avatar Dietmar Maurer

use API call to get next free VMID

We cant use the ResourceStore, because it only contains VM accessable for
actual user.
parent 9128a8c8
...@@ -2,22 +2,11 @@ Ext.define('PVE.data.ResourceStore', { ...@@ -2,22 +2,11 @@ Ext.define('PVE.data.ResourceStore', {
extend: 'PVE.data.UpdateStore', extend: 'PVE.data.UpdateStore',
singleton: true, 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) { findVMID: function(vmid) {
var me = this, i; var me = this, i;
return (me.findExact('vmid', parseInt(vmid, 10)) >= 0); return (me.findExact('vmid', parseInt(vmid, 10)) >= 0);
}, },
constructor: function(config) { constructor: function(config) {
// fixme: how to avoid those warnings // fixme: how to avoid those warnings
......
...@@ -10,6 +10,8 @@ Ext.define('PVE.form.VMIDSelector', { ...@@ -10,6 +10,8 @@ Ext.define('PVE.form.VMIDSelector', {
validateExists: undefined, validateExists: undefined,
loadNextFreeVMID: false,
initComponent: function() { initComponent: function() {
var me = this; var me = this;
...@@ -40,5 +42,15 @@ Ext.define('PVE.form.VMIDSelector', { ...@@ -40,5 +42,15 @@ Ext.define('PVE.form.VMIDSelector', {
}); });
me.callParent(); me.callParent();
if (me.loadNextFreeVMID) {
PVE.Utils.API2Request({
url: '/cluster/nextid',
method: 'GET',
success: function(response, opts) {
me.setRawValue(response.result.data);
}
});
}
} }
}); });
...@@ -5,8 +5,6 @@ Ext.define('PVE.openvz.CreateWizard', { ...@@ -5,8 +5,6 @@ Ext.define('PVE.openvz.CreateWizard', {
initComponent: function() { initComponent: function() {
var me = this; var me = this;
var nextvmid = PVE.data.ResourceStore.findNextVMID();
var summarystore = Ext.create('Ext.data.Store', { var summarystore = Ext.create('Ext.data.Store', {
model: 'KeyValue', model: 'KeyValue',
sorters: [ sorters: [
...@@ -79,7 +77,8 @@ Ext.define('PVE.openvz.CreateWizard', { ...@@ -79,7 +77,8 @@ Ext.define('PVE.openvz.CreateWizard', {
{ {
xtype: 'pveVMIDSelector', xtype: 'pveVMIDSelector',
name: 'vmid', name: 'vmid',
value: nextvmid, value: '',
loadNextFreeVMID: true,
validateExists: false validateExists: false
}, },
{ {
......
...@@ -6,8 +6,6 @@ Ext.define('PVE.qemu.CreateWizard', { ...@@ -6,8 +6,6 @@ Ext.define('PVE.qemu.CreateWizard', {
initComponent: function() { initComponent: function() {
var me = this; var me = this;
var nextvmid = PVE.data.ResourceStore.findNextVMID();
var summarystore = Ext.create('Ext.data.Store', { var summarystore = Ext.create('Ext.data.Store', {
model: 'KeyValue', model: 'KeyValue',
sorters: [ sorters: [
...@@ -59,7 +57,8 @@ Ext.define('PVE.qemu.CreateWizard', { ...@@ -59,7 +57,8 @@ Ext.define('PVE.qemu.CreateWizard', {
{ {
xtype: 'pveVMIDSelector', xtype: 'pveVMIDSelector',
name: 'vmid', name: 'vmid',
value: nextvmid, value: '',
loadNextFreeVMID: true,
validateExists: false validateExists: false
}, },
{ {
......
...@@ -45,7 +45,8 @@ Ext.define('PVE.window.Restore', { ...@@ -45,7 +45,8 @@ Ext.define('PVE.window.Restore', {
xtype: me.vmid ? 'displayfield' : 'pveVMIDSelector', xtype: me.vmid ? 'displayfield' : 'pveVMIDSelector',
name: 'vmid', name: 'vmid',
fieldLabel: 'VM ID', fieldLabel: 'VM ID',
value: me.vmid || PVE.data.ResourceStore.findNextVMID(), value: me.vmid,
loadNextFreeVMID: me.vmid ? false: true,
validateExists: false validateExists: false
} }
] ]
......
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