2010-07-28 20:24:29 +00:00
/ * *
* Execute when the DOM is fully loaded
* /
2010-07-15 22:57:48 +00:00
$ ( document ) . ready ( function ( ) {
2010-07-28 20:24:29 +00:00
// Load utility scripts
2010-07-15 22:57:48 +00:00
includeJs ( "js/custom/zvmUtils.js" ) ;
} ) ;
2010-06-16 18:21:58 +00:00
2010-07-22 19:56:09 +00:00
/ * *
* Constructor
*
* @ return Nothing
* /
2010-07-23 18:47:54 +00:00
var zvmPlugin = function ( ) {
2010-07-22 19:56:09 +00:00
} ;
2010-06-16 18:21:58 +00:00
/ * *
2010-07-19 18:28:31 +00:00
* Load clone page
2010-06-16 18:21:58 +00:00
*
2010-07-15 22:57:48 +00:00
* @ param node
2010-07-19 18:28:31 +00:00
* Source node to clone
2010-06-16 18:21:58 +00:00
* @ return Nothing
* /
2010-07-23 18:47:54 +00:00
zvmPlugin . prototype . loadClonePage = function ( node ) {
2010-07-15 22:57:48 +00:00
// Get nodes tab
var tab = getNodesTab ( ) ;
var newTabId = node + 'CloneTab' ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// If there is no existing clone tab
2010-07-15 22:57:48 +00:00
if ( ! $ ( '#' + newTabId ) . length ) {
// Get table headers
var table = $ ( '#' + node ) . parent ( ) . parent ( ) . parent ( ) . parent ( ) ;
var headers = table . find ( 'thead th' ) ;
var cols = new Array ( ) ;
for ( var i = 0 ; i < headers . length ; i ++ ) {
var col = headers . eq ( i ) . text ( ) ;
cols . push ( col ) ;
}
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Get hardware control point column
var hcpCol = $ . inArray ( 'hcp' , cols ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Get hardware control point
var nodeRow = $ ( '#' + node ) . parent ( ) . parent ( ) ;
2010-07-19 18:28:31 +00:00
var dTable = getNodesDataTable ( ) ;
var rowPos = dTable . fnGetPosition ( nodeRow . get ( 0 ) ) ;
var aData = dTable . fnGetData ( rowPos ) ;
2010-07-15 22:57:48 +00:00
var hcp = aData [ hcpCol ] ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Create status bar and hide it
2010-07-15 22:57:48 +00:00
var statBarId = node + 'CloneStatusBar' ;
2010-10-08 03:03:42 +00:00
var statBar = $ ( '<div class="statusBar" id="' + statBarId + '"></div>' ) . hide ( ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create info bar
var infoBar = createInfoBar ( 'Clone a node' ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create clone form
var cloneForm = $ ( '<div class="form"></div>' ) ;
cloneForm . append ( statBar ) ;
cloneForm . append ( infoBar ) ;
2010-11-01 14:06:53 +00:00
cloneForm . append ( '<div><label>Target node range:</label><input type="text" id="tgtNode" name="tgtNode" title="You must give a node or a node range. A node range must be given as: node1-node9 or node[1-9]."/></div>' ) ;
cloneForm . append ( '<div><label>Target user ID range:</label><input type="text" id="tgtUserId" name="tgtUserId" title="You must give a user ID or a user ID range. A user ID range must be given as: user1-user9 or user[1-9]."/></div>' ) ;
cloneForm . append ( '<div><label>Clone source:</label><input type="text" id="srcNode" name="srcNode" readonly="readonly" value="' + node + '" title="The source node to be cloned"/></div>' ) ;
cloneForm . append ( '<div><label>Hardware control point:</label><input type="text" id="newHcp" name="newHcp" readonly="readonly" value="' + hcp + '" title="The System z hardware control point (zHCP) responsible for managing the node(s). It must be the same as the source node."/></div>' ) ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Create group input
2010-07-15 22:57:48 +00:00
var group = $ ( '<div></div>' ) ;
var groupLabel = $ ( '<label for="group">Group:</label>' ) ;
2010-11-01 14:06:53 +00:00
var groupInput = $ ( '<input type="text" id="newGroup" name="newGroup" title="You must give the group where the new node(s) will be placed under."/>' ) ;
2010-07-27 19:50:01 +00:00
groupInput . one ( 'focus' , function ( ) {
2010-07-15 22:57:48 +00:00
var groupNames = $ . cookie ( 'Groups' ) ;
if ( groupNames ) {
2010-07-28 20:24:29 +00:00
// Turn on auto complete
2010-07-15 22:57:48 +00:00
$ ( this ) . autocomplete ( groupNames . split ( ',' ) ) ;
}
} ) ;
group . append ( groupLabel ) ;
group . append ( groupInput ) ;
cloneForm . append ( group ) ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Get list of disk pools
2010-07-15 22:57:48 +00:00
var temp = hcp . split ( '.' ) ;
var diskPools = $ . cookie ( temp [ 0 ] + 'DiskPools' ) ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Create disk pool input
2010-07-15 22:57:48 +00:00
var poolDiv = $ ( '<div></div>' ) ;
var poolLabel = $ ( '<label>Disk pool:</label>' ) ;
2010-11-01 14:06:53 +00:00
var poolInput = $ ( '<input type="text" id="diskPool" name="diskPool" title="You must give a disk pool. xCAT relies on DirMaint to allocate minidisks out of a pool of DASD volumes. These DASD volume pools are defined in the EXTENT CONTROL file."/>' ) . autocomplete ( diskPools . split ( ',' ) ) ;
2010-07-15 22:57:48 +00:00
poolDiv . append ( poolLabel ) ;
poolDiv . append ( poolInput ) ;
cloneForm . append ( poolDiv ) ;
2010-06-16 18:21:58 +00:00
2010-11-01 14:06:53 +00:00
cloneForm . append ( '<div><label>Disk password:</label><input type="password" id="diskPw" name="diskPw" title="The password that will be used for accessing the disk. This input is optional."/></div>' ) ;
2010-06-16 18:21:58 +00:00
2010-11-01 14:06:53 +00:00
// Generate tooltips
cloneForm . find ( 'div input[title]' ) . tooltip ( {
position : "center right" , // Place tooltip on the right edge
offset : [ - 2 , 10 ] , // A little tweaking of the position
effect : "fade" , // Use the built-in fadeIn/fadeOut effect
opacity : 0.7 // Custom opacity setting
} ) ;
2010-07-15 22:57:48 +00:00
/ * *
2010-07-28 20:24:29 +00:00
* Clone node
2010-07-15 22:57:48 +00:00
* /
var cloneBtn = createButton ( 'Clone' ) ;
2010-07-19 18:28:31 +00:00
cloneBtn . 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-19 18:28:31 +00:00
var ready = true ;
var errMsg = '' ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Check node name, userId, hardware control point, group, and password
2010-07-19 18:28:31 +00:00
var inputs = $ ( '#' + newTabId + ' input' ) ;
for ( var i = 0 ; i < inputs . length ; i ++ ) {
if ( ! inputs . eq ( i ) . val ( )
&& inputs . eq ( i ) . attr ( 'name' ) != 'diskPw'
&& inputs . eq ( i ) . attr ( 'name' ) != 'diskPool' ) {
inputs . eq ( i ) . css ( 'border' , 'solid #FF0000 1px' ) ;
ready = false ;
} else {
inputs . eq ( i ) . css ( 'border' , 'solid #BDBDBD 1px' ) ;
2010-07-15 22:57:48 +00:00
}
2010-07-19 18:28:31 +00:00
}
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Write error message
2010-07-19 18:28:31 +00:00
if ( ! ready ) {
2010-09-24 02:27:04 +00:00
errMsg = errMsg + 'You are missing some inputs.<br>' ;
2010-07-19 18:28:31 +00:00
}
// Get target node
var nodeRange = $ ( '#' + newTabId + ' input[name=tgtNode]' ) . val ( ) ;
// Get target user ID
var userIdRange = $ ( '#' + newTabId + ' input[name=tgtUserId]' ) . val ( ) ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Check node range and user ID range
2010-07-19 18:28:31 +00:00
if ( nodeRange . indexOf ( '-' ) > - 1 || userIdRange . indexOf ( '-' ) > - 1 ) {
if ( nodeRange . indexOf ( '-' ) < 0 || userIdRange . indexOf ( '-' ) < 0 ) {
2010-09-24 02:27:04 +00:00
errMsg = errMsg + 'A user ID range and node range needs to be given.<br>' ;
2010-07-19 18:28:31 +00:00
ready = false ;
} else {
var tmp = nodeRange . split ( '-' ) ;
// Get node base name
var nodeBase = tmp [ 0 ] . match ( /[a-zA-Z]+/ ) ;
2010-07-28 20:24:29 +00:00
// Get starting index
2010-07-19 18:28:31 +00:00
var nodeStart = parseInt ( tmp [ 0 ] . match ( /\d+/ ) ) ;
2010-07-28 20:24:29 +00:00
// Get ending index
2010-10-07 15:38:03 +00:00
var nodeEnd = parseInt ( tmp [ 1 ] . match ( /\d+/ ) ) ;
2010-07-19 18:28:31 +00:00
tmp = userIdRange . split ( '-' ) ;
// Get user ID base name
var userIdBase = tmp [ 0 ] . match ( /[a-zA-Z]+/ ) ;
2010-07-28 20:24:29 +00:00
// Get starting index
2010-07-19 18:28:31 +00:00
var userIdStart = parseInt ( tmp [ 0 ] . match ( /\d+/ ) ) ;
2010-07-28 20:24:29 +00:00
// Get ending index
2010-10-07 15:38:03 +00:00
var userIdEnd = parseInt ( tmp [ 1 ] . match ( /\d+/ ) ) ;
2010-07-19 18:28:31 +00:00
2010-07-28 20:24:29 +00:00
// If starting and ending index do not match
2010-07-19 18:28:31 +00:00
if ( ! ( nodeStart == userIdStart ) || ! ( nodeEnd == userIdEnd ) ) {
// Not ready to provision
2010-09-24 02:27:04 +00:00
errMsg = errMsg + 'The node range and user ID range does not match.<br>' ;
2010-07-15 22:57:48 +00:00
ready = false ;
}
}
2010-07-19 18:28:31 +00:00
}
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Get source node, hardware control point, group, disk pool, and disk password
2010-07-19 18:28:31 +00:00
var srcNode = $ ( '#' + newTabId + ' input[name=srcNode]' ) . val ( ) ;
2010-07-28 20:24:29 +00:00
var hcp = $ ( '#' + newTabId + ' input[name=newHcp]' ) . val ( ) ;
2010-07-19 18:28:31 +00:00
var group = $ ( '#' + newTabId + ' input[name=newGroup]' ) . val ( ) ;
var diskPool = $ ( '#' + newTabId + ' input[name=diskPool]' ) . val ( ) ;
var diskPw = $ ( '#' + newTabId + ' input[name=diskPw]' ) . val ( ) ;
2010-06-16 18:21:58 +00:00
2010-07-19 18:28:31 +00:00
// If a value is given for every input
if ( ready ) {
// Disable all inputs
2010-07-28 20:24:29 +00:00
var inputs = $ ( '#' + newTabId + ' input' ) ;
inputs . attr ( 'disabled' , 'disabled' ) ;
2010-07-19 18:28:31 +00:00
// If a node range is given
if ( nodeRange . indexOf ( '-' ) > - 1 ) {
var tmp = nodeRange . split ( '-' ) ;
// Get node base name
var nodeBase = tmp [ 0 ] . match ( /[a-zA-Z]+/ ) ;
2010-07-28 20:24:29 +00:00
// Get starting index
2010-07-19 18:28:31 +00:00
var nodeStart = parseInt ( tmp [ 0 ] . match ( /\d+/ ) ) ;
2010-07-28 20:24:29 +00:00
// Get ending index
2010-10-07 15:38:03 +00:00
var nodeEnd = parseInt ( tmp [ 1 ] . match ( /\d+/ ) ) ;
2010-07-19 18:28:31 +00:00
tmp = userIdRange . split ( '-' ) ;
// Get user ID base name
var userIdBase = tmp [ 0 ] . match ( /[a-zA-Z]+/ ) ;
2010-07-28 20:24:29 +00:00
// Get starting index
2010-07-19 18:28:31 +00:00
var userIdStart = parseInt ( tmp [ 0 ] . match ( /\d+/ ) ) ;
2010-07-28 20:24:29 +00:00
// Get ending index
2010-10-07 15:38:03 +00:00
var userIdEnd = parseInt ( tmp [ 1 ] . match ( /\d+/ ) ) ;
2010-07-19 18:28:31 +00:00
2010-07-28 20:24:29 +00:00
// Loop through each node in the node range
2010-07-19 18:28:31 +00:00
for ( var i = nodeStart ; i <= nodeEnd ; i ++ ) {
var node = nodeBase + i . toString ( ) ;
var userId = userIdBase + i . toString ( ) ;
var inst = i + '/' + nodeEnd ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
/ * *
2010-07-19 18:28:31 +00:00
* ( 1 ) Define node
2010-07-15 22:57:48 +00:00
* /
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodeadd' ,
tgt : '' ,
2010-07-19 18:28:31 +00:00
args : node + ';zvm.hcp=' + hcp
+ ';zvm.userid=' + userId
2010-07-28 20:24:29 +00:00
+ ';nodehm.mgt=zvm'
+ ';groups=' + group ,
msg : 'cmd=nodeadd;inst=' + inst
+ ';out=' + statBarId
+ ';node=' + node
2010-06-16 18:21:58 +00:00
} ,
2010-07-28 20:24:29 +00:00
success : updateZCloneStatus
2010-07-15 22:57:48 +00:00
} ) ;
}
2010-07-28 20:24:29 +00:00
} else {
2010-07-19 18:28:31 +00:00
/ * *
* ( 1 ) Define node
* /
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodeadd' ,
tgt : '' ,
args : nodeRange + ';zvm.hcp=' + hcp
+ ';zvm.userid=' + userIdRange
2010-07-28 20:24:29 +00:00
+ ';nodehm.mgt=zvm'
+ ';groups=' + group ,
2010-07-19 18:28:31 +00:00
msg : 'cmd=nodeadd;inst=1/1;out=' + statBarId
+ ';node=' + nodeRange
} ,
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
success : updateZCloneStatus
2010-06-16 18:21:58 +00:00
} ) ;
2010-07-15 22:57:48 +00:00
}
2010-07-19 18:28:31 +00:00
// Create loader
var loader = createLoader ( '' ) ;
$ ( '#' + statBarId ) . append ( loader ) ;
$ ( '#' + statBarId ) . show ( ) ;
2010-07-28 20:24:29 +00:00
// Disable clone button
2010-09-22 20:18:21 +00:00
$ ( this ) . attr ( 'disabled' , 'true' ) ;
2010-07-19 18:28:31 +00:00
} else {
2010-09-24 02:27:04 +00:00
// Show warning message
var warn = createWarnBar ( errMsg ) ;
warn . prependTo ( $ ( this ) . parent ( ) . parent ( ) ) ;
2010-07-19 18:28:31 +00:00
}
} ) ;
2010-07-15 22:57:48 +00:00
cloneForm . append ( cloneBtn ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Add clone tab
2010-08-03 14:58:08 +00:00
tab . add ( newTabId , 'Clone' , cloneForm , true ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
tab . select ( newTabId ) ;
2010-07-22 19:56:09 +00:00
} ;
2010-06-16 18:21:58 +00:00
/ * *
2010-07-15 22:57:48 +00:00
* Load node inventory
2010-06-16 18:21:58 +00:00
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
2010-07-23 18:47:54 +00:00
zvmPlugin . prototype . loadInventory = function ( data ) {
2010-07-15 22:57:48 +00:00
var args = data . msg . split ( ',' ) ;
2010-06-16 18:21:58 +00:00
// Get tab ID
2010-07-15 22:57:48 +00:00
var tabId = args [ 0 ] . replace ( 'out=' , '' ) ;
2010-06-16 18:21:58 +00:00
// Get node
var node = args [ 1 ] . replace ( 'node=' , '' ) ;
2010-07-15 22:57:48 +00:00
// Get node inventory
var inv = data . rsp [ 0 ] . split ( node + ':' ) ;
2010-07-29 20:22:09 +00:00
2010-06-16 18:21:58 +00:00
// Remove loader
2010-07-26 07:25:27 +00:00
var loaderId = tabId + 'TabLoader' ;
2010-06-16 18:21:58 +00:00
$ ( '#' + loaderId ) . remove ( ) ;
2010-07-15 22:57:48 +00:00
// Create status bar
2010-07-19 18:28:31 +00:00
var statBarId = node + 'StatusBar' ;
var statBar = createStatusBar ( statBarId ) ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Add loader to status bar and hide it
2010-07-15 22:57:48 +00:00
loaderId = node + 'StatusBarLoader' ;
var loader = createLoader ( loaderId ) ;
2010-07-19 18:28:31 +00:00
statBar . append ( loader ) ;
2010-07-15 22:57:48 +00:00
loader . hide ( ) ;
2010-07-19 18:28:31 +00:00
statBar . hide ( ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create array of property keys
2010-07-28 20:24:29 +00:00
var keys = new Array ( 'userId' , 'host' , 'os' , 'arch' , 'hcp' , 'priv' , 'memory' , 'proc' , 'disk' , 'nic' ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create hash table for property names
var attrNames = new Object ( ) ;
attrNames [ 'userId' ] = 'z/VM UserID:' ;
attrNames [ 'host' ] = 'z/VM Host:' ;
attrNames [ 'os' ] = 'Operating System:' ;
attrNames [ 'arch' ] = 'Architecture:' ;
attrNames [ 'hcp' ] = 'HCP:' ;
attrNames [ 'priv' ] = 'Privileges:' ;
attrNames [ 'memory' ] = 'Total Memory:' ;
attrNames [ 'proc' ] = 'Processors:' ;
attrNames [ 'disk' ] = 'Disks:' ;
attrNames [ 'nic' ] = 'NICs:' ;
// Create hash table for node attributes
2010-08-03 20:44:26 +00:00
var attrs = getAttrs ( keys , attrNames , inv ) ;
2010-07-29 20:22:09 +00:00
2010-07-15 22:57:48 +00:00
// Create division to hold user entry
var ueDivId = node + 'UserEntry' ;
var ueDiv = $ ( '<div class="userEntry" id="' + ueDivId + '"></div>' ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create division to hold inventory
var invDivId = node + 'Inventory' ;
var invDiv = $ ( '<div class="inventory" id="' + invDivId + '"></div>' ) ;
2010-06-16 18:21:58 +00:00
/ * *
2010-07-15 22:57:48 +00:00
* Show user entry
2010-06-16 18:21:58 +00:00
* /
2010-07-15 22:57:48 +00:00
var toggleLinkId = node + 'ToggleLink' ;
2010-09-28 20:24:31 +00:00
var toggleLink = $ ( '<a id="' + toggleLinkId + '">Show directory entry</a>' ) ;
2010-07-15 22:57:48 +00:00
toggleLink . one ( 'click' , function ( event ) {
// Toggle inventory division
$ ( '#' + invDivId ) . toggle ( ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create loader
2010-07-19 18:28:31 +00:00
var loader = createLoader ( node + 'TabLoader' ) ;
2010-07-15 22:57:48 +00:00
loader = $ ( '<center></center>' ) . append ( loader ) ;
ueDiv . append ( loader ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Get user entry
var msg = 'out=' + ueDivId + ';node=' + node ;
2010-06-16 18:21:58 +00:00
$ . ajax ( {
2010-07-15 22:57:48 +00:00
url : 'lib/cmd.php' ,
2010-06-16 18:21:58 +00:00
dataType : 'json' ,
data : {
2010-07-15 22:57:48 +00:00
cmd : 'lsvm' ,
2010-06-16 18:21:58 +00:00
tgt : node ,
2010-07-15 22:57:48 +00:00
args : '' ,
msg : msg
2010-06-16 18:21:58 +00:00
} ,
2010-07-15 22:57:48 +00:00
success : loadUserEntry
2010-06-16 18:21:58 +00:00
} ) ;
2010-07-15 22:57:48 +00:00
// Change text
$ ( this ) . text ( 'Show inventory' ) ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Disable toggle link
2010-06-16 18:21:58 +00:00
$ ( this ) . unbind ( event ) ;
} ) ;
2010-07-28 20:24:29 +00:00
// Align toggle link to the right
2010-07-15 22:57:48 +00:00
var toggleLnkDiv = $ ( '<div class="toggle"></div>' ) . css ( {
'text-align' : 'right'
2010-06-16 18:21:58 +00:00
} ) ;
2010-07-15 22:57:48 +00:00
toggleLnkDiv . append ( toggleLink ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
/ * *
2010-07-28 20:24:29 +00:00
* General info section
2010-07-15 22:57:48 +00:00
* /
var fieldSet = $ ( '<fieldset></fieldset>' ) ;
var legend = $ ( '<legend>General</legend>' ) ;
fieldSet . append ( legend ) ;
var oList = $ ( '<ol></ol>' ) ;
var item , label , input , args ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Loop through each property
for ( var k = 0 ; k < 5 ; k ++ ) {
// Create a list item for each property
item = $ ( '<li></li>' ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create a label - Property name
label = $ ( '<label>' + attrNames [ keys [ k ] ] + '</label>' ) ;
item . append ( label ) ;
for ( var l = 0 ; l < attrs [ keys [ k ] ] . length ; l ++ ) {
// Create a input - Property value(s)
// Handle each property uniquely
item . append ( attrs [ keys [ k ] ] [ l ] ) ;
}
oList . append ( item ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
// Append to inventory form
fieldSet . append ( oList ) ;
invDiv . append ( fieldSet ) ;
2010-06-16 18:21:58 +00:00
/ * *
2010-07-28 20:24:29 +00:00
* Hardware info section
2010-06-16 18:21:58 +00:00
* /
2010-07-15 22:57:48 +00:00
var hwList , hwItem ;
fieldSet = $ ( '<fieldset></fieldset>' ) ;
legend = $ ( '<legend>Hardware</legent>' ) ;
fieldSet . append ( legend ) ;
oList = $ ( '<ol></ol>' ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Loop through each property
var label ;
for ( k = 5 ; k < keys . length ; k ++ ) {
// Create a list item
item = $ ( '<li></li>' ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create a list to hold the property value(s)
hwList = $ ( '<ul></ul>' ) ;
hwItem = $ ( '<li></li>' ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
/ * *
2010-07-28 20:24:29 +00:00
* Privilege section
2010-07-15 22:57:48 +00:00
* /
if ( keys [ k ] == 'priv' ) {
// Create a label - Property name
label = $ ( '<label>' + attrNames [ keys [ k ] ] . replace ( ':' , '' ) + '</label>' ) ;
item . append ( label ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Loop through each line
for ( l = 0 ; l < attrs [ keys [ k ] ] . length ; l ++ ) {
// Create a new list item for each line
hwItem = $ ( '<li></li>' ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Determine privilege
args = attrs [ keys [ k ] ] [ l ] . split ( ' ' ) ;
if ( args [ 0 ] == 'Directory:' ) {
label = $ ( '<label>' + args [ 0 ] + '</label>' ) ;
hwItem . append ( label ) ;
hwItem . append ( args [ 1 ] ) ;
} else if ( args [ 0 ] == 'Currently:' ) {
label = $ ( '<label>' + args [ 0 ] + '</label>' ) ;
hwItem . append ( label ) ;
hwItem . append ( args [ 1 ] ) ;
}
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
hwList . append ( hwItem ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
item . append ( hwList ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
/ * *
2010-07-28 20:24:29 +00:00
* Memory section
2010-07-15 22:57:48 +00:00
* /
else if ( keys [ k ] == 'memory' ) {
// Create a label - Property name
label = $ ( '<label>' + attrNames [ keys [ k ] ] . replace ( ':' , '' ) + '</label>' ) ;
item . append ( label ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Loop through each value line
for ( l = 0 ; l < attrs [ keys [ k ] ] . length ; l ++ ) {
// Create a new list item for each line
hwItem = $ ( '<li></li>' ) ;
hwItem . append ( attrs [ keys [ k ] ] [ l ] ) ;
hwList . append ( hwItem ) ;
}
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
item . append ( hwList ) ;
}
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
/ * *
2010-07-28 20:24:29 +00:00
* Processor section
2010-07-15 22:57:48 +00:00
* /
else if ( keys [ k ] == 'proc' ) {
// Create a label - Property name
label = $ ( '<label>' + attrNames [ keys [ k ] ] . replace ( ':' , '' ) + '</label>' ) ;
item . append ( label ) ;
// Create a table to hold processor data
var procTable = $ ( '<table></table>' ) ;
var procBody = $ ( '<tbody></tbody>' ) ;
var procFooter = $ ( '<tfoot></tfoot>' ) ;
// Table columns - Type, Address, ID, Base, Dedicated, and Affinity
var procTabRow = $ ( '<thead> <th>Type</th> <th>Address</th> <th>ID</th> <th>Base</th> <th>Dedicated</th> <th>Affinity</th> </thead>' ) ;
procTable . append ( procTabRow ) ;
var procType , procAddr , procId , procAff ;
2010-07-19 18:28:31 +00:00
/ * *
* Remove processor
* /
var contextMenu = [ {
2010-07-15 22:57:48 +00:00
'Remove' : function ( menuItem , menu ) {
2010-09-24 03:06:44 +00:00
var addr = $ ( this ) . text ( ) ;
// Open dialog to confirm
2010-09-24 12:27:54 +00:00
var confirmDialog = $ ( '<div><p>Are you sure you want to remove this processor?</p></div>' ) ;
2010-09-24 03:06:44 +00:00
confirmDialog . dialog ( {
modal : true ,
width : 300 ,
buttons : {
"Ok" : function ( ) {
removeProcessor ( node , addr ) ;
$ ( this ) . dialog ( "close" ) ;
2010-10-07 21:01:14 +00:00
} ,
"Cancel" : function ( ) {
$ ( this ) . dialog ( "close" ) ;
2010-09-24 03:06:44 +00:00
}
}
} ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-19 18:28:31 +00:00
} ] ;
2010-07-15 22:57:48 +00:00
// Loop through each processor
var closeBtn ;
var n , temp ;
var procType , procAddr , procLink ;
for ( l = 0 ; l < attrs [ keys [ k ] ] . length ; l ++ ) {
2010-07-29 20:22:09 +00:00
if ( attrs [ keys [ k ] ] [ l ] ) {
args = attrs [ keys [ k ] ] [ l ] . split ( ' ' ) ;
// Get processor type, address, ID, and affinity
n = 3 ;
temp = args [ args . length - n ] ;
while ( ! jQuery . trim ( temp ) ) {
n = n + 1 ;
temp = args [ args . length - n ] ;
}
procType = $ ( '<td>' + temp + '</td>' ) ;
procAddr = $ ( '<td></td>' ) ;
2010-09-28 20:24:31 +00:00
procLink = $ ( '<a>' + args [ 1 ] + '</a>' ) ;
2010-07-29 20:22:09 +00:00
// Append context menu to link
procLink . contextMenu ( contextMenu , {
theme : 'vista'
} ) ;
procAddr . append ( procLink ) ;
procId = $ ( '<td>' + args [ 5 ] + '</td>' ) ;
procAff = $ ( '<td>' + args [ args . length - 1 ] + '</td>' ) ;
// Base processor
if ( args [ 6 ] == '(BASE)' ) {
baseProc = $ ( '<td>' + true + '</td>' ) ;
} else {
baseProc = $ ( '<td>' + false + '</td>' ) ;
}
// Dedicated processor
if ( args [ args . length - 3 ] == 'DEDICATED' ) {
dedicatedProc = $ ( '<td>' + true + '</td>' ) ;
} else {
dedicatedProc = $ ( '<td>' + false + '</td>' ) ;
}
// Create a new row for each processor
procTabRow = $ ( '<tr></tr>' ) ;
procTabRow . append ( procType ) ;
procTabRow . append ( procAddr ) ;
procTabRow . append ( procId ) ;
procTabRow . append ( baseProc ) ;
procTabRow . append ( dedicatedProc ) ;
procTabRow . append ( procAff ) ;
procBody . append ( procTabRow ) ;
2010-07-15 22:57:48 +00:00
}
2010-06-16 18:21:58 +00:00
}
2010-07-29 20:22:09 +00:00
2010-07-15 22:57:48 +00:00
procTable . append ( procBody ) ;
/ * *
* Add processor
* /
2010-09-28 20:24:31 +00:00
var addProcLink = $ ( '<a>Add temporary processor</a>' ) ;
2010-07-19 18:28:31 +00:00
addProcLink . bind ( 'click' , function ( event ) {
2010-09-24 02:27:04 +00:00
openAddProcDialog ( node ) ;
2010-09-23 20:43:10 +00:00
} ) ;
2010-07-15 22:57:48 +00:00
procFooter . append ( addProcLink ) ;
procTable . append ( procFooter ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
item . append ( procTable ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
/ * *
2010-07-28 20:24:29 +00:00
* Disk section
2010-07-15 22:57:48 +00:00
* /
else if ( keys [ k ] == 'disk' ) {
// Create a label - Property name
label = $ ( '<label>' + attrNames [ keys [ k ] ] . replace ( ':' , '' ) + '</label>' ) ;
item . append ( label ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create a table to hold disk (DASD) data
var dasdTable = $ ( '<table></table>' ) ;
var dasdBody = $ ( '<tbody></tbody>' ) ;
var dasdFooter = $ ( '<tfoot></tfoot>' ) ;
2010-07-19 18:28:31 +00:00
/ * *
* Remove disk
* /
contextMenu = [ {
2010-07-15 22:57:48 +00:00
'Remove' : function ( menuItem , menu ) {
2010-09-24 03:06:44 +00:00
var addr = $ ( this ) . text ( ) ;
// Open dialog to confirm
2010-09-24 12:27:54 +00:00
var confirmDialog = $ ( '<div><p>Are you sure you want to remove this disk?</p></div>' ) ;
2010-09-24 03:06:44 +00:00
confirmDialog . dialog ( {
modal : true ,
width : 300 ,
buttons : {
"Ok" : function ( ) {
removeDisk ( node , addr ) ;
$ ( this ) . dialog ( "close" ) ;
2010-10-07 21:01:14 +00:00
} ,
"Cancel" : function ( ) {
$ ( this ) . dialog ( "close" ) ;
2010-09-24 03:06:44 +00:00
}
}
} ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-19 18:28:31 +00:00
} ] ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Table columns - Virtual Device, Type, VolID, Type of Access, and Size
2010-07-15 22:57:48 +00:00
var dasdTabRow = $ ( '<thead> <th>Virtual Device #</th> <th>Type</th> <th>VolID</th> <th>Type of Access</th> <th>Size</th> </thead>' ) ;
dasdTable . append ( dasdTabRow ) ;
var dasdVDev , dasdType , dasdVolId , dasdAccess , dasdSize ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Loop through each DASD
for ( l = 0 ; l < attrs [ keys [ k ] ] . length ; l ++ ) {
2010-07-29 20:22:09 +00:00
if ( attrs [ keys [ k ] ] [ l ] ) {
args = attrs [ keys [ k ] ] [ l ] . split ( ' ' ) ;
2010-06-16 18:21:58 +00:00
2010-07-29 20:22:09 +00:00
// Get DASD virtual device, type, volume ID, access, and size
dasdVDev = $ ( '<td></td>' ) ;
2010-09-28 20:24:31 +00:00
dasdLink = $ ( '<a>' + args [ 1 ] + '</a>' ) ;
2010-07-29 20:22:09 +00:00
// Append context menu to link
dasdLink . contextMenu ( contextMenu , {
theme : 'vista'
} ) ;
dasdVDev . append ( dasdLink ) ;
dasdType = $ ( '<td>' + args [ 2 ] + '</td>' ) ;
dasdVolId = $ ( '<td>' + args [ 3 ] + '</td>' ) ;
dasdAccess = $ ( '<td>' + args [ 4 ] + '</td>' ) ;
2010-10-08 03:03:42 +00:00
dasdSize = $ ( '<td>' + args [ args . length - 9 ] + ' ' + args [ args . length - 8 ] + '</td>' ) ;
2010-07-29 20:22:09 +00:00
// Create a new row for each DASD
dasdTabRow = $ ( '<tr></tr>' ) ;
dasdTabRow . append ( dasdVDev ) ;
dasdTabRow . append ( dasdType ) ;
dasdTabRow . append ( dasdVolId ) ;
dasdTabRow . append ( dasdAccess ) ;
dasdTabRow . append ( dasdSize ) ;
dasdBody . append ( dasdTabRow ) ;
}
2010-07-15 22:57:48 +00:00
}
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
dasdTable . append ( dasdBody ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
/ * *
2010-07-19 18:28:31 +00:00
* Add disk
2010-07-15 22:57:48 +00:00
* /
2010-09-28 20:24:31 +00:00
var addDasdLink = $ ( '<a>Add disk</a>' ) ;
2010-07-19 18:28:31 +00:00
addDasdLink . bind ( 'click' , function ( event ) {
2010-09-23 20:43:10 +00:00
var hcp = attrs [ 'hcp' ] [ 0 ] . split ( '.' ) ;
2010-09-24 02:27:04 +00:00
openAddDiskDialog ( node , hcp [ 0 ] ) ;
2010-07-19 18:28:31 +00:00
} ) ;
2010-07-15 22:57:48 +00:00
dasdFooter . append ( addDasdLink ) ;
dasdTable . append ( dasdFooter ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
item . append ( dasdTable ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
/ * *
2010-07-28 20:24:29 +00:00
* NIC section
2010-07-15 22:57:48 +00:00
* /
else if ( keys [ k ] == 'nic' ) {
// Create a label - Property name
label = $ ( '<label>' + attrNames [ keys [ k ] ] . replace ( ':' , '' ) + '</label>' ) ;
item . append ( label ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create a table to hold NIC data
var nicTable = $ ( '<table></table>' ) ;
var nicBody = $ ( '<tbody></tbody>' ) ;
var nicFooter = $ ( '<tfoot></tfoot>' ) ;
2010-06-16 18:21:58 +00:00
2010-07-19 18:28:31 +00:00
/ * *
* Remove NIC
2010-07-28 20:24:29 +00:00
* /
contextMenu = [ {
2010-07-15 22:57:48 +00:00
'Remove' : function ( menuItem , menu ) {
2010-09-24 03:06:44 +00:00
var addr = $ ( this ) . text ( ) ;
// Open dialog to confirm
2010-09-24 12:27:54 +00:00
var confirmDialog = $ ( '<div><p>Are you sure you want to remove this NIC?</p></div>' ) ;
2010-09-24 03:06:44 +00:00
confirmDialog . dialog ( {
modal : true ,
width : 300 ,
buttons : {
"Ok" : function ( ) {
removeNic ( node , addr ) ;
$ ( this ) . dialog ( "close" ) ;
2010-10-07 21:01:14 +00:00
} ,
"Cancel" : function ( ) {
$ ( this ) . dialog ( "close" ) ;
2010-09-24 03:06:44 +00:00
}
}
} ) ;
2010-07-15 22:57:48 +00:00
}
} ] ;
2010-06-16 18:21:58 +00:00
2010-07-28 20:24:29 +00:00
// Table columns - Virtual device, Adapter Type, Port Name, # of Devices, MAC Address, and LAN Name
2010-07-15 22:57:48 +00:00
var nicTabRow = $ ( '<th>Virtual Device #</th> <th>Adapter Type</th> <th>Port Name</th> <th># of Devices</th> <th>LAN Name</th>' ) ;
nicTable . append ( nicTabRow ) ;
var nicVDev , nicType , nicPortName , nicNumOfDevs , nicMacAddr , nicLanName ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Loop through each NIC (Data contained in 2 lines)
for ( l = 0 ; l < attrs [ keys [ k ] ] . length ; l = l + 2 ) {
2010-07-29 20:22:09 +00:00
if ( attrs [ keys [ k ] ] [ l ] ) {
args = attrs [ keys [ k ] ] [ l ] . split ( ' ' ) ;
// Get NIC virtual device, type, port name, and number of devices
nicVDev = $ ( '<td></td>' ) ;
2010-09-28 20:24:31 +00:00
nicLink = $ ( '<a>' + args [ 1 ] + '</a>' ) ;
2010-07-29 20:22:09 +00:00
// Append context menu to link
nicLink . contextMenu ( contextMenu , {
theme : 'vista'
} ) ;
nicVDev . append ( nicLink ) ;
nicType = $ ( '<td>' + args [ 3 ] + '</td>' ) ;
nicPortName = $ ( '<td>' + args [ 10 ] + '</td>' ) ;
nicNumOfDevs = $ ( '<td>' + args [ args . length - 1 ] + '</td>' ) ;
args = attrs [ keys [ k ] ] [ l + 1 ] . split ( ' ' ) ;
nicLanName = $ ( '<td>' + args [ args . length - 2 ] + ' '
+ args [ args . length - 1 ] + '</td>' ) ;
// Create a new row for each DASD
nicTabRow = $ ( '<tr></tr>' ) ;
nicTabRow . append ( nicVDev ) ;
nicTabRow . append ( nicType ) ;
nicTabRow . append ( nicPortName ) ;
nicTabRow . append ( nicNumOfDevs ) ;
nicTabRow . append ( nicLanName ) ;
nicBody . append ( nicTabRow ) ;
}
2010-07-15 22:57:48 +00:00
}
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
nicTable . append ( nicBody ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
/ * *
* Add NIC
* /
2010-09-28 20:24:31 +00:00
var addNicLink = $ ( '<a>Add NIC</a>' ) ;
2010-07-19 18:28:31 +00:00
addNicLink . bind ( 'click' , function ( event ) {
2010-09-23 20:43:10 +00:00
var hcp = attrs [ 'hcp' ] [ 0 ] . split ( '.' ) ;
2010-09-24 02:27:04 +00:00
openAddNicDialog ( node , hcp [ 0 ] ) ;
2010-07-19 18:28:31 +00:00
} ) ;
2010-07-15 22:57:48 +00:00
nicFooter . append ( addNicLink ) ;
nicTable . append ( nicFooter ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
item . append ( nicTable ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
oList . append ( item ) ;
2010-06-16 18:21:58 +00:00
}
2010-07-15 22:57:48 +00:00
// Append inventory to division
fieldSet . append ( oList ) ;
invDiv . append ( fieldSet ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Append to tab
2010-07-19 18:28:31 +00:00
$ ( '#' + tabId ) . append ( statBar ) ;
2010-07-15 22:57:48 +00:00
$ ( '#' + tabId ) . append ( toggleLnkDiv ) ;
$ ( '#' + tabId ) . append ( ueDiv ) ;
$ ( '#' + tabId ) . append ( invDiv ) ;
2010-07-22 19:56:09 +00:00
} ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
/ * *
2010-07-19 18:28:31 +00:00
* Load provision page
2010-07-15 22:57:48 +00:00
*
* @ param tabId
* The provision tab ID
* @ return Nothing
* /
2010-07-23 18:47:54 +00:00
zvmPlugin . prototype . loadProvisionPage = function ( tabId ) {
2010-07-27 19:50:01 +00:00
// Get OS image names
2010-07-15 22:57:48 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'tabdump' ,
tgt : '' ,
args : 'osimage' ,
msg : ''
} ,
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
success : setOSImageCookies
} ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Get groups
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'extnoderange' ,
tgt : '/.*' ,
args : 'subgroups' ,
msg : ''
} ,
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
success : setGroupsCookies
} ) ;
2010-06-16 18:21:58 +00:00
2010-07-27 19:50:01 +00:00
// Error message string
var errMsg ;
2010-07-28 20:24:29 +00:00
// Get provision tab instance
2010-07-15 22:57:48 +00:00
var inst = tabId . replace ( 'zvmProvisionTab' , '' ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create provision form
var provForm = $ ( '<div class="form"></div>' ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create status bar
2010-07-27 19:50:01 +00:00
var statBarId = 'zProvisionStatBar' + inst ;
var statBar = createStatusBar ( statBarId ) ;
2010-07-15 22:57:48 +00:00
statBar . hide ( ) ;
provForm . append ( statBar ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create loader
var loader = createLoader ( 'zProvisionLoader' + inst ) ;
loader . hide ( ) ;
statBar . append ( loader ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Create info bar
var infoBar = createInfoBar ( 'Provision a zVM node' ) ;
provForm . append ( infoBar ) ;
2010-06-16 18:21:58 +00:00
2010-07-15 22:57:48 +00:00
// Append to provision tab
$ ( '#' + tabId ) . append ( provForm ) ;
2010-06-16 18:21:58 +00:00
2010-07-27 19:50:01 +00:00
// Create provision type drop down
2010-07-26 23:52:10 +00:00
var provType = $ ( '<div></div>' ) ;
2010-07-27 19:50:01 +00:00
var typeLabel = $ ( '<label>Provision:</label>' ) ;
var typeSelect = $ ( '<select></select>' ) ;
var provNewNode = $ ( '<option value="new">New node</option>' ) ;
var provExistNode = $ ( '<option value="existing">Existing node</option>' ) ;
typeSelect . append ( provNewNode ) ;
typeSelect . append ( provExistNode ) ;
provType . append ( typeLabel ) ;
provType . append ( typeSelect ) ;
2010-07-26 23:52:10 +00:00
provForm . append ( provType ) ;
2010-07-27 19:50:01 +00:00
/ * *
* Create provision new node division
2010-07-26 23:52:10 +00:00
* /
2010-07-27 19:50:01 +00:00
var provNew = createZProvisionNew ( inst ) ;
2010-07-26 23:52:10 +00:00
provForm . append ( provNew ) ;
2010-07-15 22:57:48 +00:00
/ * *
2010-07-27 19:50:01 +00:00
* Create provision existing node division
2010-07-15 22:57:48 +00:00
* /
2010-07-27 19:50:01 +00:00
var provExisting = createZProvisionExisting ( inst ) ;
2010-07-26 23:52:10 +00:00
provForm . append ( provExisting ) ;
2010-07-27 19:50:01 +00:00
// Toggle provision new/existing on select
typeSelect . change ( function ( ) {
2010-07-26 23:52:10 +00:00
var selected = $ ( this ) . val ( ) ;
if ( selected == 'new' ) {
provNew . toggle ( ) ;
provExisting . toggle ( ) ;
} else {
provNew . toggle ( ) ;
provExisting . toggle ( ) ;
}
} ) ;
2010-07-22 19:56:09 +00:00
} ;
2010-07-15 23:22:13 +00:00
/ * *
* Load the resources
*
* @ return Nothing
* /
2010-07-23 18:47:54 +00:00
zvmPlugin . prototype . loadResources = function ( ) {
2010-07-15 23:22:13 +00:00
// Reset resource table
setDiskDataTable ( '' ) ;
setNetworkDataTable ( '' ) ;
// Get hardware control points
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodels' ,
tgt : 'mgt==zvm' ,
args : 'zvm.hcp' ,
msg : ''
} ,
success : getZResources
} ) ;
2010-09-22 16:52:41 +00:00
} ;
/ * *
2010-09-24 02:27:04 +00:00
* Add node range
2010-09-22 16:52:41 +00:00
*
* @ return Nothing
* /
2010-09-23 20:43:10 +00:00
zvmPlugin . prototype . addNode = function ( ) {
2010-09-24 02:27:04 +00:00
// Create form to add node range
2010-09-23 20:43:10 +00:00
var addNodeForm = $ ( '<div class="form"></div>' ) ;
2010-09-24 02:27:04 +00:00
var info = createInfoBar ( 'Add a node range' ) ;
addNodeForm . append ( info ) ;
2010-09-23 20:43:10 +00:00
addNodeForm . append ( '<div><label for="node">Node range:</label><input type="text" id="node" name="node"/></div>' ) ;
addNodeForm . append ( '<div><label for="userId">User ID range:</label><input type="text" id="userId" name="userId"/></div>' ) ;
addNodeForm . append ( '<div><label for="hcp">Hardware control point:</label><input type="text" id="hcp" name="hcp"/></div>' ) ;
addNodeForm . append ( '<div><label for="group">Group:</label><input type="text" id="group" name="group"/></div>' ) ;
2010-11-01 14:06:53 +00:00
2010-09-24 02:27:04 +00:00
// Open form as a dialog
2010-09-23 20:43:10 +00:00
addNodeForm . dialog ( {
modal : true ,
width : 400 ,
buttons : {
2010-10-07 21:01:14 +00:00
"Ok" : function ( ) {
2010-09-23 20:43:10 +00:00
// Remove any warning messages
$ ( this ) . find ( '.ui-state-error' ) . remove ( ) ;
// Get inputs
var nodeRange = $ ( this ) . find ( 'input[name=node]' ) . val ( ) ;
var userIdRange = $ ( this ) . find ( 'input[name=userId]' ) . val ( ) ;
var group = $ ( this ) . find ( 'input[name=group]' ) . val ( ) ;
var hcp = $ ( this ) . find ( 'input[name=hcp]' ) . val ( ) ;
2010-09-24 02:27:04 +00:00
// Show warning message if inputs are not complete
2010-09-23 20:43:10 +00:00
if ( ! nodeRange || ! userIdRange || ! group || ! hcp ) {
2010-09-24 12:30:25 +00:00
var warn = createWarnBar ( 'You are missing inputs.' ) ;
2010-09-23 20:43:10 +00:00
warn . prependTo ( $ ( this ) ) ;
} else {
// Check node range and user ID range
2010-10-07 15:38:03 +00:00
// Range can be given as gpok10-gpok20, gpok[10-20], or gpok10+10
2010-09-23 20:43:10 +00:00
var errMsg = '' ;
var ready = true ;
if ( nodeRange . indexOf ( '-' ) > - 1 || userIdRange . indexOf ( '-' ) > - 1 ) {
if ( nodeRange . indexOf ( '-' ) < 0 || userIdRange . indexOf ( '-' ) < 0 ) {
errMsg = errMsg + 'A user ID range and node range needs to be given. ' ;
ready = false ;
} else {
var tmp = nodeRange . split ( '-' ) ;
2010-09-22 16:52:41 +00:00
2010-09-23 20:43:10 +00:00
// Get node base name
var nodeBase = tmp [ 0 ] . match ( /[a-zA-Z]+/ ) ;
// Get starting index
var nodeStart = parseInt ( tmp [ 0 ] . match ( /\d+/ ) ) ;
// Get ending index
2010-10-07 15:38:03 +00:00
var nodeEnd = parseInt ( tmp [ 1 ] . match ( /\d+/ ) ) ;
2010-09-22 16:52:41 +00:00
2010-09-23 20:43:10 +00:00
tmp = userIdRange . split ( '-' ) ;
2010-09-22 16:52:41 +00:00
2010-09-23 20:43:10 +00:00
// Get user ID base name
var userIdBase = tmp [ 0 ] . match ( /[a-zA-Z]+/ ) ;
// Get starting index
var userIdStart = parseInt ( tmp [ 0 ] . match ( /\d+/ ) ) ;
// Get ending index
2010-10-07 15:38:03 +00:00
var userIdEnd = parseInt ( tmp [ 1 ] . match ( /\d+/ ) ) ;
2010-09-22 16:52:41 +00:00
2010-09-23 20:43:10 +00:00
// If starting and ending index do not match
if ( ! ( nodeStart == userIdStart ) || ! ( nodeEnd == userIdEnd ) ) {
// Not ready
errMsg = errMsg + 'The node range and user ID range does not match. ' ;
ready = false ;
}
2010-09-22 16:52:41 +00:00
}
}
2010-09-23 20:43:10 +00:00
// If there are no errors
if ( ready ) {
// If a node range is given
if ( nodeRange . indexOf ( '-' ) > - 1 && userIdRange . indexOf ( '-' ) > - 1 ) {
var tmp = nodeRange . split ( '-' ) ;
// Get node base name
var nodeBase = tmp [ 0 ] . match ( /[a-zA-Z]+/ ) ;
// Get starting index
var nodeStart = parseInt ( tmp [ 0 ] . match ( /\d+/ ) ) ;
// Get ending index
2010-10-07 15:38:03 +00:00
var nodeEnd = parseInt ( tmp [ 1 ] . match ( /\d+/ ) ) ;
2010-09-23 20:43:10 +00:00
tmp = userIdRange . split ( '-' ) ;
// Get user ID base name
var userIdBase = tmp [ 0 ] . match ( /[a-zA-Z]+/ ) ;
// Get starting index
var userIdStart = parseInt ( tmp [ 0 ] . match ( /\d+/ ) ) ;
// Get ending index
2010-10-07 15:38:03 +00:00
var userIdEnd = parseInt ( tmp [ 1 ] . match ( /\d+/ ) ) ;
2010-09-23 20:43:10 +00:00
// Loop through each node in the node range
for ( var i = nodeStart ; i <= nodeEnd ; i ++ ) {
var node = nodeBase + i . toString ( ) ;
var userId = userIdBase + i . toString ( ) ;
var inst = i + '/' + nodeEnd ;
/ * *
* ( 1 ) Define node
* /
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodeadd' ,
tgt : '' ,
args : node + ';zvm.hcp=' + hcp
+ ';zvm.userid=' + userId
+ ';nodehm.mgt=zvm' + ';groups=' + group ,
msg : 'cmd=addnewnode;inst=' + inst + ';noderange=' + nodeRange
} ,
/ * *
* Return function on successful AJAX call
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
success : function ( data ) {
// Get ajax response
var rsp = data . rsp ;
var args = data . msg . split ( ';' ) ;
// Get command invoked
var cmd = args [ 0 ] . replace ( 'cmd=' , '' ) ;
var inst = args [ 1 ] . replace ( 'inst=' , '' ) ;
var nodeRange = args [ 2 ] . replace ( 'noderange=' , '' ) ;
// If the last node was added
var tmp = inst . split ( '/' ) ;
if ( tmp [ 0 ] == tmp [ 1 ] ) {
// If there was an error, do not continue
if ( rsp . length ) {
2010-09-24 12:27:54 +00:00
openDialog ( 'warn' , '(Error) Failed to create node definitions' ) ;
2010-09-23 20:43:10 +00:00
} else {
2010-09-24 12:27:54 +00:00
openDialog ( 'info' , 'Node definitions created for ' + nodeRange ) ;
2010-09-23 20:43:10 +00:00
}
}
}
} ) ;
}
} else {
2010-09-24 12:27:54 +00:00
// Only one node to add
2010-09-23 20:43:10 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodeadd' ,
tgt : '' ,
args : nodeRange + ';zvm.hcp=' + hcp
+ ';zvm.userid=' + userIdRange
+ ';nodehm.mgt=zvm' + ';groups=' + group ,
msg : 'cmd=addnewnode;node=' + nodeRange
} ,
/ * *
* Return function on successful AJAX call
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
success : function ( data ) {
// Get ajax response
var rsp = data . rsp ;
var args = data . msg . split ( ';' ) ;
// Get command invoked
var cmd = args [ 0 ] . replace ( 'cmd=' , '' ) ;
var node = args [ 1 ] . replace ( 'node=' , '' ) ;
// If there was an error, do not continue
2010-09-28 20:24:31 +00:00
if ( rsp . length ) {
2010-09-24 12:27:54 +00:00
openDialog ( 'warn' , '(Error) Failed to create node definition' ) ;
2010-09-23 20:43:10 +00:00
} else {
2010-09-24 12:27:54 +00:00
openDialog ( 'info' , 'Node definitions created for ' + node ) ;
2010-09-23 20:43:10 +00:00
}
}
} ) ;
}
// Close dialog
$ ( this ) . dialog ( "close" ) ;
2010-09-22 16:52:41 +00:00
} else {
2010-09-23 20:43:10 +00:00
// Show warning message
var warn = createWarnBar ( errMsg ) ;
warn . prependTo ( $ ( this ) ) ;
2010-09-24 02:27:04 +00:00
}
} // End of else
2010-10-07 21:01:14 +00:00
} ,
"Cancel" : function ( ) {
$ ( this ) . dialog ( "close" ) ;
}
2010-09-23 20:43:10 +00:00
}
} ) ;
2010-07-22 19:56:09 +00:00
} ;