2011-08-24 15:09:28 +00:00
/ * *
* Execute when the DOM is fully loaded
* /
$ ( document ) . ready ( function ( ) {
2012-03-14 04:46:08 +00:00
// Load utility scripts (if any)
2011-08-24 15:09:28 +00:00
} ) ;
/ * *
* Constructor
*
* @ return Nothing
* /
var bladePlugin = function ( ) {
} ;
2011-10-12 18:27:12 +00:00
/ * *
* Clone node ( service page )
*
* @ param node
* Node to clone
* @ return Nothing
* /
bladePlugin . prototype . serviceClone = function ( node ) {
} ;
2011-09-30 18:29:27 +00:00
/ * *
* Load provision page ( service page )
*
* @ param tabId
* Tab ID where page will reside
* @ return Nothing
* /
bladePlugin . prototype . loadServiceProvisionPage = function ( tabId ) {
} ;
/ * *
* Show node inventory ( service page )
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
bladePlugin . prototype . loadServiceInventory = function ( data ) {
} ;
2011-08-24 15:09:28 +00:00
/ * *
* Load node inventory
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
bladePlugin . prototype . loadInventory = function ( data ) {
var args = data . msg . split ( ',' ) ;
var tabId = args [ 0 ] . replace ( 'out=' , '' ) ;
var node = args [ 1 ] . replace ( 'node=' , '' ) ;
// Get node inventory
var inv = data . rsp ;
// Remove loader
$ ( '#' + tabId ) . find ( 'img' ) . remove ( ) ;
// Create division to hold inventory
var invDiv = $ ( '<div></div>' ) ;
// Create a fieldset
var fieldSet = $ ( '<fieldset></fieldset>' ) ;
var legend = $ ( '<legend>Hardware</legend>' ) ;
fieldSet . append ( legend ) ;
var oList = $ ( '<ol></ol>' ) ;
fieldSet . append ( oList ) ;
invDiv . append ( fieldSet ) ;
// Loop through each line
var item ;
for ( var k = 0 ; k < inv . length ; k ++ ) {
// Remove node name in front
var str = inv [ k ] . replace ( node + ': ' , '' ) ;
str = jQuery . trim ( str ) ;
// Append the string to a list
item = $ ( '<li></li>' ) ;
item . append ( str ) ;
oList . append ( item ) ;
}
// Append to inventory form
$ ( '#' + tabId ) . append ( invDiv ) ;
} ;
/ * *
* Load clone page
*
* @ param node
* Source node to clone
* @ return Nothing
* /
bladePlugin . prototype . loadClonePage = function ( node ) {
// Get nodes tab
var tab = getNodesTab ( ) ;
var newTabId = node + 'CloneTab' ;
// If there is no existing clone tab
if ( ! $ ( '#' + newTabId ) . length ) {
// Create info bar
var infoBar = createInfoBar ( 'Not supported' ) ;
// Create clone form
var cloneForm = $ ( '<div class="form"></div>' ) ;
cloneForm . append ( infoBar ) ;
// Add clone tab
tab . add ( newTabId , 'Clone' , cloneForm , true ) ;
}
tab . select ( newTabId ) ;
} ;
/ * *
* Load provision page
*
* @ param tabId
* The provision tab ID
* @ return Nothing
* /
bladePlugin . prototype . loadProvisionPage = function ( tabId ) {
// Get OS image names
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'tabdump' ,
tgt : '' ,
args : 'osimage' ,
msg : ''
} ,
success : setOSImageCookies
} ) ;
// Get groups
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'extnoderange' ,
tgt : '/.*' ,
args : 'subgroups' ,
msg : ''
} ,
success : setGroupsCookies
} ) ;
// Get provision tab instance
var inst = tabId . replace ( 'bladeProvisionTab' , '' ) ;
// Create provision form
var provForm = $ ( '<div class="form"></div>' ) ;
// Create info bar
var infoBar = createInfoBar ( 'Provision a blade. This will install an operating system onto the blade.' ) ;
provForm . append ( infoBar ) ;
// Append to provision tab
$ ( '#' + tabId ) . append ( provForm ) ;
// Create provision existing node division
var provExisting = createBladeProvisionExisting ( inst ) ;
provForm . append ( provExisting ) ;
} ;
/ * *
* Load resources
*
* @ return Nothing
* /
bladePlugin . prototype . loadResources = function ( ) {
// Get resource tab ID
var tabId = 'bladeResourceTab' ;
// Remove loader
$ ( '#' + tabId ) . find ( 'img' ) . remove ( ) ;
// Create info bar
var infoBar = createInfoBar ( 'Under construction' ) ;
// Create resource form
var resrcForm = $ ( '<div class="form"></div>' ) ;
resrcForm . append ( infoBar ) ;
$ ( '#' + tabId ) . append ( resrcForm ) ;
} ;
/ * *
* Add node range
* /
bladePlugin . prototype . addNode = function ( ) {
2011-12-01 05:58:22 +00:00
var addNodeForm = $ ( '<div id="addBladeCenter" class="form"></div>' ) ;
var info = createInfoBar ( 'Add a BladeCenter node' ) ;
addNodeForm . append ( info ) ;
2011-09-12 19:47:26 +00:00
2011-12-01 05:58:22 +00:00
var typeFS = $ ( '<fieldset></fieldset>' ) ;
var typeLegend = $ ( '<legend>Type</legend>' ) ;
typeFS . append ( typeLegend ) ;
addNodeForm . append ( typeFS ) ;
2012-03-14 04:46:08 +00:00
var settingsFS = $ ( '<fieldset id="bcSettings"></fieldset>' ) ;
var nodeLegend = $ ( '<legend>Settings</legend>' ) ;
settingsFS . append ( nodeLegend ) ;
addNodeForm . append ( settingsFS ) ;
2011-12-01 05:58:22 +00:00
typeFS . append ( '<div>' +
'<label>Node type:</label>' +
'<select id="typeSelect">' +
2012-03-14 04:46:08 +00:00
'<option value="amm">AMM</option>' +
2011-12-01 05:58:22 +00:00
'<option value="blade">Blade</option>' +
2012-03-14 04:46:08 +00:00
'<option value="scan">Blade by scan</option>' +
2011-12-01 05:58:22 +00:00
'</select>' +
'</div>' ) ;
2012-03-14 04:46:08 +00:00
// Change dialog width
$ ( '#addBladeCenter' ) . dialog ( 'option' , 'width' , '400' ) ;
2011-12-01 05:58:22 +00:00
typeFS . find ( '#typeSelect' ) . bind ( 'change' , function ( ) {
// Remove any existing warnings
$ ( '#addBladeCenter .ui-state-error' ) . remove ( ) ;
2012-03-14 04:46:08 +00:00
settingsFS . find ( 'div' ) . remove ( ) ;
2011-12-01 05:58:22 +00:00
2012-03-14 04:46:08 +00:00
// Change dialog width
$ ( '#addBladeCenter' ) . dialog ( 'option' , 'width' , '400' ) ;
var nodeType = $ ( this ) . val ( ) ;
switch ( nodeType ) {
case 'amm' :
settingsFS . append ( '<div><label>AMM name:</label><input name="ammName" type="text"/></div>' ) ;
settingsFS . append ( '<div><label>User name:</label><input name="ammUser" type="text"></div>' ) ;
settingsFS . append ( '<div><label>Password:</label><input name="ammPassword" type="password"></div>' ) ;
settingsFS . append ( '<div><label>IP address:</label><input id="ammIp" type="text"/></div>' ) ;
2011-09-21 07:11:31 +00:00
break ;
case 'blade' :
2012-03-14 04:46:08 +00:00
settingsFS . append ( '<div><label>Blade name:</label><input name="bladeName" type="text"/></input></div>' ) ;
settingsFS . append ( '<div><label>Blade group:</label><input name="bladeGroup" type="text"/></input></div>' ) ;
settingsFS . append ( '<div><label>Blade ID:</label><input name="bladeId" type="text"/t></div>' ) ;
settingsFS . append ( '<div><label>Blade series:</label>JS <input type="radio" name="bladeSeries" value="js"/> LS<input type="radio" name="bladeSeries" value="ls"/></div>' ) ;
settingsFS . append ( '<div><label style="vertical-align: middle;">Blade MPA:</label><select name="bladeMpa"></select><div>' ) ;
2011-09-21 07:11:31 +00:00
break ;
2012-03-14 04:46:08 +00:00
case 'scan' :
settingsFS . append ( '<div><label style="vertical-align: middle;">Blade MPA:</label><select id="bladeMpa"></select></div>' ) ;
// Change dialog width
$ ( '#addBladeCenter' ) . dialog ( 'option' , 'width' , '650' ) ;
2011-09-21 07:11:31 +00:00
break ;
}
2012-03-14 04:46:08 +00:00
// Do not continue if node type is AMM
if ( $ ( this ) . val ( ) == 'amm' ) {
2011-09-21 07:11:31 +00:00
return ;
}
2012-03-14 04:46:08 +00:00
// Gather AMM nodes
settingsFS . find ( 'select:eq(0)' ) . after ( createLoader ( ) ) ;
2011-09-21 07:11:31 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsdef' ,
tgt : '' ,
args : '-t;node;-w;mgt==blade;-w;id==0' ,
2012-03-14 04:46:08 +00:00
msg : nodeType
2011-09-21 07:11:31 +00:00
} ,
2012-03-14 04:46:08 +00:00
success : function ( data ) {
2011-09-21 07:11:31 +00:00
var position = 0 ;
2012-03-14 04:46:08 +00:00
var tmp = '' ;
2011-09-21 07:11:31 +00:00
var options = '' ;
2011-12-01 05:58:22 +00:00
// Remove the loading image
2012-03-14 04:46:08 +00:00
settingsFS . find ( 'img' ) . remove ( ) ;
2011-08-24 15:09:28 +00:00
2012-03-14 04:46:08 +00:00
// Do not continue if no AMM nodes are found
2011-12-01 05:58:22 +00:00
if ( data . rsp . length < 1 ) {
2012-03-14 04:46:08 +00:00
$ ( '#addBladeCenter' ) . prepend ( createWarnBar ( 'Please define an AMM node before continuing' ) ) ;
2011-09-21 07:11:31 +00:00
return ;
}
2011-08-24 15:09:28 +00:00
2012-03-14 04:46:08 +00:00
// Create options for AMM nodes
2011-09-21 07:11:31 +00:00
for ( var i in data . rsp ) {
2012-03-14 04:46:08 +00:00
tmp = data . rsp [ i ] ;
position = tmp . indexOf ( ' ' ) ;
tmp = tmp . substring ( 0 , position ) ;
options += '<option value="' + tmp + '">' + tmp + '</option>' ;
2011-09-21 07:11:31 +00:00
}
2012-03-14 04:46:08 +00:00
// Select the first AMM node
settingsFS . find ( 'select:eq(0)' ) . append ( options ) ;
if ( data . msg != 'scan' ) {
2011-09-21 07:11:31 +00:00
return ;
}
2011-12-01 05:58:22 +00:00
2012-03-14 04:46:08 +00:00
// Create Scan button
2011-12-01 05:58:22 +00:00
var scan = createButton ( 'Scan' ) ;
scan . bind ( 'click' , function ( ) {
2012-03-14 04:46:08 +00:00
var ammName = settingsFS . find ( 'select:eq(0)' ) . val ( ) ;
settingsFS . prepend ( createLoader ( ) ) ;
$ ( '#bcSettings button' ) . attr ( 'disabled' , 'disabled' ) ;
2011-09-21 07:11:31 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rscan' ,
2012-03-14 04:46:08 +00:00
tgt : ammName ,
2011-09-21 07:11:31 +00:00
args : '' ,
msg : ''
} ,
2012-03-14 04:46:08 +00:00
/ * *
* Show scanned results for AMM
*
* @ param data Data returned from HTTP request
* /
2011-09-21 07:11:31 +00:00
success : function ( data ) {
2012-03-14 04:46:08 +00:00
showScanAmmResult ( data . rsp [ 0 ] ) ;
2011-09-21 07:11:31 +00:00
}
} ) ;
} ) ;
2011-12-01 05:58:22 +00:00
2012-03-14 04:46:08 +00:00
settingsFS . find ( 'select:eq(0)' ) . after ( scan ) ;
2011-09-21 07:11:31 +00:00
}
} ) ;
} ) ;
2011-08-24 15:09:28 +00:00
2012-03-14 04:46:08 +00:00
// Create dialog for BladeCenter
addNodeForm . dialog ( {
2011-08-24 15:09:28 +00:00
modal : true ,
width : 400 ,
2011-09-28 21:38:12 +00:00
title : 'Add node' ,
2011-08-24 15:09:28 +00:00
open : function ( event , ui ) {
2011-09-21 07:11:31 +00:00
$ ( ".ui-dialog-titlebar-close" ) . hide ( ) ;
2011-08-24 15:09:28 +00:00
} ,
2011-12-01 05:58:22 +00:00
close : function ( ) {
$ ( this ) . remove ( ) ;
} ,
2011-08-24 15:09:28 +00:00
buttons : {
'Ok' : function ( ) {
2011-12-01 05:58:22 +00:00
// Remove any existing warnings
$ ( '#addBladeCenter .ui-state-error' ) . remove ( ) ;
var addMethod = $ ( '#typeSelect' ) . val ( ) ;
2011-08-24 15:09:28 +00:00
2012-03-14 04:46:08 +00:00
if ( addMethod == "amm" ) {
addAmmNode ( ) ;
2011-12-01 05:58:22 +00:00
} else if ( addMethod == "blade" ) {
2011-08-24 15:09:28 +00:00
addBladeNode ( ) ;
2011-12-01 05:58:22 +00:00
} else {
2011-09-21 07:11:31 +00:00
addMmScanNode ( ) ;
}
2011-08-24 15:09:28 +00:00
} ,
'Cancel' : function ( ) {
$ ( this ) . remove ( ) ;
}
}
} ) ;
2011-09-21 07:11:31 +00:00
2011-12-01 05:58:22 +00:00
addNodeForm . find ( '#typeSelect' ) . trigger ( 'change' ) ;
2011-08-24 15:09:28 +00:00
} ;
2011-09-12 19:47:26 +00:00
/ * *
* Add AMM node
* /
2012-03-14 04:46:08 +00:00
function addAmmNode ( ) {
var args = '' ;
2011-12-01 05:58:22 +00:00
var errorMsg = '' ;
2011-08-24 15:09:28 +00:00
2012-03-14 04:46:08 +00:00
// Check for missing inputs
2011-12-01 05:58:22 +00:00
$ ( '#addBladeCenter input' ) . each ( function ( ) {
if ( ! $ ( this ) . val ( ) ) {
2012-03-14 04:46:08 +00:00
errorMsg = 'Please provide a value for each missing field!' ;
2011-09-21 07:11:31 +00:00
}
2011-12-01 05:58:22 +00:00
2012-03-14 04:46:08 +00:00
args += $ ( this ) . val ( ) + ',' ;
2011-09-21 07:11:31 +00:00
} ) ;
2012-03-14 04:46:08 +00:00
// Do not continue if error was found
2011-12-01 05:58:22 +00:00
if ( errorMsg ) {
$ ( '#addBladeCenter' ) . prepend ( createWarnBar ( errorMsg ) ) ;
2011-09-21 07:11:31 +00:00
return ;
}
2012-03-14 04:46:08 +00:00
args = args . substring ( 0 , args . length - 1 ) ;
2011-12-01 05:58:22 +00:00
// Add the loader
2012-03-14 04:46:08 +00:00
$ ( '#addBladeCenter' ) . append ( createLoader ( ) ) ;
2011-08-24 15:09:28 +00:00
$ ( '.ui-dialog-buttonpane .ui-button' ) . attr ( 'disabled' , true ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2011-09-21 07:11:31 +00:00
cmd : 'webrun' ,
2011-08-24 15:09:28 +00:00
tgt : '' ,
2012-03-14 04:46:08 +00:00
args : 'addnode;mm;' + args ,
2011-08-24 15:09:28 +00:00
msg : ''
} ,
success : function ( data ) {
2012-03-14 04:46:08 +00:00
// Remove loader
2011-12-01 05:58:22 +00:00
$ ( '#addBladeCenter' ) . find ( 'img' ) . remove ( ) ;
2012-03-14 04:46:08 +00:00
$ ( '#addBladeCenter' ) . prepend ( createInfoBar ( 'AMM node was successfully added' ) ) ;
2011-12-01 05:58:22 +00:00
$ ( '#addBladeCenter' ) . dialog ( "option" , "buttons" , {
"Close" : function ( ) {
$ ( '#addBladeCenter' ) . dialog ( 'close' ) ;
2011-08-24 15:09:28 +00:00
}
} ) ;
}
} ) ;
}
2011-09-12 19:47:26 +00:00
/ * *
* Add blade node
* /
2011-08-24 15:09:28 +00:00
function addBladeNode ( ) {
2012-03-14 04:46:08 +00:00
// 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
2011-08-24 15:09:28 +00:00
if ( series != 'js' ) {
2012-03-14 04:46:08 +00:00
args += ';serialspeed=19200;serialport=1' ;
2011-08-24 15:09:28 +00:00
}
2012-03-14 04:46:08 +00:00
// Check for missing inputs
if ( ! name || ! group || ! id || ! mpa ) {
$ ( '#addBladeCenter' ) . prepend ( createWarnBar ( "Please provide a value for each missing field!" ) ) ;
2011-08-24 15:09:28 +00:00
return ;
}
2011-12-01 05:58:22 +00:00
// Add loader and disable buttons
$ ( '#addBladeCenter' ) . prepend ( createLoader ( ) ) ;
2011-08-24 15:09:28 +00:00
$ ( '.ui-dialog-buttonpane .ui-button' ) . attr ( 'disabled' , true ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'chdef' ,
tgt : '' ,
2012-03-14 04:46:08 +00:00
args : args ,
2011-08-24 15:09:28 +00:00
msg : ''
} ,
success : function ( data ) {
2012-03-14 04:46:08 +00:00
// Remove loader
2011-12-01 05:58:22 +00:00
$ ( '#addBladeCenter' ) . find ( 'img' ) . remove ( ) ;
2012-03-14 04:46:08 +00:00
// Gather response and display it
var rsp = data . rsp ;
var rspMessage = '' ;
for ( var i = 0 ; i < rsp . length ; i ++ ) {
rspMessage += rsp [ i ] + '<br/>' ;
2011-08-24 15:09:28 +00:00
}
2011-09-21 07:11:31 +00:00
2012-03-14 04:46:08 +00:00
// Append response message to dialog
$ ( '#addBladeCenter' ) . prepend ( createInfoBar ( rspMessage ) ) ;
// Change dialog button
2011-12-01 05:58:22 +00:00
$ ( '#addBladeCenter' ) . dialog ( "option" , "buttons" , {
"Close" : function ( ) {
$ ( '#addBladeCenter' ) . remove ( ) ;
2011-08-24 15:09:28 +00:00
}
} ) ;
}
} ) ;
2011-09-21 07:11:31 +00:00
}
2011-08-24 15:09:28 +00:00
2011-12-01 05:58:22 +00:00
/ * *
* Show rscan results
*
2012-03-14 04:46:08 +00:00
* @ param results
2011-12-01 05:58:22 +00:00
* Results from rscan of blade MPA
* @ return Nothing
* /
2012-03-14 04:46:08 +00:00
function showScanAmmResult ( results ) {
var rSection = $ ( '<div style="height: 300px; overflow: auto;" id="scanResults"></div>' ) ;
// Create table to hold results
var rTable = $ ( '<table></table>' ) ;
2011-09-21 07:11:31 +00:00
2012-03-14 04:46:08 +00:00
// Reset scan results area
$ ( '#addBladeCenter #scanResults' ) . remove ( ) ;
$ ( '#bcSettings img' ) . remove ( ) ;
$ ( '#bcSettings button' ) . attr ( 'disabled' , '' ) ;
if ( ! results )
2011-09-21 07:11:31 +00:00
return ;
2012-03-14 04:46:08 +00:00
// Do not continue if there are no results
var rows = results . split ( "\n" ) ;
2011-09-21 07:11:31 +00:00
if ( rows . length < 2 ) {
2012-03-14 04:46:08 +00:00
$ ( '#bcSettings' ) . prepend ( createWarnBar ( rows [ 0 ] ) ) ;
2011-09-21 07:11:31 +00:00
return ;
}
2011-12-01 05:58:22 +00:00
// Add the table header
2012-03-14 04:46:08 +00:00
var fields = rows [ 0 ] . match ( /\S+/g ) ;
var column = fields . length ;
var row = $ ( '<tr></tr>' ) ;
row . append ( '<td><input type="checkbox" onclick="selectAllRscanNode(this)"></td>' ) ;
2011-09-21 07:11:31 +00:00
for ( var i in fields ) {
2012-03-14 04:46:08 +00:00
row . append ( '<td>' + fields [ i ] + '</td>' ) ;
2011-09-21 07:11:31 +00:00
}
2012-03-14 04:46:08 +00:00
rTable . append ( row ) ;
2011-09-21 07:11:31 +00:00
2012-03-14 04:46:08 +00:00
// Add table body
var line ;
for ( var i = 1 ; i < rows . length ; i ++ ) {
2011-09-21 07:11:31 +00:00
line = rows [ i ] ;
2011-12-01 05:58:22 +00:00
2012-03-14 04:46:08 +00:00
if ( ! line )
2011-09-21 07:11:31 +00:00
continue ;
2011-12-01 05:58:22 +00:00
2012-03-14 04:46:08 +00:00
var fields = line . match ( /\S+/g ) ;
if ( fields [ 0 ] == 'mm' )
2011-09-21 07:11:31 +00:00
continue ;
2012-03-14 04:46:08 +00:00
// Create a row for each result
var row = $ ( '<tr></tr>' ) ;
row . append ( '<td><input type="checkbox" name="' + fields [ 1 ] + '"></td>' ) ;
2011-09-21 07:11:31 +00:00
2012-03-14 04:46:08 +00:00
// Add column for each field
for ( var j = 0 ; j < column ; j ++ ) {
2011-12-01 05:58:22 +00:00
if ( fields [ j ] ) {
if ( j == 1 ) {
2012-03-14 04:46:08 +00:00
row . append ( '<td><input value="' + fields [ j ] + '"></td>' ) ;
2011-12-01 05:58:22 +00:00
} else {
2012-03-14 04:46:08 +00:00
row . append ( '<td>' + fields [ j ] + '</td>' ) ;
2011-09-23 06:22:37 +00:00
}
2012-03-14 04:46:08 +00:00
} else {
row . append ( '<td></td>' ) ;
2011-09-21 07:11:31 +00:00
}
}
2012-03-14 04:46:08 +00:00
// Append row to table
rTable . append ( row ) ;
2011-09-21 07:11:31 +00:00
}
2012-03-14 04:46:08 +00:00
rSection . append ( rTable ) ;
$ ( '#bcSettings' ) . prepend ( rSection ) ;
2011-08-24 15:09:28 +00:00
}
2012-03-14 04:46:08 +00:00
/ * *
* Add AMM scanned node
* /
2011-09-21 07:11:31 +00:00
function addMmScanNode ( ) {
2012-03-14 04:46:08 +00:00
// Get the AMM name
var ammName = $ ( '#bcSettings select' ) . val ( ) ;
2011-12-01 05:58:22 +00:00
var nodeName = '' ;
2012-03-14 04:46:08 +00:00
$ ( '#bcSettings :checked' ) . each ( function ( ) {
2011-12-01 05:58:22 +00:00
if ( $ ( this ) . attr ( 'name' ) ) {
nodeName += $ ( this ) . attr ( 'name' ) + ',' ;
nodeName += $ ( this ) . parents ( 'tr' ) . find ( 'input' ) . eq ( 1 ) . val ( ) + ',' ;
2011-09-21 07:11:31 +00:00
}
} ) ;
2011-12-01 05:58:22 +00:00
if ( ! nodeName ) {
2012-03-14 04:46:08 +00:00
$ ( '#addBladeCenter' ) . prepend ( createWarnBar ( 'Please select a node!' ) ) ;
2011-09-21 07:11:31 +00:00
return ;
}
2011-12-01 05:58:22 +00:00
2012-03-14 04:46:08 +00:00
// Disabled button
2011-09-21 07:11:31 +00:00
$ ( '.ui-dialog-buttonpane button' ) . attr ( 'disabled' , 'disabled' ) ;
2011-12-01 05:58:22 +00:00
nodeName = nodeName . substr ( 0 , nodeName . length - 1 ) ;
$ ( '#nodeAttrs' ) . append ( createLoader ( ) ) ;
2012-03-14 04:46:08 +00:00
// Send add request
2011-09-21 07:11:31 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
2012-03-14 04:46:08 +00:00
args : 'addnode;node;' + ammName + ',' + nodeName ,
2011-09-21 07:11:31 +00:00
msg : ''
} ,
success : function ( data ) {
2011-12-01 05:58:22 +00:00
$ ( '#addBladeCenter' ) . dialog ( 'close' ) ;
2011-09-21 07:11:31 +00:00
}
} ) ;
}
2011-12-01 05:58:22 +00:00
2011-08-24 15:09:28 +00:00
/ * *
* Create provision existing node division
*
* @ param inst
* Provision tab instance
* @ return Provision existing node division
* /
function createBladeProvisionExisting ( inst ) {
// Create provision existing division
var provExisting = $ ( '<div></div>' ) ;
2011-12-19 05:03:27 +00:00
// Create VM fieldset
var nodeFS = $ ( '<fieldset></fieldset>' ) ;
var nodeLegend = $ ( '<legend>Node</legend>' ) ;
nodeFS . append ( nodeLegend ) ;
var nodeAttr = $ ( '<div style="display: inline-table; vertical-align: middle; width: 85%; margin-left: 10px;"></div>' ) ;
nodeFS . append ( $ ( '<div style="display: inline-table; vertical-align: middle;"><img src="images/provision/computer.png"></img></div>' ) ) ;
nodeFS . append ( nodeAttr ) ;
// Create image fieldset
var imgFS = $ ( '<fieldset></fieldset>' ) ;
var imgLegend = $ ( '<legend>Image</legend>' ) ;
imgFS . append ( imgLegend ) ;
var imgAttr = $ ( '<div style="display: inline-table; vertical-align: middle;"></div>' ) ;
imgFS . append ( $ ( '<div style="display: inline-table; vertical-align: middle;"><img src="images/provision/operating_system.png"></img></div>' ) ) ;
imgFS . append ( imgAttr ) ;
provExisting . append ( nodeFS , imgFS ) ;
2011-08-24 15:09:28 +00:00
// Create group input
var group = $ ( '<div></div>' ) ;
var groupLabel = $ ( '<label for="provType">Group:</label>' ) ;
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 = $ ( '<select></select>' ) ;
groupSelect . append ( '<option></option>' ) ;
for ( var i in tmp ) {
// Add group into drop down
var opt = $ ( '<option value="' + tmp [ i ] + '">' + tmp [ i ] + '</option>' ) ;
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 = $ ( '<input type="text" name="group"/>' ) ;
group . append ( groupInput ) ;
}
2011-12-19 05:03:27 +00:00
nodeAttr . append ( group ) ;
2011-08-24 15:09:28 +00:00
// Create node input
var node = $ ( '<div></div>' ) ;
var nodeLabel = $ ( '<label for="nodeName">Nodes:</label>' ) ;
var nodeDatatable = $ ( '<div id="' + dTableDivId + '" style="display: inline-block; max-width: 800px;"><p>Select a group to view its nodes</p></div>' ) ;
node . append ( nodeLabel ) ;
node . append ( nodeDatatable ) ;
2011-12-19 05:03:27 +00:00
nodeAttr . append ( node ) ;
2011-08-24 15:09:28 +00:00
// Create boot method drop down
var method = $ ( '<div></div>' ) ;
var methodLabel = $ ( '<label for="method">Boot method:</label>' ) ;
var methodSelect = $ ( '<select id="bootMethod" name="bootMethod"></select>' ) ;
methodSelect . append ( '<option value=""></option>'
+ '<option value="boot">boot</option>'
+ '<option value="install">install</option>'
+ '<option value="iscsiboot">iscsiboot</option>'
+ '<option value="netboot">netboot</option>'
+ '<option value="statelite">statelite</option>'
) ;
method . append ( methodLabel ) ;
method . append ( methodSelect ) ;
2011-12-19 05:03:27 +00:00
imgAttr . append ( method ) ;
2011-08-24 15:09:28 +00:00
// Create operating system input
var os = $ ( '<div></div>' ) ;
var osLabel = $ ( '<label for="os">Operating system:</label>' ) ;
var osInput = $ ( '<input type="text" name="os"/>' ) ;
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 ) ;
2011-12-19 05:03:27 +00:00
imgAttr . append ( os ) ;
2011-08-24 15:09:28 +00:00
// Create architecture input
var arch = $ ( '<div></div>' ) ;
var archLabel = $ ( '<label for="arch">Architecture:</label>' ) ;
var archInput = $ ( '<input type="text" name="arch"/>' ) ;
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 ) ;
2011-12-19 05:03:27 +00:00
imgAttr . append ( arch ) ;
2011-08-24 15:09:28 +00:00
// Create profile input
var profile = $ ( '<div></div>' ) ;
var profileLabel = $ ( '<label for="profile">Profile:</label>' ) ;
var profileInput = $ ( '<input type="text" name="profile"/>' ) ;
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 ) ;
2011-12-19 05:03:27 +00:00
imgAttr . append ( profile ) ;
2011-08-24 15:09:28 +00:00
/ * *
* 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 : '' ,
2011-08-24 16:08:49 +00:00
args : tgts + ';noderes.netboot=xnba;nodetype.os=' + os . val ( ) + ';nodetype.arch=' + arch . val ( ) + ';nodetype.profile=' + profile . val ( ) + ';nodetype.provmethod=' + boot . val ( ) ,
2011-08-24 15:09:28 +00:00
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
* @ return Nothing
* /
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 ( '<pre>It will take several minutes before the nodes are up and ready. Use rcons to monitor the status of the install.</pre>' ) ;
}
}
}