From 2ba31bfbc68ea7640953ac5b5f0a27f1fb3d968e Mon Sep 17 00:00:00 2001 From: phamt Date: Mon, 12 Sep 2011 14:24:09 +0000 Subject: [PATCH] Cleaned up code git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10494 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/js/provision/images.js | 173 ++++++++++++++++++--------------- xCAT-UI/lib/rcons.php | 45 ++++----- xCAT-UI/lib/systemcmd.php | 20 ++-- 3 files changed, 123 insertions(+), 115 deletions(-) diff --git a/xCAT-UI/js/provision/images.js b/xCAT-UI/js/provision/images.js index 4c1610bd3..545936aec 100644 --- a/xCAT-UI/js/provision/images.js +++ b/xCAT-UI/js/provision/images.js @@ -4,6 +4,17 @@ var origAttrs = new Object(); // Original image attributes var defAttrs; // Definable image attributes var imgTableId = 'imagesDatatable'; // Images datatable ID +var softwareList = { + "rsct" : ["rsct.core.utils", "rsct.core", "src"], + "pe" : ["IBMJava2-142-ppc64-JRE", "ibm_lapi_ip_rh6p", "ibm_lapi_us_rh6p", "IBM_pe_license", "ibm_pe_rh6p", "ppe_pdb_ppc64_rh600", "sci_ppc_32bit_rh600", "sci_ppc_64bit_rh600", "vac.cmp", + "vac.lib", "vac.lic", "vacpp.cmp", "vacpp.help.pdf", "vacpp.lib", "vacpp.man", "vacpp.rte", "vacpp.rte.lnk", "vacpp.samples", "xlf.cmp", "xlf.help.pdf", "xlf.lib", "xlf.lic", "xlf.man", + "xlf.msg.rte", "xlf.rte", "xlf.rte.lnk", "xlf.samples", "xlmass.lib", "xlsmp.lib", "xlsmp.msg.rte", "xlsmp.rte"], + "gpfs" : ["gpfs.base", "gpfs.gpl", "gpfs.gplbin", "gpfs.msg.en_US"], + "essl" : ["essl.3232.rte", "essl.3264.rte", "essl.6464.rte", "essl.common", "essl.license", "essl.man", "essl.msg", "essl.rte", "ibm-java2", "pessl.common", "pessl.license", "pessl.man", + "pessl.msg", "pessl.rte.ppe"], + "loadl" : ["IBMJava2", "LoadL-full-license-RH6", "LoadL-resmgr-full-RH6", "LoadL-scheduler-full-RH6"], + "base" : ["createrepo"] +}; /** * Load images page @@ -303,61 +314,64 @@ function loadCreateImage() { return; } - var showStr = ''; var imageOsvers = $.cookie("osvers").split(","); var imageArch = $.cookie("osarchs").split(","); var profileArray = $.cookie("profiles").split(","); - var index = 0; + + var parm = ''; + var i = 0; // Create set properties form - var setPropsForm = $('
'); + var createImgForm = $('
'); // Show the infomation - var infoBar = createInfoBar('Specify the parameters for the image you want to generate, then click Create Image.'); - setPropsForm.append(infoBar); + var infoBar = createInfoBar('Specify the parameters for the image (stateless or statelite) you want to create, then click Create.'); + createImgForm.append(infoBar); // OS version selector - showStr += '

'; + for (i in imageOsvers) { + parm += ''; } - showStr += '

'; + parm += ''; // OS arch selector - showStr += '

'; + for (i in imageArch) { + parm += ''; } - showStr += '

'; + parm += ''; // Netboot interface input - showStr += '

'; + parm += '
'; + // Profile selector - showStr += '

'; + for (i in profileArray) { + parm += ''; } - showStr += '

'; + parm += ''; + // Boot method selector - showStr += '

