From 9df72493d47f69c06dd2db9d5465b0e1d1c38e65 Mon Sep 17 00:00:00 2001 From: phamt Date: Wed, 14 Mar 2012 04:32:06 +0000 Subject: [PATCH] Fixed add node dialogs. Added change password option under Settings. Cleaned up code. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@11844 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/css/style.css | 2 +- xCAT-UI/js/custom/blade.js | 298 ++++++++++++----------- xCAT-UI/js/custom/esx.js | 123 +++++----- xCAT-UI/js/custom/hmc.js | 431 ++++++++++++++++++---------------- xCAT-UI/js/custom/ipmi.js | 144 +++++------- xCAT-UI/js/custom/kvm.js | 120 ++++------ xCAT-UI/js/custom/zvm.js | 132 +++++++---- xCAT-UI/js/nodes/nodes.js | 15 +- xCAT-UI/js/service/service.js | 14 +- xCAT-UI/js/srv_xcatauth.js | 6 +- xCAT-UI/js/ui.js | 144 +++++++++++- xCAT-UI/js/xcatauth.js | 6 + xCAT-UI/xcat/plugins/web.pm | 29 ++- 13 files changed, 829 insertions(+), 635 deletions(-) diff --git a/xCAT-UI/css/style.css b/xCAT-UI/css/style.css index e62da2f3e..909cfea7c 100644 --- a/xCAT-UI/css/style.css +++ b/xCAT-UI/css/style.css @@ -544,7 +544,7 @@ legend { .form label { color: #424242; line-height: 1.5; - vertical-align: top; + vertical-align: middle; width: 120px; padding: 0px 0px 0px 20px; display: inline-block; diff --git a/xCAT-UI/js/custom/blade.js b/xCAT-UI/js/custom/blade.js index d6390f850..0980c1888 100644 --- a/xCAT-UI/js/custom/blade.js +++ b/xCAT-UI/js/custom/blade.js @@ -2,7 +2,7 @@ * Execute when the DOM is fully loaded */ $(document).ready(function() { - // Load utility scripts + // Load utility scripts (if any) }); /** @@ -66,7 +66,6 @@ bladePlugin.prototype.loadInventory = function(data) { $('#' + tabId).find('img').remove(); // Create division to hold inventory - var invDivId = tabId + 'Inventory'; var invDiv = $('
'); // Create a fieldset @@ -199,8 +198,6 @@ bladePlugin.prototype.loadResources = function() { /** * Add node range - * - * @return Nothing */ bladePlugin.prototype.addNode = function() { var addNodeForm = $('
'); @@ -212,60 +209,61 @@ bladePlugin.prototype.addNode = function() { typeFS.append(typeLegend); addNodeForm.append(typeFS); - var nodeFS = $('
'); - var nodeLegend = $('Node'); - nodeFS.append(nodeLegend); - addNodeForm.append(nodeFS); + var settingsFS = $('
'); + var nodeLegend = $('Settings'); + settingsFS.append(nodeLegend); + addNodeForm.append(settingsFS); typeFS.append('
' + '' + '' + '
'); + // Change dialog width + $('#addBladeCenter').dialog('option', 'width', '400'); + typeFS.find('#typeSelect').bind('change', function(){ // Remove any existing warnings $('#addBladeCenter .ui-state-error').remove(); - nodeFS.find('div').remove(); + settingsFS.find('div').remove(); - var addMethod = $(this).val(); - switch(addMethod){ - case 'mm': - nodeFS.append('
'); - nodeFS.append('
'); - nodeFS.append('
'); - nodeFS.append('
'); + // Change dialog width + $('#addBladeCenter').dialog('option', 'width', '400'); + + var nodeType = $(this).val(); + switch (nodeType) { + case 'amm': + settingsFS.append('
'); + settingsFS.append('
'); + settingsFS.append('
'); + settingsFS.append('
'); break; case 'blade': - nodeFS.append('
'); - nodeFS.append('
'); - nodeFS.append('
'); - nodeFS.append('
JS LS
'); - nodeFS.append('
'); + settingsFS.append('
'); + settingsFS.append('
'); + settingsFS.append('
'); + settingsFS.append('
JS LS
'); + settingsFS.append('
'); break; - case 'scanmm': - nodeFS.append('
'); + case 'scan': + settingsFS.append('
'); + + // Change dialog width + $('#addBladeCenter').dialog('option', 'width', '650'); break; } - - // Change dialog width - if ($(this).val() == 'scanmm'){ - $('#addBladeCenter').dialog('option', 'width', '650'); - }else{ - $('#addBladeCenter').dialog('option', 'width', '400'); - } - - // If MM node, return directly - if ($(this).val() == 'mm'){ + + // Do not continue if node type is AMM + if ($(this).val() == 'amm') { return; } - // Get all MM nodes from server side - nodeFS.find('select:eq(0)').after(createLoader()); - + // Gather AMM nodes + settingsFS.find('select:eq(0)').after(createLoader()); $.ajax({ url : 'lib/cmd.php', dataType : 'json', @@ -273,64 +271,70 @@ bladePlugin.prototype.addNode = function() { cmd : 'lsdef', tgt : '', args : '-t;node;-w;mgt==blade;-w;id==0', - msg : addMethod + msg : nodeType }, - success : function(data){ + success : function(data) { var position = 0; - var tempStr = ''; + var tmp = ''; var options = ''; // Remove the loading image - nodeFS.find('img').remove(); + settingsFS.find('img').remove(); - // Check return result + // Do not continue if no AMM nodes are found if (data.rsp.length < 1) { - $('#addBladeCenter').prepend(createWarnBar('Please define MM node first!')); + $('#addBladeCenter').prepend(createWarnBar('Please define an AMM node before continuing')); return; } - // Add all MM nodes to select + // Create options for AMM nodes for (var i in data.rsp){ - tempStr = data.rsp[i]; - position = tempStr.indexOf(' '); - tempStr = tempStr.substring(0, position); - options += ''; + tmp = data.rsp[i]; + position = tmp.indexOf(' '); + tmp = tmp.substring(0, position); + options += ''; } - - nodeFS.find('select:eq(0)').append(options); - - // If adding node by rscan, we should add the scan button - if (data.msg != 'scanmm') { + + // Select the first AMM node + settingsFS.find('select:eq(0)').append(options); + if (data.msg != 'scan') { return; } + // Create Scan button var scan = createButton('Scan'); scan.bind('click', function(){ - var mmName = nodeFS.find('select:eq(0)').val(); - nodeFS.prepend(createLoader()); - $('#nodeAttrs button').attr('disabled', 'disabled'); + var ammName = settingsFS.find('select:eq(0)').val(); + settingsFS.prepend(createLoader()); + $('#bcSettings button').attr('disabled', 'disabled'); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'rscan', - tgt : mmName, + tgt : ammName, args : '', msg : '' }, + /** + * Show scanned results for AMM + * + * @param data Data returned from HTTP request + */ success: function(data){ - showScanMmResult(data.rsp[0]); + showScanAmmResult(data.rsp[0]); } }); }); - nodeFS.find('select:eq(0)').after(scan); + settingsFS.find('select:eq(0)').after(scan); } }); }); - addNodeForm.dialog( { + // Create dialog for BladeCenter + addNodeForm.dialog({ modal : true, width : 400, title : 'Add node', @@ -346,8 +350,8 @@ bladePlugin.prototype.addNode = function() { $('#addBladeCenter .ui-state-error').remove(); var addMethod = $('#typeSelect').val(); - if (addMethod == "mm") { - addMmNode(); + if (addMethod == "amm") { + addAmmNode(); } else if(addMethod == "blade") { addBladeNode(); } else{ @@ -366,31 +370,30 @@ bladePlugin.prototype.addNode = function() { /** * Add AMM node - * - * @return Nothing */ -function addMmNode(){ - var argsTmp = ''; +function addAmmNode(){ + var args = ''; var errorMsg = ''; + // Check for missing inputs $('#addBladeCenter input').each(function(){ if (!$(this).val()) { - errorMsg = 'Please provide a value for each missing field.'; + errorMsg = 'Please provide a value for each missing field!'; } - argsTmp += $(this).val() + ','; + args += $(this).val() + ','; }); + // Do not continue if error was found if (errorMsg) { - // Add warning message $('#addBladeCenter').prepend(createWarnBar(errorMsg)); return; } - argsTmp = argsTmp.substring(0, argsTmp.length - 1); + args = args.substring(0, args.length - 1); // Add the loader - $('#addBladeCenter').prepend(createLoader()); + $('#addBladeCenter').append(createLoader()); $('.ui-dialog-buttonpane .ui-button').attr('disabled', true); $.ajax( { url : 'lib/cmd.php', @@ -398,17 +401,16 @@ function addMmNode(){ data : { cmd : 'webrun', tgt : '', - args : 'addnode;mm;' + argsTmp, + args : 'addnode;mm;' + args, msg : '' }, success : function(data) { + // Remove loader $('#addBladeCenter').find('img').remove(); - var info = createInfoBar('Successfully added MM node.'); - $('#addBladeCenter').prepend(info); + $('#addBladeCenter').prepend(createInfoBar('AMM node was successfully added')); $('#addBladeCenter').dialog("option", "buttons", { "Close" : function() { $('#addBladeCenter').dialog('close'); - $('.selectgroup').trigger('click'); } }); } @@ -417,24 +419,29 @@ function addMmNode(){ /** * Add blade node - * - * @return Nothing */ function addBladeNode(){ - var name = $('#addBladeCenter #bladeName').val(); - var group = $('#addBladeCenter #bladeGroup').val(); - var id = $('#addBladeCenter #bladeId').val(); - var series = $("#addBladeCenter #bladeNode :checked").val(); - var mpa = $('#addBladeCenter #mpaSelect').val(); + // Get blade node attributes + var name = $('#bcSettings input[name="bladeName"]').val(); + var group = $('#bcSettings input[name="bladeGroup"]').val(); + var id = $('#bcSettings input[name="bladeId"]').val(); + var series = $('#bcSettings input[name="bladeSeries"]:selected').val(); + var mpa = $('#bcSettings select[name="bladeMpa"]').val(); - var argsTmp = '-t;node;-o;' + name + ';id=' + id + - ';nodetype=osi;groups=' + group + ';mgt=blade;mpa=' + mpa + ';serialflow=hard'; + var args = '-t;node;-o;' + name + + ';id=' + id + + ';nodetype=osi;groups=' + group + + ';mgt=blade;mpa=' + mpa + + ';serialflow=hard'; + + // Set the serial speed and port for LS series blade if (series != 'js') { - argsTmp += ';serialspeed=19200;serialport=1'; + args += ';serialspeed=19200;serialport=1'; } - if ((!name) || (!group) || (!id) || (!mpa)){ - $('#addBladeCenter').prepend(createWarnBar("Please provide a value for each missing field.")); + // Check for missing inputs + if (!name || !group || !id || !mpa) { + $('#addBladeCenter').prepend(createWarnBar("Please provide a value for each missing field!")); return; } @@ -447,18 +454,24 @@ function addBladeNode(){ data : { cmd : 'chdef', tgt : '', - args : argsTmp, + args : args, msg : '' }, success : function(data) { + // Remove loader $('#addBladeCenter').find('img').remove(); - var messages = data.rsp; - var notes = ""; - for (var i = 0; i < messages.length; i++) { - notes += messages[i] + " "; + + // Gather response and display it + var rsp = data.rsp; + var rspMessage = ''; + for (var i = 0; i < rsp.length; i++) { + rspMessage += rsp[i] + '
'; } - $('#addBladeCenter').prepend(createInfoBar(notes)); + // Append response message to dialog + $('#addBladeCenter').prepend(createInfoBar(rspMessage)); + + // Change dialog button $('#addBladeCenter').dialog("option", "buttons", { "Close" : function() { $('#addBladeCenter').remove(); @@ -471,81 +484,86 @@ function addBladeNode(){ /** * Show rscan results * - * @param rscanResults + * @param results * Results from rscan of blade MPA * @return Nothing */ -function showScanMmResult(rscanResults){ - var results = $('
'); - var rscanTable = $('
'); - var regex = /\S+/g; - var line = ''; - var column = 0; +function showScanAmmResult(results){ + var rSection = $('
'); - $('#nodeAttrs #scan_results').remove(); - $('#nodeAttrs img').remove(); - $('#nodeAttrs button').attr('disabled', ''); - if (!rscanResults){ + // Create table to hold results + var rTable = $('
'); + + // Reset scan results area + $('#addBladeCenter #scanResults').remove(); + $('#bcSettings img').remove(); + $('#bcSettings button').attr('disabled', ''); + if (!results) return; - } - var rows = rscanResults.split("\n"); + // Do not continue if there are no results + var rows = results.split("\n"); if (rows.length < 2){ - results.append(createWarnBar(rows[0])); - $('#nodeAttrs').append(results); + $('#bcSettings').prepend(createWarnBar(rows[0])); return; } // Add the table header - var fields = rows[0].match(regex); - column = fields.length; - row = ''; + var fields = rows[0].match(/\S+/g); + var column = fields.length; + var row = $(''); + row.append(''); for(var i in fields){ - row += '' + fields[i] + ''; + row.append('' + fields[i] + ''); } - rscanTable.append(row); + rTable.append(row); - // Add the tbody - for (var i=1; i'; + // Create a row for each result + var row = $(''); + row.append(''); - for (var j=0; j'; + row.append(''); } else { - row += fields[j]; + row.append('' + fields[j] + ''); } + } else { + row.append(''); } - - row += ''; } - row += ''; - rscanTable.append(row); + + // Append row to table + rTable.append(row); } - results.append(rscanTable); - $('#nodeAttrs').prepend(results); + rSection.append(rTable); + $('#bcSettings').prepend(rSection); } +/** + * Add AMM scanned node + */ function addMmScanNode(){ - // Get the MM name - var mmName = $('#nodeAttrs select').val(); + // Get the AMM name + var ammName = $('#bcSettings select').val(); var nodeName = ''; - $('#nodeAttrs :checked').each(function() { + $('#bcSettings :checked').each(function() { if ($(this).attr('name')) { nodeName += $(this).attr('name') + ','; nodeName += $(this).parents('tr').find('input').eq(1).val() + ','; @@ -553,30 +571,28 @@ function addMmScanNode(){ }); if (!nodeName) { - alert('You should select nodes first!'); + $('#addBladeCenter').prepend(createWarnBar('Please select a node!')); return; } - // Disabled the button + // Disabled button $('.ui-dialog-buttonpane button').attr('disabled', 'disabled'); nodeName = nodeName.substr(0, nodeName.length - 1); $('#nodeAttrs').append(createLoader()); - // Send the add request + // Send add request $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', - args : 'addnode;node;' + mmName + ',' + nodeName, + args : 'addnode;node;' + ammName + ',' + nodeName, msg : '' }, success : function(data){ - // Refresh the area on the right side $('#addBladeCenter').dialog('close'); - $('.selectgroup').trigger('click'); } }); } diff --git a/xCAT-UI/js/custom/esx.js b/xCAT-UI/js/custom/esx.js index f943ddfd4..6d4dc4065 100644 --- a/xCAT-UI/js/custom/esx.js +++ b/xCAT-UI/js/custom/esx.js @@ -110,7 +110,7 @@ esxPlugin.prototype.loadClonePage = function(node) { // If there is no existing clone tab if (!$('#' + newTabId).length) { // Create info bar - var infoBar = createInfoBar('Not supported'); + var infoBar = createInfoBar('Not yet supported'); // Create clone form var cloneForm = $('
'); @@ -163,7 +163,7 @@ esxPlugin.prototype.loadProvisionPage = function(tabId) { var provForm = $('
'); // Create info bar - var infoBar = createInfoBar('Provision an KVM virtual machine.'); + var infoBar = createInfoBar('Provision an ESX virtual machine.'); provForm.append(infoBar); // Append to provision tab @@ -477,106 +477,74 @@ esxPlugin.prototype.loadResources = function() { /** * Add node range - * - * @return Nothing */ esxPlugin.prototype.addNode = function() { - var diag = $('
'); - var info = createInfoBar('Add a node range'); - diag.append(info); + var dialog = $('
'); + var info = createInfoBar('Add a ESX node'); + dialog.append(info); // Create node inputs - var nodeFieldSet = $('
'); - var legend = $('Node'); - nodeFieldSet.append(legend); - diag.append(nodeFieldSet); - - var nodeInputs = '
' + - '
' + - '
' + - '
'; - nodeFieldSet.append(nodeInputs); + dialog.append($('
')); + dialog.append($('
')); + dialog.append($('
')); + dialog.append($('
')); - var bmcFieldSet = $('
'); - var legend = $('BMC'); - bmcFieldSet.append(legend); - diag.append(bmcFieldSet); - - // Create BMC inputs - var bmcInputs = '
' + - '
' + - '
'; - bmcFieldSet.append(bmcInputs); - - diag.dialog({ + dialog.dialog({ title: 'Add node', modal: true, width: 400, close: function(){$(this).remove();}, buttons: { - "OK" : function(){addIdataplex();}, + "OK" : function(){addEsxNode();}, "Cancel": function(){$(this).dialog('close');} } }); }; /** - * Add iDataPlex node range - * - * @return Nothing + * Add ESX node */ -function addIdataplex(){ - var tempArray = new Array(); +function addEsxNode(){ + var attr, args; var errorMessage = ''; - var attr = ''; - var args = ''; - + // Remove existing warnings - $('#addIdplx .ui-state-error').remove(); + $('#addEsx .ui-state-error').remove(); - // Get input values - $('#addIdplx input').each(function(){ + // Return input border colors to normal + $('#addEsx input').css('border', 'solid #BDBDBD 1px'); + + // Check node attributes + $('#addEsx input').each(function(){ attr = $(this).val(); - if (attr) { - tempArray.push($(this).val()); - } else { + if (!attr) { errorMessage = "Please provide a value for each missing field!"; - return false; + $(this).css('border', 'solid #FF0000 1px'); } }); + // Show error message (if any) if (errorMessage) { - $('#addIdplx').prepend(createWarnBar(errorMessage)); + $('#addEsx').prepend(createWarnBar(errorMessage)); return; } // Create loader - $('#addIdplx').append(createLoader()); + $('#addEsx').append(createLoader()); // Change dialog buttons - $('#addIdplx').dialog('option', 'buttons', { + $('#addEsx').dialog('option', 'buttons', { 'Close':function(){ - $('#addIdplx').dialog('close'); + $('#addEsx').dialog('close'); } }); // Generate chdef arguments - args = '-t;node;-o;' + tempArray[0] + ';mac=' + tempArray[1] + ';ip=' + tempArray[2] + ';groups=' + - tempArray[3] + ';mgt=esx;chain="runcmd=bmcsetup";netboot=xnba;nodetype=osi;profile=compute;' + - 'bmc=' + tempArray[4]; - $.ajax({ - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'chdef', - tgt : '', - args : args, - msg : '' - } - }); - - // Generate chdef arguments for BMC - args = '-t;node;-o;' + tempArray[4] + ';ip=' + tempArray[5] + ';groups=' + tempArray[6]; + args = '-t;node;-o;' + $('#addEsx input[name="node"]').val() + + ';ip=' + $('#addEsx input[name="ip"]').val() + + ';groups=' + $('#addEsx input[name="groups"]').val() + + ';vmhost=' + $('#addEsx input[name="vmhost"]').val() + + ';mgt=esx;netboot=xnba;nodetype=osi;profile=compute'; $.ajax({ url : 'lib/cmd.php', dataType : 'json', @@ -587,15 +555,30 @@ function addIdataplex(){ msg : '' }, success: function(data) { - $('#addIdplx img').remove(); + // Update /etc/hosts + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'makehosts', + tgt : '', + args : '', + msg : '' + }, + }); + + // Remove loader + $('#addEsx img').remove(); + + // Get return message var message = ''; for (var i in data.rsp) { - message += data.rsp[i]; + message += data.rsp[i] + '
'; } - if (message) { - $('#addIdplx').prepend(createInfoBar(message)); - } + // Show return message + if (message) + $('#addEsx').prepend(createInfoBar(message)); } }); } diff --git a/xCAT-UI/js/custom/hmc.js b/xCAT-UI/js/custom/hmc.js index d91e723ba..0feb19263 100644 --- a/xCAT-UI/js/custom/hmc.js +++ b/xCAT-UI/js/custom/hmc.js @@ -14,6 +14,44 @@ var hmcPlugin = function() { }; +/** + * Steps for hardware discovery wizard + * + * @return Discovery steps + */ +hmcPlugin.prototype.getStep = function(){ + return ['Basic patterns', + 'Supernode', + 'More patterns', + 'Power on hardware', + 'Discover frames', + 'Management node', + 'Update definitions', + 'Create LPARs']; +}; + +hmcPlugin.prototype.getInitFunction = function(){ + return [powerInitBasicPattern, + powerInitSupernode, + powerInitSiteTable, + powerInitPoweronHardware, + powerInitDiscoverFrames, + powerInitConfig, + powerInitUpdateDefinition, + powerInitCreateLpar]; +}; + +hmcPlugin.prototype.getNextFunction = function(){ + return [checkBasicPattern, + checkSupernode, + checkSiteTable, + undefined, + checkFrameMtms, + undefined, + undefined, + collectInputValue]; +}; + /** * Clone node (service page) * @@ -191,237 +229,108 @@ hmcPlugin.prototype.loadResources = function() { /** * Add node range - * - * @return Nothing */ hmcPlugin.prototype.addNode = function() { - var diaDiv = $('
'); - diaDiv.append(createInfoBar('Add a node range')); - diaDiv.append('
'); - diaDiv.append('
'); + var dialog = $('
'); + dialog.append(createInfoBar('Add a System p node range')); - // Show the dialog - diaDiv.dialog({ + // Create option to select node type + dialog.append('
' + + '
'); + dialog.append('
'); + + // Show dialog + dialog.dialog({ modal : true, width : 400, title : 'Add node', - close : function(){$('#addpnodeDiv').remove();} + close : function(){$('#addHmc').remove();} }); - // Bind the select change event - $('#pnodetype').bind('change', function() { - $('#pnodeeditarea').empty(); - if ('HMC' == $(this).val()) { - $('#addpnodeDiv').dialog('option', 'width', '400'); - $('#pnodeeditarea').append('

' + - '
'); + // Bind to select change event + $('#nodeType').bind('change', function() { + // Remove existing warnings + $('#addHmc .ui-state-error').remove(); + + // Clear settings section + $('#nodeSettings').empty(); + if ($(this).val() == 'HMC') { + $('#addHmc').dialog('option', 'width', '400'); + $('#nodeSettings').append('
'); + $('#nodeSettings').append('
'); + $('#nodeSettings').append('
'); + $('#nodeSettings').append('
'); - $('#addpnodeDiv').dialog('option', 'buttons', - {'Add': function(){addHmcNode();}, - 'Cancel': function(){$('#addpnodeDiv').dialog('close');}}); + // Change dialog buttons + $('#addHmc').dialog('option', 'buttons', { + 'Add': function() {addHmcNode();}, + 'Cancel': function() {$('#addHmc').dialog('close');} + }); } else { - //add loader image and delete buttons - $('#pnodeeditarea').append(createLoader()); - $('#addpnodeDiv').dialog('option', 'buttons', {'Cancel': function(){$('#addpnodeDiv').dialog('close');}}); - $('#addpnodeDiv').dialog('option', 'width', '650'); + // Add loader + $('#nodeSettings').append(createLoader()); + + // Change dialog buttons + $('#addHmc').dialog('option', 'buttons', { + 'Cancel': function() {$('#addHmc').dialog('close');} + }); + + // Set to longer dialog width + $('#addHmc').dialog('option', 'width', '650'); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'nodels', tgt : 'all', - args : 'ppc.nodetype==hmc', + args : 'nodetype.nodetype==hmc', msg : '' }, success : function(data) { - $('#pnodeeditarea img').remove(); + // Remove loader + $('#nodeSettings img').remove(); drawHmcSelector(data.rsp); } }); } }); - // Trigger the select change event - $('#pnodetype').trigger('change'); + // Trigger select event change + $('#nodeType').trigger('change'); }; -hmcPlugin.prototype.getStep = function(){ - return ['Basic Patterns', - 'Supernode', - 'More patterns', - 'Power on hardware', - 'Discover frames', - 'Management node', - 'Update definitions', - 'Create LPARs']; -}; - -hmcPlugin.prototype.getInitFunction = function(){ - return [powerInitBasicPattern, - powerInitSupernode, - powerInitSiteTable, - powerInitPoweronHardware, - powerInitDiscoverFrames, - powerInitConfig, - powerInitUpdateDefinition, - powerInitCreateLpar]; -}; - -hmcPlugin.prototype.getNextFunction = function(){ - return [checkBasicPattern, - checkSupernode, - checkSiteTable, - undefined, - checkFrameMtms, - undefined, - undefined, - collectInputValue]; -}; -/** - * Add HMCs into the dialog - * - * @param hmc - * HMCs - * @return Nothing - */ -function drawHmcSelector(hmcs){ - if (1 > hmcs.length) { - $('#pnodeeditarea').append(createWarnBar('Please define HMC node first.')); - return; - } - - // Add HMCs into a selector and add a scan button - var hmcoption = ''; - var scanbutton = createButton('Scan'); - for (var i in hmcs) { - hmcoption += ''; - } - - $('#pnodeeditarea').append(''); - $('#pnodeeditarea').append(scanbutton); - - scanbutton.bind('click', function() { - var hmcname = $('#pnodeeditarea select').val(); - $('#pnodeeditarea').append(createLoader()); - $.ajax({ - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'rscan', - tgt : hmcname, - args : '', - msg : '' - }, - success : function(data) { - $('#pnodeeditarea img').remove(); - - // Draw a table with checkbox - drawRscanResult(data.rsp[0]); - - // Add the add button - $('#addpnodeDiv').dialog('option', 'buttons', - {'Add': function(){addPNode();}, - 'Cancel': function(){$('#addpnodeDiv').dialog('close');}}); - } - }); - }); -} - -function drawRscanResult(rscanresult){ - var line = ''; - var tempreg = /\S+/g; - var idpreg = /^\d+$/; - var resultDiv = $('
'); - var rscantable = $('
'); - var temprow = ''; - var colnum = 0; - var fields = 0; - - $('#pnodeeditarea div').remove(); - if (!rscanresult) { - return; - } - - var rows = rscanresult.split("\n"); - if (rows.length < 2) { - return; - } - - // Add the table header - fields = rows[0].match(tempreg); - colnum = fields.length; - temprow = ''; - for(var i in fields) { - temprow += '' + fields[i] + ''; - } - rscantable.append(temprow); - - // Add the tbody - for (var i = 1; i < rows.length; i++) { - line = rows[i]; - if (!line) { - continue; - } - - var fields = line.match(tempreg); - if ('hmc' == fields[0]) { - continue; - } - - // May be the 3rd field(id) is empty, so we should add the new - if (!idpreg.test(fields[2])){ - fields = [fields[0], fields[1], ''].concat(fields.slice(2)); - } - temprow = ''; - - for(var j = 0; j < colnum; j++) { - temprow += ''; - if (fields[j]) { - if (j == 1){ - temprow += ''; - } - else{ - temprow += fields[j]; - } - } - temprow += ''; - } - temprow += ''; - rscantable.append(temprow); - } - - resultDiv.append(rscantable); - $('#pnodeeditarea').append(resultDiv); -} - /** - * Add hmc node - * - * @return Nothing + * Add HMC node */ function addHmcNode(){ - var errorinfo = ''; + // Remove existing warnings + $('#addHmc .ui-state-error').remove(); + + var errorMessage = ''; var args = ''; - $('#pnodeeditarea input').each(function(){ - if (!$(this).val()){ - errorinfo = 'Please provide a value for each missing field!'; - } + $('#nodeSettings input').each(function(){ + if (!$(this).val()) + errorMessage = 'Please provide a value for each missing field!'; args += $(this).val() + ','; }); - if (errorinfo){ - // Add warning message - alert(errorinfo); + // Do no continue if an error is found + if (errorMessage){ + $('#addHmc').prepend(createWarnBar(errorMessage)); return; } - // Disabled the button + // Disabled button $('.ui-dialog-buttonpane button').attr('disabled', 'disabled'); - + // Remove last comma args = args.substr(0, args.length - 1); - $('#pnodeeditarea').append(createLoader()); - // Send the save HMC request + // Append loader + $('#nodeSettings').append(createLoader()); + + // Send request to add HMC $.ajax({ url : 'lib/cmd.php', dataType : 'json', @@ -432,13 +341,139 @@ function addHmcNode(){ msg : '' }, success : function(data){ - // Refresh the area on the right side - $('#addpnodeDiv').dialog('close'); - $('.selectgroup').trigger('click'); + $('#addHmc').dialog('close'); } }); } +/** + * Add HMCs into dialog + * + * @param hmcs + * HMCs + * @return Nothing + */ +function drawHmcSelector(hmcs){ + // Remove existing warnings + $('#addHmc .ui-state-error').remove(); + + // Do not continue if no HMCs are given + if (hmcs.length < 1) { + $('#addHmc').prepend(createWarnBar('Please define an HMC node first!')); + return; + } + + // Add HMCs into a dropdown and add scan button + var hmcSelect = $(''); + var scanButton = createButton('Scan'); + for (var i in hmcs) { + hmcSelect.append(''); + } + + $('#nodeSettings').append($('
').append(hmcSelect, scanButton)); + + scanButton.bind('click', function() { + var hmcname = $('#nodeSettings select').val(); + $('#nodeSettings').append(createLoader()); + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'rscan', + tgt : hmcname, + args : '', + msg : '' + }, + success : function(data) { + // Remove loader + $('#nodeSettings img').remove(); + + // Draw table with checkboxes + drawRscanResult(data.rsp[0]); + + // Add the add button + $('#addHmc').dialog('option', 'buttons', { + 'Add': function(){addPNode();}, + 'Cancel': function(){$('#addHmc').dialog('close');} + }); + } + }); + }); +} + +/** + * Draw table showing HMC rscan results + * + * @param results + * Data returned from rscan + * @return Nothing + */ +function drawRscanResult(results) { + var tmpRegex = /\S+/g; + var idRegex = /^\d+$/; + var rSection = $('
'); + var rTable = $('
'); + + // Empty node settings section + $('#nodeSettings div').remove(); + if (!results) + return; + + var lines = results.split("\n"); + // Do not continue if no results are found + if (lines.length < 2) { + return; + } + + var fields = lines[0].match(tmpRegex); + var cols = fields.length; + + // Add table header + var tHead = $('').append(''); + for(var i in fields) { + tHead.append('' + fields[i] + ''); + } + rTable.append(tHead); + + // Add table body + var tBody = $(''); + rTable.append(tBody); + for (var i = 1; i < lines.length; i++) { + var row = $(''); + + // Go to next row if there is nothing + if (!lines[i]) + continue; + + fields = lines[i].match(tmpRegex); + + // Go to next row if this row is the HMC + if (fields[0] == 'hmc') + continue; + + // If the 3rd field is empty, create an empty column + if (!idRegex.test(fields[2])) + fields = [fields[0], fields[1], ''].concat(fields.slice(2)); + row.append(''); + + // Go through each field and add it to the row as a column + for(var j = 0; j < cols; j++) { + var col = $(''); + if (fields[j]) { + if (j == 1) + col.append(''); + else + col.append(fields[j]); + } + } + + tBody.append(row); + } + + rSection.append(rTable); + $('#nodeSettings').append(rSection); +} + /** * Add System p node, contains frame, cec, lpar * @@ -446,10 +481,10 @@ function addHmcNode(){ */ function addPNode(){ // Get the HMC name - var hmcname = $('#pnodeeditarea select').val(); + var hmcname = $('#nodeSettings select').val(); var nodename = ''; // Get checked nodes - $('#pnodeeditarea :checked').each(function() { + $('#nodeSettings :checked').each(function() { if ($(this).attr('name')) { nodename += $(this).attr('name') + ','; nodename += $(this).parents('tr').find('input').eq(1).val() + ','; @@ -465,7 +500,7 @@ function addPNode(){ $('.ui-dialog-buttonpane button').attr('disabled', 'disabled'); nodename = nodename.substr(0, nodename.length - 1); - $('#pnodeeditarea').append(createLoader()); + $('#nodeSettings').append(createLoader()); // Send the add request $.ajax({ url : 'lib/cmd.php', @@ -478,7 +513,7 @@ function addPNode(){ }, success : function(data) { // Refresh the area on the right side - $('#addpnodeDiv').dialog('close'); + $('#addHmc').dialog('close'); $('.selectgroup').trigger('click'); } }); diff --git a/xCAT-UI/js/custom/ipmi.js b/xCAT-UI/js/custom/ipmi.js index eb32950eb..da99f1d0b 100644 --- a/xCAT-UI/js/custom/ipmi.js +++ b/xCAT-UI/js/custom/ipmi.js @@ -14,6 +14,28 @@ var ipmiPlugin = function() { }; +/** + * Steps for hardware discovery wizard + * + * @return Discovery steps + */ +ipmiPlugin.prototype.getStep = function(){ + return ['Basic patterns', 'Switches', 'Network', 'Services', 'Power on hardware']; +}; + +/** + * return steps's init function for hardware discovery wizard + * + * @return Nothing + */ +ipmiPlugin.prototype.getInitFunction = function(){ + return [idataplexInitBasic, idataplexInitSwitch, idataplexInitNetwork, idataplexInitService, idataplexInitPowerOn]; +}; + +ipmiPlugin.prototype.getNextFunction = function(){ + return [idataplexCheckBasic, undefined, idataplexCheckNetwork, undefined, undefined]; +}; + /** * Clone node (service page) * @@ -66,7 +88,6 @@ ipmiPlugin.prototype.loadInventory = function(data) { $('#' + tabId).find('img').remove(); // Create division to hold inventory - var invDivId = tabId + 'Inventory'; var invDiv = $('
'); // Create a fieldset @@ -179,8 +200,6 @@ ipmiPlugin.prototype.loadProvisionPage = function(tabId) { /** * Load resources - * - * @return Nothing */ ipmiPlugin.prototype.loadResources = function() { // Get resource tab ID @@ -200,38 +219,19 @@ ipmiPlugin.prototype.loadResources = function() { /** * Add node range - * - * @return Nothing */ ipmiPlugin.prototype.addNode = function() { - var diag = $('
'); - var info = createInfoBar('Add a node range'); - diag.append(info); + var dialog = $('
'); + var info = createInfoBar('Add a iDataPlex node'); + dialog.append(info); // Create node inputs - var nodeFieldSet = $('
'); - var legend = $('Node'); - nodeFieldSet.append(legend); - diag.append(nodeFieldSet); - - var nodeInputs = '
' + - '
' + - '
' + - '
'; - nodeFieldSet.append(nodeInputs); - - var bmcFieldSet = $('
'); - var legend = $('BMC'); - bmcFieldSet.append(legend); - diag.append(bmcFieldSet); - - // Create BMC inputs - var bmcInputs = '
' + - '
' + - '
'; - bmcFieldSet.append(bmcInputs); + dialog.append($('
')); + dialog.append($('
')); + dialog.append($('
')); + dialog.append($('
')); - diag.dialog({ + dialog.dialog({ title: 'Add node', modal: true, width: 400, @@ -243,53 +243,29 @@ ipmiPlugin.prototype.addNode = function() { }); }; -/** - * return steps name for hardware discovery wizard - * - * @return Nothing - */ -ipmiPlugin.prototype.getStep = function(){ - return ['Basic Patterns', 'Swithes', 'Network', 'Services', 'Power on hardwares']; -}; - -/** - * return steps's init function for hardware discovery wizard - * - * @return Nothing - */ -ipmiPlugin.prototype.getInitFunction = function(){ - return [idataplexInitBasic, idataplexInitSwitch, idataplexInitNetwork, idataplexInitService, idataplexInitPowerOn]; -}; - -ipmiPlugin.prototype.getNextFunction = function(){ - return [idataplexCheckBasic, undefined, idataplexCheckNetwork, undefined, undefined]; -}; - /** * Add iDataPlex node range - * - * @return Nothing */ function addIdataplex(){ - var tempArray = new Array(); + var attr, args; var errorMessage = ''; - var attr = ''; - var args = ''; - + // Remove existing warnings $('#addIdplx .ui-state-error').remove(); - // Get input values + // Return input border colors to normal + $('#addIdplx input').css('border', 'solid #BDBDBD 1px'); + + // Check node attributes $('#addIdplx input').each(function(){ attr = $(this).val(); - if (attr) { - tempArray.push($(this).val()); - } else { + if (!attr) { errorMessage = "Please provide a value for each missing field!"; - return false; + $(this).css('border', 'solid #FF0000 1px'); } }); + // Show error message (if any) if (errorMessage) { $('#addIdplx').prepend(createWarnBar(errorMessage)); return; @@ -306,22 +282,11 @@ function addIdataplex(){ }); // Generate chdef arguments - args = '-t;node;-o;' + tempArray[0] + ';mac=' + tempArray[1] + ';ip=' + tempArray[2] + ';groups=' + - tempArray[3] + ';mgt=ipmi;chain="runcmd=bmcsetup";netboot=xnba;nodetype=osi;profile=compute;' + - 'bmc=' + tempArray[4]; - $.ajax({ - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'chdef', - tgt : '', - args : args, - msg : '' - } - }); - - // Generate chdef arguments for BMC - args = '-t;node;-o;' + tempArray[4] + ';ip=' + tempArray[5] + ';groups=' + tempArray[6]; + args = '-t;node;-o;' + $('#addIdplx input[name="node"]').val() + + ';ip=' + $('#addIdplx input[name="ip"]').val() + + ';mac=' + $('#addIdplx input[name="mac"]').val() + + ';groups=' + $('#addIdplx input[name="groups"]').val() + + ';mgt=ipmi;netboot=xnba;nodetype=osi;profile=compute'; $.ajax({ url : 'lib/cmd.php', dataType : 'json', @@ -332,15 +297,30 @@ function addIdataplex(){ msg : '' }, success: function(data) { + // Update /etc/hosts + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'makehosts', + tgt : '', + args : '', + msg : '' + }, + }); + + // Remove loader $('#addIdplx img').remove(); + + // Get return message var message = ''; for (var i in data.rsp) { - message += data.rsp[i]; + message += data.rsp[i] + '
'; } - if (message) { + // Show return message + if (message) $('#addIdplx').prepend(createInfoBar(message)); - } } }); } diff --git a/xCAT-UI/js/custom/kvm.js b/xCAT-UI/js/custom/kvm.js index bd48a855a..1388bde83 100644 --- a/xCAT-UI/js/custom/kvm.js +++ b/xCAT-UI/js/custom/kvm.js @@ -66,7 +66,6 @@ kvmPlugin.prototype.loadInventory = function(data) { $('#' + tabId).find('img').remove(); // Create division to hold inventory - var invDivId = tabId + 'Inventory'; var invDiv = $('
'); // Create a fieldset @@ -110,7 +109,7 @@ kvmPlugin.prototype.loadClonePage = function(node) { // If there is no existing clone tab if (!$('#' + newTabId).length) { // Create info bar - var infoBar = createInfoBar('Not supported'); + var infoBar = createInfoBar('Not yet supported'); // Create clone form var cloneForm = $('
'); @@ -477,44 +476,25 @@ kvmPlugin.prototype.loadResources = function() { /** * Add node range - * - * @return Nothing */ kvmPlugin.prototype.addNode = function() { - var diag = $('
'); - var info = createInfoBar('Add a node range'); - diag.append(info); + var dialog = $('
'); + var info = createInfoBar('Add a KVM node'); + dialog.append(info); // Create node inputs - var nodeFieldSet = $('
'); - var legend = $('Node'); - nodeFieldSet.append(legend); - diag.append(nodeFieldSet); - - var nodeInputs = '
' + - '
' + - '
' + - '
'; - nodeFieldSet.append(nodeInputs); + dialog.append($('
')); + dialog.append($('
')); + dialog.append($('
')); + dialog.append($('
')); - var bmcFieldSet = $('
'); - var legend = $('BMC'); - bmcFieldSet.append(legend); - diag.append(bmcFieldSet); - - // Create BMC inputs - var bmcInputs = '
' + - '
' + - '
'; - bmcFieldSet.append(bmcInputs); - - diag.dialog({ + dialog.dialog({ title: 'Add node', modal: true, width: 400, close: function(){$(this).remove();}, buttons: { - "OK" : function(){addIdataplex();}, + "OK" : function(){addKvmNode();}, "Cancel": function(){$(this).dialog('close');} } }); @@ -522,61 +502,48 @@ kvmPlugin.prototype.addNode = function() { /** * Add iDataPlex node range - * - * @return Nothing */ -function addIdataplex(){ - var tempArray = new Array(); +function addKvmNode(){ + var attr, args; var errorMessage = ''; - var attr = ''; - var args = ''; - + // Remove existing warnings - $('#addIdplx .ui-state-error').remove(); + $('#addKvm .ui-state-error').remove(); - // Get input values - $('#addIdplx input').each(function(){ + // Return input border colors to normal + $('#addKvm input').css('border', 'solid #BDBDBD 1px'); + + // Check node attributes + $('#addKvm input').each(function(){ attr = $(this).val(); - if (attr) { - tempArray.push($(this).val()); - } else { + if (!attr) { errorMessage = "Please provide a value for each missing field!"; - return false; + $(this).css('border', 'solid #FF0000 1px'); } }); + // Show error message (if any) if (errorMessage) { - $('#addIdplx').prepend(createWarnBar(errorMessage)); + $('#addKvm').prepend(createWarnBar(errorMessage)); return; } // Create loader - $('#addIdplx').append(createLoader()); + $('#addKvm').append(createLoader()); // Change dialog buttons - $('#addIdplx').dialog('option', 'buttons', { + $('#addKvm').dialog('option', 'buttons', { 'Close':function(){ - $('#addIdplx').dialog('close'); + $('#addKvm').dialog('close'); } }); // Generate chdef arguments - args = '-t;node;-o;' + tempArray[0] + ';mac=' + tempArray[1] + ';ip=' + tempArray[2] + ';groups=' + - tempArray[3] + ';mgt=kvm;chain="runcmd=bmcsetup";netboot=xnba;nodetype=osi;profile=compute;' + - 'bmc=' + tempArray[4]; - $.ajax({ - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'chdef', - tgt : '', - args : args, - msg : '' - } - }); - - // Generate chdef arguments for BMC - args = '-t;node;-o;' + tempArray[4] + ';ip=' + tempArray[5] + ';groups=' + tempArray[6]; + args = '-t;node;-o;' + $('#addKvm input[name="node"]').val() + + ';ip=' + $('#addKvm input[name="ip"]').val() + + ';groups=' + $('#addKvm input[name="groups"]').val() + + ';vmhost=' + $('#addKvm input[name="vmhost"]').val() + + ';mgt=kvm;netboot=xnba;nodetype=osi;profile=compute'; $.ajax({ url : 'lib/cmd.php', dataType : 'json', @@ -587,15 +554,30 @@ function addIdataplex(){ msg : '' }, success: function(data) { - $('#addIdplx img').remove(); + // Update /etc/hosts + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'makehosts', + tgt : '', + args : '', + msg : '' + }, + }); + + // Remove loader + $('#addKvm img').remove(); + + // Get return message var message = ''; for (var i in data.rsp) { - message += data.rsp[i]; + message += data.rsp[i] + '
'; } - if (message) { - $('#addIdplx').prepend(createInfoBar(message)); - } + // Show return message + if (message) + $('#addKvm').prepend(createInfoBar(message)); } }); } diff --git a/xCAT-UI/js/custom/zvm.js b/xCAT-UI/js/custom/zvm.js index 5befb9c14..d3ac8e98f 100644 --- a/xCAT-UI/js/custom/zvm.js +++ b/xCAT-UI/js/custom/zvm.js @@ -23,7 +23,7 @@ var zvmPlugin = function() { * @return Nothing */ zvmPlugin.prototype.serviceClone = function(node) { - var owner = $.cookie('srv_usrname'); + var owner = $.cookie('xcat_username'); var group = getUserNodeAttr(node, 'groups'); // Submit request to clone VM @@ -88,7 +88,7 @@ zvmPlugin.prototype.loadServiceProvisionPage = function(tabId) { var hcp = $('#select-table tbody tr:eq(0) td:eq(0) input[name="hcp"]:checked').val(); var group = $('#select-table tbody tr:eq(0) td:eq(1) input[name="group"]:checked').val(); var img = $('#select-table tbody tr:eq(0) td:eq(2) input[name="image"]:checked').val(); - var owner = $.cookie('srv_usrname'); + var owner = $.cookie('xcat_username'); if(!hcp || !group || !img) { // Show warning message @@ -853,7 +853,7 @@ zvmPlugin.prototype.loadInventory = function(data) { var legend = $('General'); fieldSet.append(legend); var oList = $('
    '); - var item, label, input, args; + var item, label, args; // Loop through each property for ( var k = 0; k < 5; k++) { @@ -961,7 +961,7 @@ zvmPlugin.prototype.loadInventory = function(data) { // Table columns - Type, Address, ID, Base, Dedicated, and Affinity var procTabRow = $(' Type Address ID Base Dedicated Affinity '); procTable.append(procTabRow); - var procType, procAddr, procId, procAff; + var procId, procAff; /** * Remove processor @@ -989,7 +989,6 @@ zvmPlugin.prototype.loadInventory = function(data) { }]; // Loop through each processor - var closeBtn; var n, temp; var procType, procAddr, procLink; for (l = 0; l < attrs[keys[k]].length; l++) { @@ -1188,7 +1187,7 @@ zvmPlugin.prototype.loadInventory = function(data) { // Table columns - Virtual device, Adapter Type, Port Name, # of Devices, MAC Address, and LAN Name var nicTabRow = $(' Virtual Device # Adapter Type Port Name # of Devices LAN Name'); nicTable.append(nicTabRow); - var nicVDev, nicType, nicPortName, nicNumOfDevs, nicMacAddr, nicLanName; + var nicVDev, nicType, nicPortName, nicNumOfDevs, nicLanName; // Loop through each NIC (Data contained in 2 lines) for (l = 0; l < attrs[keys[k]].length; l = l + 2) { @@ -1289,9 +1288,6 @@ zvmPlugin.prototype.loadProvisionPage = function(tabId) { success : setGroupsCookies }); - - // Error message string - var errMsg; // Get provision tab instance var inst = tabId.replace('zvmProvisionTab', ''); @@ -1388,13 +1384,14 @@ zvmPlugin.prototype.loadResources = function() { */ zvmPlugin.prototype.addNode = function() { // Create form to add node range - var addNodeForm = $('
    '); - var info = createInfoBar('Add a node range'); + var addNodeForm = $('
    '); + var info = createInfoBar('Add a z/VM node range'); addNodeForm.append(info); - addNodeForm.append('
    '); - addNodeForm.append('
    '); - addNodeForm.append('
    '); - addNodeForm.append('
    '); + addNodeForm.append('
    '); + addNodeForm.append('
    '); + addNodeForm.append('
    '); + addNodeForm.append('
    '); + addNodeForm.append('
    '); // Open form as a dialog addNodeForm.dialog({ @@ -1408,13 +1405,14 @@ zvmPlugin.prototype.addNode = function() { // Get inputs var nodeRange = $(this).find('input[name=node]').val(); + var ipRange = $(this).find('input[name=ip]').val(); var userIdRange = $(this).find('input[name=userId]').val(); - var group = $(this).find('input[name=group]').val(); + var group = $(this).find('input[name=groups]').val(); var hcp = $(this).find('input[name=hcp]').val(); // Show warning message if inputs are not complete if (!nodeRange || !userIdRange || !group || !hcp) { - var warn = createWarnBar('You are missing inputs.'); + var warn = createWarnBar('Please provide a value for each missing field!'); warn.prependTo($(this)); } else { // Check node range and user ID range @@ -1422,14 +1420,12 @@ zvmPlugin.prototype.addNode = function() { var errMsg = ''; var ready = true; if (nodeRange.indexOf('-') > -1 || userIdRange.indexOf('-') > -1) { - if (nodeRange.indexOf('-') < 0 || userIdRange.indexOf('-') < 0) { + if (nodeRange.indexOf('-') < 0 || userIdRange.indexOf('-') < 0 || ipRange.indexOf('-') < 0) { errMsg = errMsg + 'A user ID range and node range needs to be given. '; ready = false; } else { var tmp = nodeRange.split('-'); - // Get node base name - var nodeBase = tmp[0].match(/[a-zA-Z]+/); // Get starting index var nodeStart = parseInt(tmp[0].match(/\d+/)); // Get ending index @@ -1437,24 +1433,43 @@ zvmPlugin.prototype.addNode = function() { tmp = userIdRange.split('-'); - // Get user ID base name - var userIdBase = tmp[0].match(/[a-zA-Z]+/); // Get starting index var userIdStart = parseInt(tmp[0].match(/\d+/)); // Get ending index var userIdEnd = parseInt(tmp[1].match(/\d+/)); - + + tmp = ipRange.split('-'); + + // Get starting IP address + var ipStart = tmp[0].substring(tmp[0].lastIndexOf(".") + 1); + // Get ending IP address + var ipEnd = tmp[1].substring(tmp[1].lastIndexOf(".") + 1); + // If starting and ending index do not match if (!(nodeStart == userIdStart) || !(nodeEnd == userIdEnd)) { - // Not ready errMsg = errMsg + 'The node range and user ID range does not match. '; ready = false; } + + // If an IP address range is given and the starting and ending index do not match + if (ipRange && !(nodeStart == ipStart) || !(nodeEnd == ipEnd)) { + errMsg = errMsg + 'The node range and IP address range does not match. '; + ready = false; + } } } - + // If there are no errors if (ready) { + $('#addZvm').append(createLoader()); + + // Change dialog buttons + $('#addZvm').dialog('option', 'buttons', { + 'Close':function(){ + $('#addZvm').dialog('close'); + } + }); + // If a node range is given if (nodeRange.indexOf('-') > -1 && userIdRange.indexOf('-') > -1) { var tmp = nodeRange.split('-'); @@ -1474,11 +1489,21 @@ zvmPlugin.prototype.addNode = function() { var userIdStart = parseInt(tmp[0].match(/\d+/)); // Get ending index var userIdEnd = parseInt(tmp[1].match(/\d+/)); + + tmp = ipRange.split('-'); + + // Get network base + var ipBase = tmp[0].substring(0, tmp[0].lastIndexOf(".") + 1); + // Get starting IP address + var ipStart = tmp[0].substring(tmp[0].lastIndexOf(".") + 1); + // Get ending IP address + var ipEnd = tmp[1].substring(tmp[1].lastIndexOf(".") + 1); // Loop through each node in the node range for ( var i = nodeStart; i <= nodeEnd; i++) { var node = nodeBase + i.toString(); var userId = userIdBase + i.toString(); + var ip = ipBase + i.toString(); var inst = i + '/' + nodeEnd; /** @@ -1492,7 +1517,8 @@ zvmPlugin.prototype.addNode = function() { tgt : '', args : node + ';zvm.hcp=' + hcp + ';zvm.userid=' + userId - + ';nodehm.mgt=zvm' + ';groups=' + group, + + ';nodehm.mgt=zvm' + ';groups=' + group + + ';hosts.ip=' + ip, msg : 'cmd=addnewnode;inst=' + inst + ';noderange=' + nodeRange }, @@ -1508,19 +1534,33 @@ zvmPlugin.prototype.addNode = function() { var rsp = data.rsp; var args = data.msg.split(';'); - // Get command invoked - var cmd = args[0].replace('cmd=', ''); + // Get instance returned and node range var inst = args[1].replace('inst=', ''); var nodeRange = args[2].replace('noderange=', ''); // If the last node was added var tmp = inst.split('/'); if (tmp[0] == tmp[1]) { + // Update /etc/hosts + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'makehosts', + tgt : '', + args : '', + msg : '' + }, + }); + + // Remove loader + $('#addZvm img').remove(); + // If there was an error, do not continue if (rsp.length) { - openDialog('warn', '(Error) Failed to create node definitions'); + $('#addZvm').prepend(createWarnBar('Failed to create node definitions')); } else { - openDialog('info', 'Node definitions created for ' + nodeRange); + $('#addZvm').prepend(createInfoBar('Node definitions created for ' + nodeRange)); } } } @@ -1536,7 +1576,8 @@ zvmPlugin.prototype.addNode = function() { tgt : '', args : nodeRange + ';zvm.hcp=' + hcp + ';zvm.userid=' + userIdRange - + ';nodehm.mgt=zvm' + ';groups=' + group, + + ';nodehm.mgt=zvm' + ';groups=' + group + + ';hosts.ip=' + ipRange, msg : 'cmd=addnewnode;node=' + nodeRange }, @@ -1551,23 +1592,32 @@ zvmPlugin.prototype.addNode = function() { // Get ajax response var rsp = data.rsp; var args = data.msg.split(';'); - - // Get command invoked - var cmd = args[0].replace('cmd=', ''); var node = args[1].replace('node=', ''); + // Update /etc/hosts + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'makehosts', + tgt : '', + args : '', + msg : '' + }, + }); + + // Remove loader + $('#addZvm img').remove(); + // If there was an error, do not continue if (rsp.length) { - openDialog('warn', '(Error) Failed to create node definition'); - } else { - openDialog('info', 'Node definitions created for ' + node); - } + $('#addZvm').prepend(createWarnBar('Failed to create node definitions')); + } else { + $('#addZvm').prepend(createInfoBar('Node definitions created for ' + node)); + } } }); } - - // Close dialog - $(this).dialog( "close" ); } else { // Show warning message var warn = createWarnBar(errMsg); diff --git a/xCAT-UI/js/nodes/nodes.js b/xCAT-UI/js/nodes/nodes.js index afa7d1a4b..26b648802 100644 --- a/xCAT-UI/js/nodes/nodes.js +++ b/xCAT-UI/js/nodes/nodes.js @@ -1,16 +1,11 @@ /** * Global variables */ -// Node tabs -var nodesTab; -// Original node attributes -var origAttrs = new Object(); -// Node attributes -var nodeAttrs; -// Node list -var nodesList; -// Nodes datatable ID -var nodesTableId = 'nodesDatatable'; +var nodesTab; // Nodes tabs +var origAttrs = new Object(); // Original node attributes +var nodeAttrs; // Node attributes +var nodesList; // Node list +var nodesTableId = 'nodesDatatable'; // Nodes datatable ID /** * Set node tab diff --git a/xCAT-UI/js/service/service.js b/xCAT-UI/js/service/service.js index b10ddff60..b7c35e970 100644 --- a/xCAT-UI/js/service/service.js +++ b/xCAT-UI/js/service/service.js @@ -189,7 +189,7 @@ function loadServiceProvisionPage(tabId) { */ var okBtn = createButton('Ok'); okBtn.bind('click', function(event) { - var userName = $.cookie('srv_usrname'); + var userName = $.cookie('xcat_username'); var tmp = $.cookie(userName + '_usrnodes'); // Get maximun number for nodes from cookie @@ -292,7 +292,7 @@ function loadManagePage(tabId) { * Get the user nodes definitions */ function getUserNodesDef() { - var userName = $.cookie('srv_usrname'); + var userName = $.cookie('xcat_username'); var userNodes = $.cookie(userName + '_usrnodes'); if (userNodes) { // Get nodes definitions @@ -590,7 +590,7 @@ function loadNodesTable(data) { getNodesCurrentLoad(); // Refresh nodes table - var userName = $.cookie('srv_usrname'); + var userName = $.cookie('xcat_username'); var userNodes = $.cookie(userName + '_usrnodes'); if (userNodes) { // Get nodes definitions @@ -1057,7 +1057,7 @@ function setOSImageCookies(data) { function setUserNodes(data) { if (data.rsp) { // Get user name that is logged in - var userName = $.cookie('srv_usrname'); + var userName = $.cookie('xcat_username'); var usrNodes = new Array(); // Ignore first columns because it is the header @@ -1290,7 +1290,7 @@ function monitorNode(node, monitor) { * @return Nothing */ function cloneNode(tgtNodes) { - var userName = $.cookie('srv_usrname'); + var userName = $.cookie('xcat_username'); var nodes = tgtNodes.split(','); var tmp = $.cookie(userName + '_usrnodes'); var usrNodes = tmp.split(','); @@ -1586,7 +1586,7 @@ function unlockNode(tgtNodes) { * Get nodes current load information */ function getNodesCurrentLoad(){ - var userName = $.cookie('srv_usrname'); + var userName = $.cookie('xcat_username'); var nodes = $.cookie(userName + '_usrnodes'); // Get nodes current status @@ -2144,7 +2144,7 @@ function getNodeAttr(node, attrName) { * Set the maximum number of VMs a user could have */ function setMaxVM() { - var userName = $.cookie('srv_usrname'); + var userName = $.cookie('xcat_username'); $.ajax( { url : 'lib/srv_cmd.php', diff --git a/xCAT-UI/js/srv_xcatauth.js b/xCAT-UI/js/srv_xcatauth.js index 3ec07eede..a22fc56ad 100644 --- a/xCAT-UI/js/srv_xcatauth.js +++ b/xCAT-UI/js/srv_xcatauth.js @@ -64,11 +64,11 @@ function onlogin(data, txtStatus) { if (data.authenticated == 'yes') { $('#login_status').text('Login successful'); window.location = 'service.php'; - - // Set user name cookie + + // Set user name cookie var exDate = new Date(); exDate.setTime(exDate.getTime() + (240 * 60 * 1000)); - $.cookie('srv_usrname', usrName, { expires: exDate }); + $.cookie('xcat_username', usrName, { expires: exDate }); } else { $('#login_status').text('Authentication failure'); $('#login_status').css('color', '#FF0000'); diff --git a/xCAT-UI/js/ui.js b/xCAT-UI/js/ui.js index 7e5b7c8d6..563bd11c6 100644 --- a/xCAT-UI/js/ui.js +++ b/xCAT-UI/js/ui.js @@ -796,18 +796,61 @@ function createIFrame(src) { /** * Open dialog to set xCAT UI settings - * - * @return Nothing */ function openSettings() { // Create form to add node range - var settingsForm = $('
    '); + var dialog = $('
    '); var info = createInfoBar('Select the settings you desire'); - settingsForm.append(info); + dialog.append(info); + + var style = { + 'color': 'blue', + 'cursor': 'pointer', + 'padding': '5px' + }; + + var changeThemeOption = $('').css(style); + dialog.append(changeThemeOption); + + var changePasswordOption = $('').css(style); + dialog.append(changePasswordOption); + + // Open form as a dialog + dialog.dialog({ + modal: true, + title: 'Settings', + width: 400, + buttons: { + "Cancel": function(){ + $(this).dialog("close"); + } + } + }); + + // Bind to click event + changeThemeOption.click(function() { + dialog.dialog("close"); + changeTheme(); + }); + + changePasswordOption.click(function() { + dialog.dialog("close"); + changePassword(); + }); +} + +/** + * Open dialog to change xCAT theme + */ +function changeTheme() { + // Create form to add node range + var dialog = $('
    '); + var info = createInfoBar('Select the xCAT theme you desire'); + dialog.append(info); // Create select drop down for themes var themeFS = $('
    '); - settingsForm.append(themeFS); + dialog.append(themeFS); var legend = $('Theme'); themeFS.append(legend); var oList = $('
      '); @@ -827,9 +870,9 @@ function openSettings() { } // Open form as a dialog - settingsForm.dialog({ + dialog.dialog({ modal: true, - title: 'Settings', + title: 'xCAT Theme', width: 400, buttons: { "Ok": function(){ @@ -856,6 +899,93 @@ function openSettings() { }); } +/** + * Open dialog to change user password + */ +function changePassword() { + // Create form to add node range + var dialog = $('
      '); + var info = createInfoBar('Change your password'); + dialog.append(info); + + dialog.append('
      '); + dialog.append('
      '); + + // Open form as a dialog + dialog.dialog({ + modal: true, + title: 'Change Password', + width: 400, + buttons: { + "Ok": function(){ + // Remove any warning messages + $(this).find('.ui-state-error').remove(); + + var errorMessage = ""; + + // Check each input is provided + $('#changePassword input').each(function() { + if (!$(this).val()) { + errorMessage = "Please provide a value for each missing input!"; + } + }); + + // Do not continue if error found + if (errorMessage) { + dialog.prepend(createWarnBar(errorMessage)); + return; + } + + // Check new and confirm passwords match + var user = $.cookie('xcat_username'); + var newPassword = $('#changePassword input[name="newPassword"]').val(); + var confirmPassword = $('#changePassword input[name="confirmPassword"]').val(); + if (newPassword != confirmPassword) { + dialog.prepend(createWarnBar("Please confirm new password!")); + return; + } + + // Change dialog buttons + $('#changePassword').dialog('option', 'buttons', { + 'Close':function(){ + $('#changePassword').dialog('close'); + } + }); + + // Send request to change password + var url = window.location.pathname; + var page = url.replace('/xcat/', ''); + var url = 'lib/cmd.php'; + // Service portal does not have access to cmd.php + if (page == 'service.php') + url = 'lib/srv_cmd.php'; + $.ajax( { + url : url, + dataType : 'json', + data : { + cmd : 'webrun', + tgt : '', + args : 'passwd;' + user + ';' + newPassword, + msg : '' + }, + + success : function (data) { + // Show response message + var rspMessage = ""; + for (var i in data.rsp) + rspMessage += data.rsp[i] + "
      "; + + $('#changePassword').prepend(createInfoBar(rspMessage)); + } + }); + }, + "Cancel": function(){ + $(this).dialog( "close" ); + } + } + }); +} + /** * Adjust datatable column size * diff --git a/xCAT-UI/js/xcatauth.js b/xCAT-UI/js/xcatauth.js index d481f2c25..9d615b349 100644 --- a/xCAT-UI/js/xcatauth.js +++ b/xCAT-UI/js/xcatauth.js @@ -74,6 +74,12 @@ function onlogin(data, txtStatus) { window.location = 'help.php'; } + // Set user name cookie + var usrName = $("#login input[name='username']").val(); + var exDate = new Date(); + exDate.setTime(exDate.getTime() + (240 * 60 * 1000)); + $.cookie('xcat_username', usrName, { expires: exDate }); + // Set the logonflag $.cookie('logonflag', 'yes', { path : '/xcat', diff --git a/xCAT-UI/xcat/plugins/web.pm b/xCAT-UI/xcat/plugins/web.pm index 95daaf990..d7b2d4b67 100644 --- a/xCAT-UI/xcat/plugins/web.pm +++ b/xCAT-UI/xcat/plugins/web.pm @@ -61,7 +61,8 @@ sub process_request { 'rinstall' => \&web_rinstall, 'addnode' => \&web_addnode, 'graph' => \&web_graphinfo, - 'getdefaultuserentry' => \&web_getdefaultuserentry + 'getdefaultuserentry' => \&web_getdefaultuserentry, + 'passwd' => \&web_passwd ); #check whether the request is authorized or not @@ -1973,13 +1974,12 @@ sub web_addnode{ `/bin/grep '$hcpname' /etc/hosts`; if ($?){ open(OUTPUTFILE, '>>/etc/hosts'); - print OUTPUTFILE "$ip $hcpname\n"; + print OUTPUTFILE "$ip $hcpname\n"; close(OUTPUTFILE); } - if ('hmc' eq $nodetype){ - `chdef -t node -o $hcpname username=$username password=$passwd mgt=hmc nodetype=$nodetype groups=all` - } - else{ + if ('hmc' eq $nodetype) { + `chdef -t node -o $hcpname username=$username password=$passwd mgt=hmc nodetype=$nodetype ip=$ip groups=all` + } else { `chdef -t node -o $hcpname username=$username password=$passwd mgt=blade mpa=$hcpname nodetype=$nodetype id=0 groups=mm,all` } return; @@ -2225,4 +2225,21 @@ sub web_getdefaultuserentry { $callback->( { data => $entry } ); } + +sub web_passwd() { + my ( $request, $callback, $sub_req ) = @_; + + # Get current and new passwords + my $user = $request->{arg}->[1]; + my $newPassword = $request->{arg}->[2]; + + # Generate encrypted password + my $encrypted = `perl -e "print crypt($newPassword, 03162012)"`; + # Save in xCAT passwd table + `chtab username=$user passwd.key=xcat passwd.password=$encrypted`; + + my $info = "Password successfully changed"; + $callback->( { info => $info } ); + return; +} 1;