/**
* Execute when the DOM is fully loaded
*/
$(document).ready(function() {
// Load utility scripts
});
/**
* Constructor
*
* @return Nothing
*/
var hmcPlugin = function() {
};
/**
* Load node inventory
*
* @param data
* Data from HTTP request
* @return Nothing
*/
hmcPlugin.prototype.loadInventory = function(data) {
// Get arguments
var args = data.msg.split(',');
// Get tab ID
var tabId = args[0].replace('out=', '');
// Get node
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 = $('
');
// Loop through each line
var fieldSet, legend, oList, item;
for ( var k = 0; k < inv.length; k++) {
// Remove node name in front
var str = inv[k].replace(node + ': ', '');
str = jQuery.trim(str);
// If string is a header
if (str.indexOf('I/O Bus Information') > -1 || str.indexOf('Machine Configuration Info') > -1) {
// Create a fieldset
fieldSet = $('');
legend = $('');
fieldSet.append(legend);
oList = $('');
fieldSet.append(oList);
invDiv.append(fieldSet);
} else {
// If no fieldset is defined
if (!fieldSet) {
// Define general fieldset
fieldSet = $('');
legend = $('');
fieldSet.append(legend);
oList = $('');
fieldSet.append(oList);
invDiv.append(fieldSet);
}
// Append the string to a list
item = $('');
item.append(str);
oList.append(item);
}
}
// Append to inventory form
$('#' + tabId).append(invDiv);
};
/**
* Load clone page
*
* @param node
* Source node to clone
* @return Nothing
*/
hmcPlugin.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 status bar and hide it
var statBarId = node + 'CloneStatusBar';
var statBar = $('').hide();
// Create info bar
var infoBar = createInfoBar('Under construction');
// Create clone form
var cloneForm = $('');
cloneForm.append(statBar);
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
*/
hmcPlugin.prototype.loadProvisionPage = function(tabId) {
// Get OS image names
if (!$.cookie('imagenames')){
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'tabdump',
tgt : '',
args : 'osimage',
msg : ''
},
success : setOSImageCookies
});
}
// Get groups
if (!$.cookie('groups')){
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'extnoderange',
tgt : '/.*',
args : 'subgroups',
msg : ''
},
success : setGroupsCookies
});
}
// Get provision tab instance
var inst = tabId.replace('hmcProvisionTab', '');
// Create provision form
var provForm = $('');
// Create status bar
var statBarId = 'hmcProvisionStatBar' + inst;
var statBar = createStatusBar(statBarId).hide();
provForm.append(statBar);
// Create loader
var loader = createLoader('hmcProvisionLoader' + inst).hide();
statBar.append(loader);
// Create info bar
var infoBar = createInfoBar('Provision an hmc node.');
provForm.append(infoBar);
// Append to provision tab
$('#' + tabId).append(provForm);
// Create provision type drop down
provForm.append('');
/**
* Create provision new node division
*/
// You should copy whatever is in this function, put it here, and customize it
//var provNew = createProvisionNew('hmc', inst);
//provForm.append(provNew);
/**
* Create provision existing node division
*/
// You should copy whatever is in this function, put it here, and customize it
provForm.append(createHmcProvisionExisting(inst));
var hmcProvisionBtn = createButton('Provision');
hmcProvisionBtn.bind('click', function(event) {
//TODO Insert provision code here
openDialog('info', 'Under construction');
});
provForm.append(hmcProvisionBtn);
// update the node table on group select
provForm.find('#groupname').bind('change', function(){
var groupName = $(this).val();
var nodeArea = $('#hmcSelectNodesTable' + inst);
nodeArea.empty();
if (!groupName){
nodeArea.html('Select a group to view its nodes');
return;
}
nodeArea.append(createLoader());
createNodesArea(groupName, 'hmcSelectNodesTable'+ inst);
});
// Toggle provision new/existing on select
};
/**
* Load resources
*
* @return Nothing
*/
hmcPlugin.prototype.loadResources = function() {
// Get resource tab ID
var tabId = 'hmcResourceTab';
// Remove loader
$('#' + tabId).find('img').remove();
// Create info bar
var infoBar = createInfoBar('Under construction');
// Create resource form
var resrcForm = $('');
resrcForm.append(infoBar);
$('#' + tabId).append(resrcForm);
};
/**
* Add node range
*
* @return Nothing
*/
hmcPlugin.prototype.addNode = function() {
openDialog('info', 'Under construction');
};
/**
* Create hmc provision existing form
*
* @return: form content
*/
function createHmcProvisionExisting(inst){
//create the group area.
var strGroup = '
';
var groupNames = $.cookie('groups');
if (groupNames){
strGroup += '';
}
else{
strGroup += '';
}
strGroup += '
';
//create nodes area
var strNodes = '
Select a group to view its nodes
';
//create boot method
var strBoot = '';
// Create operating system
var strOs = '
';
var osName = $.cookie('osvers');
if (osName){
strOs += '';
}
else{
strOs += '';
}
strOs += '