Author: jfthomps
Date: Wed Apr 25 19:12:03 2012
New Revision: 1330491

URL: http://svn.apache.org/viewvc?rev=1330491&view=rev
Log:
VCL-545

utils.php:
-added getImageTypes
-modified printSelectInput - do not print 'name' attribute if $name is empty
-modified getVMProfiles - added resourcepath, repositoryimagetypeid, 
repositoryimagetype, datastoreimagetypeid, datastoreimagetype, virtualswitch2, 
and virtualswitch3 to returned data
-added getENUMvalues
-modified getDojoHTML - added dijit.Tooltip to editVMInfo dojo includes

vm.php:
-modified editVMInfo - added Resource Path, Repository Image Type, Virtual Disk 
Image Type, VM Network 2, VM Network 3; changed Data Store Path to Virtual Disk 
Path, VM Disk to Virtual Disk Mode, VM Path to VM Working Directory Path, and 
Virtual Switch 0/1 to VM Network 0/1; added help icons for most items and diji 
tooltip help popups
-modified getVMHostData - set any parts of the vmprofile that are null to empty 
strings
-modified AJprofileData - get values for $vmdisk from enum field in database
-modified AJupdateVMprofileItem - changes to handle new fields and additions 
that were added to editVMInfo

vm.js:
-changed all calls to document.getElementById to dojo.byId
-modified VMHostDataCB, getVMprofileDataCB, and delProfile - similar changes as 
to editVMInfo in vm.php

Modified:
    incubator/vcl/trunk/web/.ht-inc/utils.php
    incubator/vcl/trunk/web/.ht-inc/vm.php
    incubator/vcl/trunk/web/js/vm.js

