/**
* Execute when the DOM is fully loaded
*/
$(document).ready(function() {
// Load utility scripts
includeJs("js/custom/zvmUtils.js");
});
/**
* Constructor
*
* @return Nothing
*/
var zvmPlugin = function() {
};
/**
* Clone node (service page)
*
* @param node
* Node to clone
* @return Nothing
*/
zvmPlugin.prototype.serviceClone = function(node) {
var owner = $.cookie('srv_usrname');
var group = getUserNodeAttr(node, 'groups');
// Submit request to clone VM
// webportal clonezlinux [src node] [group] [owner]
var iframe = createIFrame('lib/srv_cmd.php?cmd=webportal&tgt=&args=clonezlinux;' + node + ';' + group + ';' + owner + '&msg=&opts=flush');
iframe.prependTo($('#manageTab'));
};
/**
* Load provision page (service page)
*
* @param tabId
* Tab ID where page will reside
* @return Nothing
*/
zvmPlugin.prototype.loadServiceProvisionPage = function(tabId) {
// Create provision form
var provForm = $('
');
// Create info bar
var infoBar = createInfoBar('Provision a Linux virtual machine on System z by selecting the appropriate choices below. Once you are ready, click on Provision to provision the virtual machine.');
provForm.append(infoBar);
// Append to provision tab
$('#' + tabId).append(provForm);
// Create provision table
var provTable = $('
zVM
Group
Image
');
var provBody = $('');
var provFooter = $('');
provTable.append(provHeader, provBody, provFooter);
provForm.append(provTable);
provHeader.children('th').css({
'font': 'bold 12px verdana, arial, helvetica, sans-serif'
});
// Create row to contain selections
var provRow = $('
');
provBody.append(provRow);
// Create columns for zVM, group, and image
var zvmCol = $('
');
provRow.append(zvmCol);
var groupCol = $('
');
provRow.append(groupCol);
var imageCol = $('
');
provRow.append(imageCol);
provRow.children('td').css({
'min-width': '250px'
});
/**
* Provision VM
*/
var provisionBtn = createButton('Provision');
provisionBtn.bind('click', function(event) {
// Remove any warning messages
$(this).parent().find('.ui-state-error').remove();
var hcp = $('#select-table tbody tr:eq(0) td:eq(0) input[name="hcp"]:checked').val();
var group = $('#select-table tbody tr:eq(0) td:eq(1) input[name="group"]:checked').val();
var img = $('#select-table tbody tr:eq(0) td:eq(2) input[name="image"]:checked').val();
var owner = $.cookie('srv_usrname');
if(!hcp || !group || !img) {
// Show warning message
var warn = createWarnBar('You need to select an option for each column');
warn.prependTo($(this).parent());
} else {
// Begin by creating VM
createzVM(tabId, group, hcp, img, owner);
}
});
provForm.append(provisionBtn);
// Load zVMs, groups, and images into their respective columns
loadSrvGroups(groupCol);
loadOSImages(imageCol);
// Get zVM host names
if (!$.cookie('srv_zvm')){
$.ajax( {
url : 'lib/srv_cmd.php',
dataType : 'json',
data : {
cmd : 'webportal',
tgt : '',
args : 'lszvm',
msg : ''
},
success : function(data) {
setzVMCookies(data);
loadzVMs(zvmCol);
}
});
} else {
loadzVMs(zvmCol);
}
};
/**
* Show node inventory (service page)
*
* @param data
* Data from HTTP request
* @return Nothing
*/
zvmPlugin.prototype.loadServiceInventory = function(data) {
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[0].split(node + ':');
// Remove loader
$('#' + tabId).find('img').remove();
// Create array of property keys
var keys = new Array('userId', 'host', 'os', 'arch', 'hcp', 'priv', 'memory', 'proc', 'disk', 'nic');
// 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
var attrs = getAttrs(keys, attrNames, inv);
// Create division to hold inventory
var invDivId = node + 'Inventory';
var invDiv = $('');
var infoBar = createInfoBar('Below is the inventory for the virtual machine you selected.');
invDiv.append(infoBar);
/**
* General info section
*/
var fieldSet = $('');
var legend = $('');
fieldSet.append(legend);
var oList = $('');
var item, label, args;
// Loop through each property
for ( var k = 0; k < 5; k++) {
// Create a list item for each property
item = $('');
// Create a label - Property name
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);
}
// Append to inventory form
fieldSet.append(oList);
invDiv.append(fieldSet);
/**
* Monitoring section
*/
fieldSet = $('');
legend = $('');
fieldSet.append(legend);
getMonitorMetrics(node);
// Refresh monitoring charts on-click
legend.find('a').click(function() {
getMonitorMetrics(node);
});
// Append to inventory form
invDiv.append(fieldSet);
/**
* Hardware info section
*/
var hwList, hwItem;
fieldSet = $('');
legend = $('');
var legend = $('');
fieldSet.append(legend);
var oList = $('');
var item, label, input, args;
// Loop through each property
for ( var k = 0; k < 5; k++) {
// Create a list item for each property
item = $('');
// Create a label - Property name
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);
}
// Append to inventory form
fieldSet.append(oList);
invDiv.append(fieldSet);
/**
* Hardware info section
*/
var hwList, hwItem;
fieldSet = $('');
legend = $('');
var typeLegend = $('');
typeFS.append(typeLegend);
provForm.append(typeFS);
// Create provision type drop down
var provType = $('');
var typeLabel = $('');
var typeSelect = $('');
var provNewNode = $('');
var provExistNode = $('');
typeSelect.append(provNewNode);
typeSelect.append(provExistNode);
provType.append(typeLabel);
provType.append(typeSelect);
typeFS.append(provType);
/**
* Create provision new node division
*/
var provNew = createZProvisionNew(inst);
provForm.append(provNew);
/**
* Create provision existing node division
*/
var provExisting = createZProvisionExisting(inst);
provForm.append(provExisting);
// Toggle provision new/existing on select
typeSelect.change(function(){
var selected = $(this).val();
if (selected == 'new') {
provNew.toggle();
provExisting.toggle();
} else {
provNew.toggle();
provExisting.toggle();
}
});
};
/**
* Load the resources
*
* @return Nothing
*/
zvmPlugin.prototype.loadResources = function() {
// 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
});
};
/**
* Add node range
*
* @return Nothing
*/
zvmPlugin.prototype.addNode = function() {
// Create form to add node range
var addNodeForm = $('');
var info = createInfoBar('Add a node range');
addNodeForm.append(info);
addNodeForm.append('');
addNodeForm.append('');
addNodeForm.append('');
addNodeForm.append('');
// Open form as a dialog
addNodeForm.dialog({
title: 'Add node',
modal: true,
width: 400,
buttons: {
"Ok": function(){
// 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();
// Show warning message if inputs are not complete
if (!nodeRange || !userIdRange || !group || !hcp) {
var warn = createWarnBar('You are missing inputs.');
warn.prependTo($(this));
} else {
// Check node range and user ID range
// Range can be given as gpok10-gpok20, gpok[10-20], or gpok10+10
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('-');
// 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
var nodeEnd = parseInt(tmp[1].match(/\d+/));
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
var userIdEnd = parseInt(tmp[1].match(/\d+/));
// 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;
}
}
}
// 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
var nodeEnd = parseInt(tmp[1].match(/\d+/));
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
var userIdEnd = parseInt(tmp[1].match(/\d+/));
// 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) {
openDialog('warn', '(Error) Failed to create node definitions');
} else {
openDialog('info', 'Node definitions created for ' + nodeRange);
}
}
}
});
}
} else {
// Only one node to add
$.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
if (rsp.length) {
openDialog('warn', '(Error) Failed to create node definition');
} else {
openDialog('info', 'Node definitions created for ' + node);
}
}
});
}
// Close dialog
$(this).dialog( "close" );
} else {
// Show warning message
var warn = createWarnBar(errMsg);
warn.prependTo($(this));
}
} // End of else
},
"Cancel": function(){
$(this).dialog( "close" );
}
}
});
};