From 24dcf5717c377ff1ff6d3ffc558d4935c012b893 Mon Sep 17 00:00:00 2001 From: xq2005 Date: Wed, 23 Feb 2011 08:34:23 +0000 Subject: [PATCH] existing system P nodes' provision git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@8910 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/js/custom/hmc.js | 170 +++++++++++++++++++++++++++++- xCAT-UI/js/provision/provision.js | 32 ++++++ 2 files changed, 197 insertions(+), 5 deletions(-) diff --git a/xCAT-UI/js/custom/hmc.js b/xCAT-UI/js/custom/hmc.js index 98159d3c8..4ea626807 100644 --- a/xCAT-UI/js/custom/hmc.js +++ b/xCAT-UI/js/custom/hmc.js @@ -157,12 +157,11 @@ hmcPlugin.prototype.loadProvisionPage = function(tabId) { var provForm = $('
'); // Create status bar - var statBarId = 'hmcProvisionStatBar' + inst; - var statBar = createStatusBar(statBarId).hide(); + var statBar = createStatusBar('statBar').hide(); provForm.append(statBar); // Create loader - var loader = createLoader('hmcProvisionLoader' + inst).hide(); + var loader = createLoader('loader').hide(); statBar.append(loader); // Create info bar @@ -190,8 +189,61 @@ hmcPlugin.prototype.loadProvisionPage = function(tabId) { var hmcProvisionBtn = createButton('Provision'); hmcProvisionBtn.bind('click', function(event) { - //TODO Insert provision code here - openDialog('info', 'Under construction'); + // Remove any warning messages + var tempTab = $(this).parent().parent(); + tempTab.find('.ui-state-error').remove(); + + var ready = true; + var errMsg = ''; + var tempNodes = ''; + + // Get nodes that were checked + tempNodes = getCheckedByObj(tempTab.find('table')); + if ('' == tempNodes){ + errMsg += 'You need to select a node.
'; + ready = false; + } + else{ + tempNodes = tempNodes.substr(0, tempNodes.length - 1); + } + + // If all inputs are valid, ready to provision + if (ready) { + // Disable provision button + $(this).attr('disabled', 'true'); + + // Show loader + tempTab.find('#statBar').show(); + tempTab.find('#loader').show(); + + // Disable all selects, input and checkbox + tempTab.find('input').attr('disabled', 'disabled'); + + // Get operating system image + var os = tempTab.find('#osname').val(); + var arch = tempTab.find('#arch').val(); + var profile = tempTab.find('#pro').val(); + + /** + * (1) Set operating system + */ + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'nodeadd', + tgt : '', + args : tempNodes + ';noderes.netboot=yaboot;nodetype.os=' + os + ';nodetype.arch=' + arch + ';nodetype.profile=' + profile, + msg : 'cmd=nodeadd;out=' + tempTab.attr('id') + }, + + success : pProvisionExisting + }); + } else { + // Show warning message + var warn = createWarnBar(errMsg); + warn.prependTo(tempTab); + } }); provForm.append(hmcProvisionBtn); @@ -371,4 +423,112 @@ function createNodesArea(groupName, areaId){ } } // End of function(data) }); +} + +/** + * provision for existing system p node + * + * @return Nothing + */ +function pProvisionExisting(data){ + // Get ajax response + var rsp = data.rsp; + var args = data.msg.split(';'); + + // Get command invoked + var cmd = args[0].replace('cmd=', ''); + // Get provision tab instance + var tabId = args[1].replace('out=', ''); + + //get tab obj + var tempTab = $('#' + tabId); + /** + * (2) Prepare node for boot + */ + if (cmd == 'nodeadd') { + // Get operating system + var bootMethod = tempTab.find('#boot').val(); + + // Get nodes that were checked + var tgts = getCheckedByObj(tempTab.find('table')); + + // Prepare node for boot + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'nodeset', + tgt : tgts, + args : bootMethod, + msg : 'cmd=nodeset;out=' + tabId + }, + + success : pProvisionExisting + }); + } + + /** + * (3) Boot node from network + */ + else if (cmd == 'nodeset') { + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + tempTab.find('#statBar').append(prg); + + // If there was an error, do not continue + if (prg.html().indexOf('Error') > -1) { + tempTab.find('#loader').remove(); + return; + } + + // Get nodes that were checked + var tgts = getCheckedByObj(tempTab.find('table')); + + // Boot node from network + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'rnetboot', + tgt : tgts, + args : '', + msg : 'cmd=rnetboot;out=' + tabId + }, + + success : pProvisionExisting + }); + } + + /** + * (4) Done + */ + else if (cmd == 'rnetboot') { + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + tempTab.find('#statBar').append(prg); + + tempTab.find('#loader').remove(); + } + +} + +/** + * get all select elements' name in the obj, + * + * @return all nodes name, seperate by ',' + */ +function getCheckedByObj(obj){ + var tempStr = ''; + // Get nodes that were checked + obj.find('input:checked').each(function(){ + if($(this).attr('name')){ + tempStr += $(this).attr('name') + ','; + } + }); + + if ('' != tempStr){ + tempStr = tempStr.substr(0, tempStr.length - 1); + } + + return tempStr; } \ No newline at end of file diff --git a/xCAT-UI/js/provision/provision.js b/xCAT-UI/js/provision/provision.js index 265e76edb..1aedbae89 100644 --- a/xCAT-UI/js/provision/provision.js +++ b/xCAT-UI/js/provision/provision.js @@ -36,6 +36,38 @@ function loadProvisionPage() { return; } + // Get OS image names + if (!$.cookie('imagenames')){ + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'tabdump', + tgt : '', + args : 'osimage', + msg : '' + }, + + success : setOSImageCookies + }); + } + + // Get groups + if (!$.cookie('groups')){ + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'extnoderange', + tgt : '/.*', + args : 'subgroups', + msg : '' + }, + + success : setGroupsCookies + }); + } + // Create info bar var infoBar = createInfoBar('Select a platform to provision or re-provision a node on, then click Ok.');