From a69e03f615649fd59836ca8b891e4c14ea47d8dd Mon Sep 17 00:00:00 2001 From: xq2005 Date: Wed, 21 Sep 2011 07:11:31 +0000 Subject: [PATCH] add balde node by rscan result git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@10580 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/js/custom/blade.js | 384 +++++++++++++++++++++++++------------ xCAT-UI/js/custom/hmc.js | 4 +- 2 files changed, 261 insertions(+), 127 deletions(-) diff --git a/xCAT-UI/js/custom/blade.js b/xCAT-UI/js/custom/blade.js index e4d42aa93..62a70a938 100644 --- a/xCAT-UI/js/custom/blade.js +++ b/xCAT-UI/js/custom/blade.js @@ -170,104 +170,143 @@ bladePlugin.prototype.loadResources = function() { * @return Nothing */ bladePlugin.prototype.addNode = function() { - var diag = $('
'); - var info = createInfoBar('Add an Advanced Management Module (AMM) or blade'); - diag.append(info); + var nodeTypeSelectDia = $('
'); + nodeTypeSelectDia.append('
' + + '
'); - // Select node type - diag.append($('
' + - '
')); - - // Advanced Management Module (AMM) section - var amm = $('
'); - amm.append($('
')); - amm.append($('
')); - diag.append(amm); - - // Blade section - var blade = $('
').hide(); - blade.append($('
')); - blade.append($('
')); - blade.append($('
')); - blade.append($('
JS LS
')); - blade.append($('
')); - diag.append(blade); - - diag.find('select[name="nodeType"]').bind('change', function(){ - diag.find('.ui-state-error').remove(); - $('#amm').toggle(); - $('#blade').toggle(); - - if ($(this).val() == 'mm') { - return; - } - - $('#blade select').empty(); - $('#blade select').parent().append(createLoader()); + nodeTypeSelectDia.find('#nodeTypeSelect').bind('change', function(){ + $('#nodeTypeSelectDia .ui-state-error').remove(); + var addmethod = $(this).val(); + var showstr = ''; + switch(addmethod){ + case 'mm': + showstr = '

' + + '

' + + '

' + + ''; + break; + case 'blade': + showstr = '

' + + '

' + + '

' + + 'JSLS

' + + ''; + break; + case 'scanmm': + showstr = ''; + break; + } + + $('#bladeDiaInputDiv').html(showstr); + //change the dialog width + if ($(this).val() == 'scanmm'){ + $('#nodeTypeSelectDia').dialog('option', 'width', '650'); + }else{ + $('#nodeTypeSelectDia').dialog('option', 'width', '400'); + } + + //add mm node can return directly + if ($(this).val() == 'mm'){ + return; + } + + //get all mm nodes from the server side + $('#bladeDiaInputDiv').append(createLoader()); - // Get AMMs - $.ajax({ - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'lsdef', - tgt : '', - args : '-t;node;-w;mgt==blade;-w;id==0', - msg : '' - }, - success : function(data) { - var position = 0; - var temp = ''; - var options = ''; - - // Remove loader - $('#blade img').remove(); + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'lsdef', + tgt : '', + args : '-t;node;-w;mgt==blade;-w;id==0', + msg : addmethod + }, + success : function(data){ + var position = 0; + var tempStr = ''; + var options = ''; + //remove the loading image + $('#bladeDiaInputDiv img').remove(); - // Check output - if (!data.rsp.length){ - $('#addBC').prepend(createWarnBar('Please define the AMM node first!')); - return; - } + //check return result + if (1 > data.rsp.length){ + $('#nodeTypeSelectDia').prepend(createWarnBar('Please define MM node first!')); + return; + } - // Add AMMs to select - for (var i in data.rsp){ - temp = data.rsp[i]; - position = temp.indexOf(' '); - temp = temp.substring(0, position); - options += ''; - } + //add all mm nodes to select + for (var i in data.rsp){ + tempStr = data.rsp[i]; + position = tempStr.indexOf(' '); + tempStr = tempStr.substring(0, position); + options += ''; + } - $('#blade select').append(options); - } - }); - }); + $('#bladeDiaInputDiv select').append(options); + + //if add node by rscan, we should add the scan button + if (data.msg != 'scanmm'){ + return; + } + var scanbutton = createButton('Scan'); + scanbutton.bind('click', function(){ + var mmname = $('#bladeDiaInputDiv select').val(); + $('#bladeDiaInputDiv').append(createLoader()); + $('#bladeDiaInputDiv button').attr('disabled', 'disabled'); + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'rscan', + tgt : mmname, + args : '', + msg : '' + }, + + success: function(data){ + showScanMmResult(data.rsp[0]); + } + }); + }); + $('#bladeDiaInputDiv').append(scanbutton); + } + }); + }); - diag.dialog({ + nodeTypeSelectDia.dialog( { modal : true, width : 400, title : 'Select Node Type', open : function(event, ui) { - $('.ui-dialog-titlebar-close').hide(); + $(".ui-dialog-titlebar-close").hide(); }, + close : function(){$(this).remove()}, buttons : { 'Ok' : function() { - // Remove existing warnings - $(this).find('.ui-state-error').remove(); + //remove all error bar + $('#nodeTypeSelectDia .ui-state-error').remove(); + var addMethod = $('#nodeTypeSelect').val(); - if ($(this).find('select[name="nodeType"]').attr('value') == "mm") { + if (addMethod == "mm") { addMmNode(); - } else { + } + else if(addMethod == "blade") { addBladeNode(); } + else{ + addMmScanNode(); + } }, 'Cancel' : function() { $(this).remove(); } } }); + + nodeTypeSelectDia.find('#nodeTypeSelect').trigger('change'); }; @@ -277,42 +316,43 @@ bladePlugin.prototype.addNode = function() { * @return Nothing */ function addMmNode(){ - var name = $('#addBC input[name="ammName"]').val(); - var ip = $('#addBC input[name="ammIp"]').val(); + var argsTmp = ''; + var errorinfo = ''; - if (!name || !ip){ - $('#addBC').prepend(createWarnBar('You are missing some inputs!')); - return; - } - - // Add loader - $('#addBC').prepend(createLoader()); + $('#nodeTypeSelectDia input').each(function(){ + if (!$(this).val()){ + errorinfo = 'You are missing inputs.'; + } + argsTmp += $(this).val() + ','; + }); + + if (errorinfo){ + //add warning message + $('#nodeTypeSelectDia').prepend(createWarnBar(errorinfo)); + return; + } + + argsTmp = argsTmp.substring(0, argsTmp.length - 1); + //add the loader + $('#nodeTypeSelectDia').prepend(createLoader()); $('.ui-dialog-buttonpane .ui-button').attr('disabled', true); - - var args = '-t;node;-o;' + name + ';id=0;nodetype=mm;groups=mm;mgt=blade;mpa=' + name + ';ip=' + ip; $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { - cmd : 'chdef', + cmd : 'webrun', tgt : '', - args : args, + args : 'addnode;mm;' + argsTmp, msg : '' }, success : function(data) { - // Remove loader - $('#addBC').find('img').remove(); - - var rsp = data.rsp; - var messages = ''; - for (var i = 0; i < rsp.length; i++) { - messages += rsp[i] + ' '; - } - - $('#addBC').prepend(createInfoBar(messages)); - $('#addBC').dialog('option', 'buttons', { - 'Close' : function() { - $('#addBC').remove(); + $('#nodeTypeSelectDia').find('img').remove(); + var info = createInfoBar('Add MM Node successful.'); + $('#nodeTypeSelectDia').prepend(info); + $('#nodeTypeSelectDia').dialog("option", "buttons", { + "close" : function() { + $('#nodeTypeSelectDia').dialog('close'); + $('.selectgroup').trigger('click'); } }); } @@ -325,25 +365,25 @@ function addMmNode(){ * @return Nothing */ function addBladeNode(){ - var name = $('#addBC input[name="bladeName"]').val(); - var group = $('#addBC input[name="bladeGroup"]').val(); - var id = $('#addBC input[name="bladeId"]').val(); - var series = $('#addBC input[name="bladeNode"]:checked').val(); - var mpa = $('#addBC select[name="mpa"]').val(); + var name = $('#nodeTypeSelectDia #bladeName').val(); + var group = $('#nodeTypeSelectDia #bladeGroup').val(); + var id = $('#nodeTypeSelectDia #bladeId').val(); + var series = $("#nodeTypeSelectDia #bladeNode :checked").val(); + var mpa = $('#nodeTypeSelectDia #mpaSelect').val(); - var args = '-t;node;-o;' + name + ';id=' + id + ';nodetype=osi;groups=' + group + ';mgt=blade;mpa=' + mpa + ';serialflow=hard'; + var argsTmp = '-t;node;-o;' + name + ';id=' + id + + ';nodetype=osi;groups=' + group + ';mgt=blade;mpa=' + mpa + ';serialflow=hard'; if (series != 'js') { - args += ';serialspeed=19200;serialport=1'; + argsTmp += ';serialspeed=19200;serialport=1'; } - // Check blade properties - if (!name || !group || !id || !mpa){ - $('#addBC').prepend(createWarnBar('You are missing some inputs!')); + if ((!name) || (!group) || (!id) || (!mpa)){ + $('#nodeTypeSelectDia').prepend(createWarnBar("You miss some inputs.")); return; } - // Add loader and disable buttons - $('#addBC').prepend(createLoader()); + //add loader and disable buttons + $('#nodeTypeSelectDia').prepend(createLoader()); $('.ui-dialog-buttonpane .ui-button').attr('disabled', true); $.ajax( { url : 'lib/cmd.php', @@ -351,28 +391,122 @@ function addBladeNode(){ data : { cmd : 'chdef', tgt : '', - args : args, + args : argsTmp, msg : '' }, success : function(data) { - $('#addBC').find('img').remove(); - var rsp = data.rsp; - var messages = ''; - for (var i = 0; i < rsp.length; i++) { - messages += rsp[i] + ' '; + $('#nodeTypeSelectDia').find('img').remove(); + var messages = data.rsp; + var notes = ""; + for ( var i = 0; i < messages.length; i++) { + notes += messages[i]; } - $('#addBC').prepend(createInfoBar(messages)); - - $('#addBC').dialog('option', 'buttons', { - 'Close' : function() { - $('#addBC').remove(); + + $('#nodeTypeSelectDia').prepend(createInfoBar(notes)); + $('#nodeTypeSelectDia').dialog("option", "buttons", { + "close" : function() { + $('#nodeTypeSelectDia').remove(); } }); } }); - } +function showScanMmResult(rscanresult){ + var resultDiv = $('
'); + var rscantable = $('
'); + var tempreg = /\S+/g; + var line = ''; + var fields; + var colnum = 0; + + $('#bladeDiaInputDiv #scanresult').remove(); + $('#bladeDiaInputDiv img').remove(); + $('#bladeDiaInputDiv button').attr('disabled', ''); + 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 ('mm' == fields[0]){ + continue; + } + + temprow = ''; + + for(var j = 0; j < colnum; j++){ + temprow += ''; + if (fields[j]){ + temprow += fields[j]; + } + temprow += ''; + } + temprow += ''; + rscantable.append(temprow); + } + + resultDiv.append(rscantable); + + $('#bladeDiaInputDiv').append(resultDiv); +} + +function addMmScanNode(){ + //get the mm name + var mmname = $('#bladeDiaInputDiv select').val(); + var nodename = ''; + //get all need added node + $('#bladeDiaInputDiv :checked').each(function(){ + if ($(this).attr('name')){ + nodename += $(this).attr('name') + ','; + } + }); + + if (!nodename){ + alert('You should select nodes first!'); + return; + } + //disabled the button + $('.ui-dialog-buttonpane button').attr('disabled', 'disabled'); + + nodename = nodename.substr(0, nodename.length - 1); + $('#bladeDiaInputDiv').append(createLoader()); + //send the add request + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'webrun', + tgt : '', + args : 'addnode;node;' + mmname + ',' + nodename, + msg : '' + }, + success : function(data){ + //refresh the area on the right side + $('#nodeTypeSelectDia').dialog('close'); + $('.selectgroup').trigger('click'); + } + }); +} /** * Create provision existing node division * diff --git a/xCAT-UI/js/custom/hmc.js b/xCAT-UI/js/custom/hmc.js index c96aefc95..e8967bf52 100644 --- a/xCAT-UI/js/custom/hmc.js +++ b/xCAT-UI/js/custom/hmc.js @@ -357,7 +357,7 @@ function addHmcNode(){ data : { cmd : 'webrun', tgt : '', - args : 'addpnode;hmc;' + args, + args : 'addnode;hmc;' + args, msg : '' }, success : function(data){ @@ -401,7 +401,7 @@ function addPNode(){ data : { cmd : 'webrun', tgt : '', - args : 'addpnode;node;' + hmcname + ',' + nodename, + args : 'addnode;node;' + hmcname + ',' + nodename, msg : '' }, success : function(data) {