2011-11-03 02:21:11 +00:00
/ * *
* Execute when the DOM is fully loaded
* /
$ ( document ) . ready ( function ( ) {
// Load utility scripts (if any)
} ) ;
/ * *
* Constructor
*
* @ return Nothing
* /
var esxPlugin = function ( ) {
} ;
/ * *
* Clone node ( service page )
*
* @ param node
* Node to clone
* @ return Nothing
* /
esxPlugin . prototype . serviceClone = function ( node ) {
} ;
/ * *
* Load provision page ( service page )
*
* @ param tabId
* Tab ID where page will reside
* @ return Nothing
* /
esxPlugin . prototype . loadServiceProvisionPage = function ( tabId ) {
} ;
/ * *
* Show node inventory ( service page )
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
esxPlugin . prototype . loadServiceInventory = function ( data ) {
} ;
/ * *
* Load node inventory
*
* @ param data
* Data from HTTP request
* @ return Nothing
* /
esxPlugin . prototype . loadInventory = function ( data ) {
var args = data . msg . split ( ',' ) ;
var tabId = args [ 0 ] . replace ( 'out=' , '' ) ;
var node = args [ 1 ] . replace ( 'node=' , '' ) ;
// Get node inventory
var inv = data . rsp ;
// Remove loader
$ ( '#' + tabId ) . find ( 'img' ) . remove ( ) ;
// Create division to hold inventory
var invDivId = tabId + 'Inventory' ;
var invDiv = $ ( '<div></div>' ) ;
// Create a fieldset
var fieldSet = $ ( '<fieldset></fieldset>' ) ;
var legend = $ ( '<legend>Hardware</legend>' ) ;
fieldSet . append ( legend ) ;
var oList = $ ( '<ol></ol>' ) ;
fieldSet . append ( oList ) ;
invDiv . append ( fieldSet ) ;
// Loop through each line
var item ;
for ( var k = 0 ; k < inv . length ; k ++ ) {
// Remove node name
var attr = inv [ k ] . replace ( node + ': ' , '' ) ;
attr = jQuery . trim ( attr ) ;
// Append attribute to list
item = $ ( '<li></li>' ) ;
item . append ( attr ) ;
oList . append ( item ) ;
}
// Append to inventory form
$ ( '#' + tabId ) . append ( invDiv ) ;
} ;
/ * *
* Load clone page
*
* @ param node
* Source node to clone
* @ return Nothing
* /
esxPlugin . prototype . loadClonePage = function ( node ) {
// Get nodes tab
var tab = getNodesTab ( ) ;
var newTabId = node + 'CloneTab' ;
// If there is no existing clone tab
if ( ! $ ( '#' + newTabId ) . length ) {
// Create info bar
2012-03-14 04:46:08 +00:00
var infoBar = createInfoBar ( 'Not yet supported' ) ;
2011-11-03 02:21:11 +00:00
// Create clone form
var cloneForm = $ ( '<div class="form"></div>' ) ;
cloneForm . append ( infoBar ) ;
// Add clone tab
tab . add ( newTabId , 'Clone' , cloneForm , true ) ;
}
tab . select ( newTabId ) ;
} ;
/ * *
* Load provision page
*
* @ param tabId
* The provision tab ID
* @ return Nothing
* /
esxPlugin . prototype . loadProvisionPage = function ( tabId ) {
// Get OS image names
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'tabdump' ,
tgt : '' ,
args : 'osimage' ,
msg : ''
} ,
success : setOSImageCookies
} ) ;
// Get groups
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'extnoderange' ,
tgt : '/.*' ,
args : 'subgroups' ,
msg : ''
} ,
success : setGroupsCookies
} ) ;
// Create provision form
var provForm = $ ( '<div class="form"></div>' ) ;
// Create info bar
2012-03-14 04:46:08 +00:00
var infoBar = createInfoBar ( 'Provision an ESX virtual machine.' ) ;
2011-11-03 02:21:11 +00:00
provForm . append ( infoBar ) ;
// Append to provision tab
$ ( '#' + tabId ) . append ( provForm ) ;
2011-12-19 05:03:27 +00:00
// Create VM fieldset
2011-11-03 02:21:11 +00:00
var vmFS = $ ( '<fieldset></fieldset>' ) ;
var vmLegend = $ ( '<legend>Virtual Machine</legend>' ) ;
vmFS . append ( vmLegend ) ;
2011-12-19 05:03:27 +00:00
var vmAttr = $ ( '<div style="display: inline-table; vertical-align: middle;"></div>' ) ;
vmFS . append ( $ ( '<div style="display: inline-table; vertical-align: middle;"><img src="images/provision/computer.png"></img></div>' ) ) ;
vmFS . append ( vmAttr ) ;
// Create hardware fieldset
2011-11-03 02:21:11 +00:00
var hwFS = $ ( '<fieldset></fieldset>' ) ;
var hwLegend = $ ( '<legend>Hardware</legend>' ) ;
hwFS . append ( hwLegend ) ;
2011-12-19 05:03:27 +00:00
var hwAttr = $ ( '<div style="display: inline-table; vertical-align: middle;"></div>' ) ;
hwFS . append ( $ ( '<div style="display: inline-table; vertical-align: middle;"><img src="images/provision/hardware.png"></img></div>' ) ) ;
hwFS . append ( hwAttr ) ;
// Create image fieldset
2011-11-03 02:21:11 +00:00
var imgFS = $ ( '<fieldset></fieldset>' ) ;
var imgLegend = $ ( '<legend>Image</legend>' ) ;
imgFS . append ( imgLegend ) ;
2011-12-19 05:03:27 +00:00
var imgAttr = $ ( '<div style="display: inline-table; vertical-align: middle;"></div>' ) ;
imgFS . append ( $ ( '<div style="display: inline-table; vertical-align: middle;"><img src="images/provision/operating_system.png"></img></div>' ) ) ;
imgFS . append ( imgAttr ) ;
2011-11-03 02:21:11 +00:00
provForm . append ( vmFS , hwFS , imgFS ) ;
// Create hypervisor input
2011-12-01 04:10:40 +00:00
var host = $ ( '<div></div>' ) ;
var hostLabel = $ ( '<label>Host:</label>' ) ;
host . append ( hostLabel ) ;
var hostInput = $ ( '<input type="text" name="host"/>' ) ;
host . append ( hostInput ) ;
2011-12-19 05:03:27 +00:00
vmAttr . append ( host ) ;
2011-11-03 02:21:11 +00:00
// Create group input
var group = $ ( '<div></div>' ) ;
var groupLabel = $ ( '<label>Group:</label>' ) ;
group . append ( groupLabel ) ;
// Turn on auto complete for group
var groupNames = $ . cookie ( 'groups' ) ;
if ( groupNames ) {
// Split group names into an array
var tmp = groupNames . split ( ',' ) ;
// Create drop down for groups
2011-12-01 04:10:40 +00:00
var groupSelect = $ ( '<select name="group"></select>' ) ;
2011-11-03 02:21:11 +00:00
groupSelect . append ( '<option></option>' ) ;
for ( var i in tmp ) {
// Add group into drop down
var opt = $ ( '<option value="' + tmp [ i ] + '">' + tmp [ i ] + '</option>' ) ;
groupSelect . append ( opt ) ;
}
group . append ( groupSelect ) ;
} else {
// If no groups are cookied
var groupInput = $ ( '<input type="text" name="group"/>' ) ;
group . append ( groupInput ) ;
}
2011-12-19 05:03:27 +00:00
vmAttr . append ( group ) ;
2011-11-03 02:21:11 +00:00
// Create node input
var node = $ ( '<div></div>' ) ;
var nodeLabel = $ ( '<label>VM name:</label>' ) ;
var nodeInput = $ ( '<input type="text" name="node"/>' ) ;
node . append ( nodeLabel ) ;
node . append ( nodeInput ) ;
2011-12-19 05:03:27 +00:00
vmAttr . append ( node ) ;
2011-11-03 02:21:11 +00:00
// Create memory input
var memory = $ ( '<div></div>' ) ;
var memoryLabel = $ ( '<label>Memory:</label>' ) ;
2011-12-01 04:10:40 +00:00
var memoryInput = $ ( '<input type="text" name="memory" size="5"/>' ) ;
2011-11-03 02:21:11 +00:00
memory . append ( memoryLabel ) ;
memory . append ( memoryInput ) ;
2011-12-19 05:03:27 +00:00
hwAttr . append ( memory ) ;
2011-11-03 02:21:11 +00:00
// Create processor dropdown
var cpu = $ ( '<div></div>' ) ;
var cpuLabel = $ ( '<label>Processor:</label>' ) ;
var cpuSelect = $ ( '<select name="cpu"></select>' ) ;
cpuSelect . append ( '<option value="1">1</option>'
+ '<option value="2">2</option>'
+ '<option value="3">3</option>'
+ '<option value="4">4</option>'
+ '<option value="5">5</option>'
+ '<option value="6">6</option>'
+ '<option value="7">7</option>'
+ '<option value="8">8</option>'
) ;
cpu . append ( cpuLabel ) ;
cpu . append ( cpuSelect ) ;
2011-12-19 05:03:27 +00:00
hwAttr . append ( cpu ) ;
2011-11-03 02:21:11 +00:00
// Create NIC dropdown
var nic = $ ( '<div></div>' ) ;
var nicLabel = $ ( '<label>NIC:</label>' ) ;
2011-12-01 04:10:40 +00:00
var nicInput = $ ( '<input type="text" name="nic"/>' ) ;
2011-11-03 02:21:11 +00:00
nic . append ( nicLabel ) ;
2011-12-01 04:10:40 +00:00
nic . append ( nicInput ) ;
2011-12-19 05:03:27 +00:00
hwAttr . append ( nic ) ;
2011-11-03 02:21:11 +00:00
// Create disk input
var disk = $ ( '<div></div>' ) ;
var diskLabel = $ ( '<label>Disk size:</label>' ) ;
2011-12-01 04:10:40 +00:00
var diskInput = $ ( '<input type="text" name="disk" size="5"/>' ) ;
var diskSizeSelect = $ ( '<select name="diskUnit"></select>' ) ;
diskSizeSelect . append ( '<option value="G">GB</option>' +
'<option value="M">MB</option>'
2011-11-03 02:21:11 +00:00
) ;
disk . append ( diskLabel , diskInput , diskSizeSelect ) ;
2011-12-19 05:03:27 +00:00
hwAttr . append ( disk ) ;
2011-11-03 02:21:11 +00:00
2011-12-01 04:10:40 +00:00
// Create disk storage input
var storage = $ ( '<div></div>' ) ;
var storageLabel = $ ( '<label>Storage:</label>' ) ;
var storageInput = $ ( '<input type="text" name="storage"/>' ) ;
storage . append ( storageLabel ) ;
storage . append ( storageInput ) ;
2011-12-19 05:03:27 +00:00
hwAttr . append ( storage ) ;
2011-12-01 04:10:40 +00:00
2011-11-03 02:21:11 +00:00
// Create operating system input
var os = $ ( '<div></div>' ) ;
2011-12-01 04:10:40 +00:00
var osLabel = $ ( '<label>Operating system:</label>' ) ;
2011-11-03 02:21:11 +00:00
var osInput = $ ( '<input type="text" name="os"/>' ) ;
osInput . one ( 'focus' , function ( ) {
var tmp = $ . cookie ( 'osvers' ) ;
if ( tmp ) {
// Turn on auto complete
$ ( this ) . autocomplete ( {
source : tmp . split ( ',' )
} ) ;
}
} ) ;
os . append ( osLabel ) ;
os . append ( osInput ) ;
2011-12-19 05:03:27 +00:00
imgAttr . append ( os ) ;
2011-11-03 02:21:11 +00:00
// Create architecture input
var arch = $ ( '<div></div>' ) ;
2011-12-01 04:10:40 +00:00
var archLabel = $ ( '<label>Architecture:</label>' ) ;
2011-11-03 02:21:11 +00:00
var archInput = $ ( '<input type="text" name="arch"/>' ) ;
archInput . one ( 'focus' , function ( ) {
var tmp = $ . cookie ( 'osarchs' ) ;
if ( tmp ) {
// Turn on auto complete
$ ( this ) . autocomplete ( {
source : tmp . split ( ',' )
} ) ;
}
} ) ;
arch . append ( archLabel ) ;
arch . append ( archInput ) ;
2011-12-19 05:03:27 +00:00
imgAttr . append ( arch ) ;
2011-11-03 02:21:11 +00:00
// Create profile input
var profile = $ ( '<div></div>' ) ;
2011-12-01 04:10:40 +00:00
var profileLabel = $ ( '<label>Profile:</label>' ) ;
2011-11-03 02:21:11 +00:00
var profileInput = $ ( '<input type="text" name="profile"/>' ) ;
profileInput . one ( 'focus' , function ( ) {
var tmp = $ . cookie ( 'profiles' ) ;
if ( tmp ) {
// Turn on auto complete
$ ( this ) . autocomplete ( {
source : tmp . split ( ',' )
} ) ;
}
} ) ;
profile . append ( profileLabel ) ;
profile . append ( profileInput ) ;
2011-12-19 05:03:27 +00:00
imgAttr . append ( profile ) ;
2011-11-03 02:21:11 +00:00
// Create boot method dropdown
var method = $ ( '<div></div>' ) ;
2011-12-01 04:10:40 +00:00
var methodLabel = $ ( '<label>Boot method:</label>' ) ;
2011-11-03 02:21:11 +00:00
var methodSelect = $ ( '<select id="bootMethod" name="bootMethod"></select>' ) ;
methodSelect . append ( '<option value=""></option>'
+ '<option value="boot">boot</option>'
+ '<option value="install">install</option>'
+ '<option value="iscsiboot">iscsiboot</option>'
+ '<option value="netboot">netboot</option>'
+ '<option value="statelite">statelite</option>'
) ;
method . append ( methodLabel ) ;
method . append ( methodSelect ) ;
2011-12-19 05:03:27 +00:00
imgAttr . append ( method ) ;
2011-11-03 02:21:11 +00:00
/ * *
* Provision existing
* /
var provisionBtn = createButton ( 'Provision' ) ;
provisionBtn . bind ( 'click' , function ( event ) {
// Remove any warning messages
$ ( this ) . parents ( '.ui-tabs-panel' ) . find ( '.ui-state-error' ) . remove ( ) ;
var ready = true ;
2011-11-23 17:59:48 +00:00
// Get tab ID
2011-12-01 04:10:40 +00:00
var tabId = $ ( this ) . parents ( '.ui-tabs-panel' ) . attr ( 'id' ) ;
2011-11-23 17:59:48 +00:00
// Check if fields are properly filled in
2011-12-01 04:10:40 +00:00
var inputs = $ ( '#' + tabId + ' input:visible' ) ;
2011-11-23 17:59:48 +00:00
for ( var i = 0 ; i < inputs . length ; i ++ ) {
2011-12-01 04:10:40 +00:00
if ( ! inputs . eq ( i ) . val ( ) && inputs . eq ( i ) . attr ( 'name' ) != 'storage' ) {
2011-11-23 17:59:48 +00:00
inputs . eq ( i ) . css ( 'border' , 'solid #FF0000 1px' ) ;
ready = false ;
} else {
inputs . eq ( i ) . css ( 'border' , 'solid #BDBDBD 1px' ) ;
}
}
2011-12-01 04:10:40 +00:00
var selects = $ ( '#' + tabId + ' select:visible' ) ;
2011-11-23 17:59:48 +00:00
for ( var i = 0 ; i < selects . length ; i ++ ) {
if ( ! selects . eq ( i ) . val ( ) ) {
selects . eq ( i ) . css ( 'border' , 'solid #FF0000 1px' ) ;
ready = false ;
} else {
selects . eq ( i ) . css ( 'border' , 'solid #BDBDBD 1px' ) ;
}
}
2011-12-01 04:10:40 +00:00
if ( ready ) {
var inst = tabId . replace ( 'kvmProvisionTab' , '' ) ;
// Prepend status bar
var statBar = createStatusBar ( 'kvmProvisionStatBar' + inst ) ;
statBar . append ( createLoader ( '' ) ) ;
statBar . prependTo ( $ ( '#' + tabId ) ) ;
var host = $ ( '#' + tabId + ' input[name=host]' ) . val ( ) ;
var group = $ ( '#' + tabId + ' select[name=group]' ) . val ( ) ;
var node = $ ( '#' + tabId + ' input[name=node]' ) . val ( ) ;
var memory = $ ( '#' + tabId + ' input[name=memory]' ) . val ( ) ;
var cpu = $ ( '#' + tabId + ' select[name=cpu]' ) . val ( ) ;
var nic = $ ( '#' + tabId + ' input[name=nic]' ) . val ( ) ;
var disk = $ ( '#' + tabId + ' input[name=disk]' ) . val ( ) + $ ( '#' + tabId + ' select[name=diskUnit]' ) . val ( ) ;
var storage = $ ( '#' + tabId + ' input[name=storage]' ) . val ( ) ;
var os = $ ( '#' + tabId + ' input[name=os]' ) . val ( ) ;
var arch = $ ( '#' + tabId + ' input[name=arch]' ) . val ( ) ;
var profile = $ ( '#' + tabId + ' input[name=profile]' ) . val ( ) ;
var boot = $ ( '#' + tabId + ' select[name=bootMethod]' ) . val ( ) ;
/ * *
* ( 1 ) Define node
* /
var args = '-t;node;-o;' + node +
';vmhost=' + host +
';groups=' + group +
';vmmemory=' + memory +
';vmcpus=' + cpu +
';vmnics=' + nic +
';vmstorage=' + storage +
';os=' + os +
';arch=' + arch +
';profile=' + profile +
';netboot=xnba' +
';nodetype=osi' +
';serialport=0' +
';serialspeed=115200' +
';mgt=esx' ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'chdef' ,
tgt : '' ,
args : args ,
msg : 'cmd=chdef;out=' + inst
} ,
success : updateESXProvisionStatus
} ) ;
} else {
// Show warning message
var warn = createWarnBar ( 'Please provide a value for each missing field.' ) ;
warn . prependTo ( $ ( this ) . parent ( ) . parent ( ) ) ;
}
2011-11-03 02:21:11 +00:00
} ) ;
provForm . append ( provisionBtn ) ;
} ;
/ * *
* Load resources
*
* @ return Nothing
* /
esxPlugin . prototype . loadResources = function ( ) {
// Get resource tab ID
var tabId = 'esxResourceTab' ;
// Remove loader
$ ( '#' + tabId ) . find ( 'img' ) . remove ( ) ;
// Create info bar
2012-03-14 19:23:51 +00:00
var infoBar = createInfoBar ( 'Not yet supported' ) ;
2011-11-03 02:21:11 +00:00
// Create resource form
var resrcForm = $ ( '<div class="form"></div>' ) ;
resrcForm . append ( infoBar ) ;
$ ( '#' + tabId ) . append ( resrcForm ) ;
} ;
/ * *
* Add node range
* /
esxPlugin . prototype . addNode = function ( ) {
2012-03-14 04:46:08 +00:00
var dialog = $ ( '<div id="addEsx" class="form"></div>' ) ;
var info = createInfoBar ( 'Add a ESX node' ) ;
dialog . append ( info ) ;
2011-11-03 02:21:11 +00:00
// Create node inputs
2012-03-14 04:46:08 +00:00
dialog . append ( $ ( '<div><label>Node:</label><input name="node" type="text"></div>' ) ) ;
dialog . append ( $ ( '<div><label>VM host:</label><input name="vmhost" type="text"></div>' ) ) ;
dialog . append ( $ ( '<div><label>IP address:</label><input name="ip" type="text"></div>' ) ) ;
dialog . append ( $ ( '<div><label>Groups:</label><input name="groups" type="text"></div>' ) ) ;
2011-11-03 02:21:11 +00:00
2012-03-14 04:46:08 +00:00
dialog . dialog ( {
2011-11-03 02:21:11 +00:00
title : 'Add node' ,
modal : true ,
width : 400 ,
close : function ( ) { $ ( this ) . remove ( ) ; } ,
buttons : {
2012-03-14 04:46:08 +00:00
"OK" : function ( ) { addEsxNode ( ) ; } ,
2011-11-03 02:21:11 +00:00
"Cancel" : function ( ) { $ ( this ) . dialog ( 'close' ) ; }
}
} ) ;
} ;
/ * *
2012-03-14 04:46:08 +00:00
* Add ESX node
2011-11-03 02:21:11 +00:00
* /
2012-03-14 04:46:08 +00:00
function addEsxNode ( ) {
var attr , args ;
2011-11-03 02:21:11 +00:00
var errorMessage = '' ;
2012-03-14 04:46:08 +00:00
2011-11-03 02:21:11 +00:00
// Remove existing warnings
2012-03-14 04:46:08 +00:00
$ ( '#addEsx .ui-state-error' ) . remove ( ) ;
// Return input border colors to normal
$ ( '#addEsx input' ) . css ( 'border' , 'solid #BDBDBD 1px' ) ;
2011-11-03 02:21:11 +00:00
2012-03-14 04:46:08 +00:00
// Check node attributes
$ ( '#addEsx input' ) . each ( function ( ) {
2011-11-03 02:21:11 +00:00
attr = $ ( this ) . val ( ) ;
2012-03-14 04:46:08 +00:00
if ( ! attr ) {
2011-12-01 04:10:40 +00:00
errorMessage = "Please provide a value for each missing field!" ;
2012-03-14 04:46:08 +00:00
$ ( this ) . css ( 'border' , 'solid #FF0000 1px' ) ;
2011-11-03 02:21:11 +00:00
}
} ) ;
2012-03-14 04:46:08 +00:00
// Show error message (if any)
2011-11-03 02:21:11 +00:00
if ( errorMessage ) {
2012-03-14 04:46:08 +00:00
$ ( '#addEsx' ) . prepend ( createWarnBar ( errorMessage ) ) ;
2011-11-03 02:21:11 +00:00
return ;
}
// Create loader
2012-03-14 04:46:08 +00:00
$ ( '#addEsx' ) . append ( createLoader ( ) ) ;
2011-11-03 02:21:11 +00:00
// Change dialog buttons
2012-03-14 04:46:08 +00:00
$ ( '#addEsx' ) . dialog ( 'option' , 'buttons' , {
2011-11-03 02:21:11 +00:00
'Close' : function ( ) {
2012-03-14 04:46:08 +00:00
$ ( '#addEsx' ) . dialog ( 'close' ) ;
2011-11-03 02:21:11 +00:00
}
} ) ;
// Generate chdef arguments
2012-03-14 04:46:08 +00:00
args = '-t;node;-o;' + $ ( '#addEsx input[name="node"]' ) . val ( )
+ ';ip=' + $ ( '#addEsx input[name="ip"]' ) . val ( )
+ ';groups=' + $ ( '#addEsx input[name="groups"]' ) . val ( )
+ ';vmhost=' + $ ( '#addEsx input[name="vmhost"]' ) . val ( )
+ ';mgt=esx;netboot=xnba;nodetype=osi;profile=compute' ;
2011-11-03 02:21:11 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'chdef' ,
tgt : '' ,
args : args ,
msg : ''
} ,
success : function ( data ) {
2012-03-14 04:46:08 +00:00
// Update /etc/hosts
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'makehosts' ,
tgt : '' ,
args : '' ,
msg : ''
2012-03-15 13:58:10 +00:00
}
2012-03-14 04:46:08 +00:00
} ) ;
// Remove loader
$ ( '#addEsx img' ) . remove ( ) ;
// Get return message
2011-11-03 02:21:11 +00:00
var message = '' ;
for ( var i in data . rsp ) {
2012-03-14 04:46:08 +00:00
message += data . rsp [ i ] + '<br/>' ;
2011-11-03 02:21:11 +00:00
}
2012-03-14 04:46:08 +00:00
// Show return message
if ( message )
$ ( '#addEsx' ) . prepend ( createInfoBar ( message ) ) ;
2011-11-03 02:21:11 +00:00
}
} ) ;
}
/ * *
* Update the provision node status
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function updateESXProvisionStatus ( data ) {
// Get ajax response
var rsp = data . rsp ;
var args = data . msg . split ( ';' ) ;
// Get command invoked
var cmd = args [ 0 ] . replace ( 'cmd=' , '' ) ;
// Get provision tab instance
var inst = args [ 1 ] . replace ( 'out=' , '' ) ;
// Get provision tab and status bar ID
2011-12-01 04:10:40 +00:00
var statBarId = 'kvmProvisionStatBar' + inst ;
var tabId = 'kvmProvisionTab' + inst ;
var node = $ ( '#' + tabId + ' input[name=node]' ) . val ( ) ;
2011-11-03 02:21:11 +00:00
/ * *
2011-12-01 04:10:40 +00:00
* ( 2 ) Create virtual machine
2011-11-03 02:21:11 +00:00
* /
2011-12-01 04:10:40 +00:00
if ( cmd == 'chdef' ) {
2011-11-03 02:21:11 +00:00
// Write ajax response to status bar
var prg = writeRsp ( rsp , '' ) ;
$ ( '#' + statBarId ) . find ( 'div' ) . append ( prg ) ;
// Get parameters
2011-12-01 04:10:40 +00:00
var disk = $ ( '#' + tabId + ' input[name=disk]' ) . val ( ) + $ ( '#' + tabId + ' select[name=diskUnit]' ) . val ( ) ;
2011-11-03 02:21:11 +00:00
// Begin installation
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2011-12-01 04:10:40 +00:00
cmd : 'mkvm' ,
2011-11-03 02:21:11 +00:00
tgt : '' ,
2011-12-01 04:10:40 +00:00
args : node + ';-s;' + disk ,
msg : 'cmd=mkvm;out=' + inst
2011-11-03 02:21:11 +00:00
} ,
success : updateESXProvisionStatus
} ) ;
}
/ * *
2011-12-01 04:10:40 +00:00
* ( 3 ) Prepare node for boot
* /
if ( cmd == 'mkvm' ) {
// Write ajax response to status bar
var prg = writeRsp ( rsp , '' ) ;
$ ( '#' + statBarId ) . find ( 'div' ) . append ( prg ) ;
// Get provision method
var boot = $ ( '#' + tabId + ' select[name=bootMethod]' ) . val ( ) ;
// Prepare node for boot
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodeset' ,
tgt : node ,
args : boot ,
msg : 'cmd=nodeset;out=' + inst
} ,
success : updateESXProvisionStatus
} ) ;
}
/ * *
* ( 4 ) Power on node
* /
if ( cmd == 'nodeset' ) {
var prg = writeRsp ( rsp , '' ) ;
$ ( '#' + statBarId ) . find ( 'div' ) . append ( prg ) ;
// Prepare node for boot
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpower' ,
tgt : node ,
args : 'on' ,
msg : 'cmd=rpower;out=' + inst
} ,
success : updateESXProvisionStatus
} ) ;
}
/ * *
* ( 5 ) Done
2011-11-03 02:21:11 +00:00
* /
2011-12-01 04:10:40 +00:00
else if ( cmd == 'rpower' ) {
2011-11-03 02:21:11 +00:00
// Write ajax response to status bar
var prg = writeRsp ( rsp , '' ) ;
$ ( '#' + statBarId ) . find ( 'div' ) . append ( prg ) ;
$ ( '#' + statBarId ) . find ( 'img' ) . remove ( ) ;
// If installation was successful
if ( prg . html ( ) . indexOf ( 'Error' ) == - 1 ) {
2011-12-01 04:10:40 +00:00
$ ( '#' + statBarId ) . find ( 'div' ) . append ( '<pre>It will take several minutes before the nodes are up and ready. Use rcons to monitor the status of the install.</pre>' ) ;
2011-11-03 02:21:11 +00:00
}
}
}