You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by jf...@apache.org on 2012/11/16 20:40:33 UTC
svn commit: r1410549 - in /vcl/branches/vcl-2.3-bugfixes/web: .ht-inc/vm.php
js/vm.js
Author: jfthomps
Date: Fri Nov 16 19:40:33 2012
New Revision: 1410549
URL: http://svn.apache.org/viewvc?rev=1410549&view=rev
Log:
VCL-643
VM Limit can be decreased to below the current number of assigned VMs
vm.php:
-modified editVMInfo - changed vm limit widget to do updates immediately after change instead of after focus change
-modified updateVMlimit - changed to send JSON as reponse; if limit has not changed, return success right away; check for new limit being below the number of currently assigned VMs, and if so, return an error and new limit that is the current number of assigned VMs
vm.js:
-modified updateVMlimit - call xhrPost with handleAs set to JSON
-modified updateVMlimitCB - handle data as JSON; if status is LIMIT, set limit to specified value
Modified:
vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/vm.php
vcl/branches/vcl-2.3-bugfixes/web/js/vm.js
Modified: vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/vm.php
URL: http://svn.apache.org/viewvc/vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/vm.php?rev=1410549&r1=1410548&r2=1410549&view=diff
==============================================================================
--- vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/vm.php (original)
+++ vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/vm.php Fri Nov 16 19:40:33 2012
@@ -78,6 +78,7 @@ function editVMInfo() {
print " constraints=\"{min:1,max:" . MAXVMLIMIT . "}\"\n";
print " maxlength=\"3\"\n";
print " id=\"vmlimit\"\n";
+ print " intermediateChanges=\"true\"\n";
print " onChange=\"updateVMlimit('$cont')\">\n";
print " </td>\n";
print " </tr>\n";
@@ -523,25 +524,56 @@ function getVMHostData($id='') {
function updateVMlimit() {
global $mysql_link_vcl;
$vmhostid = processInputVar('vmhostid', ARG_NUMERIC);
+ $newlimit = processInputVar('newlimit', ARG_NUMERIC);
$data = getVMHostData($vmhostid);
+
+ if($data[$vmhostid]['vmlimit'] == $newlimit) {
+ sendJSON(array('status' => 'SUCCESS'));
+ return;
+ }
$resources = getUserResources(array("computerAdmin"), array("administer"));
if(! array_key_exists($data[$vmhostid]['computerid'], $resources['computer'])) {
- print 'You do not have access to manage this host.';
+ print "alert('You do not have access to manage this host.');";
+ $rc = array('status' => 'ERROR',
+ 'msg' => "You do not have access to manage this host.");
+ sendJSON($rc);
return;
}
- $newlimit = processInputVar('newlimit', ARG_NUMERIC);
if($newlimit < 0 || $newlimit > MAXVMLIMIT) {
- print "ERROR: newlimit out of range";
+ $rc = array('status' => 'ERROR',
+ 'msg' => "ERROR: newlimit out of range");
+ sendJSON($rc);
+ return;
+ }
+
+ # get number of vms assigned to vmhost
+ $query = "SELECT COUNT(id) as assigned "
+ . "FROM computer "
+ . "WHERE type = 'virtualmachine' AND "
+ . "vmhostid = $vmhostid AND "
+ . "deleted = 0";
+ $qh = doQuery($query, 101);
+ $row = mysql_fetch_assoc($qh);
+ if($row['assigned'] > $newlimit) {
+ $rc = array('status' => 'LIMIT',
+ 'msg' => "Cannot reduce VM limit below the current number of assigned VMs",
+ 'limit' => $row['assigned']);
+ sendJSON($rc);
return;
}
+
$query = "UPDATE vmhost SET vmlimit = $newlimit WHERE id = $vmhostid";
$qh = doQuery($query, 101);
- if(mysql_affected_rows($mysql_link_vcl))
- print "SUCCESS";
- else
- print "ERROR: failed to update vmlimit";
+ if(mysql_affected_rows($mysql_link_vcl) == 0) {
+ $rc = array('status' => 'ERROR',
+ 'msg' => "ERROR: failed to update vmlimit",
+ 'data' => $data);
+ sendJSON($rc);
+ return;
+ }
+ sendJSON(array('status' => 'SUCCESS'));
}
////////////////////////////////////////////////////////////////////////////////
Modified: vcl/branches/vcl-2.3-bugfixes/web/js/vm.js
URL: http://svn.apache.org/viewvc/vcl/branches/vcl-2.3-bugfixes/web/js/vm.js?rev=1410549&r1=1410548&r2=1410549&view=diff
==============================================================================
--- vcl/branches/vcl-2.3-bugfixes/web/js/vm.js (original)
+++ vcl/branches/vcl-2.3-bugfixes/web/js/vm.js Fri Nov 16 19:40:33 2012
@@ -141,6 +141,7 @@ function updateVMlimit(cont) {
dojo.xhrPost({
url: 'index.php',
load: updateVMlimitCB,
+ handleAs: "json",
error: errorHandler,
content: {continuation: cont,
vmhostid: hostid,
@@ -150,8 +151,10 @@ function updateVMlimit(cont) {
}
function updateVMlimitCB(data, ioArgs) {
- if(data != 'SUCCESS') {
- alert(data);
+ if(data.items.status != 'SUCCESS') {
+ if(data.items.status == 'LIMIT')
+ dijit.byId('vmlimit').set('value', data.items.limit);
+ alert(data.items.msg);
}
document.body.style.cursor = 'default';
}