Modified: incubator/vcl/trunk/web/.ht-inc/utils.php
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/utils.php?rev=1330491&r1=1330490&r2=1330491&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/utils.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/utils.php Wed Apr 25 19:12:03 2012
@@ -1546,6 +1546,25 @@ function getImageConnectMethodTexts($ima
 
 
////////////////////////////////////////////////////////////////////////////////
 ///
+/// \fn getImageTypes()
+///
+/// \return array of image types where each key is the id and each value is the
+/// name
+///
+/// \brief builds an array of image types from the imagetype table
+///
+////////////////////////////////////////////////////////////////////////////////
+function getImageTypes() {
+       $query = "SELECT id, name FROM imagetype ORDER BY name";
+       $qh = doQuery($query);
+       $data = array();
+       while($row = mysql_fetch_assoc($qh))
+               $data[$row['id']] = $row['name'];
+       return $data;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
 /// \fn checkClearImageMeta($imagemetaid, $imageid, $ignorefield)
 ///
 /// \param $imagemetaid - id from imagemeta table
@@ -7774,28 +7793,25 @@ function printSelectInput($name, $dataAr
                $multiple = "multiple";
        else
                $multiple = "";
-       print "      <SELECT name=$name $multiple $domid $extra>\n";
+       if($name != '')
+               print "      <select name=$name $multiple $domid $extra>\n";
+       else
+               print "      <select $multiple $domid $extra>\n";
        foreach(array_keys($dataArr) as $id) {
-               if(($skip && $id == 4) || ($dataArr[$id] != 0 && 
empty($dataArr[$id]))) {
+               if(($skip && $id == 4) || ($dataArr[$id] != 0 && 
empty($dataArr[$id])))
                        continue;
-               }
-               if($id == $selectedid) {
-                  print "        <OPTION value=\"$id\" selected=\"selected\">";
-               }
-               else {
-                  print "        <OPTION value=\"$id\">";
-               }
-               if(is_array($dataArr[$id]) && array_key_exists("prettyname", 
$dataArr[$id])) {
-                       print $dataArr[$id]["prettyname"] . "</OPTION>\n";
-               }
-               elseif(is_array($dataArr[$id]) && array_key_exists("name", 
$dataArr[$id])) {
-                       print $dataArr[$id]["name"] . "</OPTION>\n";
-               }
-               else {
-                       print $dataArr[$id] . "</OPTION>\n";
-               }
+               if($id == $selectedid)
+                  print "        <option value=\"$id\" selected=\"selected\">";
+               else
+                  print "        <option value=\"$id\">";
+               if(is_array($dataArr[$id]) && array_key_exists("prettyname", 
$dataArr[$id]))
+                       print $dataArr[$id]["prettyname"] . "</option>\n";
+               elseif(is_array($dataArr[$id]) && array_key_exists("name", 
$dataArr[$id]))
+                       print $dataArr[$id]["name"] . "</option>\n";
+               else
+                       print $dataArr[$id] . "</option>\n";
        }
-       print "      </SELECT>\n";
+       print "      </select>\n";
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -9352,18 +9368,27 @@ function getVMProfiles($id="") {
               .        "vp.profilename AS name, "
               .        "i.prettyname AS image, "
               .        "vp.imageid, "
+              .        "vp.resourcepath, "
               .        "vp.repositorypath, "
+              .        "vp.repositoryimagetypeid, "
+              .        "t1.name AS repositoryimagetype, "
               .        "vp.datastorepath, "
+              .        "vp.datastoreimagetypeid, "
+              .        "t2.name AS datastoreimagetype, "
               .        "vp.vmpath, "
               .        "vp.virtualswitch0, "
               .        "vp.virtualswitch1, "
+              .        "vp.virtualswitch2, "
+              .        "vp.virtualswitch3, "
               .        "vp.vmdisk, "
               .        "vp.username, "
               .        "vp.password, "
               .        "vp.eth0generated, "
               .        "vp.eth1generated "
               . "FROM vmprofile vp "
-              . "LEFT JOIN image i ON (vp.imageid = i.id)";
+              . "LEFT JOIN image i ON (vp.imageid = i.id) "
+              . "LEFT JOIN imagetype t1 ON (vp.repositoryimagetypeid = t1.id) "
+              . "LEFT JOIN imagetype t2 ON (vp.datastoreimagetypeid = t2.id)";
        if(! empty($id))
                $query .= " AND vp.id = $id";
        $qh = doQuery($query, 101);
@@ -9375,6 +9400,30 @@ function getVMProfiles($id="") {
 
 
////////////////////////////////////////////////////////////////////////////////
 ///
+/// \fn getENUMvalues($table, $field)
+///
+/// \param $table - name of a table from the database
+/// \param $field - field in $table
+///
+/// \return array of valid values for $table.$field
+///
+/// \brief gets valid values for $table.$field
+///
+////////////////////////////////////////////////////////////////////////////////
+function getENUMvalues($table, $field) {
+       $query = "DESC $table";
+       $qh = doQuery($query);
+       while($row = mysql_fetch_assoc($qh)) {
+               if($row['Field'] == "$field") {
+                       $data = preg_replace(array('/^enum\(/', "/'/", 
'/\)$/'), array('', '', ''), $row['Type']);
+                       $types = explode(',', $data);
+                       return $types;
+               }
+       }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
 /// \fn addContinuationsEntry($nextmode, $data, $duration, $deleteFromSelf,
 ///                           $multicall, $repeatProtect)
 ///
@@ -10639,6 +10688,7 @@ function getDojoHTML($refresh) {
                                              'dijit.layout.ContentPane',
                                              'dijit.layout.TabContainer',
                                              'dojo.data.ItemFileReadStore',
+                                             'dijit.Tooltip',
                                              'dijit.Dialog');
                        break;
                case 'siteMaintenance':

Modified: incubator/vcl/trunk/web/.ht-inc/vm.php
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/.ht-inc/vm.php?rev=1330491&r1=1330490&r2=1330491&view=diff
==============================================================================
--- incubator/vcl/trunk/web/.ht-inc/vm.php (original)
+++ incubator/vcl/trunk/web/.ht-inc/vm.php Wed Apr 25 19:12:03 2012
@@ -171,6 +171,7 @@ function editVMInfo() {
 
        if(! checkUserHasPerm('Manage VM Profiles'))
                return;
+       $imagetypes = getImageTypes();
        print "<div id=\"vmprofiles\" dojoType=\"dijit.layout.ContentPane\" 
title=\"VM Host Profiles\">\n";
        if(count($profiles))
                print "<span id=\"selectprofilediv\">";
@@ -208,61 +209,88 @@ function editVMInfo() {
        print "</button><br><br>";
        $cont = addContinuationsEntry('AJupdateVMprofileItem');
        print "(Click a value to edit it)<br>\n";
+       print "(* denotes required fields)<br>\n";
        print "<input type=hidden id=pcont value=\"$cont\">\n";
        print "<table summary=\"\">\n";
        print "  <tr>\n";
-       print "    <th align=right>Name:</th>\n";
+       print "    <th align=right>Name:*</th>\n";
        print "    <td><span id=pname dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pname', 'profilename');\"></span></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
-       print "    <th align=right>Image:</th>\n";
+       print "    <th align=right>Image:*</th>\n";
        print "    <td><span id=pimage dojoType=\"dijit.form.FilteringSelect\" 
searchAttr=\"name\" onchange=\"updateProfile('pimage', 'imageid');\" 
style=\"width: 420px\"></span></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
+       print "    <th align=right>Resource Path:</th>\n";
+       print "    <td><span id=presourcepath dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('presourcepath', 'resourcepath');\"></span><img 
tabindex=0 src=\"images/helpicon.png\" id=\"resourcepathhelp\" /></td>\n";
+       print "  </tr>\n";
+       print "  <tr>\n";
        print "    <th align=right>Repository Path:</th>\n";
-       print "    <td><span id=prepositorypath 
dojoType=\"dijit.InlineEditBox\" onChange=\"updateProfile('prepositorypath', 
'repositorypath');\"></span></td>\n";
+       print "    <td><span id=prepositorypath 
dojoType=\"dijit.InlineEditBox\" onChange=\"updateProfile('prepositorypath', 
'repositorypath');\"></span><img tabindex=0 src=\"images/helpicon.png\" 
id=\"repositorypathhelp\" /></td>\n";
+       print "  </tr>\n";
+       print "  <tr>\n";
+       print "    <th align=right>Repository Image Type:</th>\n";
+       print "    <td>\n";
+       printSelectInput("", $imagetypes, -1, 0, 0, 'prepositoryimgtype', 
'dojoType="dijit.form.Select" onChange="updateProfile(\'prepositoryimgtype\', 
\'repositoryimagetypeid\');"');
+       print "    <img tabindex=0 src=\"images/helpicon.png\" 
id=\"repositoryimgtypehelp\" />\n";
+       print "    </td>\n";
+       print "  </tr>\n";
+       print "  <tr>\n";
+       print "    <th align=right>Virtual Disk Path:*</th>\n";
+       print "    <td><span id=pdspath dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pdspath', 'datastorepath');\"></span><img tabindex=0 
src=\"images/helpicon.png\" id=\"dspathhelp\" /></td>\n";
+       print "  </tr>\n";
+       print "  <tr>\n";
+       print "    <th align=right>Virtual Disk Image Type:*</th>\n";
+       print "    <td>\n";
+       printSelectInput("", $imagetypes, -1, 0, 0, 'pdatastoreimgtype', 
'dojoType="dijit.form.Select" onChange="updateProfile(\'pdatastoreimgtype\', 
\'datastoreimagetypeid\');"');
+       print "    <img tabindex=0 src=\"images/helpicon.png\" 
id=\"datastoreimgtypehelp\" />\n";
+       print "    </td>\n";
+       print "  </tr>\n";
+       print "  <tr>\n";
+       print "    <th align=right>Virtual Disk Mode:*</th>\n";
+       print "    <td><select id=pvmdisk 
dojoType=\"dijit.form.FilteringSelect\" searchAttr=\"name\" 
onchange=\"updateProfile('pvmdisk', 'vmdisk');\"></select><img tabindex=0 
src=\"images/helpicon.png\" id=\"vmdiskhelp\" /></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
-       print "    <th align=right>Data Store Path:</th>\n";
-       print "    <td><span id=pdspath dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pdspath', 'datastorepath');\"></span></td>\n";
+       print "    <th align=right>VM Working Directory Path:</th>\n";
+       print "    <td><span id=pvmpath dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pvmpath', 'vmpath');\"></span><img tabindex=0 
src=\"images/helpicon.png\" id=\"vmpathhelp\" /></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
-       print "    <th align=right>VM Path:</th>\n";
-       print "    <td><span id=pvmpath dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pvmpath', 'vmpath');\"></span></td>\n";
+       print "    <th align=right>VM Network 0:*</th>\n";
+       print "    <td><span id=pvs0 dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pvs0', 'virtualswitch0');\"></span><img tabindex=0 
src=\"images/helpicon.png\" id=\"vs0help\" /></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
-       print "    <th align=right>Virtual Switch 0:</th>\n";
-       print "    <td><span id=pvs0 dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pvs0', 'virtualswitch0');\"></span></td>\n";
+       print "    <th align=right>VM Network 1:*</th>\n";
+       print "    <td><span id=pvs1 dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pvs1', 'virtualswitch1');\"></span><img tabindex=0 
src=\"images/helpicon.png\" id=\"vs1help\" /></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
-       print "    <th align=right>Virtual Switch 1:</th>\n";
-       print "    <td><span id=pvs1 dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pvs1', 'virtualswitch1');\"></span></td>\n";
+       print "    <th align=right>VM Network 2:</th>\n";
+       print "    <td><span id=pvs2 dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pvs2', 'virtualswitch2');\"></span><img tabindex=0 
src=\"images/helpicon.png\" id=\"vs2help\" /></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
-       print "    <th align=right>VM Disk:</th>\n";
-       print "    <td><select id=pvmdisk 
dojoType=\"dijit.form.FilteringSelect\" searchAttr=\"name\" 
onchange=\"updateProfile('pvmdisk', 'vmdisk');\"></select></td>\n";
+       print "    <th align=right>VM Network 3:</th>\n";
+       print "    <td><span id=pvs3 dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pvs3', 'virtualswitch3');\"></span><img tabindex=0 
src=\"images/helpicon.png\" id=\"vs3help\" /></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
-       print "    <th align=right>Generate eth0 MAC:</th>\n";
-       print "    <td><select id=pgenmac0 dojoType=\"dijit.form.Select\" 
searchAttr=\"name\" onchange=\"updateProfile('pgenmac0', 
'eth0generated');\">\n";
+       print "    <th align=right>Generate eth0 MAC:*</th>\n";
+       print "    <td><select id=pgenmac0 dojoType=\"dijit.form.Select\" 
onchange=\"updateProfile('pgenmac0', 'eth0generated');\">\n";
        print "    <option value=\"1\">Yes</option>\n";
        print "    <option value=\"0\">No</option>\n";
-       print "    </select></td>\n";
+       print "    </select><img tabindex=0 src=\"images/helpicon.png\" 
id=\"genmac0help\" /></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
-       print "    <th align=right>Generate eth1 MAC:</th>\n";
-       print "    <td><select id=pgenmac1 dojoType=\"dijit.form.Select\" 
searchAttr=\"name\" onchange=\"updateProfile('pgenmac1', 
'eth1generated');\">\n";
+       print "    <th align=right>Generate eth1 MAC:*</th>\n";
+       print "    <td><select id=pgenmac1 dojoType=\"dijit.form.Select\" 
onchange=\"updateProfile('pgenmac1', 'eth1generated');\">\n";
        print "    <option value=\"1\">Yes</option>\n";
        print "    <option value=\"0\">No</option>\n";
-       print "    </select></td>\n";
+       print "    </select><img tabindex=0 src=\"images/helpicon.png\" 
id=\"genmac1help\" /></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
        print "    <th align=right>Username:</th>\n";
-       print "    <td><span id=pusername dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pusername', 'username');\"></span></td>\n";
+       print "    <td><span id=pusername dojoType=\"dijit.InlineEditBox\" 
onChange=\"updateProfile('pusername', 'username');\"></span><img tabindex=0 
src=\"images/helpicon.png\" id=\"usernamehelp\" /></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
        print "    <th align=right>Password:</th>\n";
-       print "    <td><input type=password id=ppassword 
onkeyup=\"checkProfilePassword();\"></input></td>\n";
+       print "    <td><input type=password id=ppassword 
onkeyup=\"checkProfilePassword();\"></input><img tabindex=0 
src=\"images/helpicon.png\" id=\"passwordhelp\" /></td>\n";
        print "  </tr>\n";
        print "  <tr>\n";
        print "    <th align=right>Confirm:</th>\n";
@@ -288,6 +316,52 @@ function editVMInfo() {
        print "</div>\n";
 
        print "</div>\n";
+
+       print "<div dojoType=\"dijit.Tooltip\" 
connectId=\"resourcepathhelp\">\n";
+       print _("Resource Path only needs to be configured if VMware vCenter is 
used. It defines the location where VMs will be created in the vCenter 
inventory tree. The inventory tree contains at least one Datacenter, and may 
also contain Folders, Clusters, and Resource Pools.<br>Example: 
/DatacenterA/Folder1/Cluster2/ResourcePool3");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" 
connectId=\"repositorypathhelp\">\n";
+       print _("(Optional) The path where master copies of images are stored 
which are used to transfer images to VM host datastores or to other 
repositories. This is required if multiple management nodes need to share 
images. VMs do not run directly off of the images stored in the repository. It 
can refer to and be mounted on either the management node or VM host.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" 
connectId=\"repositoryimgtypehelp\">\n";
+       print _("Virtual disk type of the images stored here.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"dspathhelp\">\n";
+       print _("The location where master copies of images are stored which 
are used by running VMs. It can be either on local or network storge. If on 
network storage, it can be shared among multiple hosts.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" 
connectId=\"datastoreimgtypehelp\">\n";
+       print _("Virtual disk type of the images stored here.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"vmdiskhelp\">\n";
+       print _("Defines whether the Virtual Disk Path storage is dedicated to 
a single host or shared among multiple hosts. If set to dedicated, Repository 
Path must be definied and VCL will remove copies of images in the Virtual Disk 
Path to free up space if they are not being used.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"vmpathhelp\">\n";
+       print _("(Optional) This is the path on VM host where VM working 
directories will reside. If not configured, the Datastore Path location will be 
used. It can be either on local or network storge. It should be dedicated for 
each VM host and should be optimized for read-write performance.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"vs0help\">\n";
+       print _("The VM Network parameters should match the network names 
configured on the VM host. For ESXi, the Virtual Switch parameters must match 
the Virtual Machine Port Group Network Labels configured in the vSphere Client. 
VM Network 0 should be your public or private network.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"vs1help\">\n";
+       print _("The VM Network parameters should match the network names 
configured on the VM host. For ESXi, the Virtual Switch parameters must match 
the Virtual Machine Port Group Network Labels configured in the vSphere Client. 
VM Network 1 should be your public or private network.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"vs2help\">\n";
+       print _("(Optional) The VM Network parameters should match the network 
names configured on the VM host. For ESXi, the Virtual Switch parameters must 
match the Virtual Machine Port Group Network Labels configured in the vSphere 
Client. VM Network 2 is optional for connecting the VM to additional 
networks.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"vs3help\">\n";
+       print _("(Optional) The VM Network parameters should match the network 
names configured on the VM host. For ESXi, the Virtual Switch parameters must 
match the Virtual Machine Port Group Network Labels configured in the vSphere 
Client. VM Network 3 is optional for connecting the VM to additional 
networks.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"genmac0help\">\n";
+       print _("Specifies whether VMs are assigned MAC addresses defined in 
the VCL database or if random MAC addresses should be assigned.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"genmac1help\">\n";
+       print _("Specifies whether VMs are assigned MAC addresses defined in 
the VCL database or if random MAC addresses should be assigned.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"usernamehelp\">\n";
+       print _("Name of the administrative or root user residing on the VM 
host.");
+       print "</div>\n";
+       print "<div dojoType=\"dijit.Tooltip\" connectId=\"passwordhelp\">\n";
+       print _("Password of the administrative or root user residing on the VM 
host.");
+       print "</div>\n";
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -437,6 +511,10 @@ function getVMHostData($id='') {
        $ret = array();
        while($row = mysql_fetch_assoc($qh)) {
                $ret[$row['id']] = $row;
+               foreach($profiles[$row['vmprofileid']] AS $key => $value) {
+                       if(is_null($value))
+                               $profiles[$row['vmprofileid']][$key] = '';
+               }
                $ret[$row['id']]['vmprofiledata'] = 
$profiles[$row['vmprofileid']];
        }
        uasort($ret, 'sortKeepIndex');
@@ -776,8 +854,9 @@ function AJprofileData($profileid="") {
        $imagedata = array('identifier' => 'id', 'items' => $images);
        
        $vmdiskitems = array();
-       $vmdiskitems[] = array('id' => 'localdisk', 'name' => 'localdisk');
-       $vmdiskitems[] = array('id' => 'networkdisk', 'name' => 'networkdisk');
+       $vmdisks = getENUMvalues('vmprofile', 'vmdisk');
+       foreach($vmdisks as $val)
+               $vmdiskitems[] = array('id' => $val, 'name' => $val);
        $vmdisk = array('identifier' => 'id', 'items' => $vmdiskitems);
 
        $arr = array('profile' => $profiledata[$profileid],
@@ -801,15 +880,27 @@ function AJupdateVMprofileItem() {
        }
        $profileid = processInputVar('profileid', ARG_NUMERIC);
        $item = processInputVar('item', ARG_STRING);
-       if(! 
preg_match('/^(profilename|imageid|repositorypath|datastorepath|vmpath|virtualswitch0|virtualswitch1|vmdisk|username|password|eth0generated|eth1generated)$/',
 $item)) {
+       if(! 
preg_match('/^(profilename|imageid|resourcepath|repositorypath|repositoryimagetypeid|datastorepath|datastoreimagetypeid|vmdisk|vmpath|virtualswitch[0-3]|username|password|eth0generated|eth1generated)$/',
 $item)) {
                print "alert('Invalid data submitted.');";
                return;
        }
-       if(preg_match('/^vmware_mac_eth[01]_generated$/', $item)) {
+       if(preg_match('/^eth[01]generated$/', $item)) {
                $newvalue = processInputVar('newvalue', ARG_NUMERIC);
                if($newvalue != 0 && $newvalue != 1)
                        $newvalue = 0;
        }
+       elseif(preg_match('/imagetypeid$/', $item)) {
+               $newvalue = processInputVar('newvalue', ARG_STRING);
+               $imagetypes = getImageTypes();
+               if(! array_key_exists($newvalue, $imagetypes))
+                       $newvalue = 1;
+       }
+       elseif($item == 'vmdisk') {
+               $newvalue = processInputVar('newvalue', ARG_STRING);
+               $vmdisks = getENUMvalues('vmprofile', 'vmdisk');
+               if(! in_array($newvalue, $vmdisks))
+                       $newvalue = $vmdisks[0];
+       }
        elseif($item == 'password')
                $newvalue = $_POST['newvalue'];
        else

Modified: incubator/vcl/trunk/web/js/vm.js
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/web/js/vm.js?rev=1330491&r1=1330490&r2=1330491&view=diff
==============================================================================
--- incubator/vcl/trunk/web/js/vm.js (original)
+++ incubator/vcl/trunk/web/js/vm.js Wed Apr 25 19:12:03 2012
@@ -21,22 +21,22 @@ var allvms = '';
 var curprofile = '';
 
 function getVMHostData(cont) {
-       var hostid = document.getElementById('vmhostid').value;
+       var hostid = dojo.byId('vmhostid').value;
        document.body.style.cursor = 'wait';
        dijit.byId('messages').hide();
-       document.getElementById('vmhostdata').className = 'hidden';
-       document.getElementById('movevms').className = 'hidden';
-       document.getElementById('vmstate').innerHTML = '';
+       dojo.byId('vmhostdata').className = 'hidden';
+       dojo.byId('movevms').className = 'hidden';
+       dojo.byId('vmstate').innerHTML = '';
 
-       var selobj1 = document.getElementById('currvms');
+       var selobj1 = dojo.byId('currvms');
        for(var i = selobj1.options.length - 1; i >= 0; i--) {
                selobj1.remove(i);
        }
-       var selobj2 = document.getElementById('freevms');
+       var selobj2 = dojo.byId('freevms');
        for(i = selobj2.options.length - 1; i >= 0; i--) {
                selobj2.remove(i);
        }
-       var selobj3 = document.getElementById('movevmssel');
+       var selobj3 = dojo.byId('movevmssel');
        for(i = selobj3.options.length - 1; i >= 0; i--) {
                selobj3.remove(i);
        }
@@ -58,13 +58,13 @@ function VMHostDataCB(data, ioArgs) {
                document.body.style.cursor = 'default';
                return;
        }
-       document.getElementById('vmlimit').value = data.items.vmlimit;
-       document.getElementById('vmhostdata').className = 'shown';
+       dojo.byId('vmlimit').value = data.items.vmlimit;
+       dojo.byId('vmhostdata').className = 'shown';
 
        curprofileid = data.items.profileid;
 
        // leave this block for allowing changing of profiles later
-       /*var selobj = document.getElementById('vmprofileid');
+       /*var selobj = dojo.byId('vmprofileid');
        for(var i = 0; i < selobj.options.length; i++) {
                if(selobj.options[i].value == data.items.profile.id) {
                        selobj.selectedIndex = i;
@@ -76,12 +76,19 @@ function VMHostDataCB(data, ioArgs) {
        obj.setTitle(profile.profilename);
        var ct = '<table>';
        ct += '<tr><th align=right>Image:</th><td>' + profile.image + 
'</td></tr>';
+       ct += '<tr><th align=right>Resource Path:</th><td>' + 
profile.resourcepath + '</td></tr>';
        ct += '<tr><th align=right>Repository Path:</th><td>' + 
profile.repositorypath + '</td></tr>';
-       ct += '<tr><th align=right>Datastore Path:</th><td>' + 
profile.datastorepath + '</td></tr>';
-       ct += '<tr><th align=right>VM Path:</th><td>' + profile.vmpath + 
'</td>';
-       ct += '<tr><th align=right>Virtual Switch 0:</th><td>' + 
profile.virtualswitch0 + '</td></tr>';
-       ct += '<tr><th align=right>Virtual Switch 1:</th><td>' + 
profile.virtualswitch1 + '</td></tr>';
-       ct += '<tr><th align=right>VM Disk:</th><td>' + profile.vmdisk + 
'</td></tr>';
+       ct += '<tr><th align=right>Repository Image Type:</th><td>' + 
profile.repositoryimagetype + '</td></tr>';
+       ct += '<tr><th align=right>Virtual Disk Path:</th><td>' + 
profile.datastorepath + '</td></tr>';
+       ct += '<tr><th align=right>Virtual Disk Image Type:</th><td>' + 
profile.datastoreimagetype + '</td></tr>';
+       ct += '<tr><th align=right>Virtual Disk Mode:</th><td>' + 
profile.vmdisk + '</td></tr>';
+       ct += '<tr><th align=right>VM Working Directory Path:</th><td>' + 
profile.vmpath + '</td>';
+       ct += '<tr><th align=right>VM Network 0:</th><td>' + 
profile.virtualswitch0 + '</td></tr>';
+       ct += '<tr><th align=right>VM Network 1:</th><td>' + 
profile.virtualswitch1 + '</td></tr>';
+       ct += '<tr><th align=right>VM Network 2:</th><td>' + 
profile.virtualswitch2 + '</td></tr>';
+       ct += '<tr><th align=right>VM Network 3:</th><td>' + 
profile.virtualswitch3 + '</td></tr>';
+       ct += '</table>';
+       ct += '</table>';
        ct += '</table>';
        obj.setContent(ct);
        if(obj.open)
@@ -90,11 +97,11 @@ function VMHostDataCB(data, ioArgs) {
        allvms = data.items.allvms;
        currvms = data.items.currvms;
 
-       var inobj = document.getElementById('currvms');
+       var inobj = dojo.byId('currvms');
        for(var i = 0; i < data.items.currvms.length; i++) {
                inobj.options[inobj.options.length] = new 
Option(data.items.currvms[i].name, data.items.currvms[i].id);
        }
-       var outobj = document.getElementById('freevms');
+       var outobj = dojo.byId('freevms');
        for(var i = 0; i < data.items.freevms.length; i++) {
                outobj.options[outobj.options.length] = new 
Option(data.items.freevms[i].name, data.items.freevms[i].id);
        }
@@ -112,8 +119,8 @@ function VMHostDataCB(data, ioArgs) {
        }
 
        if(data.items.movevms.length) {
-               document.getElementById('movevms').className = 'shown';
-               obj = document.getElementById('movevmssel');
+               dojo.byId('movevms').className = 'shown';
+               obj = dojo.byId('movevmssel');
                var movevms = data.items.movevms;
                for(var i = 0; i < movevms.length; i++) {
                        var label = movevms[i]['hostname'] + ' (' + 
movevms[i]['time'] + ')';
@@ -121,14 +128,14 @@ function VMHostDataCB(data, ioArgs) {
                }
        }
 
-       //document.getElementById('changevmcont').value = 
data.items.continuation;
+       //dojo.byId('changevmcont').value = data.items.continuation;
 
        document.body.style.cursor = 'default';
 }
 
 function updateVMlimit(cont) {
-       var hostid = document.getElementById('vmhostid').value;
-       var newlimit = document.getElementById('vmlimit').value;
+       var hostid = dojo.byId('vmhostid').value;
+       var newlimit = dojo.byId('vmlimit').value;
        document.body.style.cursor = 'wait';
 
        dojo.xhrPost({
@@ -150,7 +157,7 @@ function updateVMlimitCB(data, ioArgs) {
 }
 
 function showVMstate() {
-       var selobj = document.getElementById('currvms');
+       var selobj = dojo.byId('currvms');
        var cnt = 0;
        var state = '';
        for(var i = 0; i < selobj.options.length; i++) {
@@ -160,14 +167,14 @@ function showVMstate() {
                }
        }
        if(cnt == 1)
-               document.getElementById('vmstate').innerHTML = state;
+               dojo.byId('vmstate').innerHTML = state;
        else
-               document.getElementById('vmstate').innerHTML = '';
+               dojo.byId('vmstate').innerHTML = '';
 }
 
 function changeVMprofile() {
-       var hostid = document.getElementById('vmhostid').value;
-       var selobj = document.getElementById('vmprofileid');
+       var hostid = dojo.byId('vmhostid').value;
+       var selobj = dojo.byId('vmprofileid');
        var newid = selobj.options[selobj.selectedIndex].value;
        dijit.byId('profileDlg').show();
 }
@@ -177,7 +184,7 @@ function cancelVMprofileChange() {
                fromok = 0;
        }
        else {
-               var selobj = document.getElementById('vmprofileid');
+               var selobj = dojo.byId('vmprofileid');
                for(var i = 0; i < selobj.options.length; i++) {
                        if(selobj.options[i].value == curprofileid) {
                                selobj.selectedIndex = i;
@@ -189,9 +196,9 @@ function cancelVMprofileChange() {
 
 function submitChangeProfile() {
        fromok = 1;
-       var hostid = document.getElementById('vmhostid').value;
-       var cont = document.getElementById('changevmcont').value;
-       var selobj = document.getElementById('vmprofileid');
+       var hostid = dojo.byId('vmhostid').value;
+       var cont = dojo.byId('changevmcont').value;
+       var selobj = dojo.byId('vmprofileid');
        var oldid = curprofileid;
        var newid = selobj.options[selobj.selectedIndex].value;
        dijit.byId('profileDlg').hide();
@@ -209,17 +216,17 @@ function submitChangeProfile() {
 }
 
 function submitChangeProfileCB(data, ioArgs) {
-       var selobj = document.getElementById('vmprofileid');
+       var selobj = dojo.byId('vmprofileid');
        curprofileid = selobj.options[selobj.selectedIndex].value;
-       document.getElementById('changevmcont').value = data.items.continuation;
+       dojo.byId('changevmcont').value = data.items.continuation;
        alert(data.items.msg);
 }
 
 function vmToHost(cont) {
        document.body.style.cursor = 'wait';
-       var hostid = document.getElementById('vmhostid').value;
+       var hostid = dojo.byId('vmhostid').value;
 
-       var obj = document.getElementById('freevms');
+       var obj = dojo.byId('freevms');
        var listids = new Array();
        for(var i = obj.options.length - 1; i >= 0; i--) {
                if(obj.options[i].selected) {
@@ -227,8 +234,8 @@ function vmToHost(cont) {
                }
        }
        //var limit = dijit.byId('vmlimit').value;
-       var limit = document.getElementById('vmlimit').value;
-       var currcnt = document.getElementById('currvms').options.length;
+       var limit = dojo.byId('vmlimit').value;
+       var currcnt = dojo.byId('currvms').options.length;
        if(limit < currcnt + listids.length) {
                alert('You\'re attempting to add more VMs to this host\nthan 
the current VM limit.  This is not allowed.');
                document.body.style.cursor = 'default';
@@ -271,7 +278,7 @@ function vmToHostCB(data, ioArgs) {
        var vms = data.items.vms;
        var addrem = data.items.addrem; // 1 for add, 0 for rem
        var fails = data.items.fails;
-       var obj = document.getElementById('freevms');
+       var obj = dojo.byId('freevms');
        for(var i = obj.options.length - 1; i >= 0; i--) {
                if(obj.options[i].selected) {
                        var remove = 1;
@@ -286,7 +293,7 @@ function vmToHostCB(data, ioArgs) {
                                obj.remove(i);
                }
        }
-       var obj = document.getElementById('currvms');
+       var obj = dojo.byId('currvms');
        for(var i = 0; i < vms.length; i++) {
                var lastid = -1;
                for(var j = 0; j < allvms.length; j++) {
@@ -355,9 +362,9 @@ function vmToHostCB(data, ioArgs) {
 
 function vmFromHost(cont) {
        document.body.style.cursor = 'wait';
-       var hostid = document.getElementById('vmhostid').value;
+       var hostid = dojo.byId('vmhostid').value;
 
-       var obj = document.getElementById('currvms');
+       var obj = dojo.byId('currvms');
        var listids = new Array();
        for(var i = obj.options.length - 1; i >= 0; i--) {
                if(obj.options[i].selected)
@@ -397,7 +404,7 @@ function vmFromHostCB(data, ioArgs) {
        var addrem = data.items.addrem; // 1 for add, 0 for rem
        var checks = data.items.checks;
        var fails = data.items.fails;
-       var obj = document.getElementById('currvms');
+       var obj = dojo.byId('currvms');
        for(var i = obj.options.length - 1; i >= 0; i--) {
                if(obj.options[i].selected) {
                        var remove = 1;
@@ -417,7 +424,7 @@ function vmFromHostCB(data, ioArgs) {
                        }
                        if(remove) {
                                obj.remove(i);
-                               document.getElementById('vmstate').innerHTML = 
'';
+                               dojo.byId('vmstate').innerHTML = '';
                                currvms.splice(i, 1);
                        }
                }
@@ -432,8 +439,8 @@ function vmFromHostCB(data, ioArgs) {
        }
 
        if(data.items.vms.length) {
-               document.getElementById('movevms').className = 'shown';
-               obj = document.getElementById('movevmssel');
+               dojo.byId('movevms').className = 'shown';
+               obj = dojo.byId('movevmssel');
                var vms = data.items.vms;
                for(var i = 0; i < vms.length; i++) {
                        var label = vms[i]['hostname'] + ' (' + vms[i]['time'] 
+ ')';
@@ -512,17 +519,17 @@ function reloadVMhostCB(data, ioArgs) {
 function setMessageWindow(title, okbtntext, content, submitFunc) {
        obj = dijit.byId('messages');
        obj.titleNode.innerHTML = title;
-       document.getElementById('messagestext').innerHTML = content;
-       document.getElementById('messagesokbtn').innerHTML = okbtntext;
-       document.getElementById('messagesokbtn').onclick = submitFunc;
+       dojo.byId('messagestext').innerHTML = content;
+       dojo.byId('messagesokbtn').innerHTML = okbtntext;
+       dojo.byId('messagesokbtn').onclick = submitFunc;
        obj.show();
 }
 
 function cancelVMmove(cont) {
        document.body.style.cursor = 'wait';
-       var hostid = document.getElementById('vmhostid').value;
+       var hostid = dojo.byId('vmhostid').value;
 
-       var obj = document.getElementById('movevmssel');
+       var obj = dojo.byId('movevmssel');
        var listids = new Array();
        for(var i = obj.options.length - 1; i >= 0; i--) {
                if(obj.options[i].selected)
@@ -547,8 +554,8 @@ function cancelVMmove(cont) {
 
 function getVMprofileData(cont) {
        document.body.style.cursor = 'wait';
-       document.getElementById('vmprofiledata').className = 'hidden';
-       var profileid = document.getElementById('profileid').value;
+       dojo.byId('vmprofiledata').className = 'hidden';
+       var profileid = dojo.byId('profileid').value;
 
        dojo.xhrPost({
                url: 'index.php',
@@ -582,26 +589,32 @@ function getVMprofileDataCB(data, ioArgs
                obj.setValue(curprofile.vmdisk);
 
        dijit.byId('pname').noValueIndicator = '(empty)';
+       dijit.byId('presourcepath').noValueIndicator = '(empty)';
        dijit.byId('prepositorypath').noValueIndicator = '(empty)';
        dijit.byId('pdspath').noValueIndicator = '(empty)';
        dijit.byId('pvmpath').noValueIndicator = '(empty)';
        dijit.byId('pvs0').noValueIndicator = '(empty)';
        dijit.byId('pvs1').noValueIndicator = '(empty)';
+       dijit.byId('pvs2').noValueIndicator = '(empty)';
+       dijit.byId('pvs3').noValueIndicator = '(empty)';
        dijit.byId('pusername').noValueIndicator = '(empty)';
 
        dijit.byId('pname').setValue(curprofile.profilename);
+       dijit.byId('presourcepath').setValue(curprofile.resourcepath);
        dijit.byId('prepositorypath').setValue(curprofile.repositorypath);
        dijit.byId('pdspath').setValue(curprofile.datastorepath);
        dijit.byId('pvmpath').setValue(curprofile.vmpath);
        dijit.byId('pvs0').setValue(curprofile.virtualswitch0);
        dijit.byId('pvs1').setValue(curprofile.virtualswitch1);
+       dijit.byId('pvs2').setValue(curprofile.virtualswitch2);
+       dijit.byId('pvs3').setValue(curprofile.virtualswitch3);
        dijit.byId('pusername').setValue(curprofile.username);
        dijit.byId('pgenmac0').setValue(curprofile.eth0generated);
        dijit.byId('pgenmac1').setValue(curprofile.eth1generated);
-       document.getElementById('ppassword').value = curprofile.password;
-       document.getElementById('ppwdconfirm').value = curprofile.password;
+       dojo.byId('ppassword').value = curprofile.password;
+       dojo.byId('ppwdconfirm').value = curprofile.password;
        checkProfilePassword();
-       document.getElementById('vmprofiledata').className = 'shown';
+       dojo.byId('vmprofiledata').className = 'shown';
        document.body.style.cursor = 'default';
 }
 
@@ -612,7 +625,7 @@ function newProfile(cont) {
                    + '<input type=text id=newprofile><br>'
                    + '<font color=red><em><span 
id=nperrormsg></span></em></font><br>';
        var func = function() {
-               var newname = document.getElementById('newprofile').value;
+               var newname = dojo.byId('newprofile').value;
                var regex = new RegExp('^[-A-Za-z0-9:\(\)# ]{3,56}$');
                if(! newname.match(regex)) {
                        alert('Name must be between 3 and 56 characters\nand 
can only include letters, numbers,\nspaces, and these characters -:()#');
@@ -634,13 +647,13 @@ function newProfile(cont) {
 
 function newProfileCB(data, ioArgs) {
        if(data.items.failed) {
-               document.getElementById('nperrormsg').innerHTML =
+               dojo.byId('nperrormsg').innerHTML =
                   'A profile with this name already exists';
                return;
        }
        dijit.byId('messages').hide();
        alert('Be sure to finish configuring this profile');
-       var obj = document.getElementById('profileid');
+       var obj = dojo.byId('profileid');
        obj.options[obj.options.length] = new 
Option(data.items.profile.profilename, data.items.profile.id);
        obj.options[obj.options.length - 1].selected = true;
        dojo.removeClass('selectprofilediv', 'hidden');
@@ -662,28 +675,48 @@ function delProfile(cont) {
        content += "<td>" + curprofile.image + "</td>";
        content += "</tr>";
        content += "<tr>";
+       content += "<th align=right>Resource Path:</th>";
+       content += "<td>" + curprofile.resourcepath + "</td>";
+       content += "</tr>";
+       content += "<tr>";
        content += "<th align=right>Repository Path:</th>";
        content += "<td>" + curprofile.repositorypath + "</td>";
        content += "</tr>";
        content += "<tr>";
-       content += "<th align=right>Data Store Path:</th>";
+       content += "<th align=right>Repository Image Type:</th>";
+       content += "<td>" + curprofile.repositoryimagetype + "</td>";
+       content += "</tr>";
+       content += "<tr>";
+       content += "<th align=right>Virtual Disk Path:</th>";
        content += "<td>" + curprofile.datastorepath + "</td>";
        content += "</tr>";
        content += "<tr>";
-       content += "<th align=right>VM Path:</th>";
+       content += "<th align=right>Virtual Disk Image Type:</th>";
+       content += "<td>" + curprofile.datastoreimagetype + "</td>";
+       content += "</tr>";
+       content += "<tr>";
+       content += "<th align=right>Virtual Disk Mode:</th>";
+       content += "<td>" + curprofile.vmdisk + "</td>";
+       content += "</tr>";
+       content += "<tr>";
+       content += "<th align=right>VM Working Directory Path:</th>";
        content += "<td>" + curprofile.vmpath + "</td>";
        content += "</tr>";
        content += "<tr>";
-       content += "<th align=right>Virtual Switch 0:</th>";
+       content += "<th align=right>VM Network 0:</th>";
        content += "<td>" + curprofile.virtualswitch0 + "</td>";
        content += "</tr>";
        content += "<tr>";
-       content += "<th align=right>Virtual Switch 1:</th>";
+       content += "<th align=right>VM Network 1:</th>";
        content += "<td>" + curprofile.virtualswitch1 + "</td>";
        content += "</tr>";
        content += "<tr>";
-       content += "<th align=right>VM Disk:</th>";
-       content += "<td>" + curprofile.vmdisk + "</td>";
+       content += "<th align=right>VM Network 2:</th>";
+       content += "<td>" + curprofile.virtualswitch2 + "</td>";
+       content += "</tr>";
+       content += "<tr>";
+       content += "<th align=right>VM Network 3:</th>";
+       content += "<td>" + curprofile.virtualswitch3 + "</td>";
        content += "</tr>";
        content += "<tr>";
        content += "<th align=right>Generate eth0 MAC:</th>";
@@ -701,9 +734,9 @@ function delProfile(cont) {
        content += "</tr>";
        content += "</table>";
        var func = function() {
-               var profileid = document.getElementById('profileid').value;
+               var profileid = dojo.byId('profileid').value;
                if(profileid == curprofileid)
-                       document.getElementById('vmhostdata').className = 
'hidden';
+                       dojo.byId('vmhostdata').className = 'hidden';
                document.body.style.cursor = 'wait';
                dojo.xhrPost({
                        url: 'index.php',
@@ -731,9 +764,9 @@ function delProfileCB(data, ioArgs) {
                return;
        }
        dijit.byId('messages').hide();
-       var obj = document.getElementById('profileid');
+       var obj = dojo.byId('profileid');
        obj.remove(obj.selectedIndex);
-       document.getElementById('vmprofiledata').className = 'hidden';
+       dojo.byId('vmprofiledata').className = 'hidden';
        if(obj.options.length == 0)
                dojo.addClass('selectprofilediv', 'hidden');
        document.body.style.cursor = 'default';
@@ -744,17 +777,17 @@ function updateProfile(id, field) {
        if(dijit.byId(id))
                var newvalue = dijit.byId(id).value;
        else
-               var newvalue = document.getElementById(id).value;
+               var newvalue = dojo.byId(id).value;
        if(curprofile[field] == newvalue)
                return;
        if(field == 'password')
-               document.getElementById('savestatus').innerHTML = 'Saving...';
+               dojo.byId('savestatus').innerHTML = 'Saving...';
        document.body.style.cursor = 'wait';
        
-       var profileid = document.getElementById('profileid').value;
-       var cont = document.getElementById('pcont').value;
+       var profileid = dojo.byId('profileid').value;
+       var cont = dojo.byId('pcont').value;
        if(profileid == curprofileid)
-               document.getElementById('vmhostdata').className = 'hidden';
+               dojo.byId('vmhostdata').className = 'hidden';
 
        dojo.xhrPost({
                url: 'index.php',
@@ -774,9 +807,9 @@ function updateProfileCB(data, ioArgs) {
 }
 
 function checkProfilePassword() {
-       var pobj = document.getElementById('ppassword');
-       var cobj = document.getElementById('ppwdconfirm');
-       var mobj = document.getElementById('ppwdmatch');
+       var pobj = dojo.byId('ppassword');
+       var cobj = dojo.byId('ppwdconfirm');
+       var mobj = dojo.byId('ppwdmatch');
 
        if(pobj.value == "" && cobj.value == "") {
                mobj.innerHTML = '';


Reply via email to