');
break;
case 'scan':
settingsFS.append('');
// Change dialog width
$('#addBladeCenter').dialog('option', 'width', '650');
break;
}
// Do not continue if node type is AMM
if ($(this).val() == 'amm') {
return;
}
// Gather AMM nodes
settingsFS.find('select:eq(0)').after(createLoader());
$.ajax({
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'lsdef',
tgt : '',
args : '-t;node;-w;mgt==blade;-w;id==0',
msg : nodeType
},
success : function(data) {
var position = 0;
var tmp = '';
var options = '';
// Remove the loading image
settingsFS.find('img').remove();
// Do not continue if no AMM nodes are found
if (data.rsp.length < 1) {
$('#addBladeCenter').prepend(createWarnBar('Please define an AMM node before continuing'));
return;
}
// Create options for AMM nodes
for (var i in data.rsp){
tmp = data.rsp[i];
position = tmp.indexOf(' ');
tmp = tmp.substring(0, position);
options += '';
}
// 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 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 : ammName,
args : '',
msg : ''
},
/**
* Show scanned results for AMM
*
* @param data Data returned from HTTP request
*/
success: function(data){
showScanAmmResult(data.rsp[0]);
}
});
});
settingsFS.find('select:eq(0)').after(scan);
}
});
});
// Create dialog for BladeCenter
addNodeForm.dialog({
modal : true,
width : 400,
title : 'Add node',
open : function(event, ui) {
$(".ui-dialog-titlebar-close").hide();
},
close : function(){
$(this).remove();
},
buttons : {
'Ok' : function() {
// Remove any existing warnings
$('#addBladeCenter .ui-state-error').remove();
var addMethod = $('#typeSelect').val();
if (addMethod == "amm") {
addAmmNode();
} else if(addMethod == "blade") {
addBladeNode();
} else{
addMmScanNode();
}
},
'Cancel' : function() {
$(this).remove();
}
}
});
addNodeForm.find('#typeSelect').trigger('change');
};
/**
* Add AMM node
*/
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!';
}
args += $(this).val() + ',';
});
// Do not continue if error was found
if (errorMsg) {
$('#addBladeCenter').prepend(createWarnBar(errorMsg));
return;
}
args = args.substring(0, args.length - 1);
// Add the loader
$('#addBladeCenter').append(createLoader());
$('.ui-dialog-buttonpane .ui-button').attr('disabled', true);
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'webrun',
tgt : '',
args : 'addnode;mm;' + args,
msg : ''
},
success : function(data) {
// Remove loader
$('#addBladeCenter').find('img').remove();
$('#addBladeCenter').prepend(createInfoBar('AMM node was successfully added'));
$('#addBladeCenter').dialog("option", "buttons", {
"Close" : function() {
$('#addBladeCenter').dialog('destroy').remove();
}
});
}
});
}
/**
* Add blade node
*/
function addBladeNode(){
// 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 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') {
args += ';serialspeed=19200;serialport=1';
}
// Check for missing inputs
if (!name || !group || !id || !mpa) {
$('#addBladeCenter').prepend(createWarnBar("Please provide a value for each missing field!"));
return;
}
// Add loader and disable buttons
$('#addBladeCenter').prepend(createLoader());
$('.ui-dialog-buttonpane .ui-button').attr('disabled', true);
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'chdef',
tgt : '',
args : args,
msg : ''
},
success : function(data) {
// Remove loader
$('#addBladeCenter').find('img').remove();
// Gather response and display it
var rsp = data.rsp;
var rspMessage = '';
for (var i = 0; i < rsp.length; i++) {
rspMessage += rsp[i] + ' ';
}
// Append response message to dialog
$('#addBladeCenter').prepend(createInfoBar(rspMessage));
// Change dialog button
$('#addBladeCenter').dialog("option", "buttons", {
"Close" : function() {
$('#addBladeCenter').remove();
}
});
}
});
}
/**
* Show rscan results
*
* @param results Results from rscan of blade MPA
*/
function showScanAmmResult(results){
var rSection = $('');
// Create table to hold results
var rTable = $('
');
// Reset scan results area
$('#addBladeCenter #scanResults').remove();
$('#bcSettings img').remove();
$('#bcSettings button').attr('disabled', '');
if (!results)
return;
// Do not continue if there are no results
var rows = results.split("\n");
if (rows.length < 2){
$('#bcSettings').prepend(createWarnBar(rows[0]));
return;
}
// Add the table header
var fields = rows[0].match(/\S+/g);
var column = fields.length;
var row = $('
');
row.append('
');
for(var i in fields){
row.append('
' + fields[i] + '
');
}
rTable.append(row);
// Add table body
var line;
for (var i = 1; i < rows.length; i++) {
line = rows[i];
if (!line)
continue;
var fields = line.match(/\S+/g);
if (fields[0] == 'mm')
continue;
// Create a row for each result
var row = $('
');
row.append('
');
// Add column for each field
for (var j = 0; j < column; j++){
if (fields[j]) {
if (j == 1) {
row.append('
');
} else {
row.append('
' + fields[j] + '
');
}
} else {
row.append('
');
}
}
// Append row to table
rTable.append(row);
}
rSection.append(rTable);
$('#bcSettings').prepend(rSection);
}
/**
* Add AMM scanned node
*/
function addMmScanNode(){
// Get the AMM name
var ammName = $('#bcSettings select').val();
var nodeName = '';
$('#bcSettings :checked').each(function() {
if ($(this).attr('name')) {
nodeName += $(this).attr('name') + ',';
nodeName += $(this).parents('tr').find('input').eq(1).val() + ',';
}
});
if (!nodeName) {
$('#addBladeCenter').prepend(createWarnBar('Please select a node!'));
return;
}
// Disabled button
$('.ui-dialog-buttonpane button').attr('disabled', 'disabled');
nodeName = nodeName.substr(0, nodeName.length - 1);
$('#nodeAttrs').append(createLoader());
// Send add request
$.ajax({
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'webrun',
tgt : '',
args : 'addnode;node;' + ammName + ',' + nodeName,
msg : ''
},
success : function(data){
$('#addBladeCenter').dialog('destroy').remove();
}
});
}
/**
* Create provision existing node division
*
* @param inst Provision tab instance
* @return Provision existing node division
*/
function createBladeProvisionExisting(inst) {
// Create provision existing division
var provExisting = $('');
// Create node fieldset
var nodeFS = $('');
var nodeLegend = $('');
nodeFS.append(nodeLegend);
var nodeAttr = $('');
nodeFS.append($(''));
nodeFS.append(nodeAttr);
// Create image fieldset
var imgFS = $('');
var imgLegend = $('');
imgFS.append(imgLegend);
var imgAttr = $('');
imgFS.append($(''));
imgFS.append(imgAttr);
provExisting.append(nodeFS, imgFS);
// Create group input
var group = $('');
var groupLabel = $('');
group.append(groupLabel);
// Turn on auto complete for group
var dTableDivId = 'bladeNodesDatatableDIV' + inst; // Division ID where nodes datatable will be appended
var groupNames = $.cookie('groups');
if (groupNames) {
// Split group names into an array
var tmp = groupNames.split(',');
// Create drop down for groups
var groupSelect = $('');
groupSelect.append('');
for ( var i in tmp) {
// Add group into drop down
var opt = $('');
groupSelect.append(opt);
}
group.append(groupSelect);
// Create node datatable
groupSelect.change(function() {
// Get group selected
var thisGroup = $(this).val();
// If a valid group is selected
if (thisGroup) {
createNodesDatatable(thisGroup, dTableDivId);
} // End of if (thisGroup)
});
} else {
// If no groups are cookied
var groupInput = $('');
group.append(groupInput);
}
nodeAttr.append(group);
// Create node input
var node = $('');
var nodeLabel = $('');
var nodeDatatable = $('
Select a group to view its nodes
');
node.append(nodeLabel);
node.append(nodeDatatable);
nodeAttr.append(node);
// Create boot method drop down
var method = $('');
var methodLabel = $('');
var methodSelect = $('');
methodSelect.append(''
+ ''
+ ''
+ ''
+ ''
+ ''
);
method.append(methodLabel);
method.append(methodSelect);
imgAttr.append(method);
// Create operating system input
var os = $('');
var osLabel = $('');
var osInput = $('');
osInput.one('focus', function() {
var tmp = $.cookie('osvers');
if (tmp) {
// Turn on auto complete
$(this).autocomplete({
source: tmp.split(',')
});
}
});
os.append(osLabel);
os.append(osInput);
imgAttr.append(os);
// Create architecture input
var arch = $('');
var archLabel = $('');
var archInput = $('');
archInput.one('focus', function() {
var tmp = $.cookie('osarchs');
if (tmp) {
// Turn on auto complete
$(this).autocomplete({
source: tmp.split(',')
});
}
});
arch.append(archLabel);
arch.append(archInput);
imgAttr.append(arch);
// Create profile input
var profile = $('');
var profileLabel = $('');
var profileInput = $('');
profileInput.one('focus', function() {
var tmp = $.cookie('profiles');
if (tmp) {
// Turn on auto complete
$(this).autocomplete({
source: tmp.split(',')
});
}
});
profile.append(profileLabel);
profile.append(profileInput);
imgAttr.append(profile);
/**
* Provision existing
*/
var provisionBtn = createButton('Provision');
provisionBtn.bind('click', function(event) {
// Remove any warning messages
$(this).parents('.ui-tabs-panel').find('.ui-state-error').remove();
var ready = true;
var errorMessage = '';
// Get provision tab ID
var thisTabId = 'bladeProvisionTab' + inst;
// Get nodes that were checked
var dTableId = 'bladeNodesDatatable' + inst;
var tgts = getNodesChecked(dTableId);
if (!tgts) {
errorMessage += 'You need to select a node. ';
ready = false;
}
// Check booth method
var boot = $('#' + thisTabId + ' select[name=bootMethod]');
if (!boot.val()) {
errorMessage += 'You need to select a boot method. ';
boot.css('border', 'solid #FF0000 1px');
ready = false;
} else {
boot.css('border', 'solid #BDBDBD 1px');
}
// Check operating system image
var os = $('#' + thisTabId + ' input[name=os]');
if (!os.val()) {
errorMessage += 'You need to select a operating system image. ';
os.css('border', 'solid #FF0000 1px');
ready = false;
} else {
os.css('border', 'solid #BDBDBD 1px');
}
// Check architecture
var arch = $('#' + thisTabId + ' input[name=arch]');
if (!arch.val()) {
errorMessage += 'You need to select an architecture. ';
arch.css('border', 'solid #FF0000 1px');
ready = false;
} else {
arch.css('border', 'solid #BDBDBD 1px');
}
// Check profile
var profile = $('#' + thisTabId + ' input[name=profile]');
if (!profile.val()) {
errorMessage += 'You need to select a profile. ';
profile.css('border', 'solid #FF0000 1px');
ready = false;
} else {
profile.css('border', 'solid #BDBDBD 1px');
}
// If all inputs are valid, ready to provision
if (ready) {
// Disable provision button
$(this).attr('disabled', 'true');
// Prepend status bar
var statBar = createStatusBar('bladeProvisionStatBar' + inst);
statBar.append(createLoader(''));
statBar.prependTo($('#' + thisTabId));
// Disable all inputs
var inputs = $('#' + thisTabId + ' input');
inputs.attr('disabled', 'disabled');
// Disable all selects
var selects = $('#' + thisTabId + ' select');
selects.attr('disabled', 'disabled');
/**
* (1) Set operating system
*/
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'nodeadd',
tgt : '',
args : tgts + ';noderes.netboot=xnba;nodetype.os=' + os.val() + ';nodetype.arch=' + arch.val() + ';nodetype.profile=' + profile.val() + ';nodetype.provmethod=' + boot.val(),
msg : 'cmd=nodeadd;out=' + inst
},
success : updateBladeProvisionExistingStatus
});
} else {
// Show warning message
var warn = createWarnBar(errorMessage);
warn.prependTo($(this).parent().parent());
}
});
provExisting.append(provisionBtn);
return provExisting;
}
/**
* Update the provision existing node status
*
* @param data Data returned from HTTP request
*/
function updateBladeProvisionExistingStatus(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 inst = args[1].replace('out=', '');
// Get provision tab and status bar ID
var statBarId = 'bladeProvisionStatBar' + inst;
var tabId = 'bladeProvisionTab' + inst;
/**
* (2) Remote install
*/
if (cmd == 'nodeadd') {
// Write ajax response to status bar
var prg = writeRsp(rsp, '');
$('#' + statBarId).find('div').append(prg);
// Get parameters
var os = $('#' + tabId + ' input[name="os"]').val();
var profile = $('#' + tabId + ' input[name="profile"]').val();
var arch = $('#' + tabId + ' input[name="arch"]').val();
// Get nodes that were checked
var dTableId = 'bladeNodesDatatable' + inst;
var tgts = getNodesChecked(dTableId);
// Begin installation
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'rbootseq',
tgt : tgts,
args : 'net,hd',
msg : 'cmd=rbootseq;out=' + inst
},
success : updateBladeProvisionExistingStatus
});
}
/**
* (3) Prepare node for boot
*/
if (cmd == 'nodeadd') {
// Get provision method
var bootMethod = $('#' + tabId + ' select[name=bootMethod]').val();
// Get nodes that were checked
var dTableId = 'bladeNodesDatatable' + inst;
var tgts = getNodesChecked(dTableId);
// Prepare node for boot
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'nodeset',
tgt : tgts,
args : bootMethod,
msg : 'cmd=nodeset;out=' + inst
},
success : updateBladeProvisionExistingStatus
});
}
/**
* (4) Power on node
*/
if (cmd == 'nodeset') {
var prg = writeRsp(rsp, '');
$('#' + statBarId).find('div').append(prg);
// Get nodes that were checked
var dTableId = 'bladeNodesDatatable' + inst;
var tgts = getNodesChecked(dTableId);
// Prepare node for boot
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'rpower',
tgt : tgts,
args : 'boot',
msg : 'cmd=rpower;out=' + inst
},
success : updateBladeProvisionExistingStatus
});
}
/**
* (5) Done
*/
else if (cmd == 'rpower') {
// Write ajax response to status bar
var prg = writeRsp(rsp, '');
$('#' + statBarId).find('div').append(prg);
$('#' + statBarId).find('img').remove();
// If installation was successful
if (prg.html().indexOf('Error') == -1) {
$('#' + statBarId).find('div').append('
It will take several minutes before the nodes are up and ready. Use rcons to monitor the status of the install.