Author: jfthomps
Date: Mon Sep 13 19:22:31 2010
New Revision: 996650
URL: http://svn.apache.org/viewvc?rev=996650&view=rev
Log:
VCL-313
need a way to set computers as vmhosts without a bare metal provisioning engine
this is just some initial work on this so that people can get started with VCL
using preloaded vm hosts without having to touch the database directly;
it allows computers to be added in the vmhostinuse state, but the state cannot
be set to vmhostinuse afterward without xCAT
computers.php:
-modified viewComputers, editOrAddComputer, and bulkAddComputer - added
vmhostinuse as an option for the state
-modified confirmEditOrAddComputer and confirmAddBulkComputers- if stateid = 20
(vmhostinuse) set nextmode to addComputerSetVMHostProfile
-added addComputerSetVMHostProfile
-modified submitAddBulkComputers and addComputer - if stateid = 20, insert
entry into vmhost; changed from using SELECT LAST_INSERT_ID to calling
dbLastInsertID; changed queries to insert into resourcegroupmembers to be a
single query
-modified computerUtilities - changed text for setting state to vmhostinuse to
'convert to vmhostinuse' to help distinguish from adding computers in the
vmhostinuse state
-modified compStateChange - for vmprofile, use inline prints to create select
object instead of calling printSelectInput since it doesn't have name or
prettyname
errors.php:
-removed 196, 197, 236, and 237
states.php: added addComputerSetVMHostProfile
Modified:
incubator/vcl/trunk/web/.ht-inc/computers.php
incubator/vcl/trunk/web/.ht-inc/errors.php
incubator/vcl/trunk/web/.ht-inc/states.php
Modified: incubator/vcl/trunk/web/.ht-inc/computers.php
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/computers.php?rev=996650&r1=996649&r2=996650&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/computers.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/computers.php Mon Sep 13 19:22:31 2010
@@ -263,7 +263,8 @@ function viewComputers($showall=0) {
getComputerCounts($computers);
$userCompIDs = array_keys($resources["computer"]);
$states = array("2" => "available",
- "10" => "maintenance");
+ "10" => "maintenance",
+ "20" => "vmhostinuse");
$platforms = getPlatforms();
$tmp = getUserResources(array("scheduleAdmin"), array("manageGroup"));
$schedules = $tmp["schedule"];
@@ -619,6 +620,8 @@ function editOrAddComputer($state) {
$states = array(2 => "available",
10 => "maintenance");
}
+ if($state)
+ $states[20] = 'vmhostinuse';
$platforms = getPlatforms();
$tmp = getUserResources(array("scheduleAdmin"), array("manageGroup"));
$schedules = $tmp["schedule"];
@@ -882,6 +885,8 @@ function confirmEditOrAddComputer($state
print " <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
if(! $state && $data['stateid'] == 10)
$cont = addContinuationsEntry('computerAddMaintenanceNote',
$data, SECINDAY, 0);
+ elseif($state && $data['stateid'] == 20)
+ $cont = addContinuationsEntry('addComputerSetVMHostProfile',
$data, SECINDAY, 0);
else
$cont = addContinuationsEntry($nextmode, $data, SECINDAY, 0, 0);
print " <INPUT type=hidden name=continuation value=\"$cont\">\n";
@@ -981,6 +986,42 @@ function computerAddMaintenanceNote() {
////////////////////////////////////////////////////////////////////////////////
///
+/// \fn addComputerSetVMHostProfile()
+///
+/// \brief prints a page for user to select a vm host profile for the
+/// computer(s)
+///
+////////////////////////////////////////////////////////////////////////////////
+function addComputerSetVMHostProfile() {
+ $dobulk = getContinuationVar('dobulk', 0);
+ print "<div align=center>\n";
+ print "<H2>Add Computer</H2>\n";
+ print "Select a VM Host Profile to be used on this computer:<br><br>\n";
+ $profiles = getVMProfiles();
+ print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
+ print "<select name=\"profileid\">\n";
+ foreach($profiles as $id => $profile)
+ print "<option
value=\"$id\">{$profile['profilename']}</option>\n";
+ print "</select><br><br>\n";
+ print "VM Host Profiles can be created/modified under <a href=\"";
+ print BASEURL . SCRIPT . "?mode=editVMInfo\">Virtual
Hosts</a><br><br>\n";
+ if($dobulk) {
+ $data = processBulkComputerInput();
+ $data['profiles'] = $profiles;
+ $cont = addContinuationsEntry('submitAddBulkComputers', $data,
SECINDAY, 0, 0);
+ }
+ else {
+ $data = processComputerInput();
+ $data['profiles'] = $profiles;
+ $cont = addContinuationsEntry('submitAddComputer', $data,
SECINDAY, 0, 0);
+ }
+ print "<INPUT type=hidden name=continuation value=\"$cont\">\n";
+ print "<INPUT type=submit value=\"Add Computer\">\n";
+ print "</FORM>\n";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
/// \fn submitAddComputer()
///
/// \brief adds a new computer with the submitted information
@@ -989,8 +1030,6 @@ function computerAddMaintenanceNote() {
function submitAddComputer() {
$data = processComputerInput();
addComputer($data);
- #print "<H2>Add Computer</H2>\n";
- #print "The computer has been added.";
clearPrivCache();
viewComputers();
}
@@ -1102,7 +1141,8 @@ function bulkAddComputer() {
// makes things easier later
$states = array("2" => "available",
- "10" => "maintenance");
+ "10" => "maintenance",
+ "20" => "vmhostinuse");
$platforms = getPlatforms();
$tmp = getUserResources(array("scheduleAdmin"), array("manageGroup"));
$schedules = $tmp["schedule"];
@@ -1418,7 +1458,12 @@ function confirmAddBulkComputers() {
print " <TR>\n";
print " <TD>\n";
print " <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
- $cont = addContinuationsEntry('submitAddBulkComputers', $data,
SECINDAY, 0, 0);
+ if($data['stateid'] == 20) {
+ $data['dobulk'] = 1;
+ $cont = addContinuationsEntry('addComputerSetVMHostProfile',
$data, SECINDAY, 0);
+ }
+ else
+ $cont = addContinuationsEntry('submitAddBulkComputers', $data,
SECINDAY, 0, 0);
print " <INPUT type=hidden name=continuation value=\"$cont\">\n";
print " <INPUT type=submit value=Submit>\n";
print " </FORM>\n";
@@ -1470,6 +1515,15 @@ function submitAddBulkComputers() {
$maccnt = 0;
}
+ if($data['stateid'] == 20) {
+ $profileid = processInputVar('profileid', ARG_NUMERIC);
+ $profiles = getContinuationVar('profiles');
+ if(! array_key_exists($profileid, $profiles)) {
+ $tmp = array_keys($profiles);
+ $profileid = $tmp[0];
+ }
+ }
+
$dhcpdata = array();
$count = 0;
$addedrows = 0;
@@ -1525,40 +1579,45 @@ function submitAddBulkComputers() {
$query .= "'{$data["type"]}')";
$qh = doQuery($query, 235);
$addedrows += mysql_affected_rows($mysql_link_vcl);
- $qh = doQuery("SELECT LAST_INSERT_ID() FROM computer", 236);
- if(! $row = mysql_fetch_row($qh)) {
- abort(237);
- }
+ $compid = dbLastInsertID();
+
$query = "INSERT INTO resource "
. "(resourcetypeid, "
. "subid) "
. "VALUES (12, "
- . $row[0] . ")";
+ . "$compid)";
doQuery($query, 238);
+ $resid = dbLastInsertID();
// add computer into selected groups
- $qh = doQuery("SELECT LAST_INSERT_ID() FROM resource", 101);
- if(! $row = mysql_fetch_row($qh)) {
- abort(237);
- }
+ $vals = array();
+ foreach(array_keys($data["computergroup"]) as $groupid)
+ $vals[] = "($resid, $groupid)";
+ $allvals = implode(',', $vals);
+ $query = "INSERT INTO resourcegroupmembers "
+ . "(resourceid, "
+ . "resourcegroupid) "
+ . "VALUES $allvals";
+ doQuery($query, 101);
- foreach(array_keys($data["computergroup"]) as $groupid) {
- $query = "INSERT INTO resourcegroupmembers "
- . "(resourceid, "
- . "resourcegroupid) "
- . "VALUES ({$row[0]}, "
- . "$groupid)";
+ if($data['stateid'] == 20) {
+ # create vmhost entry
+ $query = "INSERT INTO vmhost "
+ . "(computerid, "
+ . "vmlimit, "
+ . "vmprofileid) "
+ . "VALUES ($compid, "
+ . "2, "
+ . "$profileid)";
doQuery($query, 101);
}
}
print "<DIV align=center>\n";
print "<H2>Add Multiple Computers</H2>\n";
- if($count == $addedrows) {
+ if($count == $addedrows)
print "The computers were added successfully.<br><br>\n";
- }
- else {
+ else
print $count - $addedrows . " computers failed to get
added<br><br>\n";
- }
print "</div>\n";
if($domacs)
generateDhcpForm($dhcpdata);
@@ -2166,7 +2225,7 @@ function computerUtilities() {
$states = array("2" => "available",
"23" => "hpc",
"10" => "maintenance",
- "20" => "vmhostinuse");
+ "20" => "convert to vmhostinuse");
print " <TD colspan=2>\n";
printSelectInput("stateid", $states);
print " <INPUT type=button onclick=compStateChangeSubmit();
value=\"Confirm State Change\">";
@@ -2397,7 +2456,10 @@ function compStateChange() {
print "Select a VM Host Profile and then click
<strong>Submit</strong>\n";
print "to place the computers into the vmhostinuse
state:<br><br>\n";
print "<FORM action=\"" . BASEURL . SCRIPT . "\"
method=post>\n";
- printSelectInput('profileid', $profiles);
+ print "<select name=\"profileid\">\n";
+ foreach($profiles as $id => $profile)
+ print "<option
value=\"$id\">{$profile['profilename']}</option>\n";
+ print "</select><br><br>\n";
print "<br><br>\n";
}
elseif($data['stateid'] == 23) {
@@ -3472,45 +3534,57 @@ function addComputer($data) {
. "type, "
. "notes, "
. "provisioningid) "
- . "VALUES (" . $data["stateid"] . ", "
+ . "VALUES ({$data["stateid"]}, "
. "$ownerid, "
- . $data["platformid"] . ", "
- . $data["scheduleid"] . ", "
+ . "{$data["platformid"]}, "
+ . "{$data["scheduleid"]}, "
. "4, "
- . $data["ram"] . ", "
- . $data["numprocs"] . ", "
- . $data["procspeed"] . ", "
- . $data["network"] . ", "
- . "'" . $data["hostname"] . "', "
- . "'" . $data["ipaddress"] . "', "
- . "'" . $data["type"] . "', "
+ . "{$data["ram"]}, "
+ . "{$data["numprocs"]}, "
+ . "{$data["procspeed"]}, "
+ . "{$data["network"]}, "
+ . "'{$data["hostname"]}', "
+ . "'{$data["ipaddress"]}', "
+ . "'{$data["type"]}', "
. "$notes, "
- . "'" . $data["provisioningid"] . "')";
+ . "'{$data["provisioningid"]}')";
doQuery($query, 195);
+ $compid = dbLastInsertID();
- $qh = doQuery("SELECT LAST_INSERT_ID() FROM computer", 196);
- if(! $row = mysql_fetch_row($qh)) {
- abort(197);
- }
$query = "INSERT INTO resource "
. "(resourcetypeid, "
. "subid) "
. "VALUES (12, "
- . $row[0] . ")";
+ . "$compid)";
doQuery($query, 198);
+ $resid = dbLastInsertID();
// add computer into selected groups
- $qh = doQuery("SELECT LAST_INSERT_ID() FROM resource", 101);
- if(! $row = mysql_fetch_row($qh)) {
- abort(197);
- }
+ $vals = array();
+ foreach(array_keys($data["computergroup"]) as $groupid)
+ $vals[] = "($resid, $groupid)";
+ $allvals = implode(',', $vals);
+ $query = "INSERT INTO resourcegroupmembers "
+ . "(resourceid, "
+ . "resourcegroupid) "
+ . "VALUES $allvals";
+ doQuery($query, 101);
- foreach(array_keys($data["computergroup"]) as $groupid) {
- $query = "INSERT INTO resourcegroupmembers "
- . "(resourceid, "
- . "resourcegroupid) "
- . "VALUES ({$row[0]}, "
- . "$groupid)";
+ if($data['stateid'] == 20) {
+ $profileid = processInputVar('profileid', ARG_NUMERIC);
+ $profiles = getContinuationVar('profiles');
+ if(! array_key_exists($profileid, $profiles)) {
+ $tmp = array_keys($profiles);
+ $profileid = $tmp[0];
+ }
+ # create vmhost entry
+ $query = "INSERT INTO vmhost "
+ . "(computerid, "
+ . "vmlimit, "
+ . "vmprofileid) "
+ . "VALUES ($compid, "
+ . "2, "
+ . "$profileid)";
doQuery($query, 101);
}
}
Modified: incubator/vcl/trunk/web/.ht-inc/errors.php
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/errors.php?rev=996650&r1=996649&r2=996650&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/errors.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/errors.php Mon Sep 13 19:22:31 2010
@@ -100,8 +100,6 @@ $ERRORS = array (
"190" => "Failed to execute query 1 in submitDeleteComputer",
"191" => "Failed to execute query 2 in submitDeleteComputer",
"195" => "Failed to execute query 1 in addComputer",
- "196" => "Failed to execute query 2 in addComputer",
- "197" => "Failed to fetch last insert id in addComputer",
"198" => "Failed to execute query 3 in addComputer",
"200" => "Failed to execute query 1 in updateImage",
"205" => "Failed to execute query 1 in addImage",
@@ -123,8 +121,6 @@ $ERRORS = array (
"228" => "Failed to execute query 4 in acknowledgeRequest",
"229" => "Failed to execute query 5 in acknowledgeRequest",
"235" => "Failed to execute query 1 in submitBulkAddComputers",
- "236" => "Failed to execute query 2 in submitBulkAddComputers",
- "237" => "Failed to fetch last insert id in submitBulkAddComputers",
"238" => "Failed to execute query 3 in submitBulkAddComputers",
"240" => "Failed to execute query 1 in addUser",
"241" => "Failed to execute query 2 in addUser",
Modified: incubator/vcl/trunk/web/.ht-inc/states.php
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/states.php?rev=996650&r1=996649&r2=996650&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/states.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/states.php Mon Sep 13 19:22:31 2010
@@ -394,6 +394,7 @@ $actions['mode']['confirmAddComputer'] =
$actions['args']['confirmAddComputer'] = 1;
$actions['mode']['submitEditComputer'] = "submitEditComputer";
$actions['mode']['computerAddMaintenanceNote'] = "computerAddMaintenanceNote";
+$actions['mode']['addComputerSetVMHostProfile'] =
"addComputerSetVMHostProfile";
$actions['mode']['submitAddComputer'] = "submitAddComputer";
$actions['mode']['submitComputerGroups'] = "submitComputerGroups";
$actions['mode']['confirmDeleteComputer'] = "confirmDeleteComputer";
@@ -426,6 +427,7 @@ $actions['pages']['confirmAddComputer']
$actions['pages']['submitEditComputer'] = "manageComputers";
$actions['pages']['computerAddMaintenanceNote'] = "manageComputers";
$actions['pages']['computerAddedMaintenceNote'] = "manageComputers";
+$actions['pages']['addComputerSetVMHostProfile'] = "manageComputers";
$actions['pages']['submitAddComputer'] = "manageComputers";
$actions['pages']['submitComputerGroups'] = "manageComputers";
$actions['pages']['confirmDeleteComputer'] = "manageComputers";