2010-06-16 18:21:58 +00:00
/ * *
* Global variables
* /
2012-03-14 04:32:06 +00:00
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
2011-07-20 21:13:09 +00:00
2010-06-16 18:21:58 +00:00
/ * *
2011-01-13 23:06:31 +00:00
* Set node tab
2010-06-16 18:21:58 +00:00
*
2011-01-13 23:06:31 +00:00
* @ param tab
2010-06-16 18:21:58 +00:00
* Tab object
* @ return Nothing
* /
2011-01-13 23:06:31 +00:00
function setNodesTab ( tab ) {
nodesTab = tab ;
2010-06-16 18:21:58 +00:00
}
/ * *
2011-01-13 23:06:31 +00:00
* Get node tab
2010-06-16 18:21:58 +00:00
*
* @ return Tab object
* /
function getNodesTab ( ) {
2011-01-13 23:06:31 +00:00
return nodesTab ;
}
/ * *
* Get node list
*
* @ return Node list
* /
function getNodesList ( ) {
return nodesList ;
}
/ * *
* Get nodes table ID
*
* @ return Nodes table ID
* /
function getNodesTableId ( ) {
return nodesTableId ;
2010-06-16 18:21:58 +00:00
}
/ * *
* Load nodes page
*
* @ return Nothing
* /
function loadNodesPage ( ) {
// If groups are not already loaded
if ( ! $ ( '#groups' ) . length ) {
// Create a groups division
2010-12-21 00:52:10 +00:00
var groups = $ ( '<div id="groups"></div>' ) ;
var nodes = $ ( '<div id="nodes"></div>' ) ;
$ ( '#content' ) . append ( groups ) ;
$ ( '#content' ) . append ( nodes ) ;
2010-06-16 18:21:58 +00:00
2011-09-09 03:31:05 +00:00
// Create loader and info bar
groups . append ( createLoader ( ) ) ;
2010-06-16 18:21:58 +00:00
// Get groups
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'extnoderange' ,
tgt : '/.*' ,
args : 'subgroups' ,
msg : ''
} ,
2011-09-09 03:31:05 +00:00
// Load groups
2011-06-16 02:48:34 +00:00
success : function ( data ) {
loadGroups ( data ) ;
2011-09-09 03:31:05 +00:00
var cookieGroup = $ . cookie ( 'selectgrouponnodes' ) ;
if ( cookieGroup ) {
2011-09-02 07:48:30 +00:00
$ ( '#groups .groupdiv div' ) . each ( function ( ) {
2011-09-09 03:31:05 +00:00
if ( $ ( this ) . text ( ) == cookieGroup ) {
2011-09-02 07:48:30 +00:00
$ ( this ) . trigger ( 'click' ) ;
return false ;
}
} ) ;
2011-09-09 03:31:05 +00:00
} else {
// Trigger the first group click event
2011-09-02 07:48:30 +00:00
$ ( '#groups .groupdiv div' ) . eq ( 0 ) . trigger ( 'click' ) ;
}
2011-06-16 02:48:34 +00:00
}
2010-06-16 18:21:58 +00:00
} ) ;
}
}
2011-06-16 02:48:34 +00:00
/ * *
2011-09-09 03:31:05 +00:00
* Show cluster summary in pie charts
2011-06-16 02:48:34 +00:00
*
2011-09-09 03:31:05 +00:00
* @ param groupName
* Group name
2011-06-16 02:48:34 +00:00
* @ return Nothing
* /
2011-09-09 03:31:05 +00:00
function loadPieSummary ( groupName ) {
2011-08-31 02:28:59 +00:00
var summaryTable = '<table style="border: 0px none;">' +
2011-07-12 06:37:55 +00:00
'<tr>' +
2011-09-09 03:31:05 +00:00
'<td><div id="statuspie" class="summarypie"></div></td>' +
'<td><div id="ospie" class="summarypie"></div></td>' +
'<td><div id="archpie" class="summarypie"></div></td>' +
2011-07-12 06:37:55 +00:00
'</tr>' +
'<tr>' +
2011-09-09 03:31:05 +00:00
'<td><div id="provmethodpie" class="summarypie"></td>' +
'<td><div id="nodetypepie" class="summarypie"></div></td>' +
2011-07-12 06:37:55 +00:00
'</tr></table>' ;
2011-08-31 02:28:59 +00:00
$ ( '#summaryTab' ) . append ( summaryTable ) ;
$ ( '#summaryTab .summarypie' ) . append ( createLoader ( ) ) ;
2011-07-12 06:37:55 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
2011-09-09 03:31:05 +00:00
args : 'summary;' + groupName ,
2011-07-12 06:37:55 +00:00
msg : ''
} ,
2011-09-09 03:31:05 +00:00
success : function ( data ) {
for ( var i in data . rsp ) {
2011-07-12 06:37:55 +00:00
drawPieSummary ( i , data . rsp [ i ] ) ;
}
}
} ) ;
2011-06-16 02:48:34 +00:00
}
/ * *
2011-09-09 03:31:05 +00:00
* Get nodes information and draw pie chart
2011-06-16 02:48:34 +00:00
*
2011-09-09 03:31:05 +00:00
* @ param index
* Node index
* @ param valuePair
* Node information key value pairing
2011-06-16 02:48:34 +00:00
* @ return Nothing
* /
2011-09-09 03:31:05 +00:00
function drawPieSummary ( index , valuePair ) {
2011-07-12 06:37:55 +00:00
var position = 0 ;
var key = '' ;
var val = '' ;
2011-09-09 03:31:05 +00:00
var chartTitle = '' ;
2011-07-12 06:37:55 +00:00
var dataArray = [ ] ;
var tempArray = [ ] ;
2011-08-31 02:28:59 +00:00
var container = $ ( '#summaryTab .summarypie' ) . eq ( index ) ;
2011-07-12 06:37:55 +00:00
2011-09-09 03:31:05 +00:00
position = valuePair . indexOf ( '=' ) ;
chartTitle = valuePair . substr ( 0 , position ) ;
tempArray = valuePair . substr ( position + 1 ) . split ( ';' ) ;
2011-07-12 06:37:55 +00:00
2011-09-09 03:31:05 +00:00
for ( var i in tempArray ) {
2011-07-12 06:37:55 +00:00
position = tempArray [ i ] . indexOf ( ':' ) ;
key = tempArray [ i ] . substr ( 0 , position ) ;
val = Number ( tempArray [ i ] . substr ( position + 1 ) ) ;
dataArray . push ( [ key , val ] ) ;
}
container . empty ( ) ;
2011-09-09 03:31:05 +00:00
var plot = $ . jqplot ( container . attr ( 'id' ) , [ dataArray ] , {
title : chartTitle ,
2011-07-12 06:37:55 +00:00
seriesDefaults : {
renderer : $ . jqplot . PieRenderer ,
rendererOptions : {
padding : 5 ,
2011-07-20 21:13:09 +00:00
fill : true ,
shadow : true ,
2011-07-12 06:37:55 +00:00
shadowOffset : 2 ,
shadowDepth : 5 ,
shadowAlpha : 0.07 ,
dataLabels : 'value' ,
showDataLabels : true
}
} ,
legend : {
show : true ,
location : 'e'
}
} ) ;
2011-06-16 02:48:34 +00:00
}
2010-06-16 18:21:58 +00:00
/ * *
* Load groups
*
* @ param data
* Data returned from HTTP request
2011-09-09 03:31:05 +00:00
* @ return Nothing
2010-06-16 18:21:58 +00:00
* /
function loadGroups ( data ) {
2010-07-17 13:09:04 +00:00
// Remove loader
$ ( '#groups' ) . find ( 'img' ) . remove ( ) ;
2010-12-21 00:52:10 +00:00
// Save group in cookie
2010-06-16 18:21:58 +00:00
var groups = data . rsp ;
setGroupsCookies ( data ) ;
// Create a list of groups
2011-06-27 08:49:13 +00:00
$ ( '#groups' ) . append ( '<div class="grouplabel">Groups</div>' ) ;
var grouplist = $ ( '<div class="groupdiv"></div>' ) ;
2010-06-16 18:21:58 +00:00
// Create a link for each group
2011-08-31 02:28:59 +00:00
for ( var i = 0 ; i < groups . length ; i ++ ) {
2011-08-16 08:38:46 +00:00
grouplist . append ( '<div>' + groups [ i ] + '</div>' ) ;
2010-06-16 18:21:58 +00:00
}
2010-11-11 21:36:51 +00:00
2011-06-27 08:49:13 +00:00
$ ( '#groups' ) . append ( grouplist ) ;
2011-07-20 21:13:09 +00:00
2011-09-09 03:31:05 +00:00
// Bind the click event
2011-06-27 08:49:13 +00:00
$ ( '#groups .groupdiv div' ) . bind ( 'click' , function ( ) {
2011-07-20 21:13:09 +00:00
var thisGroup = $ ( this ) . text ( ) ;
2011-06-27 08:49:13 +00:00
$ ( '#groups .groupdiv div' ) . removeClass ( 'selectgroup' ) ;
$ ( this ) . addClass ( 'selectgroup' ) ;
2011-09-09 03:31:05 +00:00
// Save selected group into cookie
2011-09-02 07:48:30 +00:00
$ . cookie ( 'selectgrouponnodes' , thisGroup , { expires : 7 } ) ;
2011-10-31 09:37:54 +00:00
drawNodesArea ( thisGroup , '' , thisGroup ) ;
2010-11-11 21:36:51 +00:00
} ) ;
2011-01-13 23:06:31 +00:00
// Make a link to add nodes
2011-06-27 08:49:13 +00:00
$ ( '#groups' ) . append ( '<div class="actionDiv" id="adddiv"></div>' ) ;
$ ( '#groups #adddiv' ) . append ( mkAddNodeLink ( ) ) ;
2011-01-13 23:06:31 +00:00
}
2011-06-16 02:48:34 +00:00
/ * *
2012-01-11 09:55:23 +00:00
* Empty the nodes area and add three tabs for nodes result
2011-06-16 02:48:34 +00:00
*
2011-09-09 03:31:05 +00:00
* @ param targetgroup
* The name range for nodels command
* @ param cmdargs
* Filter arguments for nodels command
* @ param message
* The useful information from the HTTP request
* @ return Nothing
2011-06-16 02:48:34 +00:00
* /
2011-06-24 06:23:08 +00:00
function drawNodesArea ( targetgroup , cmdargs , message ) {
2011-07-20 21:13:09 +00:00
// Clear nodes division
2011-06-16 02:48:34 +00:00
$ ( '#nodes' ) . empty ( ) ;
// Create a tab for this group
var tab = new Tab ( 'nodesPageTabs' ) ;
setNodesTab ( tab ) ;
tab . init ( ) ;
$ ( '#nodes' ) . append ( tab . object ( ) ) ;
2011-08-31 02:28:59 +00:00
tab . add ( 'summaryTab' , 'Summary' , '' , false ) ;
2011-09-09 14:53:17 +00:00
tab . add ( 'nodesTab' , 'Nodes' , '' , false ) ;
2011-06-16 02:48:34 +00:00
tab . add ( 'graphTab' , 'Graphic' , '' , false ) ;
2011-10-05 03:34:42 +00:00
2011-09-09 14:53:17 +00:00
// Load nodes table when tab is selected
2011-10-05 03:34:42 +00:00
$ ( '#nodesPageTabs' ) . bind ( 'tabsselect' , function ( event , ui ) {
// Load summary when tab is selected
if ( ! $ ( '#summaryTab' ) . children ( ) . length && ui . index == 0 ) {
loadPieSummary ( targetgroup ) ;
}
// Load nodes table when tab is selected
else if ( ! $ ( '#nodesTab' ) . children ( ) . length && ui . index == 1 ) {
2011-09-09 14:53:17 +00:00
// Create loader
$ ( '#nodesTab' ) . append ( $ ( '<center></center>' ) . append ( createLoader ( ) ) ) ;
// To improve performance, get all nodes within selected group
// Get node definitions only for first 50 nodes
2011-06-16 02:48:34 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2011-09-09 14:53:17 +00:00
cmd : 'nodels' ,
tgt : targetgroup ,
args : cmdargs ,
msg : message
2011-06-16 02:48:34 +00:00
} ,
2011-09-09 14:53:17 +00:00
/ * *
* Get node definitions for first 50 nodes
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
success : function ( data ) {
var rsp = data . rsp ;
var group = data . msg ;
// Save nodes in a list so it can be accessed later
nodesList = new Array ( ) ;
for ( var i in rsp ) {
if ( rsp [ i ] [ 0 ] ) {
nodesList . push ( rsp [ i ] [ 0 ] ) ;
}
}
// Sort nodes list
nodesList . sort ( ) ;
// Get first 50 nodes
var nodes = '' ;
for ( var i = 0 ; i < nodesList . length ; i ++ ) {
if ( i > 49 ) {
break ;
}
nodes += nodesList [ i ] + ',' ;
}
// Remove last comma
nodes = nodes . substring ( 0 , nodes . length - 1 ) ;
// Get nodes definitions
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsdef' ,
tgt : '' ,
args : nodes ,
msg : targetgroup
} ,
success : loadNodes
} ) ;
}
2011-06-16 02:48:34 +00:00
} ) ;
}
2011-10-05 03:34:42 +00:00
// Load graphical layout when tab is selected
else if ( ! $ ( '#graphTab' ) . children ( ) . length && ui . index == 2 ) {
// For the graphical tab, check the graphical data first
2011-09-09 14:53:17 +00:00
createPhysicalLayout ( nodesList ) ;
}
} ) ;
2011-10-05 03:34:42 +00:00
// Get last view (if any)
// This can be summary, nodes, or graphic
2011-10-05 14:30:24 +00:00
if ( $ . cookie ( 'tabindex_history' ) ) {
var order = $ . cookie ( 'tabindex_history' ) . split ( ',' ) ;
order [ 0 ] = parseInt ( order [ 0 ] ) ;
order [ 1 ] = parseInt ( order [ 1 ] ) ;
if ( order [ 0 ] == 0 || order [ 1 ] == 0 ) {
// For some reason, you cannot trigger a select of index 0
loadPieSummary ( targetgroup ) ;
} else if ( order [ 0 ] == 1 || order [ 0 ] == 2 ) {
$ ( '#nodesPageTabs' ) . tabs ( 'select' , order [ 0 ] ) ;
} else if ( order [ 1 ] == 1 || order [ 1 ] == 2 ) {
$ ( '#nodesPageTabs' ) . tabs ( 'select' , order [ 1 ] ) ;
} else {
loadPieSummary ( targetgroup ) ;
}
2011-10-05 03:34:42 +00:00
} else {
loadPieSummary ( targetgroup ) ;
2011-10-05 14:30:24 +00:00
}
2011-06-16 02:48:34 +00:00
}
2011-07-20 21:13:09 +00:00
2011-01-13 23:06:31 +00:00
/ * *
* Make a link to add nodes
*
* @ returns Link to add nodes
* /
function mkAddNodeLink ( ) {
2010-09-20 18:57:08 +00:00
// Create link to add nodes
2011-06-27 08:49:13 +00:00
var addNodeLink = $ ( '<a title="Add a node or a node range to xCAT">+ Add Node</a>' ) ;
2011-01-13 23:06:31 +00:00
addNodeLink . click ( function ( ) {
// Create info bar
2010-09-23 20:43:10 +00:00
var info = createInfoBar ( 'Select the hardware management for the new node range' ) ;
2011-01-13 23:06:31 +00:00
// Create form to add node
2010-09-23 20:43:10 +00:00
var addNodeForm = $ ( '<div class="form"></div>' ) ;
addNodeForm . append ( info ) ;
addNodeForm . append ( '<div><label for="mgt">Hardware management:</label>'
2010-12-21 00:52:10 +00:00
+ '<select id="mgt" name="mgt">'
2011-12-19 05:03:27 +00:00
+ '<option value="esx">ESX</option>'
+ '<option value="kvm">KVM</option>'
+ '<option value="zvm">z\/VM</option>'
2011-07-12 06:37:55 +00:00
+ '<option value="ipmi">iDataPlex</option>'
2011-07-20 21:13:09 +00:00
+ '<option value="blade">BladeCenter</option>'
2011-09-09 14:53:17 +00:00
+ '<option value="hmc">System p</option>' // Documentation refers to 'IBM System p' (where p is NOT capitalized)
2010-09-23 20:43:10 +00:00
+ '</select>'
2011-01-13 23:06:31 +00:00
+ '</div>' ) ;
2010-12-02 21:28:24 +00:00
// Create advanced link to set advanced node properties
var advanced = $ ( '<div></div>' ) ;
2011-05-13 16:09:37 +00:00
var advancedLnk = $ ( '<a>Advanced</a>' ) . css ( {
'cursor' : 'pointer' ,
'color' : '#0000FF'
} ) ;
2011-01-13 23:06:31 +00:00
advancedLnk . click ( function ( ) {
// Get node attributes
2010-12-02 21:28:24 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsdef' ,
tgt : '' ,
args : '-t;node;-h' ,
msg : ''
} ,
2010-12-03 22:09:36 +00:00
/ * *
2011-01-13 23:06:31 +00:00
* Set node attributes and open dialog
2010-12-03 22:09:36 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
2010-12-02 21:28:24 +00:00
success : function ( data ) {
2011-01-13 23:06:31 +00:00
// Save node attributes
setNodeAttrs ( data ) ;
// Open a dialog to set node attributes
openSetAttrsDialog ( ) ;
2010-12-02 21:28:24 +00:00
}
} ) ;
// Close dialog
2011-01-13 23:06:31 +00:00
addNodeForm . dialog ( 'close' ) ;
2010-12-02 21:28:24 +00:00
} ) ;
advanced . append ( advancedLnk ) ;
addNodeForm . append ( advanced ) ;
2010-09-23 20:43:10 +00:00
2010-09-24 02:27:04 +00:00
// Open dialog to add node
2010-09-23 20:43:10 +00:00
addNodeForm . dialog ( {
modal : true ,
width : 400 ,
2011-09-28 21:38:12 +00:00
title : 'Add node' ,
2011-07-04 09:26:00 +00:00
close : function ( ) { $ ( this ) . remove ( ) ; } ,
2010-09-23 20:43:10 +00:00
buttons : {
2011-01-13 23:06:31 +00:00
'Ok' : function ( ) {
2010-09-24 02:27:04 +00:00
// Get hardware management
2010-09-23 20:43:10 +00:00
var mgt = $ ( this ) . find ( 'select[name=mgt]' ) . val ( ) ;
var plugin ;
switch ( mgt ) {
2011-12-19 05:03:27 +00:00
case "kvm" :
plugin = new kvmPlugin ( ) ;
break ;
case "esx" :
plugin = new esxPlugin ( ) ;
break ;
2010-09-23 20:43:10 +00:00
case "blade" :
plugin = new bladePlugin ( ) ;
break ;
case "hmc" :
plugin = new hmcPlugin ( ) ;
break ;
case "ipmi" :
plugin = new ipmiPlugin ( ) ;
break ;
case "zvm" :
plugin = new zvmPlugin ( ) ;
break ;
}
plugin . addNode ( ) ;
2011-01-13 23:06:31 +00:00
$ ( this ) . dialog ( 'close' ) ;
2010-10-07 21:01:14 +00:00
} ,
2011-01-13 23:06:31 +00:00
'Cancel' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
2010-10-07 21:01:14 +00:00
}
2010-09-21 01:35:08 +00:00
}
2011-01-13 23:06:31 +00:00
} ) ;
2010-09-21 01:35:08 +00:00
2010-09-20 18:57:08 +00:00
} ) ;
2010-11-01 14:06:53 +00:00
// Generate tooltips
addNodeLink . tooltip ( {
2011-01-13 23:06:31 +00:00
position : 'center right' ,
2010-12-03 22:09:36 +00:00
offset : [ - 2 , 10 ] ,
2011-01-13 23:06:31 +00:00
effect : 'fade' ,
2010-12-10 14:38:30 +00:00
opacity : 0.7 ,
predelay : 800
2010-11-01 14:06:53 +00:00
} ) ;
2011-01-13 23:06:31 +00:00
return addNodeLink ;
2010-06-16 18:21:58 +00:00
}
/ * *
* Load nodes belonging to a given group
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
2010-11-11 15:07:40 +00:00
function loadNodes ( data ) {
2011-08-24 03:10:37 +00:00
// Clear the tab before inserting the table
$ ( '#nodesTab' ) . children ( ) . remove ( ) ;
2011-01-13 23:06:31 +00:00
// Data returned
2010-06-16 18:21:58 +00:00
var rsp = data . rsp ;
// Group name
var group = data . msg ;
2011-01-13 23:06:31 +00:00
// Hash of Node attributes
2010-06-16 18:21:58 +00:00
var attrs = new Object ( ) ;
// Node attributes
var headers = new Object ( ) ;
2010-11-09 05:05:10 +00:00
2010-12-09 03:44:11 +00:00
// Variable to send command and request node status
var getNodeStatus = true ;
2011-07-20 21:13:09 +00:00
2010-11-12 18:59:25 +00:00
// Clear hash table containing node attributes
origAttrs = '' ;
2010-12-02 21:28:24 +00:00
2011-01-13 23:06:31 +00:00
var node , args ;
2010-11-24 18:11:42 +00:00
for ( var i in rsp ) {
2011-01-13 23:06:31 +00:00
// Get node name
if ( rsp [ i ] . indexOf ( 'Object name:' ) > - 1 ) {
2010-06-16 18:21:58 +00:00
var temp = rsp [ i ] . split ( ': ' ) ;
node = jQuery . trim ( temp [ 1 ] ) ;
// Create a hash for the node attributes
attrs [ node ] = new Object ( ) ;
i ++ ;
}
// Get key and value
2010-12-20 18:59:08 +00:00
args = rsp [ i ] . split ( '=' , 2 ) ;
2010-06-16 18:21:58 +00:00
var key = jQuery . trim ( args [ 0 ] ) ;
2012-01-11 09:55:23 +00:00
var val = jQuery . trim ( rsp [ i ] . substring ( rsp [ i ] . indexOf ( '=' ) + 1 ) ) ;
2010-12-20 18:59:08 +00:00
2010-06-16 18:21:58 +00:00
// Create a hash table
attrs [ node ] [ key ] = val ;
headers [ key ] = 1 ;
2010-12-09 03:44:11 +00:00
2011-01-13 23:06:31 +00:00
// If node status is available
2010-12-09 03:44:11 +00:00
if ( key == 'status' ) {
2011-01-13 23:06:31 +00:00
// Do not request node status
2010-12-09 03:44:11 +00:00
getNodeStatus = false ;
}
2010-06-16 18:21:58 +00:00
}
2011-01-13 23:06:31 +00:00
// Add nodes that are not in data returned
for ( var i in nodesList ) {
if ( ! attrs [ nodesList [ i ] ] ) {
// Create attributes list and save node name
attrs [ nodesList [ i ] ] = new Object ( ) ;
attrs [ nodesList [ i ] ] [ 'node' ] = nodesList [ i ] ;
}
}
2010-11-12 18:59:25 +00:00
// Save attributes in hash table
origAttrs = attrs ;
2010-06-16 18:21:58 +00:00
// Sort headers
var sorted = new Array ( ) ;
2010-11-24 18:11:42 +00:00
for ( var key in headers ) {
2010-12-08 16:28:12 +00:00
// Do not put comments and status in twice
2011-08-24 03:10:37 +00:00
if ( key != 'usercomment' && key != 'status' && key . indexOf ( 'status' ) < 0 ) {
2010-11-11 03:45:47 +00:00
sorted . push ( key ) ;
}
2010-06-16 18:21:58 +00:00
}
sorted . sort ( ) ;
2011-05-02 20:33:25 +00:00
// Add column for check box, node, ping, power, monitor, and comments
2010-11-09 21:22:43 +00:00
sorted . unshift ( '<input type="checkbox" onclick="selectAllCheckbox(event, $(this))">' ,
'node' ,
2010-12-19 19:08:47 +00:00
'<span><a>status</a></span><img src="images/loader.gif"></img>' ,
'<span><a>power</a></span><img src="images/loader.gif" style="display: none;"></img>' ,
2011-05-02 20:33:25 +00:00
'<span><a>monitor</a></span><img src="images/loader.gif" style="display: none;"></img>' ,
2010-11-09 21:22:43 +00:00
'comments' ) ;
2010-06-16 18:21:58 +00:00
// Create a datatable
2011-01-13 23:06:31 +00:00
var nodesTable = new DataTable ( nodesTableId ) ;
nodesTable . init ( sorted ) ;
2010-06-16 18:21:58 +00:00
// Go through each node
2010-11-24 18:11:42 +00:00
for ( var node in attrs ) {
2010-06-16 18:21:58 +00:00
// Create a row
var row = new Array ( ) ;
2010-12-09 03:44:11 +00:00
2010-12-21 00:52:10 +00:00
// Create a check box, node link, and get node status
2010-06-16 18:21:58 +00:00
var checkBx = '<input type="checkbox" name="' + node + '"/>' ;
2010-09-28 20:24:31 +00:00
var nodeLink = $ ( '<a class="node" id="' + node + '">' + node + '</a>' ) . bind ( 'click' , loadNode ) ;
2011-01-14 05:05:06 +00:00
// If there is no status attribute for the node, do not try to access hash table
2011-09-09 03:31:05 +00:00
// else the code will break
2011-01-04 14:02:43 +00:00
var status = '' ;
2011-01-14 05:05:06 +00:00
if ( attrs [ node ] [ 'status' ] ) {
2011-01-04 14:02:43 +00:00
status = attrs [ node ] [ 'status' ] . replace ( 'sshd' , 'ping' ) ;
}
2011-01-14 05:05:06 +00:00
2011-05-02 20:33:25 +00:00
// Push in checkbox, node, status, monitor, and power
row . push ( checkBx , nodeLink , status , '' , '' ) ;
2011-01-04 14:02:43 +00:00
2011-01-13 23:06:31 +00:00
// If the node attributes are known (i.e the group is known)
if ( attrs [ node ] [ 'groups' ] ) {
// Put in comments
2011-09-09 03:31:05 +00:00
var comments = attrs [ node ] [ 'usercomment' ] ;
2011-01-13 23:06:31 +00:00
// If no comments exists, show 'No comments' and set icon image source
var iconSrc ;
if ( ! comments ) {
comments = 'No comments' ;
2011-01-14 20:25:14 +00:00
iconSrc = 'images/nodes/ui-icon-no-comment.png' ;
2011-01-13 23:06:31 +00:00
} else {
2011-01-14 20:25:14 +00:00
iconSrc = 'images/nodes/ui-icon-comment.png' ;
2011-01-13 23:06:31 +00:00
}
// Create comments icon
var tipID = node + 'Tip' ;
var icon = $ ( '<img id="' + tipID + '" src="' + iconSrc + '"></img>' ) . css ( {
'width' : '18px' ,
'height' : '18px'
} ) ;
// Create tooltip
var tip = createCommentsToolTip ( comments ) ;
var col = $ ( '<span></span>' ) . append ( icon ) ;
col . append ( tip ) ;
row . push ( col ) ;
2010-12-09 03:44:11 +00:00
2011-01-13 23:06:31 +00:00
// Generate tooltips
icon . tooltip ( {
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.8 ,
relative : true ,
delay : 500
} ) ;
2010-11-11 03:45:47 +00:00
} else {
2011-01-13 23:06:31 +00:00
// Do not put in comments if attributes are not known
row . push ( '' ) ;
2010-11-11 03:45:47 +00:00
}
2010-06-16 18:21:58 +00:00
// Go through each header
2011-05-02 20:33:25 +00:00
for ( var i = 6 ; i < sorted . length ; i ++ ) {
2010-06-16 18:21:58 +00:00
// Add the node attributes to the row
var key = sorted [ i ] ;
2010-11-11 15:07:40 +00:00
2010-12-08 16:28:12 +00:00
// Do not put comments and status in twice
2011-08-24 03:10:37 +00:00
if ( key != 'usercomment' && key != 'status' && key . indexOf ( 'status' ) < 0 ) {
2010-11-11 03:45:47 +00:00
var val = attrs [ node ] [ key ] ;
if ( val ) {
row . push ( val ) ;
} else {
row . push ( '' ) ;
}
2010-12-21 00:52:10 +00:00
}
2010-06-16 18:21:58 +00:00
}
// Add the row to the table
2011-01-13 23:06:31 +00:00
nodesTable . add ( row ) ;
2010-06-16 18:21:58 +00:00
}
// Clear the tab before inserting the table
$ ( '#nodesTab' ) . children ( ) . remove ( ) ;
2010-11-09 05:05:10 +00:00
// Create info bar for nodes tab
2011-11-23 17:59:48 +00:00
var info = createInfoBar ( 'Double-click on a cell to edit a node\'s properties. Click outside the table to save changes. Hit the Escape key to ignore changes.' ) ;
2010-11-09 05:05:10 +00:00
$ ( '#nodesTab' ) . append ( info ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 13:41:29 +00:00
// Create action bar
2010-06-16 18:21:58 +00:00
var actionBar = $ ( '<div class="actionBar"></div>' ) ;
/ * *
2011-09-09 03:31:05 +00:00
* Create menu for actions to perform against a given node
2010-06-16 18:21:58 +00:00
* /
2010-12-03 22:09:36 +00:00
// Power on
2010-09-28 20:24:31 +00:00
var powerOnLnk = $ ( '<a>Power on</a>' ) ;
2011-01-13 23:06:31 +00:00
powerOnLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
powerNode ( tgtNodes , 'on' ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-11-09 05:05:10 +00:00
2010-12-03 22:09:36 +00:00
// Power off
2010-09-28 20:24:31 +00:00
var powerOffLnk = $ ( '<a>Power off</a>' ) ;
2011-01-13 23:06:31 +00:00
powerOffLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
powerNode ( tgtNodes , 'off' ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
} ) ;
2011-05-02 20:33:25 +00:00
// Turn monitoring on
var monitorOnLnk = $ ( '<a>Monitor on</a>' ) ;
monitorOnLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
if ( tgtNodes ) {
monitorNode ( tgtNodes , 'on' ) ;
}
} ) ;
// Turn monitoring off
var monitorOffLnk = $ ( '<a>Monitor off</a>' ) ;
monitorOffLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
if ( tgtNodes ) {
monitorNode ( tgtNodes , 'off' ) ;
}
} ) ;
2010-06-16 18:21:58 +00:00
2010-11-09 05:05:10 +00:00
// Clone
2010-09-28 20:24:31 +00:00
var cloneLnk = $ ( '<a>Clone</a>' ) ;
2011-01-13 23:06:31 +00:00
cloneLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) . split ( ',' ) ;
2010-11-24 18:11:42 +00:00
for ( var i in tgtNodes ) {
2010-08-03 20:44:26 +00:00
var mgt = getNodeAttr ( tgtNodes [ i ] , 'mgt' ) ;
2011-01-13 23:06:31 +00:00
2010-07-22 19:56:09 +00:00
// Create an instance of the plugin
var plugin ;
switch ( mgt ) {
case "blade" :
2010-07-23 18:47:54 +00:00
plugin = new bladePlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "fsp" :
2010-07-23 18:47:54 +00:00
plugin = new fspPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "hmc" :
2010-07-23 18:47:54 +00:00
plugin = new hmcPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "ipmi" :
2010-07-23 18:47:54 +00:00
plugin = new ipmiPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "ivm" :
2010-07-23 18:47:54 +00:00
plugin = new ivmPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "zvm" :
2010-07-23 18:47:54 +00:00
plugin = new zvmPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
}
plugin . loadClonePage ( tgtNodes [ i ] ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Delete
2010-09-28 20:24:31 +00:00
var deleteLnk = $ ( '<a>Delete</a>' ) ;
2011-01-13 23:06:31 +00:00
deleteLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
2010-11-24 18:11:42 +00:00
loadDeletePage ( tgtNodes ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-11-09 05:05:10 +00:00
// Unlock
2010-09-28 20:24:31 +00:00
var unlockLnk = $ ( '<a>Unlock</a>' ) ;
2011-01-13 23:06:31 +00:00
unlockLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
loadUnlockPage ( tgtNodes ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Run script
2010-09-28 20:24:31 +00:00
var scriptLnk = $ ( '<a>Run script</a>' ) ;
2011-01-13 23:06:31 +00:00
scriptLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
loadScriptPage ( tgtNodes ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Update
2010-09-28 20:24:31 +00:00
var updateLnk = $ ( '<a>Update</a>' ) ;
2011-01-13 23:06:31 +00:00
updateLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
2010-07-15 13:41:29 +00:00
if ( tgtNodes ) {
2010-07-17 13:09:04 +00:00
loadUpdatenodePage ( tgtNodes ) ;
2010-07-15 13:41:29 +00:00
}
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Set boot state
2010-09-28 20:24:31 +00:00
var setBootStateLnk = $ ( '<a>Set boot state</a>' ) ;
2011-01-13 23:06:31 +00:00
setBootStateLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
2010-06-16 18:21:58 +00:00
if ( tgtNodes ) {
loadNodesetPage ( tgtNodes ) ;
}
2010-07-15 13:41:29 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Boot to network
2010-09-28 20:24:31 +00:00
var boot2NetworkLnk = $ ( '<a>Boot to network</a>' ) ;
2011-01-13 23:06:31 +00:00
boot2NetworkLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
2010-06-16 18:21:58 +00:00
if ( tgtNodes ) {
2010-07-15 22:57:48 +00:00
loadNetbootPage ( tgtNodes ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
} ) ;
2011-06-28 08:37:16 +00:00
2011-09-09 03:31:05 +00:00
// Provision node
2011-06-28 08:37:16 +00:00
var provisionLnk = $ ( '<a>Provision</a>' ) ;
2011-09-09 03:31:05 +00:00
provisionLnk . click ( function ( ) {
2011-06-28 08:37:16 +00:00
var tgtNodes = getNodesChecked ( nodesTableId ) ;
if ( tgtNodes ) {
2011-09-09 03:31:05 +00:00
// Jump directly to the provision page
jump2Provision ( tgtNodes ) ;
2011-06-28 08:37:16 +00:00
}
} ) ;
2010-06-16 18:21:58 +00:00
2010-12-03 22:09:36 +00:00
// Remote console
2010-11-09 05:05:10 +00:00
var rcons = $ ( '<a>Open console</a>' ) ;
2010-09-20 07:41:43 +00:00
rcons . bind ( 'click' , function ( event ) {
2011-01-13 23:06:31 +00:00
var tgtNodes = getNodesChecked ( nodesTableId ) ;
2010-09-20 07:41:43 +00:00
if ( tgtNodes ) {
2010-09-20 18:57:08 +00:00
loadRconsPage ( tgtNodes ) ;
2010-09-20 07:41:43 +00:00
}
} ) ;
2010-11-24 18:11:42 +00:00
2010-12-03 22:09:36 +00:00
// Edit properties
var editProps = $ ( '<a>Edit properties</a>' ) ;
editProps . bind ( 'click' , function ( event ) {
2011-01-13 23:06:31 +00:00
var tgtNodes = getNodesChecked ( nodesTableId ) . split ( ',' ) ;
2010-11-24 18:11:42 +00:00
for ( var i in tgtNodes ) {
2011-08-24 19:28:24 +00:00
editNodeProps ( tgtNodes [ i ] ) ;
2010-11-24 18:11:42 +00:00
}
} ) ;
2011-05-02 20:33:25 +00:00
// Install Ganglia
var installMonLnk = $ ( '<a>Install monitoring</a>' ) ;
installMonLnk . click ( function ( ) {
var tgtNodes = getNodesChecked ( nodesTableId ) ;
if ( tgtNodes ) {
installGanglia ( tgtNodes ) ;
}
} ) ;
2011-09-09 03:31:05 +00:00
// Actions
var actionsLnk = '<a>Actions</a>' ;
var actsMenu = createMenu ( [ cloneLnk , deleteLnk , monitorOnLnk , monitorOffLnk , powerOnLnk , powerOffLnk , scriptLnk ] ) ;
// Configurations
2011-06-03 08:12:21 +00:00
var configLnk = '<a>Configuration</a>' ;
2011-07-06 16:14:48 +00:00
var configMenu = createMenu ( [ unlockLnk , updateLnk , editProps , installMonLnk ] ) ;
2011-09-09 03:31:05 +00:00
// Provision
var provLnk = '<a>Provision</a>' ;
2011-09-09 14:53:17 +00:00
var provMenu = createMenu ( [ boot2NetworkLnk , setBootStateLnk , rcons , provisionLnk ] ) ;
2010-06-16 18:21:58 +00:00
2011-01-13 23:06:31 +00:00
// Create an action menu
2011-09-09 03:31:05 +00:00
var actionsMenu = createMenu ( [ [ actionsLnk , actsMenu ] , [ configLnk , configMenu ] , [ provLnk , provMenu ] ] ) ;
2011-01-13 23:06:31 +00:00
actionsMenu . superfish ( ) ;
2011-05-09 18:25:31 +00:00
actionsMenu . css ( 'display' , 'inline-block' ) ;
2011-06-03 08:12:21 +00:00
actionBar . append ( actionsMenu ) ;
2011-09-28 20:01:24 +00:00
// Set correct theme for action menu
actionsMenu . find ( 'li' ) . hover ( function ( ) {
2011-09-28 21:38:12 +00:00
setMenu2Theme ( $ ( this ) ) ;
2011-09-28 20:01:24 +00:00
} , function ( ) {
2011-09-28 21:38:12 +00:00
setMenu2Normal ( $ ( this ) ) ;
2011-09-28 20:01:24 +00:00
} ) ;
2011-09-09 03:31:05 +00:00
2010-12-21 00:52:10 +00:00
// Insert action bar and nodes datatable
2011-01-13 23:06:31 +00:00
$ ( '#nodesTab' ) . append ( nodesTable . object ( ) ) ;
2011-05-09 18:25:31 +00:00
2010-06-16 18:21:58 +00:00
// Turn table into a datatable
2011-01-13 23:06:31 +00:00
var nodesDatatable = $ ( '#' + nodesTableId ) . dataTable ( {
2011-06-03 08:12:21 +00:00
'iDisplayLength' : 50 ,
2011-08-24 03:10:37 +00:00
'bLengthChange' : false ,
"sScrollX" : "100%" ,
"bAutoWidth" : true ,
"fnInitComplete" : function ( ) {
2011-09-09 21:56:30 +00:00
adjustColumnSize ( nodesTableId ) ;
2011-08-24 03:10:37 +00:00
}
2010-11-16 20:28:20 +00:00
} ) ;
2010-09-21 23:58:17 +00:00
2011-01-13 23:06:31 +00:00
// Filter table when enter key is pressed
$ ( '#' + nodesTableId + '_filter input' ) . unbind ( ) ;
$ ( '#' + nodesTableId + '_filter input' ) . bind ( 'keyup' , function ( e ) {
if ( e . keyCode == 13 ) {
var table = $ ( '#' + nodesTableId ) . dataTable ( ) ;
table . fnFilter ( $ ( this ) . val ( ) ) ;
// If there are nodes found, get the node attributes
if ( ! $ ( '#' + nodesTableId + ' .dataTables_empty' ) . length ) {
2011-01-14 05:05:06 +00:00
getNodeAttrs ( group ) ;
2011-01-13 23:06:31 +00:00
}
}
} ) ;
// Load node definitions when next or previous buttons are clicked
$ ( '#' + nodesTableId + '_next, #' + nodesTableId + '_previous' ) . click ( function ( ) {
getNodeAttrs ( group ) ;
} ) ;
2010-12-21 00:52:10 +00:00
/ * *
2011-01-13 23:06:31 +00:00
* Change how datatable behaves
2010-12-21 00:52:10 +00:00
* /
2010-11-11 15:07:40 +00:00
// Do not sort ping, power, and comment column
2011-01-13 23:06:31 +00:00
var cols = $ ( '#' + nodesTableId + ' thead tr th' ) . click ( function ( ) {
getNodeAttrs ( group ) ;
} ) ;
2011-08-24 03:10:37 +00:00
var checkboxCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(0)' ) ;
var pingCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(2)' ) ;
var powerCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(3)' ) ;
var monitorCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(4)' ) ;
var commentCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(5)' ) ;
checkboxCol . unbind ( 'click' ) ;
2010-09-21 23:58:17 +00:00
pingCol . unbind ( 'click' ) ;
powerCol . unbind ( 'click' ) ;
2011-05-02 20:33:25 +00:00
monitorCol . unbind ( 'click' ) ;
2010-11-11 15:07:40 +00:00
commentCol . unbind ( 'click' ) ;
2011-08-24 03:10:37 +00:00
2010-09-22 21:08:15 +00:00
// Create enough space for loader to be displayed
2010-12-01 01:54:05 +00:00
// Center align power, ping, and comments
2011-05-02 20:33:25 +00:00
$ ( '#' + nodesTableId + ' td:nth-child(3),td:nth-child(4),td:nth-child(5)' ) . css ( {
'text-align' : 'center'
} ) ;
2010-12-01 01:54:05 +00:00
2011-05-02 20:33:25 +00:00
// No minimum width for comments column
$ ( '#' + nodesTableId + ' tbody tr td:nth-child(6)' ) . css ( 'text-align' , 'center' ) ;
// Instead refresh the node, power, and monitor status
2011-01-13 23:06:31 +00:00
pingCol . find ( 'span a' ) . click ( function ( ) {
2011-01-14 20:25:14 +00:00
refreshNodeStatus ( group , nodesTableId ) ;
2010-09-21 23:58:17 +00:00
} ) ;
2011-01-13 23:06:31 +00:00
powerCol . find ( 'span a' ) . click ( function ( ) {
2011-01-14 20:25:14 +00:00
refreshPowerStatus ( group , nodesTableId ) ;
2010-09-21 23:58:17 +00:00
} ) ;
2011-05-02 20:33:25 +00:00
monitorCol . find ( 'span a' ) . click ( function ( ) {
refreshGangliaStatus ( group , nodesTableId ) ;
} ) ;
2011-09-09 19:34:05 +00:00
// Create a division to hold actions menu
var menuDiv = $ ( '<div id="' + nodesTableId + '_menuDiv" class="menuDiv"></div>' ) ;
2011-06-16 02:48:34 +00:00
$ ( '#' + nodesTableId + '_wrapper' ) . prepend ( menuDiv ) ;
menuDiv . append ( actionBar ) ;
2011-09-09 19:34:05 +00:00
$ ( '#' + nodesTableId + '_filter' ) . appendTo ( menuDiv ) ;
2010-12-01 01:54:05 +00:00
2011-06-16 02:48:34 +00:00
// Create tooltip for status
2011-05-02 20:33:25 +00:00
var tooltipConf = {
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.8 ,
relative : true ,
predelay : 800
} ;
2010-12-19 19:08:47 +00:00
var pingTip = createStatusToolTip ( ) ;
pingCol . find ( 'span' ) . append ( pingTip ) ;
2011-05-02 20:33:25 +00:00
pingCol . find ( 'span a' ) . tooltip ( tooltipConf ) ;
2010-12-19 19:08:47 +00:00
2011-01-13 23:06:31 +00:00
// Create tooltip for power
2010-12-19 19:08:47 +00:00
var powerTip = createPowerToolTip ( ) ;
powerCol . find ( 'span' ) . append ( powerTip ) ;
2011-05-02 20:33:25 +00:00
powerCol . find ( 'span a' ) . tooltip ( tooltipConf ) ;
2011-06-16 02:48:34 +00:00
// Create tooltip for monitor
2011-05-02 20:33:25 +00:00
var monitorTip = createMonitorToolTip ( ) ;
monitorCol . find ( 'span' ) . append ( monitorTip ) ;
monitorCol . find ( 'span a' ) . tooltip ( tooltipConf ) ;
2010-12-19 19:08:47 +00:00
2010-11-09 05:05:10 +00:00
/ * *
* Enable editable columns
* /
2011-05-02 20:33:25 +00:00
// Do not make 1st, 2nd, 3rd, 4th, 5th, or 6th column editable
$ ( '#' + nodesTableId + ' td:not(td:nth-child(1),td:nth-child(2),td:nth-child(3),td:nth-child(4),td:nth-child(5),td:nth-child(6))' ) . editable (
2011-08-24 03:37:12 +00:00
function ( value , settings ) {
2011-09-09 03:31:05 +00:00
// If users did not make changes, return the value directly
// jeditable saves the old value in this.revert
2011-08-24 03:37:12 +00:00
if ( $ ( this ) . attr ( 'revert' ) == value ) {
return value ;
}
2010-11-09 05:05:10 +00:00
// Get column index
var colPos = this . cellIndex ;
// Get row index
2011-01-13 23:06:31 +00:00
var dTable = $ ( '#' + nodesTableId ) . dataTable ( ) ;
2010-11-09 05:05:10 +00:00
var rowPos = dTable . fnGetPosition ( this . parentNode ) ;
// Update datatable
2011-01-13 23:06:31 +00:00
dTable . fnUpdate ( value , rowPos , colPos , false ) ;
2010-11-09 05:05:10 +00:00
2011-07-20 21:13:09 +00:00
// Get table headers
2011-08-24 19:28:24 +00:00
var headers = $ ( '#' + nodesTableId ) . parents ( '.dataTables_scroll' ) . find ( '.dataTables_scrollHead thead tr:eq(0) th' ) ;
2010-11-09 05:05:10 +00:00
// Get node name
var node = $ ( this ) . parent ( ) . find ( 'td a.node' ) . text ( ) ;
2011-07-20 21:13:09 +00:00
// Get attribute name
var attrName = jQuery . trim ( headers . eq ( colPos ) . text ( ) ) ;
// Get column value
var value = $ ( this ) . text ( ) ;
2010-11-09 05:05:10 +00:00
2011-07-20 21:13:09 +00:00
// Build argument
var args = attrName + '=' + value ;
2010-11-09 05:05:10 +00:00
2011-07-20 21:13:09 +00:00
// Send command to change node attributes
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'chdef' ,
tgt : '' ,
args : '-t;node;-o;' + node + ';' + args ,
msg : 'out=nodesTab;tgt=' + node
} ,
2010-11-09 05:05:10 +00:00
2011-07-20 21:13:09 +00:00
success : showChdefOutput
} ) ;
2011-09-02 07:48:30 +00:00
2011-09-09 03:31:05 +00:00
// Save the data into global origAttrs
2011-09-02 07:48:30 +00:00
origAttrs [ node ] [ attrName ] = value ;
2011-07-20 21:13:09 +00:00
return value ;
2010-11-09 05:05:10 +00:00
} , {
2010-12-21 00:52:10 +00:00
onblur : 'submit' , // Clicking outside editable area submits changes
2010-11-09 21:22:43 +00:00
type : 'textarea' ,
2010-11-09 05:05:10 +00:00
placeholder : ' ' ,
2011-09-09 03:31:05 +00:00
event : "dblclick" , // Double click and edit
2010-11-09 21:22:43 +00:00
height : '30px' // The height of the text area
2010-11-09 05:05:10 +00:00
} ) ;
2011-07-20 21:13:09 +00:00
2010-06-16 18:21:58 +00:00
/ * *
2010-12-09 03:44:11 +00:00
* Get the node status and definable node attributes
2010-06-16 18:21:58 +00:00
* /
2010-12-09 03:44:11 +00:00
// If request to get node status is made
if ( getNodeStatus ) {
2011-01-13 23:06:31 +00:00
var tgt = getNodesShown ( nodesTableId ) ;
2010-12-09 03:44:11 +00:00
// Get node status
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodestat' ,
2011-01-13 23:06:31 +00:00
tgt : tgt ,
2010-12-19 19:08:47 +00:00
args : '-u' ,
2010-12-09 03:44:11 +00:00
msg : ''
} ,
success : loadNodeStatus
} ) ;
} else {
// Hide status loader
2011-08-24 03:10:37 +00:00
var statCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(2)' ) ;
2010-12-09 03:44:11 +00:00
statCol . find ( 'img' ) . hide ( ) ;
2011-09-09 21:56:30 +00:00
adjustColumnSize ( nodesTableId ) ;
2010-12-09 03:44:11 +00:00
}
2010-11-09 21:22:43 +00:00
2011-08-31 02:28:59 +00:00
if ( undefined == nodeAttrs ) {
// Get definable node attributes
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsdef' ,
tgt : '' ,
args : '-t;node;-h' ,
msg : ''
} ,
2010-12-03 22:09:36 +00:00
2011-08-31 02:28:59 +00:00
success : setNodeAttrs
} ) ;
}
2010-11-24 18:11:42 +00:00
2010-06-16 18:21:58 +00:00
/ * *
2011-06-16 02:48:34 +00:00
* Additional ajax requests need to be made for zVM
* load advanced information based on hardware architecture
* /
2011-06-27 08:49:13 +00:00
advancedLoad ( group ) ;
2011-01-13 23:06:31 +00:00
}
/ * *
* Get nodes currently shown in datatable
*
* @ param tableId
* Datatable ID
* @ return String of nodes shown
* /
function getNodesShown ( tableId ) {
// String of nodes shown
var shownNodes = '' ;
// Get rows of shown nodes
var nodes = $ ( '#' + tableId + ' tbody tr' ) ;
// Go through each row
var cols ;
for ( var i = 0 ; i < nodes . length ; i ++ ) {
// Get second column containing node name
cols = nodes . eq ( i ) . find ( 'td' ) ;
shownNodes += cols . eq ( 1 ) . text ( ) + ',' ;
}
// Remove last comma
shownNodes = shownNodes . substring ( 0 , shownNodes . length - 1 ) ;
return shownNodes ;
}
/ * *
* Get attributes for nodes not yet initialized
*
* @ param group
* Group name
* @ return Nothing
* /
function getNodeAttrs ( group ) {
// Get datatable headers and rows
2011-08-24 16:08:49 +00:00
var headers = $ ( '#' + nodesTableId ) . parents ( '.dataTables_scroll' ) . find ( '.dataTables_scrollHead thead tr:eq(0) th' ) ;
2011-01-13 23:06:31 +00:00
var nodes = $ ( '#' + nodesTableId + ' tbody tr' ) ;
// Find group column
var head , groupsCol ;
for ( var i = 0 ; i < headers . length ; i ++ ) {
head = headers . eq ( i ) . html ( ) ;
if ( head == 'groups' ) {
groupsCol = i ;
break ;
}
}
// Check if groups definition is set
var node , cols ;
var tgtNodes = '' ;
for ( var i = 0 ; i < nodes . length ; i ++ ) {
cols = nodes . eq ( i ) . find ( 'td' ) ;
if ( ! cols . eq ( groupsCol ) . html ( ) ) {
node = cols . eq ( 1 ) . text ( ) ;
tgtNodes += node + ',' ;
}
}
// If there are node definitions to load
if ( tgtNodes ) {
// Remove last comma
tgtNodes = tgtNodes . substring ( 0 , tgtNodes . length - 1 ) ;
// Get node definitions
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsdef' ,
tgt : '' ,
args : tgtNodes ,
msg : group
} ,
success : addNodes2Table
} ) ;
// Create dialog to indicate table is updating
var update = $ ( '<div id="updatingDialog" class="ui-state-highlight ui-corner-all">'
+ '<p><span class="ui-icon ui-icon-info"></span> Updating table <img src="images/loader.gif"/></p>'
+ '</div>' ) ;
update . dialog ( {
modal : true ,
width : 300 ,
position : 'center'
} ) ;
}
}
/ * *
* Add nodes to datatable
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function addNodes2Table ( data ) {
// Data returned
var rsp = data . rsp ;
// Group name
var group = data . msg ;
// Hash of node attributes
var attrs = new Object ( ) ;
// Node attributes
var headers = $ ( '#' + nodesTableId + ' thead tr th' ) ;
// Variable to send command and request node status
var getNodeStatus = true ;
// Go through each attribute
var node , args ;
for ( var i in rsp ) {
// Get node name
if ( rsp [ i ] . indexOf ( 'Object name:' ) > - 1 ) {
var temp = rsp [ i ] . split ( ': ' ) ;
node = jQuery . trim ( temp [ 1 ] ) ;
// Create a hash for node attributes
attrs [ node ] = new Object ( ) ;
i ++ ;
}
// Get key and value
args = rsp [ i ] . split ( '=' , 2 ) ;
var key = jQuery . trim ( args [ 0 ] ) ;
var val = jQuery . trim ( rsp [ i ] . substring ( rsp [ i ] . indexOf ( '=' ) + 1 , rsp [ i ] . length ) ) ;
// Create a hash table
attrs [ node ] [ key ] = val ;
// Save attributes in original hash table
origAttrs [ node ] [ key ] = val ;
// If node status is available
if ( key == 'status' ) {
// Do not request node status
getNodeStatus = false ;
}
}
// Set the first four headers
var headersCol = new Object ( ) ;
headersCol [ 'node' ] = 1 ;
headersCol [ 'status' ] = 2 ;
headersCol [ 'power' ] = 3 ;
headersCol [ 'comments' ] = 4 ;
// Go through each header
for ( var i = 5 ; i < headers . length ; i ++ ) {
// Get the column index
headersCol [ headers . eq ( i ) . html ( ) ] = i ;
}
// Go through each node
var datatable = $ ( '#' + nodesTableId ) . dataTable ( ) ;
var rows = datatable . fnGetData ( ) ;
for ( var node in attrs ) {
// Get row containing node
var nodeRowPos ;
for ( var i in rows ) {
// If column contains node
if ( rows [ i ] [ 1 ] . indexOf ( '>' + node + '<' ) > - 1 ) {
nodeRowPos = i ;
break ;
}
}
// Get node status
var status = '' ;
if ( attrs [ node ] [ 'status' ] ) {
status = attrs [ node ] [ 'status' ] . replace ( 'sshd' , 'ping' ) ;
}
rows [ nodeRowPos ] [ headersCol [ 'status' ] ] = status ;
// Go through each header
for ( var key in headersCol ) {
// Do not put comments and status in twice
2011-08-24 16:08:49 +00:00
if ( key != 'usercomment' && key != 'status' && key . indexOf ( 'status' ) < 0 ) {
2011-01-13 23:06:31 +00:00
var val = attrs [ node ] [ key ] ;
if ( val ) {
rows [ nodeRowPos ] [ headersCol [ key ] ] = val ;
}
}
}
// Update row
datatable . fnUpdate ( rows [ nodeRowPos ] , nodeRowPos , 0 , false ) ;
// Insert node comments
2011-06-16 02:48:34 +00:00
// This is done after datatable is updated because
2011-01-13 23:06:31 +00:00
// you cannot insert an object using fnUpdate()
var comments = attrs [ node ] [ 'usercomment' ] ;
2011-06-16 02:48:34 +00:00
// If no comments exists, show 'No comments' and
2011-01-13 23:06:31 +00:00
// set icon image source
var iconSrc ;
if ( ! comments ) {
comments = 'No comments' ;
2011-01-14 20:25:14 +00:00
iconSrc = 'images/nodes/ui-icon-no-comment.png' ;
2011-01-13 23:06:31 +00:00
} else {
2011-01-14 20:25:14 +00:00
iconSrc = 'images/nodes/ui-icon-comment.png' ;
2011-01-13 23:06:31 +00:00
}
// Create icon for node comments
var tipID = node + 'Tip' ;
var commentsCol = $ ( '#' + node ) . parent ( ) . parent ( ) . find ( 'td' ) . eq ( 4 ) ;
// Create tooltip
var icon = $ ( '<img id="' + tipID + '" src="' + iconSrc + '"></img>' ) . css ( {
'width' : '18px' ,
'height' : '18px'
} ) ;
var tip = createCommentsToolTip ( comments ) ;
var span = $ ( '<span></span>' ) . append ( icon ) ;
span . append ( tip ) ;
commentsCol . append ( span ) ;
// Generate tooltips
icon . tooltip ( {
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.8 ,
relative : true ,
delay : 500
} ) ;
}
2011-01-13 23:50:50 +00:00
// Enable node link
$ ( '.node' ) . bind ( 'click' , loadNode ) ;
2011-01-13 23:06:31 +00:00
// Close dialog for updating table
$ ( '.ui-dialog-content' ) . dialog ( 'close' ) ;
/ * *
* Enable editable columns
* /
2011-07-20 21:13:09 +00:00
// Do not make 1st, 2nd, 3rd, 4th, 5th, or 6th column editable
$ ( '#' + nodesTableId + ' td:not(td:nth-child(1),td:nth-child(2),td:nth-child(3),td:nth-child(4),td:nth-child(5),td:nth-child(6))' ) . editable (
2011-01-13 23:06:31 +00:00
function ( value , settings ) {
2011-08-24 03:37:12 +00:00
//if users did not do changes, return the value directly
//jeditable save the old value in this.revert
if ( $ ( this ) . attr ( 'revert' ) == value ) {
return value ;
}
2011-01-13 23:06:31 +00:00
// Get column index
var colPos = this . cellIndex ;
// Get row index
var dTable = $ ( '#' + nodesTableId ) . dataTable ( ) ;
var rowPos = dTable . fnGetPosition ( this . parentNode ) ;
// Update datatable
dTable . fnUpdate ( value , rowPos , colPos , false ) ;
2011-07-20 21:13:09 +00:00
// Get table headers
var headers = $ ( '#' + nodesTableId + ' thead tr th' ) ;
2011-01-13 23:06:31 +00:00
// Get node name
var node = $ ( this ) . parent ( ) . find ( 'td a.node' ) . text ( ) ;
2011-07-20 21:13:09 +00:00
// Get attribute name
var attrName = jQuery . trim ( headers . eq ( colPos ) . text ( ) ) ;
// Get column value
var value = $ ( this ) . text ( ) ;
2011-01-13 23:06:31 +00:00
2011-07-20 21:13:09 +00:00
// Build argument
var args = attrName + '=' + value ;
2011-01-13 23:06:31 +00:00
2011-07-20 21:13:09 +00:00
// Send command to change node attributes
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'chdef' ,
tgt : '' ,
args : '-t;node;-o;' + node + ';' + args ,
msg : 'out=nodesTab;tgt=' + node
} ,
success : showChdefOutput
} ) ;
2011-01-13 23:06:31 +00:00
2011-07-20 21:13:09 +00:00
return value ;
2011-01-13 23:06:31 +00:00
} , {
onblur : 'submit' , // Clicking outside editable area submits changes
type : 'textarea' ,
placeholder : ' ' ,
2011-09-09 03:31:05 +00:00
event : 'dblclick' ,
2011-01-13 23:06:31 +00:00
height : '30px' // The height of the text area
} ) ;
// If request to get node status is made
if ( getNodeStatus ) {
// Get node status
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodestat' ,
tgt : group ,
args : '-u' ,
msg : ''
} ,
success : loadNodeStatus
} ) ;
} else {
// Hide status loader
2011-08-24 03:10:37 +00:00
var statCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(2)' ) ;
2011-01-13 23:06:31 +00:00
statCol . find ( 'img' ) . hide ( ) ;
}
/ * *
* Additional ajax requests need to be made for zVM
* /
2011-06-27 08:49:13 +00:00
advancedLoad ( group ) ;
2011-09-09 21:56:30 +00:00
adjustColumnSize ( nodesTableId ) ;
2010-06-16 18:21:58 +00:00
}
2011-05-02 20:33:25 +00:00
/ * *
* Load the status of Ganglia for a given group
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function loadGangliaStatus ( data ) {
// Get datatable
var datatable = $ ( '#' + nodesTableId ) . dataTable ( ) ;
var ganglia = data . rsp ;
2012-02-20 03:12:54 +00:00
var rowNum , node , status ;
2011-05-02 20:33:25 +00:00
for ( var i in ganglia ) {
// ganglia[0] = nodeName and ganglia[1] = state
node = jQuery . trim ( ganglia [ i ] [ 0 ] ) ;
status = jQuery . trim ( ganglia [ i ] [ 1 ] ) ;
2011-09-28 22:31:18 +00:00
if ( node ) {
// Get the row containing the node
rowNum = findRow ( node , '#' + nodesTableId , 1 ) ;
// Update the power status column
datatable . fnUpdate ( status , rowNum , 4 ) ;
}
2011-05-02 20:33:25 +00:00
}
// Hide Ganglia loader
2011-08-24 03:10:37 +00:00
var gangliaCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(4)' ) ;
2011-05-02 20:33:25 +00:00
gangliaCol . find ( 'img' ) . hide ( ) ;
2011-09-09 21:56:30 +00:00
adjustColumnSize ( nodesTableId ) ;
2011-05-02 20:33:25 +00:00
}
/ * *
* Refresh the status of Ganglia for each node
*
* @ param group
* Group name
* @ return Nothing
* /
function refreshGangliaStatus ( group ) {
// Show ganglia loader
2011-08-24 03:10:37 +00:00
var gangliaCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(4)' ) ;
2011-05-02 20:33:25 +00:00
gangliaCol . find ( 'img' ) . show ( ) ;
// Get power status for nodes shown
var nodes = getNodesShown ( nodesTableId ) ;
// Get the status of Ganglia
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'gangliastatus;' + nodes ,
msg : ''
} ,
success : loadGangliaStatus
} ) ;
}
2010-06-16 18:21:58 +00:00
/ * *
2010-07-29 17:32:24 +00:00
* Load power status for each node
2010-06-16 18:21:58 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function loadPowerStatus ( data ) {
2011-01-13 23:06:31 +00:00
var dTable = $ ( '#' + nodesTableId ) . dataTable ( ) ;
2010-06-16 18:21:58 +00:00
var power = data . rsp ;
2010-12-03 22:09:36 +00:00
var rowPos , node , status , args ;
2010-06-16 18:21:58 +00:00
2010-11-24 18:11:42 +00:00
for ( var i in power ) {
2010-09-24 02:27:04 +00:00
// power[0] = nodeName and power[1] = state
2010-06-16 18:21:58 +00:00
args = power [ i ] . split ( ':' ) ;
node = jQuery . trim ( args [ 0 ] ) ;
status = jQuery . trim ( args [ 1 ] ) ;
2011-01-13 23:06:31 +00:00
2010-06-16 18:21:58 +00:00
// Get the row containing the node
2011-01-13 23:06:31 +00:00
rowPos = findRow ( node , '#' + nodesTableId , 1 ) ;
2010-07-26 08:23:47 +00:00
2010-09-24 02:27:04 +00:00
// Update the power status column
2011-01-13 23:06:31 +00:00
dTable . fnUpdate ( status , rowPos , 3 , false ) ;
2010-06-16 18:21:58 +00:00
}
2010-09-22 04:04:59 +00:00
2010-09-22 04:10:59 +00:00
// Hide power loader
2011-08-24 03:10:37 +00:00
var powerCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(3)' ) ;
2010-09-22 04:04:59 +00:00
powerCol . find ( 'img' ) . hide ( ) ;
2011-09-09 21:56:30 +00:00
adjustColumnSize ( nodesTableId ) ;
2010-06-16 18:21:58 +00:00
}
2010-09-21 23:58:17 +00:00
/ * *
* Refresh power status for each node
*
* @ param group
* Group name
2011-01-14 20:25:14 +00:00
* @ param tableId
2011-06-16 02:48:34 +00:00
* Table to update node status
2010-09-21 23:58:17 +00:00
* @ return Nothing
* /
2011-01-14 20:25:14 +00:00
function refreshPowerStatus ( group , tableId ) {
2010-09-22 04:04:59 +00:00
// Show power loader
2011-08-24 03:10:37 +00:00
var powerCol = $ ( '#' + tableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(3)' ) ;
2010-09-22 04:04:59 +00:00
powerCol . find ( 'img' ) . show ( ) ;
2011-01-13 23:06:31 +00:00
// Get power status for nodes shown
2011-01-14 20:25:14 +00:00
var nodes = getNodesShown ( tableId ) ;
2011-01-13 23:06:31 +00:00
// Get power status
2010-09-21 23:58:17 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpower' ,
2011-01-13 23:06:31 +00:00
tgt : nodes ,
2010-09-21 23:58:17 +00:00
args : 'stat' ,
msg : ''
} ,
success : loadPowerStatus
} ) ;
}
2010-06-16 18:21:58 +00:00
/ * *
2010-12-08 16:28:12 +00:00
* Load node status for each node
2010-06-16 18:21:58 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
2010-12-08 16:28:12 +00:00
function loadNodeStatus ( data ) {
2011-01-13 23:06:31 +00:00
var dTable = $ ( '#' + nodesTableId ) . dataTable ( ) ;
2010-12-08 16:28:12 +00:00
var rsp = data . rsp ;
var args , rowPos , node , status ;
2010-06-16 18:21:58 +00:00
2011-01-13 23:06:31 +00:00
// Get all nodes within datatable
2010-12-08 16:28:12 +00:00
for ( var i in rsp ) {
args = rsp [ i ] . split ( ':' ) ;
2010-12-21 00:52:10 +00:00
2010-12-08 16:28:12 +00:00
// args[0] = node and args[1] = status
node = jQuery . trim ( args [ 0 ] ) ;
status = jQuery . trim ( args [ 1 ] ) . replace ( 'sshd' , 'ping' ) ;
2011-01-13 23:06:31 +00:00
// Get row containing node
rowPos = findRow ( node , '#' + nodesTableId , 1 ) ;
2010-06-16 18:21:58 +00:00
2011-01-13 23:06:31 +00:00
// Update ping status column
dTable . fnUpdate ( status , rowPos , 2 , false ) ;
2010-06-16 18:21:58 +00:00
}
2010-09-22 04:04:59 +00:00
2010-12-08 16:28:12 +00:00
// Hide status loader
2011-08-24 03:10:37 +00:00
var statCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(2)' ) ;
2010-12-08 16:28:12 +00:00
statCol . find ( 'img' ) . hide ( ) ;
2011-09-09 21:56:30 +00:00
adjustColumnSize ( nodesTableId ) ;
2010-06-16 18:21:58 +00:00
}
2010-09-21 23:58:17 +00:00
/ * *
* Refresh ping status for each node
*
* @ param group
* Group name
2011-01-14 20:25:14 +00:00
* @ param tableId
2011-06-16 02:48:34 +00:00
* Table to update node status
2010-09-21 23:58:17 +00:00
* @ return Nothing
* /
2011-01-14 20:25:14 +00:00
function refreshNodeStatus ( group , tableId ) {
2010-09-22 04:04:59 +00:00
// Show ping loader
2011-08-24 20:31:28 +00:00
var pingCol = $ ( '#' + tableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(2)' ) ;
2010-09-22 04:04:59 +00:00
pingCol . find ( 'img' ) . show ( ) ;
2011-01-13 23:06:31 +00:00
// Get power status for nodes shown
2011-01-14 20:25:14 +00:00
var nodes = getNodesShown ( tableId ) ;
2011-01-13 23:06:31 +00:00
2010-12-08 16:28:12 +00:00
// Get the node status
2010-09-21 23:58:17 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2010-12-08 16:28:12 +00:00
cmd : 'nodestat' ,
2011-01-13 23:06:31 +00:00
tgt : nodes ,
2010-12-19 19:08:47 +00:00
args : '-u' ,
2010-09-21 23:58:17 +00:00
msg : ''
} ,
2010-12-08 16:28:12 +00:00
success : loadNodeStatus
2010-09-21 23:58:17 +00:00
} ) ;
}
2010-06-16 18:21:58 +00:00
/ * *
* Load inventory for given node
*
* @ param e
* Windows event
* @ return Nothing
* /
function loadNode ( e ) {
if ( ! e ) {
e = window . event ;
}
2010-08-03 21:22:46 +00:00
2010-06-16 18:21:58 +00:00
// Get node that was clicked
var node = ( e . target ) ? e . target . id : e . srcElement . id ;
2010-08-03 20:44:26 +00:00
var mgt = getNodeAttr ( node , 'mgt' ) ;
2010-08-03 21:22:46 +00:00
2010-07-22 19:56:09 +00:00
// Create an instance of the plugin
var plugin ;
switch ( mgt ) {
case "blade" :
2010-07-23 18:47:54 +00:00
plugin = new bladePlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "fsp" :
2010-07-23 18:47:54 +00:00
plugin = new fspPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "hmc" :
2010-07-23 18:47:54 +00:00
plugin = new hmcPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "ipmi" :
2010-07-23 18:47:54 +00:00
plugin = new ipmiPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "ivm" :
2010-07-23 18:47:54 +00:00
plugin = new ivmPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
case "zvm" :
2010-07-23 18:47:54 +00:00
plugin = new zvmPlugin ( ) ;
2010-07-22 19:56:09 +00:00
break ;
}
2010-06-16 18:21:58 +00:00
// Get tab area where a new tab will be inserted
var myTab = getNodesTab ( ) ;
2010-07-26 07:25:27 +00:00
var inst = 0 ;
2010-07-26 18:34:29 +00:00
var newTabId = 'nodeTab' + inst ;
2010-07-26 07:25:27 +00:00
while ( $ ( '#' + newTabId ) . length ) {
// If one already exists, generate another one
inst = inst + 1 ;
2010-07-26 18:34:29 +00:00
newTabId = 'nodeTab' + inst ;
2010-07-26 07:25:27 +00:00
}
2010-07-15 22:57:48 +00:00
// Reset node process
$ . cookie ( node + 'Processes' , 0 ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Add new tab, only if one does not exist
2010-07-26 07:25:27 +00:00
var loader = createLoader ( newTabId + 'TabLoader' ) ;
2010-07-15 22:57:48 +00:00
loader = $ ( '<center></center>' ) . append ( loader ) ;
2010-08-03 14:58:08 +00:00
myTab . add ( newTabId , node , loader , true ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Get node inventory
var msg = 'out=' + newTabId + ',node=' + node ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rinv' ,
tgt : node ,
args : 'all' ,
msg : msg
} ,
2010-07-22 19:56:09 +00:00
success : plugin . loadInventory
2010-07-15 22:57:48 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
// Select new tab
myTab . select ( newTabId ) ;
}
/ * *
2011-01-13 23:06:31 +00:00
* Unlock a node by setting the ssh keys
2010-06-16 18:21:58 +00:00
*
* @ param tgtNodes
* Nodes to unlock
* @ return Nothing
* /
function loadUnlockPage ( tgtNodes ) {
// Get nodes tab
var tab = getNodesTab ( ) ;
// Generate new tab ID
var instance = 0 ;
2010-12-03 22:09:36 +00:00
var newTabId = 'unlockTab' + instance ;
2010-06-16 18:21:58 +00:00
while ( $ ( '#' + newTabId ) . length ) {
// If one already exists, generate another one
instance = instance + 1 ;
2010-12-03 22:09:36 +00:00
newTabId = 'unlockTab' + instance ;
2010-06-16 18:21:58 +00:00
}
var unlockForm = $ ( '<div class="form"></div>' ) ;
// Create status bar, hide on load
2010-12-04 01:47:10 +00:00
var statBarId = 'unlockStatusBar' + instance ;
2010-06-16 18:21:58 +00:00
var statusBar = createStatusBar ( statBarId ) . hide ( ) ;
unlockForm . append ( statusBar ) ;
// Create loader
var loader = createLoader ( '' ) ;
2011-04-27 20:28:00 +00:00
statusBar . find ( 'div' ) . append ( loader ) ;
2010-06-16 18:21:58 +00:00
// Create info bar
2010-12-03 22:09:36 +00:00
var infoBar = createInfoBar ( 'Give the root password for this node range to setup its SSH keys.' ) ;
2010-06-16 18:21:58 +00:00
unlockForm . append ( infoBar ) ;
2010-11-01 14:06:53 +00:00
unlockForm . append ( '<div><label>Target node range:</label><input type="text" id="node" name="node" readonly="readonly" value="' + tgtNodes + '" title="The node or node range to unlock"/></div>' ) ;
unlockForm . append ( '<div><label>Password:</label><input type="password" id="password" name="password" title="The root password to unlock this node"/></div>' ) ;
2010-06-16 18:21:58 +00:00
2010-11-01 14:06:53 +00:00
// Generate tooltips
unlockForm . find ( 'div input[title]' ) . tooltip ( {
2010-12-03 22:09:36 +00:00
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
2010-12-04 14:54:04 +00:00
opacity : 0.7 ,
2010-12-10 14:38:30 +00:00
predelay : 800 ,
2010-12-04 14:54:04 +00:00
events : {
def : "mouseover,mouseout" ,
input : "mouseover,mouseout" ,
widget : "focus mouseover,blur mouseout" ,
tooltip : "mouseover,mouseout"
}
2010-11-01 14:06:53 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
/ * *
* Ok
* /
var okBtn = createButton ( 'Ok' ) ;
2011-01-13 23:06:31 +00:00
okBtn . click ( function ( ) {
2010-09-24 02:27:04 +00:00
// Remove any warning messages
$ ( this ) . parent ( ) . parent ( ) . find ( '.ui-state-error' ) . remove ( ) ;
2010-12-04 14:54:04 +00:00
// If a password is given
var password = $ ( '#' + newTabId + ' input[name=password]' ) . css ( 'border' , 'solid #BDBDBD 1px' ) ;
if ( password . val ( ) ) {
2010-07-15 22:57:48 +00:00
// Setup SSH keys
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
2010-12-04 14:54:04 +00:00
args : 'unlock;' + tgtNodes + ';' + password . val ( ) ,
2010-07-15 22:57:48 +00:00
msg : 'out=' + statBarId + ';cmd=unlock;tgt=' + tgtNodes
} ,
success : updateStatusBar
} ) ;
// Show status bar
statusBar . show ( ) ;
2011-01-05 23:31:53 +00:00
// Disable all inputs and Ok button
$ ( '#' + newTabId + ' input' ) . attr ( 'disabled' , 'disabled' ) ;
2010-09-22 20:18:21 +00:00
$ ( this ) . attr ( 'disabled' , 'true' ) ;
2010-09-24 02:27:04 +00:00
} else {
// Show warning message
2010-12-03 22:09:36 +00:00
var warn = createWarnBar ( 'You are missing some values!' ) ;
2010-09-24 02:27:04 +00:00
warn . prependTo ( $ ( this ) . parent ( ) . parent ( ) ) ;
2010-12-04 14:54:04 +00:00
password . css ( 'border' , 'solid #FF0000 1px' ) ;
2010-07-15 22:57:48 +00:00
}
} ) ;
2010-06-16 18:21:58 +00:00
unlockForm . append ( okBtn ) ;
2010-08-03 14:58:08 +00:00
tab . add ( newTabId , 'Unlock' , unlockForm , true ) ;
2010-06-16 18:21:58 +00:00
tab . select ( newTabId ) ;
}
/ * *
* Load script page
*
* @ param tgtNodes
* Targets to run script against
* @ return Nothing
* /
function loadScriptPage ( tgtNodes ) {
// Get nodes tab
var tab = getNodesTab ( ) ;
// Generate new tab ID
var inst = 0 ;
var newTabId = 'scriptTab' + inst ;
while ( $ ( '#' + newTabId ) . length ) {
// If one already exists, generate another one
inst = inst + 1 ;
newTabId = 'scriptTab' + inst ;
}
// Open new tab
// Create remote script form
var scriptForm = $ ( '<div class="form"></div>' ) ;
// Create status bar
var barId = 'scriptStatusBar' + inst ;
var statBar = createStatusBar ( barId ) ;
statBar . hide ( ) ;
scriptForm . append ( statBar ) ;
// Create loader
2010-09-22 19:32:09 +00:00
var loader = createLoader ( 'scriptLoader' + inst ) ;
2011-04-27 20:28:00 +00:00
statBar . find ( 'div' ) . append ( loader ) ;
2010-06-16 18:21:58 +00:00
// Create info bar
2010-12-03 22:09:36 +00:00
var infoBar = createInfoBar ( 'Load a script to run against this node range.' ) ;
2010-06-16 18:21:58 +00:00
scriptForm . append ( infoBar ) ;
// Target node or group
2010-11-01 14:06:53 +00:00
var tgt = $ ( '<div><label for="target">Target node range:</label><input type="text" name="target" value="' + tgtNodes + '" title="The node or node range to run a given script against"/></div>' ) ;
2010-06-16 18:21:58 +00:00
scriptForm . append ( tgt ) ;
// Upload file
var upload = $ ( '<form action="lib/upload.php" method="post" enctype="multipart/form-data"></form>' ) ;
var label = $ ( '<label for="file">Remote file:</label>' ) ;
var file = $ ( '<input type="file" name="file" id="file"/>' ) ;
var subBtn = createButton ( 'Load' ) ;
upload . append ( label ) ;
upload . append ( file ) ;
upload . append ( subBtn ) ;
scriptForm . append ( upload ) ;
2010-11-01 14:06:53 +00:00
// Generate tooltips
scriptForm . find ( 'div input[title]' ) . tooltip ( {
2010-12-03 22:09:36 +00:00
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
2010-12-04 14:54:04 +00:00
opacity : 0.7 ,
2010-12-10 14:38:30 +00:00
predelay : 800 ,
2010-12-04 14:54:04 +00:00
events : {
def : "mouseover,mouseout" ,
input : "mouseover,mouseout" ,
widget : "focus mouseover,blur mouseout" ,
tooltip : "mouseover,mouseout"
}
2010-11-01 14:06:53 +00:00
} ) ;
2010-06-16 18:21:58 +00:00
// Script
var script = $ ( '<div><label>Script:</label><textarea/>' ) ;
scriptForm . append ( script ) ;
// Ajax form options
var options = {
// Output to text area
target : '#' + newTabId + ' textarea'
} ;
upload . ajaxForm ( options ) ;
/ * *
* Run
* /
var runBtn = createButton ( 'Run' ) ;
2011-01-13 23:06:31 +00:00
runBtn . click ( function ( ) {
2010-09-24 02:27:04 +00:00
// Remove any warning messages
$ ( this ) . parent ( ) . parent ( ) . find ( '.ui-state-error' ) . remove ( ) ;
2010-12-04 14:54:04 +00:00
// Get script to run
var textarea = $ ( '#' + newTabId + ' textarea' ) . css ( 'border' , 'solid #BDBDBD 1px' ) ;
2010-06-16 18:21:58 +00:00
// If no inputs are empty
2010-12-04 14:54:04 +00:00
if ( textarea . val ( ) ) {
2010-06-16 18:21:58 +00:00
// Run script
runScript ( inst ) ;
} else {
2010-09-24 02:27:04 +00:00
// Show warning message
var warn = createWarnBar ( 'You are missing some values' ) ;
warn . prependTo ( $ ( this ) . parent ( ) . parent ( ) ) ;
2010-12-04 14:54:04 +00:00
textarea . css ( 'border' , 'solid #FF0000 1px' ) ;
2010-06-16 18:21:58 +00:00
}
} ) ;
scriptForm . append ( runBtn ) ;
// Append to discover tab
2010-08-03 14:58:08 +00:00
tab . add ( newTabId , 'Script' , scriptForm , true ) ;
2010-06-16 18:21:58 +00:00
// Select new tab
tab . select ( newTabId ) ;
}
/ * *
* Sort a list
*
* @ return Sorted list
* /
jQuery . fn . sort = function ( ) {
2011-01-13 23:06:31 +00:00
return this . pushStack ( [ ] . sort . apply ( this , arguments ) , [ ] ) ;
2010-06-16 18:21:58 +00:00
} ;
function sortAlpha ( a , b ) {
return a . innerHTML > b . innerHTML ? 1 : - 1 ;
} ;
/ * *
* Power on a given node
*
* @ param node
* Node to power on or off
* @ param power2
* Power node to given state
* @ return Nothing
* /
function powerNode ( node , power2 ) {
2011-12-19 05:03:27 +00:00
// Show power loader
var powerCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(3)' ) ;
powerCol . find ( 'img' ) . show ( ) ;
2010-06-16 18:21:58 +00:00
node = node . replace ( 'Power' , '' ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpower' ,
tgt : node ,
args : power2 ,
msg : node
} ,
success : updatePowerStatus
} ) ;
}
/ * *
2010-11-24 18:11:42 +00:00
* Load delete node page
2010-06-16 18:21:58 +00:00
*
* @ param tgtNodes
* Nodes to delete
* @ return Nothing
* /
2010-11-24 18:11:42 +00:00
function loadDeletePage ( tgtNodes ) {
2010-12-01 01:54:05 +00:00
// Get nodes tab
2010-06-16 18:21:58 +00:00
var myTab = getNodesTab ( ) ;
// Generate new tab ID
var inst = 0 ;
2010-12-03 22:09:36 +00:00
newTabId = 'deleteTab' + inst ;
2010-06-16 18:21:58 +00:00
while ( $ ( '#' + newTabId ) . length ) {
// If one already exists, generate another one
inst = inst + 1 ;
2010-12-03 22:09:36 +00:00
newTabId = 'deleteTab' + inst ;
2010-06-16 18:21:58 +00:00
}
// Create status bar, hide on load
2010-12-04 01:47:10 +00:00
var statBarId = 'deleteStatusBar' + inst ;
var statBar = createStatusBar ( statBarId ) . hide ( ) ;
2010-06-16 18:21:58 +00:00
// Create loader
var loader = createLoader ( '' ) ;
2011-04-27 20:28:00 +00:00
statBar . find ( 'div' ) . append ( loader ) ;
2010-06-16 18:21:58 +00:00
statBar . hide ( ) ;
// Create target nodes string
var tgtNodesStr = '' ;
var nodes = tgtNodes . split ( ',' ) ;
// Loop through each node
2010-11-24 18:11:42 +00:00
for ( var i in nodes ) {
2010-06-16 18:21:58 +00:00
// If it is the 1st and only node
if ( i == 0 && i == nodes . length - 1 ) {
tgtNodesStr += nodes [ i ] ;
}
// If it is the 1st node of many nodes
else if ( i == 0 && i != nodes . length - 1 ) {
// Append a comma to the string
tgtNodesStr += nodes [ i ] + ', ' ;
} else {
// If it is the last node
if ( i == nodes . length - 1 ) {
// Append nothing to the string
tgtNodesStr += nodes [ i ] ;
} else {
2010-07-25 23:53:27 +00:00
// Append a comma to the string
tgtNodesStr += nodes [ i ] + ', ' ;
2010-06-16 18:21:58 +00:00
}
}
}
2010-12-21 00:52:10 +00:00
// Create delete form
2010-06-16 18:21:58 +00:00
var deleteForm = $ ( '<div class="form"></div>' ) ;
deleteForm . append ( statBar ) ;
2010-07-25 23:53:27 +00:00
deleteForm . append ( statBar ) ;
2011-01-13 23:06:31 +00:00
// Confirm delete
2010-12-03 22:09:36 +00:00
var instr = $ ( '<p>Are you sure you want to delete ' + tgtNodesStr + '?</p>' ) . css ( 'word-wrap' , 'break-word' ) ;
2010-07-25 23:53:27 +00:00
deleteForm . append ( instr ) ;
2010-06-16 18:21:58 +00:00
/ * *
* Delete
* /
var deleteBtn = createButton ( 'Delete' ) ;
2011-01-13 23:06:31 +00:00
deleteBtn . click ( function ( ) {
2010-06-16 18:21:58 +00:00
// Delete the virtual server
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rmvm' ,
tgt : tgtNodes ,
args : '' ,
msg : 'out=' + statBarId + ';cmd=rmvm;tgt=' + tgtNodes
} ,
success : updateStatusBar
} ) ;
// Show status bar loader
statBar . show ( ) ;
2010-07-29 20:22:09 +00:00
// Disable delete button
2010-09-22 20:18:21 +00:00
$ ( this ) . attr ( 'disabled' , 'true' ) ;
2010-06-16 18:21:58 +00:00
} ) ;
2010-07-25 07:41:49 +00:00
2010-12-21 00:52:10 +00:00
/ * *
* Cancel
* /
2010-07-25 07:41:49 +00:00
var cancelBtn = createButton ( 'Cancel' ) ;
cancelBtn . bind ( 'click' , function ( ) {
myTab . remove ( $ ( this ) . parent ( ) . parent ( ) . attr ( 'id' ) ) ;
} ) ;
2010-06-16 18:21:58 +00:00
deleteForm . append ( deleteBtn ) ;
2010-07-25 07:41:49 +00:00
deleteForm . append ( cancelBtn ) ;
2010-08-03 14:58:08 +00:00
myTab . add ( newTabId , 'Delete' , deleteForm , true ) ;
2010-06-16 18:21:58 +00:00
myTab . select ( newTabId ) ;
}
/ * *
2010-07-29 17:32:24 +00:00
* Update status bar of a given tab
2010-06-16 18:21:58 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function updateStatusBar ( data ) {
2010-07-29 17:32:24 +00:00
// Get ajax response
2010-06-16 18:21:58 +00:00
var rsp = data . rsp ;
var args = data . msg . split ( ';' ) ;
var statBarId = args [ 0 ] . replace ( 'out=' , '' ) ;
var cmd = args [ 1 ] . replace ( 'cmd=' , '' ) ;
var tgts = args [ 2 ] . replace ( 'tgt=' , '' ) . split ( ',' ) ;
2010-08-04 20:06:12 +00:00
if ( cmd == 'unlock' || cmd == 'updatenode' ) {
2010-06-16 18:21:58 +00:00
// Hide loader
$ ( '#' + statBarId ) . find ( 'img' ) . hide ( ) ;
2010-07-27 22:56:42 +00:00
// Write ajax response to status bar
var prg = writeRsp ( rsp , '' ) ;
2011-04-27 20:28:00 +00:00
$ ( '#' + statBarId ) . find ( 'div' ) . append ( prg ) ;
2010-06-16 18:21:58 +00:00
} else if ( cmd == 'rmvm' ) {
// Get data table
2011-01-13 23:06:31 +00:00
var dTable = $ ( '#' + nodesTableId ) . dataTable ( ) ;
2010-06-16 18:21:58 +00:00
var failed = false ;
// Hide loader
$ ( '#' + statBarId ) . find ( 'img' ) . hide ( ) ;
2010-07-27 22:56:42 +00:00
// Write ajax response to status bar
var prg = writeRsp ( rsp , '' ) ;
2011-04-27 20:28:00 +00:00
$ ( '#' + statBarId ) . find ( 'div' ) . append ( prg ) ;
2010-07-27 22:56:42 +00:00
2010-09-24 02:27:04 +00:00
// If there was an error, do not continue
2010-07-27 22:56:42 +00:00
if ( prg . html ( ) . indexOf ( 'Error' ) > - 1 ) {
failed = true ;
2010-06-16 18:21:58 +00:00
}
// Update data table
2010-12-03 22:09:36 +00:00
var rowPos ;
2010-11-24 18:11:42 +00:00
for ( var i in tgts ) {
2010-06-16 18:21:58 +00:00
if ( ! failed ) {
2011-01-13 23:06:31 +00:00
// Get row containing the node link and delete it
rowPos = findRow ( tgts [ i ] , '#' + nodesTableId , 1 ) ;
2010-06-16 18:21:58 +00:00
dTable . fnDeleteRow ( rowPos ) ;
}
}
2012-02-20 03:12:54 +00:00
// Adjust column size
adjustColumnSize ( nodesTableId ) ;
2010-09-22 19:32:09 +00:00
} else if ( cmd == 'xdsh' ) {
// Hide loader
$ ( '#' + statBarId ) . find ( 'img' ) . hide ( ) ;
// Write ajax response to status bar
2011-04-27 20:28:00 +00:00
var prg = $ ( '<pre></pre>' ) ;
2010-10-08 03:56:24 +00:00
for ( var i in rsp ) {
for ( var j in tgts ) {
2011-03-17 17:59:18 +00:00
rsp [ i ] = rsp [ i ] . replace ( new RegExp ( tgts [ j ] + ':' , 'g' ) , '' ) ;
2010-10-08 03:56:24 +00:00
}
prg . append ( rsp [ i ] ) ;
prg . append ( '<br>' ) ;
}
2011-04-27 20:28:00 +00:00
$ ( '#' + statBarId ) . find ( 'div' ) . append ( prg ) ;
2010-09-22 19:32:09 +00:00
// Enable fields
$ ( '#' + statBarId ) . parent ( ) . find ( 'input' ) . removeAttr ( 'disabled' ) ;
$ ( '#' + statBarId ) . parent ( ) . find ( 'textarea' ) . removeAttr ( 'disabled' ) ;
// Enable buttons
$ ( '#' + statBarId ) . parent ( ) . find ( 'button' ) . removeAttr ( 'disabled' ) ;
2010-07-15 22:57:48 +00:00
} else {
2010-06-16 18:21:58 +00:00
// Hide loader
$ ( '#' + statBarId ) . find ( 'img' ) . hide ( ) ;
2010-09-22 19:32:09 +00:00
2010-07-27 22:56:42 +00:00
// Write ajax response to status bar
var prg = writeRsp ( rsp , '[A-Za-z0-9._-]+:' ) ;
2011-04-27 20:28:00 +00:00
$ ( '#' + statBarId ) . find ( 'div' ) . append ( prg ) ;
2010-06-16 18:21:58 +00:00
}
}
/ * *
2010-07-29 17:32:24 +00:00
* Update power status of a node in the datatable
2010-06-16 18:21:58 +00:00
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
function updatePowerStatus ( data ) {
2011-12-19 05:03:27 +00:00
// Hide power loader
var powerCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(3)' ) ;
powerCol . find ( 'img' ) . hide ( ) ;
2010-06-16 18:21:58 +00:00
// Get datatable
2011-01-13 23:06:31 +00:00
var dTable = $ ( '#' + nodesTableId ) . dataTable ( ) ;
2010-06-16 18:21:58 +00:00
// Get xCAT response
var rsp = data . rsp ;
// Loop through each line
2010-12-03 22:09:36 +00:00
var node , status , rowPos , strPos ;
2010-11-24 18:11:42 +00:00
for ( var i in rsp ) {
2011-01-13 23:06:31 +00:00
// Get node name
2010-12-03 22:09:36 +00:00
node = rsp [ i ] . split ( ":" ) [ 0 ] ;
2010-06-16 18:21:58 +00:00
// If there is no error
if ( rsp [ i ] . indexOf ( "Error" ) < 0 || rsp [ i ] . indexOf ( "Failed" ) < 0 ) {
// Get the row containing the node link
2011-01-13 23:06:31 +00:00
rowPos = findRow ( node , '#' + nodesTableId , 1 ) ;
2010-06-16 18:21:58 +00:00
// If it was power on, then the data return would contain "Starting"
2010-12-03 22:09:36 +00:00
strPos = rsp [ i ] . indexOf ( "Starting" ) ;
2010-06-16 18:21:58 +00:00
if ( strPos > - 1 ) {
status = 'on' ;
} else {
status = 'off' ;
}
// Update the power status column
2011-01-13 23:06:31 +00:00
dTable . fnUpdate ( status , rowPos , 3 , false ) ;
2010-06-16 18:21:58 +00:00
} else {
// Power on/off failed
alert ( rsp [ i ] ) ;
}
}
2011-08-24 19:28:24 +00:00
// Adjust datatable column size
2011-09-09 21:56:30 +00:00
adjustColumnSize ( nodesTableId ) ;
2010-06-16 18:21:58 +00:00
}
/ * *
* Run a script
*
* @ param inst
* Remote script tab instance
* @ return Nothing
* /
function runScript ( inst ) {
2010-12-21 00:52:10 +00:00
// Get tab ID
2010-06-16 18:21:58 +00:00
var tabId = 'scriptTab' + inst ;
// Get node name
var tgts = $ ( '#' + tabId + ' input[name=target]' ) . val ( ) ;
// Get script
var script = $ ( '#' + tabId + ' textarea' ) . val ( ) ;
2010-09-22 19:32:09 +00:00
var statBarId = 'scriptStatusBar' + inst ;
$ ( '#' + statBarId ) . show ( ) ; // Show status bar
$ ( '#' + statBarId + ' img' ) . show ( ) ; // Show loader
2010-11-09 05:05:10 +00:00
$ ( '#' + statBarId + ' p' ) . remove ( ) ; // Clear status bar
2010-06-16 18:21:58 +00:00
// Disable all fields
2010-09-22 19:32:09 +00:00
$ ( '#' + tabId + ' input' ) . attr ( 'disabled' , 'true' ) ;
$ ( '#' + tabId + ' textarea' ) . attr ( 'disabled' , 'true' ) ;
// Disable buttons
$ ( '#' + tabId + ' button' ) . attr ( 'disabled' , 'true' ) ;
2010-06-16 18:21:58 +00:00
// Run script
$ . ajax ( {
url : 'lib/zCmd.php' ,
dataType : 'json' ,
data : {
cmd : 'xdsh' ,
tgt : tgts ,
args : '-e' ,
att : script ,
msg : 'out=scriptStatusBar' + inst + ';cmd=xdsh;tgt=' + tgts
} ,
success : updateStatusBar
} ) ;
}
/ * *
2010-08-03 20:44:26 +00:00
* Get an attribute of a given node
2010-06-16 18:21:58 +00:00
*
* @ param node
* The node
2010-08-03 20:44:26 +00:00
* @ param attrName
2010-11-17 18:53:40 +00:00
* The attribute
2010-08-03 20:44:26 +00:00
* @ return The attribute of the node
2010-06-16 18:21:58 +00:00
* /
2010-08-03 20:44:26 +00:00
function getNodeAttr ( node , attrName ) {
// Get the row
2011-08-24 04:09:39 +00:00
var row = $ ( '[id=' + node + ']' ) . parents ( 'tr' ) ;
2010-06-16 18:21:58 +00:00
2010-08-03 20:44:26 +00:00
// Search for the column containing the attribute
2010-08-03 21:22:46 +00:00
var attrCol ;
2011-08-24 04:09:39 +00:00
var cols = row . parents ( '.dataTables_scroll' ) . find ( '.dataTables_scrollHead thead tr:eq(0) th' ) ;
2010-08-03 21:22:46 +00:00
// Loop through each column
for ( var i in cols ) {
// Find column that matches the attribute
if ( cols . eq ( i ) . html ( ) == attrName ) {
attrCol = cols . eq ( i ) ;
break ;
}
}
2010-11-17 18:53:40 +00:00
// If the column containing the attribute is found
2010-08-03 21:22:46 +00:00
if ( attrCol ) {
// Get the attribute column index
var attrIndex = attrCol . index ( ) ;
2010-06-16 18:21:58 +00:00
2010-08-03 21:22:46 +00:00
// Get the attribute for the given node
var attr = row . find ( 'td:eq(' + attrIndex + ')' ) ;
return attr . text ( ) ;
} else {
return '' ;
}
2010-06-16 18:21:58 +00:00
}
/ * *
* Set a cookie for the OS images
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
function setOSImageCookies ( data ) {
2010-12-21 00:52:10 +00:00
// Get response
2010-06-16 18:21:58 +00:00
var rsp = data . rsp ;
var imageNames = new Array ;
var profilesHash = new Object ( ) ;
var osVersHash = new Object ( ) ;
var osArchsHash = new Object ( ) ;
2011-03-18 03:31:21 +00:00
var imagePos = 0 ;
var profilePos = 0 ;
var osversPos = 0 ;
var osarchPos = 0 ;
2011-09-09 03:31:05 +00:00
// Get column value
2011-03-18 03:31:21 +00:00
var colNameArray = rsp [ 0 ] . substr ( 1 ) . split ( ',' ) ;
for ( var i in colNameArray ) {
switch ( colNameArray [ i ] ) {
2011-09-09 03:31:05 +00:00
case 'imagename' :
2011-03-18 03:31:21 +00:00
imagePos = i ;
2011-09-09 03:31:05 +00:00
break ;
case 'profile' :
2011-03-18 03:31:21 +00:00
profilePos = i ;
2011-09-09 03:31:05 +00:00
break ;
case 'osvers' :
2011-03-18 03:31:21 +00:00
osversPos = i ;
2011-09-09 03:31:05 +00:00
break ;
case 'osarch' :
2011-03-18 03:31:21 +00:00
osarchPos = i ;
2011-09-09 03:31:05 +00:00
break ;
2011-03-18 03:31:21 +00:00
default :
2011-09-09 03:31:05 +00:00
break ;
2011-03-18 03:31:21 +00:00
}
}
2011-09-09 03:31:05 +00:00
2010-12-21 00:52:10 +00:00
// Go through each index
2010-11-24 18:11:42 +00:00
for ( var i = 1 ; i < rsp . length ; i ++ ) {
2011-01-13 23:06:31 +00:00
// Get image name
2010-06-16 18:21:58 +00:00
var cols = rsp [ i ] . split ( ',' ) ;
2011-03-18 03:31:21 +00:00
var osImage = cols [ imagePos ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
var profile = cols [ profilePos ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
var osVer = cols [ osversPos ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
var osArch = cols [ osarchPos ] . replace ( new RegExp ( '"' , 'g' ) , '' ) ;
2010-12-21 00:52:10 +00:00
2010-06-16 18:21:58 +00:00
imageNames . push ( osImage ) ;
profilesHash [ profile ] = 1 ;
osVersHash [ osVer ] = 1 ;
osArchsHash [ osArch ] = 1 ;
}
// Save image names in a cookie
2010-11-22 16:18:55 +00:00
$ . cookie ( 'imagenames' , imageNames ) ;
2010-06-16 18:21:58 +00:00
// Save profiles in a cookie
var tmp = new Array ;
2010-11-24 18:11:42 +00:00
for ( var key in profilesHash ) {
2010-06-16 18:21:58 +00:00
tmp . push ( key ) ;
}
2010-11-22 16:18:55 +00:00
$ . cookie ( 'profiles' , tmp ) ;
2010-06-16 18:21:58 +00:00
// Save OS versions in a cookie
2011-01-31 17:16:12 +00:00
tmp = new Array ;
2010-11-24 18:11:42 +00:00
for ( var key in osVersHash ) {
2010-06-16 18:21:58 +00:00
tmp . push ( key ) ;
}
2010-11-22 16:18:55 +00:00
$ . cookie ( 'osvers' , tmp ) ;
2010-06-16 18:21:58 +00:00
// Save OS architectures in a cookie
2011-01-31 17:16:12 +00:00
tmp = new Array ;
2010-11-24 18:11:42 +00:00
for ( var key in osArchsHash ) {
2010-06-16 18:21:58 +00:00
tmp . push ( key ) ;
}
2010-11-22 16:18:55 +00:00
$ . cookie ( 'osarchs' , tmp ) ;
2010-06-16 18:21:58 +00:00
}
/ * *
* Set a cookie for the groups
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
function setGroupsCookies ( data ) {
var rsp = data . rsp ;
2010-11-22 16:18:55 +00:00
$ . cookie ( 'groups' , rsp ) ;
2010-06-16 18:21:58 +00:00
}
2010-09-20 18:57:08 +00:00
/ * *
2011-01-13 23:06:31 +00:00
* Find the row index containing a column with a given string
2010-09-20 18:57:08 +00:00
*
2011-01-13 23:06:31 +00:00
* @ param str
2010-12-03 22:09:36 +00:00
* String to search for
* @ param table
* Table to check
* @ param col
* Column to find string under
* @ return The row index containing the search string
2010-09-20 18:57:08 +00:00
* /
2011-01-13 23:06:31 +00:00
function findRow ( str , table , col ) {
2010-12-03 22:09:36 +00:00
var dTable , rows , cols ;
2010-07-26 08:23:47 +00:00
// Get datatable
2010-12-03 22:09:36 +00:00
dTable = $ ( table ) . dataTable ( ) ;
rows = dTable . fnGetData ( ) ;
2011-01-13 23:06:31 +00:00
2010-12-03 22:09:36 +00:00
// Loop through each row
2011-01-13 23:06:31 +00:00
for ( var i in rows ) {
// If the column contains the search string
if ( rows [ i ] [ col ] . indexOf ( str ) > - 1 ) {
2010-12-03 22:09:36 +00:00
return i ;
2010-07-26 08:23:47 +00:00
}
}
2010-12-03 22:09:36 +00:00
2010-07-26 08:23:47 +00:00
return - 1 ;
}
2010-07-26 18:34:29 +00:00
2010-07-28 20:24:29 +00:00
/ * *
2011-01-13 23:06:31 +00:00
* Select all checkboxes in the datatable
2010-07-28 20:24:29 +00:00
*
* @ param event
* Event on element
* @ param obj
* Object triggering event
* @ return Nothing
* /
function selectAllCheckbox ( event , obj ) {
// Get datatable ID
// This will ascend from <input> <td> <tr> <thead> <table>
2011-08-24 19:28:24 +00:00
var tableObj = obj . parents ( '.dataTables_scroll' ) . find ( '.dataTables_scrollBody' ) ;
2010-07-25 07:41:49 +00:00
var status = obj . attr ( 'checked' ) ;
2011-02-17 09:06:21 +00:00
tableObj . find ( ' :checkbox' ) . attr ( 'checked' , status ) ;
2010-07-25 07:41:49 +00:00
event . stopPropagation ( ) ;
2010-09-20 07:41:43 +00:00
}
2010-09-20 18:57:08 +00:00
/ * *
* Load rcons page
*
* @ param tgtNodes
* Targets to run rcons against
* @ return Nothing
* /
function loadRconsPage ( tgtNodes ) {
2010-09-20 07:41:43 +00:00
var hostName = window . location . host ;
var urlPath = window . location . pathname ;
var redirectUrl = 'https://' ;
var pos = 0 ;
2010-12-03 22:09:36 +00:00
2010-11-09 05:05:10 +00:00
// We only support one node
2010-09-20 07:41:43 +00:00
if ( - 1 != tgtNodes . indexOf ( ',' ) ) {
2010-12-03 22:09:36 +00:00
alert ( "You can only open one console at a time!" ) ;
2010-09-20 07:41:43 +00:00
return ;
}
redirectUrl += hostName ;
pos = urlPath . lastIndexOf ( '/' ) ;
redirectUrl += urlPath . substring ( 0 , pos + 1 ) ;
2012-03-14 19:20:37 +00:00
redirectUrl += 'rcons.php' ;
2010-09-20 07:41:43 +00:00
2010-11-09 05:05:10 +00:00
// Open the rcons page
2012-03-14 19:20:37 +00:00
window . open ( redirectUrl + "?rconsnd=" + tgtNodes , '' , "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=590,height=436" ) ;
2010-11-09 05:05:10 +00:00
}
2010-11-09 21:22:43 +00:00
/ * *
2011-01-13 23:06:31 +00:00
* Create a tool tip for comments
2010-11-09 21:22:43 +00:00
*
2010-11-11 15:07:40 +00:00
* @ param comment
2011-01-13 23:06:31 +00:00
* Comments to be placed in a tool tip
2010-11-09 21:22:43 +00:00
* @ return Tool tip
* /
2010-11-11 15:07:40 +00:00
function createCommentsToolTip ( comment ) {
2010-11-09 21:22:43 +00:00
// Create tooltip container
var toolTip = $ ( '<div class="tooltip"></div>' ) ;
2010-11-11 15:07:40 +00:00
// Create textarea to hold comment
var txtArea = $ ( '<textarea>' + comment + '</textarea>' ) . css ( {
2010-11-10 17:14:08 +00:00
'font-size' : '10px' ,
2010-11-09 21:22:43 +00:00
'height' : '50px' ,
'width' : '200px' ,
'background-color' : '#000' ,
'color' : '#fff' ,
2010-11-10 19:11:37 +00:00
'border' : '0px' ,
'display' : 'block'
2010-11-09 21:22:43 +00:00
} ) ;
2010-11-10 17:14:08 +00:00
// Create links to save and cancel changes
2010-11-10 19:11:37 +00:00
var lnkStyle = {
2010-11-10 17:14:08 +00:00
'color' : '#58ACFA' ,
'font-size' : '10px' ,
2010-11-10 19:11:37 +00:00
'display' : 'inline-block' ,
'padding' : '5px' ,
'float' : 'right'
} ;
2011-01-13 23:06:31 +00:00
2010-11-10 21:18:35 +00:00
var saveLnk = $ ( '<a>Save</a>' ) . css ( lnkStyle ) . hide ( ) ;
var cancelLnk = $ ( '<a>Cancel</a>' ) . css ( lnkStyle ) . hide ( ) ;
2010-11-18 16:44:01 +00:00
var infoSpan = $ ( '<span>Click to edit</span>' ) . css ( lnkStyle ) ;
2010-11-10 17:14:08 +00:00
// Save changes onclick
2010-11-09 21:22:43 +00:00
saveLnk . bind ( 'click' , function ( ) {
2010-11-11 15:07:40 +00:00
// Get node and comment
2010-11-10 17:21:39 +00:00
var node = $ ( this ) . parent ( ) . parent ( ) . find ( 'img' ) . attr ( 'id' ) . replace ( 'Tip' , '' ) ;
2010-11-09 21:22:43 +00:00
var comments = $ ( this ) . parent ( ) . find ( 'textarea' ) . val ( ) ;
2010-11-11 15:07:40 +00:00
// Save comment
2010-11-09 21:22:43 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2010-11-18 16:35:59 +00:00
cmd : 'chdef' ,
2010-11-09 21:22:43 +00:00
tgt : '' ,
2010-11-18 16:35:59 +00:00
args : '-t;node;-o;' + node + ';usercomment=' + comments ,
2010-12-03 22:09:36 +00:00
msg : 'out=nodesTab;tgt=' + node
2010-11-09 21:22:43 +00:00
} ,
2010-11-18 16:35:59 +00:00
success : showChdefOutput
2010-11-09 21:22:43 +00:00
} ) ;
2010-11-10 17:14:08 +00:00
// Hide cancel and save links
$ ( this ) . hide ( ) ;
cancelLnk . hide ( ) ;
} ) ;
// Cancel changes onclick
cancelLnk . bind ( 'click' , function ( ) {
2010-11-11 15:07:40 +00:00
// Get original comment and put it back
2010-11-10 17:14:08 +00:00
var orignComments = $ ( this ) . parent ( ) . find ( 'textarea' ) . text ( ) ;
$ ( this ) . parent ( ) . find ( 'textarea' ) . val ( orignComments ) ;
// Hide cancel and save links
$ ( this ) . hide ( ) ;
saveLnk . hide ( ) ;
2010-11-18 16:44:01 +00:00
infoSpan . show ( ) ;
2010-11-09 21:22:43 +00:00
} ) ;
2010-11-11 15:07:40 +00:00
// Show save link when comment is edited
2010-11-09 21:22:43 +00:00
txtArea . bind ( 'click' , function ( ) {
saveLnk . show ( ) ;
2010-11-10 17:14:08 +00:00
cancelLnk . show ( ) ;
2010-11-18 16:44:01 +00:00
infoSpan . hide ( ) ;
2010-11-09 21:22:43 +00:00
} ) ;
toolTip . append ( txtArea ) ;
2010-11-10 17:14:08 +00:00
toolTip . append ( cancelLnk ) ;
2010-11-10 19:11:37 +00:00
toolTip . append ( saveLnk ) ;
2010-11-18 16:44:01 +00:00
toolTip . append ( infoSpan ) ;
2010-11-09 21:22:43 +00:00
return toolTip ;
}
2010-12-19 19:08:47 +00:00
/ * *
* Create a tool tip for node status
*
* @ return Tool tip
* /
function createStatusToolTip ( ) {
// Create tooltip container
2010-12-20 14:52:48 +00:00
var toolTip = $ ( '<div class="tooltip"></div>' ) . css ( {
2011-08-24 20:31:28 +00:00
'width' : '150px' ,
'font-weight' : 'normal'
2010-12-19 19:08:47 +00:00
} ) ;
2010-12-20 14:52:48 +00:00
// Create info text
2011-08-24 20:31:28 +00:00
var info = $ ( '<p></p>' ) . css ( {
'white-space' : 'normal'
} ) ;
2010-12-20 14:52:48 +00:00
info . append ( 'Click here to refresh the node status. To configure the xCAT monitor, ' ) ;
// Create link to turn on xCAT monitoring
var monitorLnk = $ ( '<a>click here</a>' ) . css ( {
'color' : '#58ACFA' ,
'font-size' : '10px'
} ) ;
// Open dialog to configure xCAT monitor
monitorLnk . bind ( 'click' , function ( ) {
// Check if xCAT monitor is enabled
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'monls' ,
tgt : '' ,
args : 'xcatmon' ,
msg : ''
} ,
success : openConfXcatMon
} ) ;
} ) ;
info . append ( monitorLnk ) ;
toolTip . append ( info ) ;
2010-12-19 19:08:47 +00:00
return toolTip ;
}
/ * *
* Create a tool tip for power status
*
* @ return Tool tip
* /
function createPowerToolTip ( ) {
// Create tooltip container
var toolTip = $ ( '<div class="tooltip">Click here to refresh the power status</div>' ) . css ( {
2011-08-24 20:31:28 +00:00
'width' : '150px' ,
'white-space' : 'normal' ,
'font-weight' : 'normal'
} ) ;
2010-12-19 19:08:47 +00:00
return toolTip ;
}
2011-05-02 20:33:25 +00:00
/ * *
* Create a tool tip for monitoring status
*
* @ return Tool tip
* /
function createMonitorToolTip ( ) {
// Create tooltip container
var toolTip = $ ( '<div class="tooltip">Click here to refresh the monitoring status</div>' ) . css ( {
2011-08-24 20:31:28 +00:00
'width' : '150px' ,
'white-space' : 'normal' ,
'font-weight' : 'normal'
2011-05-02 20:33:25 +00:00
} ) ;
return toolTip ;
}
2010-12-20 14:52:48 +00:00
/ * *
* Open dialog to configure xCAT monitor
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function openConfXcatMon ( data ) {
// Create info bar
var info = createInfoBar ( 'Configure the xCAT monitor. Select to enable or disable the monitor below.' ) ;
var dialog = $ ( '<div></div>' ) ;
dialog . append ( info ) ;
// Create status area
var statusArea = $ ( '<div></div>' ) . css ( 'padding-top' , '10px' ) ;
var label = $ ( '<label>Status:</label>' ) ;
statusArea . append ( label ) ;
// Get xCAT monitor status
var status = data . rsp [ 0 ] ;
var buttons ;
// If xCAT monitor is disabled
if ( status . indexOf ( 'not-monitored' ) > - 1 ) {
status = $ ( '<span>Disabled</span>' ) . css ( 'padding' , '0px 5px' ) ;
statusArea . append ( status ) ;
// Create enable and cancel buttons
buttons = {
"Enable" : function ( ) {
// Enable xCAT monitor
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'monstart' ,
tgt : '' ,
args : 'xcatmon' ,
msg : ''
} ,
success : function ( data ) {
openDialog ( 'info' , data . rsp [ 0 ] ) ;
}
} ) ;
$ ( this ) . dialog ( "close" ) ;
} ,
"Cancel" : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
} ;
} else {
status = $ ( '<span>Enabled</span>' ) . css ( 'padding' , '0px 5px' ) ;
statusArea . append ( status ) ;
// Create disable and cancel buttons
buttons = {
"Disable" : function ( ) {
// Disable xCAT monitor
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'monstop' ,
tgt : '' ,
args : 'xcatmon' ,
msg : ''
} ,
success : function ( data ) {
openDialog ( 'info' , data . rsp [ 0 ] ) ;
}
} ) ;
$ ( this ) . dialog ( "close" ) ;
} ,
"Cancel" : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
} ;
}
dialog . append ( statusArea ) ;
// Open dialog
dialog . dialog ( {
modal : true ,
width : 500 ,
buttons : buttons
} ) ;
}
2010-11-09 21:22:43 +00:00
/ * *
2010-11-18 16:35:59 +00:00
* Show chdef output
2010-11-09 21:22:43 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
2010-11-18 16:35:59 +00:00
function showChdefOutput ( data ) {
2010-11-10 21:18:35 +00:00
// Get output
var out = data . rsp ;
2010-11-24 18:11:42 +00:00
var args = data . msg . split ( ';' ) ;
var tabID = args [ 0 ] . replace ( 'out=' , '' ) ;
2010-12-03 22:09:36 +00:00
var tgt = args [ 1 ] . replace ( 'tgt=' , '' ) ;
2010-11-09 21:22:43 +00:00
// Find info bar on nodes tab, if any
2010-11-24 18:11:42 +00:00
var info = $ ( '#' + tabID ) . find ( '.ui-state-highlight' ) ;
2010-11-09 21:22:43 +00:00
if ( ! info . length ) {
// Create info bar if one does not exist
info = createInfoBar ( '' ) ;
2010-12-01 01:54:05 +00:00
$ ( '#' + tabID ) . append ( info ) ;
2010-11-09 21:22:43 +00:00
}
2010-11-10 21:18:35 +00:00
// Go through output and append to paragraph
2010-12-03 22:09:36 +00:00
var prg = $ ( '<p></p>' ) ;
2010-11-24 18:11:42 +00:00
for ( var i in out ) {
2010-12-03 22:09:36 +00:00
prg . append ( tgt + ': ' + out [ i ] + '<br>' ) ;
2010-11-09 21:22:43 +00:00
}
2010-12-03 22:09:36 +00:00
info . append ( prg ) ;
2010-11-24 18:11:42 +00:00
}
/ * *
2011-01-13 23:06:31 +00:00
* Set node attributes
2010-11-24 18:11:42 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
2011-01-13 23:06:31 +00:00
function setNodeAttrs ( data ) {
2010-12-02 21:28:24 +00:00
// Clear hash table containing definable node attributes
2011-01-13 23:06:31 +00:00
nodeAttrs = new Array ( ) ;
2010-12-02 21:28:24 +00:00
2010-11-24 18:11:42 +00:00
// Get definable attributes
var attrs = data . rsp [ 2 ] . split ( /\n/ ) ;
// Go through each line
var attr , key , descr ;
for ( var i in attrs ) {
attr = attrs [ i ] ;
// If the line is not empty
if ( attr ) {
2011-01-13 23:06:31 +00:00
// If the line has the attribute name
2010-11-24 18:11:42 +00:00
if ( attr . indexOf ( ':' ) && attr . indexOf ( ' ' ) ) {
// Get attribute name and description
key = jQuery . trim ( attr . substring ( 0 , attr . indexOf ( ':' ) ) ) ;
descr = jQuery . trim ( attr . substring ( attr . indexOf ( ':' ) + 1 ) ) ;
2010-12-20 19:55:19 +00:00
// Remove arrow brackets
descr = descr . replace ( new RegExp ( '<|>' , 'g' ) , '' ) ;
2011-07-20 21:13:09 +00:00
// Set hash table where key = attribute name and value = description
2011-01-13 23:06:31 +00:00
nodeAttrs [ key ] = descr ;
2010-12-20 19:55:19 +00:00
} else {
// Remove arrow brackets
attr = attr . replace ( new RegExp ( '<|>' , 'g' ) , '' ) ;
2010-11-24 18:11:42 +00:00
// Append description to hash table
2011-01-13 23:06:31 +00:00
nodeAttrs [ key ] = nodeAttrs [ key ] + '\n' + attr ;
2010-11-24 18:11:42 +00:00
}
} // End of if
} // End of for
}
/ * *
* Load set node properties page
*
* @ param tgtNode
* Target node to set properties
* @ return Nothing
* /
2011-08-24 19:28:24 +00:00
function editNodeProps ( tgtNode ) {
2010-11-24 18:11:42 +00:00
// Get nodes tab
var tab = getNodesTab ( ) ;
// Generate new tab ID
var inst = 0 ;
2010-12-03 22:09:36 +00:00
var newTabId = 'editPropsTab' + inst ;
2010-11-24 18:11:42 +00:00
while ( $ ( '#' + newTabId ) . length ) {
// If one already exists, generate another one
inst = inst + 1 ;
2010-12-03 22:09:36 +00:00
newTabId = 'editPropsTab' + inst ;
2010-11-24 18:11:42 +00:00
}
// Open new tab
// Create set properties form
2010-12-03 22:09:36 +00:00
var editPropsForm = $ ( '<div class="form"></div>' ) ;
2010-11-24 18:11:42 +00:00
// Create info bar
var infoBar = createInfoBar ( 'Choose the properties you wish to change on the node. When you are finished, click Save.' ) ;
2010-12-03 22:09:36 +00:00
editPropsForm . append ( infoBar ) ;
2010-11-24 18:11:42 +00:00
// Create an input for each definable attribute
var div , label , input , descr , value ;
// Set node attribute
origAttrs [ tgtNode ] [ 'node' ] = tgtNode ;
2011-01-13 23:06:31 +00:00
for ( var key in nodeAttrs ) {
2010-11-24 18:11:42 +00:00
// If an attribute value exists
if ( origAttrs [ tgtNode ] [ key ] ) {
// Set the value
value = origAttrs [ tgtNode ] [ key ] ;
} else {
value = '' ;
}
// Create label and input for attribute
2011-08-24 19:28:24 +00:00
div = $ ( '<div></div>' ) . css ( 'display' , 'inline-table' ) ;
2010-11-24 18:11:42 +00:00
label = $ ( '<label>' + key + ':</label>' ) . css ( 'vertical-align' , 'middle' ) ;
2011-01-13 23:06:31 +00:00
input = $ ( '<input type="text" value="' + value + '" title="' + nodeAttrs [ key ] + '"/>' ) . css ( 'margin-top' , '5px' ) ;
2010-11-24 18:11:42 +00:00
// Change border to blue onchange
input . bind ( 'change' , function ( event ) {
$ ( this ) . css ( 'border-color' , 'blue' ) ;
} ) ;
div . append ( label ) ;
div . append ( input ) ;
2010-12-03 22:09:36 +00:00
editPropsForm . append ( div ) ;
2010-11-24 18:11:42 +00:00
}
2010-12-03 22:09:36 +00:00
2010-11-24 18:11:42 +00:00
// Change style for last division
div . css ( {
'display' : 'block' ,
'margin' : '0px 0px 10px 0px'
} ) ;
// Generate tooltips
2010-12-03 22:09:36 +00:00
editPropsForm . find ( 'div input[title]' ) . tooltip ( {
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.8 ,
2010-12-02 21:28:24 +00:00
delay : 0 ,
predelay : 800 ,
events : {
def : "mouseover,mouseout" ,
input : "mouseover,mouseout" ,
widget : "focus mouseover,blur mouseout" ,
tooltip : "mouseover,mouseout"
}
2010-11-24 18:11:42 +00:00
} ) ;
2011-09-09 03:31:05 +00:00
// Save changes
2010-11-24 18:11:42 +00:00
var saveBtn = createButton ( 'Save' ) ;
2011-01-13 23:06:31 +00:00
saveBtn . click ( function ( ) {
2010-11-24 18:11:42 +00:00
// Get all inputs
var inputs = $ ( '#' + newTabId + ' input' ) ;
// Go through each input
var args = '' ;
var attrName , attrVal ;
inputs . each ( function ( ) {
// If the border color is blue
if ( $ ( this ) . css ( 'border-left-color' ) == 'rgb(0, 0, 255)' ) {
// Change border color back to normal
$ ( this ) . css ( 'border-color' , '' ) ;
// Get attribute name and value
attrName = $ ( this ) . parent ( ) . find ( 'label' ) . text ( ) . replace ( ':' , '' ) ;
attrVal = $ ( this ) . val ( ) ;
// Build argument string
if ( args ) {
// Handle subsequent arguments
args += ';' + attrName + '=' + attrVal ;
} else {
// Handle the 1st argument
args += attrName + '=' + attrVal ;
}
}
} ) ;
// Send command to change node attributes
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'chdef' ,
tgt : '' ,
args : '-t;node;-o;' + tgtNode + ';' + args ,
2010-12-03 22:09:36 +00:00
msg : 'out=' + newTabId + ';tgt=' + tgtNode
2010-11-24 18:11:42 +00:00
} ,
success : showChdefOutput
} ) ;
} ) ;
2010-12-03 22:09:36 +00:00
editPropsForm . append ( saveBtn ) ;
2010-11-24 18:11:42 +00:00
2011-09-09 03:31:05 +00:00
// Cancel changes
2010-11-24 18:11:42 +00:00
var cancelBtn = createButton ( 'Cancel' ) ;
2011-01-13 23:06:31 +00:00
cancelBtn . click ( function ( ) {
2010-11-24 18:11:42 +00:00
// Close the tab
tab . remove ( $ ( this ) . parent ( ) . parent ( ) . attr ( 'id' ) ) ;
} ) ;
2010-12-03 22:09:36 +00:00
editPropsForm . append ( cancelBtn ) ;
2010-11-24 18:11:42 +00:00
// Append to discover tab
2010-12-03 22:09:36 +00:00
tab . add ( newTabId , 'Edit' , editPropsForm , true ) ;
2010-11-24 18:11:42 +00:00
// Select new tab
tab . select ( newTabId ) ;
2010-12-02 21:28:24 +00:00
}
/ * *
2011-01-13 23:06:31 +00:00
* Open set node attributes dialog
2010-12-02 21:28:24 +00:00
*
* @ return Nothing
* /
2011-01-13 23:06:31 +00:00
function openSetAttrsDialog ( ) {
2010-12-02 21:28:24 +00:00
// Open new tab
// Create set properties form
var setPropsForm = $ ( '<div class="form"></div>' ) ;
// Create info bar
var infoBar = createInfoBar ( 'Choose the properties you wish to change on the node. When you are finished, click Save.' ) ;
setPropsForm . append ( infoBar ) ;
// Create an input for each definable attribute
var div , label , input , descr , value ;
2011-01-13 23:06:31 +00:00
for ( var key in nodeAttrs ) {
2010-12-02 21:28:24 +00:00
value = '' ;
// Create label and input for attribute
div = $ ( '<div></div>' ) . css ( 'display' , 'inline' ) ;
label = $ ( '<label>' + key + ':</label>' ) . css ( 'vertical-align' , 'middle' ) ;
2011-01-13 23:06:31 +00:00
input = $ ( '<input type="text" value="' + value + '" title="' + nodeAttrs [ key ] + '"/>' ) . css ( 'margin-top' , '5px' ) ;
2010-12-02 21:28:24 +00:00
// Change border to blue onchange
input . bind ( 'change' , function ( event ) {
$ ( this ) . css ( 'border-color' , 'blue' ) ;
} ) ;
div . append ( label ) ;
div . append ( input ) ;
setPropsForm . append ( div ) ;
}
// Change style for last division
div . css ( {
'display' : 'block' ,
'margin' : '0px 0px 10px 0px'
} ) ;
// Generate tooltips
setPropsForm . find ( 'div input[title]' ) . tooltip ( {
2010-12-03 22:09:36 +00:00
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.8 ,
2010-12-02 21:28:24 +00:00
delay : 0 ,
predelay : 800 ,
events : {
def : "mouseover,mouseout" ,
input : "mouseover,mouseout" ,
widget : "focus mouseover,blur mouseout" ,
tooltip : "mouseover,mouseout"
} ,
// Change z index to show tooltip in front
onBeforeShow : function ( ) {
this . getTip ( ) . css ( 'z-index' , $ . topZIndex ( ) ) ;
}
} ) ;
// Enable vertical scroll
setPropsForm . css ( 'overflow' , 'auto' ) ;
// Open form as a dialog
setPropsForm . dialog ( {
2011-12-01 05:58:46 +00:00
title : 'Set attributes' ,
2010-12-02 21:28:24 +00:00
modal : true ,
height : 400 ,
2011-01-10 15:12:37 +00:00
width : 700 ,
2010-12-02 21:28:24 +00:00
buttons : {
"Save" : function ( ) {
// Remove any warning messages
$ ( this ) . find ( '.ui-state-error' ) . remove ( ) ;
// Get all inputs
var inputs = $ ( this ) . find ( 'input' ) ;
// Go through each input
var args = '' ;
var tgtNode , attrName , attrVal ;
inputs . each ( function ( ) {
// If the border color is blue
if ( $ ( this ) . css ( 'border-left-color' ) == 'rgb(0, 0, 255)' ) {
// Change border color back to normal
$ ( this ) . css ( 'border-color' , '' ) ;
// Get attribute name and value
attrName = $ ( this ) . parent ( ) . find ( 'label' ) . text ( ) . replace ( ':' , '' ) ;
attrVal = $ ( this ) . val ( ) ;
// Get node name
if ( attrName == 'node' ) {
tgtNode = attrVal ;
} else {
// Build argument string
if ( args ) {
// Handle subsequent arguments
args += ';' + attrName + '=' + attrVal ;
} else {
// Handle the 1st argument
args += attrName + '=' + attrVal ;
}
}
}
} ) ;
// Send command to change node attributes
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'chdef' ,
tgt : '' ,
args : '-t;node;-o;' + tgtNode + ';' + args ,
msg : 'node=' + tgtNode
} ,
/ * *
2010-12-21 00:52:10 +00:00
* Show results
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
2010-12-02 21:28:24 +00:00
success : function ( data ) {
// Get output
var out = data . rsp ;
var node = data . msg . replace ( 'node=' , '' ) ;
// Go through output and append to paragraph
var msg = '' ;
for ( var i in out ) {
if ( ! msg ) {
msg = node + ': ' + out [ i ] ;
} else {
msg += '<br>' + node + ': ' + out [ i ] ;
}
}
openDialog ( 'info' , msg ) ;
}
} ) ;
// Close dialog
$ ( this ) . dialog ( "close" ) ;
} ,
"Cancel" : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
}
} ) ;
2011-05-02 20:33:25 +00:00
}
/ * *
* Turn on monitoring for a given node
*
* @ param node
* Node to monitor on or off
* @ param monitor
* Monitor state , on or off
* @ return Nothing
* /
function monitorNode ( node , monitor ) {
2011-12-19 05:03:27 +00:00
// Show ganglia loader
var gangliaCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(4)' ) ;
gangliaCol . find ( 'img' ) . show ( ) ;
2011-05-02 20:33:25 +00:00
if ( monitor == 'on' ) {
// Append loader to warning bar
var warningBar = $ ( '#nodesTab' ) . find ( '.ui-state-error p' ) ;
if ( warningBar . length ) {
2011-09-09 03:31:05 +00:00
warningBar . append ( createLoader ( '' ) ) ;
2011-05-02 20:33:25 +00:00
}
if ( node ) {
// Check if ganglia RPMs are installed
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'gangliacheck;' + node ,
msg : node // Node range will be passed along in data.msg
} ,
/ * *
* Start ganglia on a given node range
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
success : function ( data ) {
// Get response
var out = data . rsp [ 0 ] . split ( /\n/ ) ;
// Go through each line
var warn = false ;
var warningMsg = '' ;
for ( var i in out ) {
// If an RPM is not installed
if ( out [ i ] . indexOf ( 'not installed' ) > - 1 ) {
warn = true ;
if ( warningMsg ) {
warningMsg += '<br>' + out [ i ] ;
} else {
warningMsg = out [ i ] ;
}
}
}
// If there are warnings
if ( warn ) {
// Create warning bar
var warningBar = createWarnBar ( warningMsg ) ;
warningBar . css ( 'margin-bottom' , '10px' ) ;
warningBar . prependTo ( $ ( '#nodesTab' ) ) ;
} else {
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
2011-12-19 05:03:27 +00:00
args : 'gangliastart;' + data . msg + ';-r' ,
msg : data . msg
2011-05-02 20:33:25 +00:00
} ,
success : function ( data ) {
// Remove any warnings
$ ( '#nodesTab' ) . find ( '.ui-state-error' ) . remove ( ) ;
2011-12-19 05:03:27 +00:00
// Update datatable
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'gangliastatus;' + data . msg ,
msg : ''
} ,
success : loadGangliaStatus
} ) ;
2011-05-02 20:33:25 +00:00
}
} ) ;
} // End of if (warn)
} // End of function(data)
} ) ;
} else {
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : 'gangliastart' ,
msg : ''
} ,
success : function ( data ) {
// Remove any warnings
$ ( '#nodesTab' ) . find ( '.ui-state-error' ) . remove ( ) ;
}
} ) ;
} // End of if (node)
} else {
var args ;
if ( node ) {
2011-12-19 05:03:27 +00:00
args = 'gangliastop;' + node + ';-r' ;
2011-05-02 20:33:25 +00:00
} else {
args = 'gangliastop' ;
}
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
args : args ,
msg : ''
} ,
success : function ( data ) {
2011-12-19 05:03:27 +00:00
// Hide ganglia loader
var gangliaCol = $ ( '#' + nodesTableId + '_wrapper .dataTables_scrollHead .datatable thead tr th:eq(4)' ) ;
gangliaCol . find ( 'img' ) . hide ( ) ;
2011-05-02 20:33:25 +00:00
}
} ) ;
}
}
/ * *
* Install Ganglia on a given node
*
* @ param node
* Node to install Ganglia on
* @ return Nothing
* /
function installGanglia ( node ) {
var iframe = createIFrame ( 'lib/cmd.php?cmd=webrun&tgt=&args=installganglia;' + node + '&msg=' + node + '&opts=flush' ) ;
iframe . prependTo ( $ ( '#nodesTab' ) ) ;
// Turn on Ganglia for node
monitorNode ( node , 'on' ) ;
2011-06-16 02:48:34 +00:00
}
/ * *
2011-09-09 03:31:05 +00:00
* After nodes are loaded , load more information based on different hardware architectures
2011-06-16 02:48:34 +00:00
*
2011-09-09 03:31:05 +00:00
* @ param group
* Group name
2011-06-16 02:48:34 +00:00
* @ return Nothing
* /
2011-06-27 08:49:13 +00:00
function advancedLoad ( group ) {
2011-06-16 02:48:34 +00:00
var tempIndex = 0 ;
2011-08-24 19:28:24 +00:00
var tableHeaders = $ ( '#' + nodesTableId ) . parents ( '.dataTables_scroll' ) . find ( '.dataTables_scrollHead thead tr:eq(0) th' ) ;
2011-06-16 02:48:34 +00:00
var colNameHash = new Object ( ) ;
var colName = '' ;
var archCol = 0 , hcpCol = 0 ;
2011-09-09 03:31:05 +00:00
// Find out the column name and their index
2011-06-16 02:48:34 +00:00
for ( tempIndex = 0 ; tempIndex < tableHeaders . size ( ) ; tempIndex ++ ) {
var header = tableHeaders . eq ( tempIndex ) ;
2011-09-09 03:31:05 +00:00
// Skip headers that are links, e.g. status, power, and monitor
2011-06-16 02:48:34 +00:00
if ( header . find ( 'a' ) . size ( ) > 0 ) {
continue ;
}
colName = header . text ( ) ;
2011-09-09 03:31:05 +00:00
if ( colName ) {
2011-06-16 02:48:34 +00:00
colNameHash [ colName ] = tempIndex ;
}
}
2011-09-09 03:31:05 +00:00
// If there is no arch column, exit because you cannot distinguish hardware type
if ( ! colNameHash [ 'arch' ] ) {
2011-06-16 02:48:34 +00:00
return ;
}
2011-09-09 03:31:05 +00:00
if ( ! colNameHash [ 'hcp' ] ) {
2011-06-16 02:48:34 +00:00
return ;
}
archCol = colNameHash [ 'arch' ] ;
hcpCol = colNameHash [ 'hcp' ] ;
// Get hardware control point
var rows = $ ( '#' + nodesTableId + ' tbody tr' ) ;
var hcps = new Object ( ) ;
var rowsNum = rows . size ( ) ;
for ( var j = 0 ; j < rowsNum ; j ++ ) {
var val = rows . eq ( j ) . find ( 'td' ) . eq ( hcpCol ) . html ( ) ;
var archval = rows . eq ( j ) . find ( 'td' ) . eq ( archCol ) . html ( ) ;
if ( - 1 == archval . indexOf ( '390' ) ) {
continue ;
}
hcps [ val ] = 1 ;
}
var args ;
for ( var h in hcps ) {
// Get node without domain name
args = h . split ( '.' ) ;
// If there are no disk pools or network names cookie for this hcp
if ( ! $ . cookie ( args [ 0 ] + 'diskpools' ) || ! $ . cookie ( args [ 0 ] + 'networks' ) ) {
// Check if SMAPI is online
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'lsvm' ,
tgt : args [ 0 ] ,
args : '' ,
msg : 'group=' + group + ';hcp=' + args [ 0 ]
} ,
// Load hardware control point specific info
// Get disk pools and network names
success : loadHcpInfo
} ) ;
}
} // End of for
2011-06-28 08:37:16 +00:00
}
/ * *
2012-03-14 19:20:37 +00:00
* Jump to provision page on - click
2011-06-28 08:37:16 +00:00
*
2011-09-09 03:31:05 +00:00
* @ param tgtNodes
* Target nodes
2011-06-28 08:37:16 +00:00
* @ return Nothing
* /
2011-09-09 03:31:05 +00:00
function jump2Provision ( tgtNodes ) {
var nodeArray = tgtNodes . split ( ',' ) ;
2011-06-28 08:37:16 +00:00
var nodeName = '' ;
var index = 0 ;
2011-09-09 03:31:05 +00:00
var archType = '' ;
var errorMsg = '' ;
2011-09-02 07:48:30 +00:00
var master = '' ;
var tftpserver = '' ;
var nfsserver = '' ;
2012-03-14 19:20:37 +00:00
var diaDiv = $ ( '<div title="Provision" class="form" id="deployDiv"></div>' ) ;
2011-09-09 03:31:05 +00:00
// Check the first node's arch type
2011-06-28 08:37:16 +00:00
for ( index in nodeArray ) {
nodeName = nodeArray [ index ] ;
2011-09-09 03:31:05 +00:00
// Skip if node does not have arch
2011-06-28 08:37:16 +00:00
if ( ! origAttrs [ nodeName ] [ 'arch' ] ) {
2011-09-12 19:47:26 +00:00
errorMsg = 'Nodes should have arch defined! ' ;
2011-06-28 08:37:16 +00:00
break ;
}
2012-03-14 19:20:37 +00:00
if ( index == 0 ) {
2011-09-09 03:31:05 +00:00
archType = origAttrs [ nodeName ] [ 'arch' ] ;
2011-06-28 08:37:16 +00:00
}
2011-09-09 03:31:05 +00:00
// Skip if nodes do not have same arch
if ( archType != origAttrs [ nodeName ] [ 'arch' ] ) {
errorMsg = 'Nodes should belong to the same arch!<br/>' ;
2011-06-28 08:37:16 +00:00
break ;
}
}
2011-09-09 03:31:05 +00:00
// Skip if nodes do not have MAC address
2011-06-28 08:37:16 +00:00
for ( index in nodeArray ) {
2011-07-06 07:59:41 +00:00
if ( ! origAttrs [ nodeName ] [ 'mac' ] || ! origAttrs [ nodeName ] [ 'ip' ] ) {
2011-09-09 03:31:05 +00:00
errorMsg += 'Nodes should have the IP and MAC addresses defined!<br/>' ;
2011-06-28 08:37:16 +00:00
break ;
}
}
2011-09-09 03:31:05 +00:00
if ( archType . indexOf ( '390' ) != - 1 ) {
2012-03-14 19:20:37 +00:00
errorMsg += 'Please use the provision page' ;
2011-06-28 08:37:16 +00:00
}
2011-09-09 03:31:05 +00:00
// Open dialog to show error message
2012-03-14 19:20:37 +00:00
if ( errorMsg ) {
2011-09-09 03:31:05 +00:00
diaDiv . append ( createWarnBar ( errorMsg ) ) ;
2011-06-28 08:37:16 +00:00
diaDiv . dialog ( {
modal : true ,
width : 400 ,
buttons : {
'Close' : function ( ) {
$ ( this ) . dialog ( 'destroy' ) ;
}
}
} ) ;
return ;
}
2011-09-09 03:31:05 +00:00
if ( origAttrs [ nodeName ] [ 'xcatmaster' ] ) {
2011-09-02 07:48:30 +00:00
master = origAttrs [ nodeName ] [ 'xcatmaster' ] ;
}
2011-09-09 03:31:05 +00:00
if ( origAttrs [ nodeName ] [ 'tftpserver' ] ) {
2011-09-02 07:48:30 +00:00
tftpserver = origAttrs [ nodeName ] [ 'tftpserver' ] ;
}
2011-09-09 03:31:05 +00:00
if ( origAttrs [ nodeName ] [ 'nfsserver' ] ) {
2011-09-02 07:48:30 +00:00
nfsserver = origAttrs [ nodeName ] [ 'nfsserver' ] ;
}
2011-09-09 03:31:05 +00:00
window . location . href = 'provision.php?nodes=' + tgtNodes + '&arch=' + archType + '&master=' + master +
2011-09-02 07:48:30 +00:00
'&tftpserver=' + tftpserver + '&nfsserver=' + nfsserver ;
2010-06-16 18:21:58 +00:00
}