2010-07-29 17:32:24 +00:00
/ * *
* Load nodeset page
*
2010-08-03 20:44:26 +00:00
* @ param tgtNodes
2010-07-29 17:32:24 +00:00
* Targets to run nodeset against
* @ return Nothing
* /
2010-08-03 20:44:26 +00:00
function loadNodesetPage ( tgtNodes ) {
2010-07-29 17:32:24 +00:00
// Get OS images
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'tabdump' ,
tgt : '' ,
args : 'osimage' ,
msg : ''
} ,
success : setOSImageCookies
} ) ;
// Get nodes tab
var tab = getNodesTab ( ) ;
// Generate new tab ID
var inst = 0 ;
var tabId = 'nodesetTab' + inst ;
while ( $ ( '#' + tabId ) . length ) {
// If one already exists, generate another one
inst = inst + 1 ;
tabId = 'nodesetTab' + inst ;
}
2010-10-08 03:03:42 +00:00
// Open new tab & create nodeset form
2010-07-29 17:32:24 +00:00
var nodesetForm = $ ( '<div class="form"></div>' ) ;
// Create status bar
var statBarId = 'nodesetStatusBar' + inst ;
2010-12-04 01:47:10 +00:00
var statBar = createStatusBar ( statBarId ) . hide ( ) ;
2010-07-29 17:32:24 +00:00
nodesetForm . append ( statBar ) ;
// Create loader
var loader = createLoader ( 'nodesetLoader' ) ;
statBar . append ( loader ) ;
// Create info bar
2010-12-03 22:09:36 +00:00
var infoBar = createInfoBar ( 'Set the boot state for a node range.' ) ;
2010-07-29 17:32:24 +00:00
nodesetForm . append ( infoBar ) ;
// Create 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 set the boot state for"/></div>' ) ;
2010-07-29 17:32:24 +00:00
nodesetForm . append ( tgt ) ;
// Create boot method drop down
var method = $ ( '<div></div>' ) ;
var methodLabel = $ ( '<label for="method">Boot method:</label>' ) ;
var methodSelect = $ ( '<select id="bootMethod" name="bootMethod"></select>' ) ;
2010-09-24 02:27:04 +00:00
methodSelect . append ( '<option value="boot">boot</option>'
+ '<option value="install">install</option>'
+ '<option value="iscsiboot">iscsiboot</option>'
+ '<option value="netboot">netboot</option>'
+ '<option value="statelite">statelite</option>'
) ;
2010-07-29 17:32:24 +00:00
method . append ( methodLabel ) ;
method . append ( methodSelect ) ;
nodesetForm . append ( method ) ;
// Create boot type drop down
var type = $ ( '<div></div>' ) ;
var typeLabel = $ ( '<label for="type">Boot type:</label>' ) ;
var typeSelect = $ ( '<select id="bootType" name="bootType"></select>' ) ;
2010-09-24 02:27:04 +00:00
typeSelect . append ( '<option value="zvm">zvm</option>'
+ '<option value="install">pxe</option>'
+ '<option value="iscsiboot">yaboot</option>'
) ;
2010-07-29 17:32:24 +00:00
type . append ( typeLabel ) ;
type . append ( typeSelect ) ;
nodesetForm . append ( type ) ;
// Create operating system input
var os = $ ( '<div></div>' ) ;
var osLabel = $ ( '<label for="os">Operating system:</label>' ) ;
2010-11-01 14:06:53 +00:00
var osInput = $ ( '<input type="text" name="os" title="You must give the operating system of this node or node range, e.g. rhel5.5"/>' ) ;
2010-07-29 17:32:24 +00:00
osInput . one ( 'focus' , function ( ) {
2010-11-22 16:18:55 +00:00
var tmp = $ . cookie ( 'osvers' ) ;
2010-07-29 17:32:24 +00:00
if ( tmp ) {
// Turn on auto complete
$ ( this ) . autocomplete ( tmp . split ( ',' ) ) ;
}
} ) ;
os . append ( osLabel ) ;
os . append ( osInput ) ;
nodesetForm . append ( os ) ;
// Create architecture input
var arch = $ ( '<div></div>' ) ;
var archLabel = $ ( '<label for="arch">Architecture:</label>' ) ;
2010-11-01 14:06:53 +00:00
var archInput = $ ( '<input type="text" name="arch" title="You must give the architecture of this node or node range, e.g. s390x"/>' ) ;
2010-07-29 17:32:24 +00:00
archInput . one ( 'focus' , function ( ) {
2010-11-22 16:18:55 +00:00
var tmp = $ . cookie ( 'osarchs' ) ;
2010-07-29 17:32:24 +00:00
if ( tmp ) {
// Turn on auto complete
$ ( this ) . autocomplete ( tmp . split ( ',' ) ) ;
}
} ) ;
arch . append ( archLabel ) ;
arch . append ( archInput ) ;
nodesetForm . append ( arch ) ;
// Create profiles input
var profile = $ ( '<div></div>' ) ;
var profileLabel = $ ( '<label for="profile">Profile:</label>' ) ;
2010-11-01 14:06:53 +00:00
var profileInput = $ ( '<input type="text" name="profile" title="You must give the profile for this node or node range. The typical default profile is: compute."/>' ) ;
2010-07-29 17:32:24 +00:00
profileInput . one ( 'focus' , function ( ) {
2010-11-22 16:18:55 +00:00
tmp = $ . cookie ( 'profiles' ) ;
2010-07-29 17:32:24 +00:00
if ( tmp ) {
// Turn on auto complete
$ ( this ) . autocomplete ( tmp . split ( ',' ) ) ;
}
} ) ;
profile . append ( profileLabel ) ;
profile . append ( profileInput ) ;
nodesetForm . append ( profile ) ;
2010-11-01 14:06:53 +00:00
// Generate tooltips
nodesetForm . find ( 'div input[title]' ) . tooltip ( {
2010-12-03 22:09:36 +00:00
position : "center right" ,
offset : [ - 2 , 10 ] ,
effect : "fade" ,
opacity : 0.7
2010-11-01 14:06:53 +00:00
} ) ;
2010-07-29 17:32:24 +00:00
/ * *
* Ok
* /
var okBtn = createButton ( 'Ok' ) ;
okBtn . bind ( 'click' , function ( event ) {
2010-09-24 02:27:04 +00:00
// Remove any warning messages
$ ( this ) . parent ( ) . parent ( ) . find ( '.ui-state-error' ) . remove ( ) ;
2010-07-29 17:32:24 +00:00
// Check state, OS, arch, and profile
var ready = true ;
var inputs = $ ( '#' + tabId + ' input' ) ;
for ( var i = 0 ; i < inputs . length ; i ++ ) {
if ( ! inputs . eq ( i ) . val ( ) && inputs . eq ( i ) . attr ( 'name' ) != 'diskPw' ) {
inputs . eq ( i ) . css ( 'border' , 'solid #FF0000 1px' ) ;
ready = false ;
} else {
inputs . eq ( i ) . css ( 'border' , 'solid #BDBDBD 1px' ) ;
}
}
if ( ready ) {
// Get nodes
var tgts = $ ( '#' + tabId + ' input[name=target]' ) . val ( ) ;
// Get boot method
var method = $ ( '#' + tabId + ' select[id=bootMethod]' ) . val ( ) ;
// Get boot type
var type = $ ( '#' + tabId + ' select[id=bootType]' ) . val ( ) ;
// Get OS, arch, and profile
var os = $ ( '#' + tabId + ' input[name=os]' ) . val ( ) ;
var arch = $ ( '#' + tabId + ' input[name=arch]' ) . val ( ) ;
var profile = $ ( '#' + tabId + ' input[name=profile]' ) . val ( ) ;
// Disable Ok button
2010-09-22 20:18:21 +00:00
$ ( this ) . attr ( 'disabled' , 'true' ) ;
2010-07-29 17:32:24 +00:00
/ * *
* ( 1 ) Set the OS , arch , and profile
* /
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodeadd' ,
tgt : '' ,
args : tgts + ';noderes.netboot=' + type
+ ';nodetype.os=' + os
+ ';nodetype.arch=' + arch
+ ';nodetype.profile=' + profile ,
msg : 'cmd=nodeadd;inst=' + inst
} ,
success : updateNodesetStatus
} ) ;
// Show status bar
statBar . show ( ) ;
} 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-07-29 17:32:24 +00:00
}
} ) ;
nodesetForm . append ( okBtn ) ;
// Append to discover tab
2010-08-03 14:58:08 +00:00
tab . add ( tabId , 'Nodeset' , nodesetForm , true ) ;
2010-07-29 17:32:24 +00:00
// Select new tab
tab . select ( tabId ) ;
}
/ * *
* Update nodeset status
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function updateNodesetStatus ( data ) {
// Get ajax response
var rsp = data . rsp ;
var args = data . msg . split ( ';' ) ;
var cmd = args [ 0 ] . replace ( 'cmd=' , '' ) ;
// Get nodeset instance
var inst = args [ 1 ] . replace ( 'inst=' , '' ) ;
// Get status bar ID
var statBarId = 'nodesetStatusBar' + inst ;
// Get tab ID
var tabId = 'nodesetTab' + inst ;
// Get nodes
var tgts = $ ( '#' + tabId + ' input[name=target]' ) . val ( ) ;
// Get boot method
var method = $ ( '#' + tabId + ' select[id=bootMethod]' ) . val ( ) ;
/ * *
* ( 2 ) Update / etc / hosts
* /
if ( cmd == 'nodeadd' ) {
if ( rsp . length ) {
$ ( '#' + statBarId ) . find ( 'img' ) . hide ( ) ;
$ ( '#' + statBarId ) . append ( '<p>(Error) Failed to create node definition</p>' ) ;
} else {
// Create target nodes string
var tgtNodesStr = '' ;
2010-07-29 17:59:33 +00:00
var nodes = tgts . split ( ',' ) ;
2010-07-29 17:32:24 +00:00
// Loop through each node
for ( var i in nodes ) {
// 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 {
// Append a comma to the string
tgtNodesStr += nodes [ i ] + ', ' ;
}
}
}
$ ( '#' + statBarId ) . append ( '<p>Node definition created for ' + tgtNodesStr + '</p>' ) ;
2010-07-29 17:59:33 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'makehosts' ,
tgt : '' ,
args : '' ,
msg : 'cmd=makehosts;inst=' + inst
} ,
2010-07-29 17:32:24 +00:00
2010-07-29 17:59:33 +00:00
success : updateNodesetStatus
} ) ;
}
2010-07-29 17:32:24 +00:00
}
/ * *
* ( 4 ) Update DNS
* /
else if ( cmd == 'makehosts' ) {
// If no output, no errors occurred
if ( rsp . length ) {
$ ( '#' + statBarId ) . append ( '<p>(Error) Failed to update /etc/hosts</p>' ) ;
} else {
$ ( '#' + statBarId ) . append ( '<p>/etc/hosts updated</p>' ) ;
}
// Update DNS
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'makedns' ,
tgt : '' ,
args : '' ,
msg : 'cmd=makedns;inst=' + inst
} ,
success : updateNodesetStatus
} ) ;
}
/ * *
* ( 5 ) Update DHCP
* /
else if ( cmd == 'makedns' ) {
// Write ajax response to status bar
var prg = writeRsp ( rsp , '' ) ;
$ ( '#' + statBarId ) . append ( prg ) ;
// Update DHCP
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'makedhcp' ,
tgt : '' ,
args : '-a' ,
msg : 'cmd=makedhcp;inst=' + inst
} ,
success : updateNodesetStatus
} ) ;
}
/ * *
* ( 6 ) Prepare node for boot
* /
else if ( cmd == 'makedhcp' ) {
// Write ajax response to status bar
var prg = writeRsp ( rsp , '' ) ;
$ ( '#' + statBarId ) . append ( prg ) ;
// Prepare node for boot
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodeset' ,
tgt : tgts ,
args : method ,
msg : 'cmd=nodeset;inst=' + inst
} ,
success : updateNodesetStatus
} ) ;
}
/ * *
* ( 7 ) Boot node from network
* /
else if ( cmd == 'nodeset' ) {
// Write ajax response to status bar
var prg = writeRsp ( rsp , '' ) ;
$ ( '#' + statBarId ) . append ( prg ) ;
// Hide loader
$ ( '#' + statBarId ) . find ( 'img' ) . hide ( ) ;
}
}