'; - setPropsForm.append(showStr); - createHpcSelect(setPropsForm); - - // Add and show the tab - tab.add(tabId, 'Create Image', setPropsForm, true); - tab.select(tabId); - - // Check the selected osver and osarch for hcp stack select - // If they are valid, show the hpc stack select area. - hpcShow(); + parm += '
'; + createImgForm.append(parm); + createHpcSelect(createImgForm); // The button used to create images is created here - var createImageBtn = createButton("Create Image"); + var createImageBtn = createButton("Create"); createImageBtn.bind('click', function(event) { createImage(); }); - $('#createImageTab').append(createImageBtn); + createImgForm.append(createImageBtn); + + // Add and show the tab + tab.add(tabId, 'Create', createImgForm, true); + tab.select(tabId); + + // Check the selected osver and osarch for hcp stack select + // If they are valid, show the hpc stack select area + hpcShow(); } /** @@ -377,43 +391,35 @@ function createHpcSelect(container) { + '3. You should have a diskless image created with the base OS installed and verified on at least one test node.
' + '4. You should install the softwares on the management node, and copy all correponding packages into the location ' + '"/install/custom/otherpkgs/" based on ' + 'these documentations.
'; - hpcFieldset.append(createInfoBar(str)); // Advanced software when select the compute profile str = ''; + + '
  • RSCT
  • ' + '
  • PE
  • ' + + '
  • ESSl&PESSL
  • ' + + ''; hpcFieldset.append(str); - container.append(hpcFieldset); + container.append($('
    ').append(hpcFieldset)); } -var softwareList = { - "rsct" : [ "rsct.core.utils", "rsct.core", "src" ], - "pe" : [ "IBMJava2-142-ppc64-JRE", "ibm_lapi_ip_rh6p", "ibm_lapi_us_rh6p", "IBM_pe_license", "ibm_pe_rh6p", "ppe_pdb_ppc64_rh600", "sci_ppc_32bit_rh600", "sci_ppc_64bit_rh600", "vac.cmp", - "vac.lib", "vac.lic", "vacpp.cmp", "vacpp.help.pdf", "vacpp.lib", "vacpp.man", "vacpp.rte", "vacpp.rte.lnk", "vacpp.samples", "xlf.cmp", "xlf.help.pdf", "xlf.lib", "xlf.lic", "xlf.man", - "xlf.msg.rte", "xlf.rte", "xlf.rte.lnk", "xlf.samples", "xlmass.lib", "xlsmp.lib", "xlsmp.msg.rte", "xlsmp.rte" ], - "gpfs" : [ "gpfs.base", "gpfs.gpl", "gpfs.gplbin", "gpfs.msg.en_US" ], - "essl" : [ "essl.3232.rte", "essl.3264.rte", "essl.6464.rte", "essl.common", "essl.license", "essl.man", "essl.msg", "essl.rte", "ibm-java2", "pessl.common", "pessl.license", "pessl.man", - "pessl.msg", "pessl.rte.ppe" ], - "loadl" : [ "IBMJava2", "LoadL-full-license-RH6", "LoadL-resmgr-full-RH6", "LoadL-scheduler-full-RH6" ], - "base" : [ "createrepo" ] -}; - /** - * Check the dependance of essl and start the software check for essl + * Check the dependance for ESSL and start the software check for ESSL * * @param softwareObject - * The checkbox object of essl + * The checkbox object of ESSL * @return nothing */ function esslCheck(softwareObject) { var softwareName = softwareObject.name; - if (false == $('#createImageTab input[name=pe]').attr('checked')) { - var warnBar = createWarnBar('You must select the pe first.'); - $('#createImageTab #esslli').append(warnBar); + if (!$('#createImageTab input[name=pe]').attr('checked')) { + var warnBar = createWarnBar('You must first select the PE'); $(':checkbox[name=essl]').attr("checked", false); + + // Clear existing warnings and append new warning + $('#hpcsoft .ui-state-error').remove(); + $('#hpcsoft').prepend(warnBar); + return; } else { softwareCheck(softwareObject); @@ -421,10 +427,10 @@ function esslCheck(softwareObject) { } /** - * Check the parameters for HPC software + * Check the parameters for the HPC software * * @param softwareObject - * The checkbox object of the hpc software + * Checkbox object of the HPC software * @return True: The checkbox is checked * False: Error message shown on page */ @@ -458,7 +464,7 @@ function softwareCheck(softwareObject) { } /** - * Check whether the RPMs are copied to the special location + * Check if the RPMs are copied to the special location * * @param data * Data returned from HTTP request @@ -483,16 +489,20 @@ function rpmCopyCheck(data) { } } $('#createImageTab #' + softwareName + 'li').find('img').remove(); + // No error, show the check image - if ('' == errorStr) { - var infoPart = '
    '; + if (!errorStr) { + var infoPart = '
    '; $('#createImageTab #' + softwareName + 'li').append(infoPart); } else { // Show the error message - errorStr = 'To install the rsct on your compute node. You should:
    ' + errorStr + ''; + errorStr = 'To install the RSCT on your compute node. You should:
    ' + errorStr + ''; var warnBar = createWarnBar(errorStr); - $('#createImageTab #' + softwareName + 'li').append(warnBar); $(':checkbox[name=' + softwareName + ']').attr("checked", false); + + // Clear existing warnings and append new warning + $('#hpcsoft .ui-state-error').remove(); + $('#hpcsoft').prepend(warnBar); } } @@ -505,21 +515,20 @@ function rpmCopyCheck(data) { */ function genRpmCmd(softwareName) { var cmdString; - cmdString = "rpm -q "; + cmdString = 'rpm -q '; for (var i in softwareList[softwareName]) { - cmdString += softwareList[softwareName][i] + " "; + cmdString += softwareList[softwareName][i] + ' '; } - for (var i in softwareList["base"]) { - cmdString += softwareList["base"][i] + " "; + for (var i in softwareList['base']) { + cmdString += softwareList['base'][i] + ' '; } return cmdString; } /** - * Check whether the rpms for the hpc software are copied to the special - * location + * Check if the RPMs for the HPC software are copied to the special location * * @param softwareName * The name of the software @@ -527,8 +536,8 @@ function genRpmCmd(softwareName) { * False: Add the error message to the page */ function genLsCmd(softwareName) { - var osvers = $("#createImageTab #osvers").val(); - var osarch = $("#createImageTab #osarch").val(); + var osvers = $('#createImageTab #osvers').val(); + var osarch = $('#createImageTab #osarch').val(); var path = '/install/post/otherpkgs/' + osvers + '/' + osarch + '/' + softwareName; var checkCmd = 'ls '; @@ -541,34 +550,38 @@ function genLsCmd(softwareName) { } /** - * When the RPM check info return, check if all RPMs are installed. + * Check if all RPMs are installed * * @param checkInfo - * "rpm -q ***"'s return name: software name - * @return True: The RPMs are all installed - * False: Some of the rpms are not installed + * 'rpm -q' output + * @return True: All RPMs are installed + * False: Some RPMs are not installed */ function rpmCheck(checkInfo, name) { var errorStr = ''; - var checkArray = checkInfo.split("\n"); - for ( var i in checkArray) { - if (-1 != checkArray[i].indexOf("not install")) { - errorStr += checkArray[i] + "
    "; + var checkArray = checkInfo.split('\n'); + for (var i in checkArray) { + if (checkArray[i].indexOf('not install') != -1) { + errorStr += checkArray[i] + '
    '; } } - if ('' == errorStr) { + if (!errorStr) { return true; } errorStr = errorStr.substr(0, errorStr.length - 1); - $(':checkbox[name=' + name + ']').attr("checked", false); + $(':checkbox[name=' + name + ']').attr('checked', false); // Add the error - var warnBar = createWarnBar(errorSstr); + var warnBar = createWarnBar(errorStr); $('#createImageTab #' + name + 'li').find('img').remove(); - $('#createImageTab #' + name + 'li').append(warnBar); + + // Clear existing warnings and append new warning + $('#hpcsoft .ui-state-error').remove(); + $('#hpcsoft').prepend(warnBar); + return; } @@ -1044,7 +1057,7 @@ function createImage() { $('#createImageTab .ui-state-error').remove(); // If there no input for the bootInterface if (!bootInterface) { - var warnBar = createWarnBar('Please specify the net boot interface'); + var warnBar = createWarnBar('Please specify the netboot interface'); $("#createImageTab").prepend(warnBar); return; } diff --git a/xCAT-UI/lib/rcons.php b/xCAT-UI/lib/rcons.php index 59b82e370..5ddc2825a 100644 --- a/xCAT-UI/lib/rcons.php +++ b/xCAT-UI/lib/rcons.php @@ -6,29 +6,27 @@ $query = ''; $output = ''; $temp = ''; $pythonProcess = ''; -if (!isAuthenticated()){ - echo ("Please log in firsr."); +if (!isAuthenticated()) { + echo ("Please login before continuing!"); } $query = 's=' . $_POST['s'] . '&w=' . $_POST['w'] . '&h=' . $_POST['h']; -if (isset($_POST['q'])){ +if (isset($_POST['q'])) { $query .= '&q=1'; -} -else{ +} else { $query .= '&q=0'; } -if (isset($_POST['f'])){ +if (isset($_POST['f'])) { $pythonProcess = exec('ps -aef | grep -v grep | grep ajaxterm.py'); - if ('' == $pythonProcess){ + if ('' == $pythonProcess) { exec('nohup ' . dirname(__FILE__) . '/ajaxterm/ajaxterm.py >/dev/null 2>&1 &'); } - sleep(1); $temp = $query . '&k=' . urlencode($_SESSION["username"] . "\r"); $output = rconsSynchronise($temp); - if (0 < substr_count($output, 'error')){ + if (0 < substr_count($output, 'error')) { echo json_encode(array('err'=>$output)); exit; } @@ -36,36 +34,33 @@ if (isset($_POST['f'])){ $temp = $query . '&k=' . urlencode(getpassword() . "\r"); $output = rconsSynchronise($temp); - if (0 < substr_count($output, 'error')){ + if (0 < substr_count($output, 'error')) { echo json_encode(array('err'=>$output)); exit; } sleep(1); $temp = $query . '&c=1&k=' . urlencode('rcons ' . $_POST['s'] . "\r"); -} -else{ +} else { $temp = $query . '&c=1&k=' . urlencode($_POST['k']); } $output = rconsSynchronise($temp); -if (0 < substr_count($output, 'error')){ +if (0 < substr_count($output, 'error')) { echo (array('err'=>$output)); -} -else{ +} else { $xml = simplexml_load_string($output); - if ('pre' == $xml->getName()){ + if ('pre' == $xml->getName()) { $output = $xml->asXML(); $output = preg_replace('/'. chr(160) . '/', ' ', $output); echo json_encode(array('term'=>$output)); - } - else{ + } else { echo json_encode(array('nc'=>'nc')); } } -function rconsSynchronise($parameter){ +function rconsSynchronise($parameter) { $flag = false; $return = ""; $out = ""; @@ -77,19 +72,21 @@ function rconsSynchronise($parameter){ $out = "GET /u?$parameter HTTP/1.1\r\nHost: 127.0.0.1:8022\r\nConnection: Close\r\n\r\n"; fwrite($fp, $out); - while(!feof($fp)){ + while (!feof($fp)) { $line = fgets($fp,1024); - if (0 == strlen($line)){ + if (0 == strlen($line)) { continue; } - if('<' == substr($line, 0, 1)){ + + if ('<' == substr($line, 0, 1)) { $flag = true; $return .= $line; break; } } - if ($flag){ - while(!feof($fp)){ + + if ($flag) { + while (!feof($fp)) { $return .= fgets($fp, 1024); } } diff --git a/xCAT-UI/lib/systemcmd.php b/xCAT-UI/lib/systemcmd.php index 824aad522..469551789 100644 --- a/xCAT-UI/lib/systemcmd.php +++ b/xCAT-UI/lib/systemcmd.php @@ -5,14 +5,13 @@ require_once "$TOPDIR/lib/functions.php"; require_once "$TOPDIR/lib/jsonwrapper.php"; /** - * Issue a xCAT command, e.g. rpm -qa xCAT - * This will handle system commands. + * This will handle system commands, e.g. rpm -qa xCAT * * @param $cmd The system command * @return The system response. Replies are in the form of JSON */ -if (!isAuthenticated()){ - echo ("Please log in from the main page first!"); +if (!isAuthenticated()) { + echo ("Please login before continuing!"); exit; } @@ -20,16 +19,15 @@ if (isset($_GET["cmd"])) { // HTTP GET requests $cmd = $_GET["cmd"]; $msg = NULL; - - if (isset($_GET["msg"])){ - $msg = $_GET["msg"]; - } $ret = ""; - if ("ostype" == $cmd) { - $ret = strtolower(PHP_OS); + if (isset($_GET["msg"])) { + $msg = $_GET["msg"]; } - else { + + if ($cmd == "ostype") { + $ret = strtolower(PHP_OS); + } else { $ret = shell_exec($cmd); }