').click(function () {
// Do not load panel again if it is already loaded
if ($('#zvmConfigProfile').find('.dataTables_wrapper').length)
return;
else
$('#zvmConfigProfile').append(createLoader(''));
queryProfiles('zvmConfigProfile');
});
// Create accordion panel for images
var imgSection = $('');
var imgLnk = $('
').click(function () {
// Do not load panel again if it is already loaded
if ($('#zvmConfigImages').find('.dataTables_wrapper').length)
return;
else
$('#zvmConfigImages').append(createLoader(''));
queryImages('zvmConfigImages');
});
// Create accordion panel for groups
var groupsSection = $('');
var groupsLnk = $('
').click(function () {
// Do not load panel again if it is already loaded
if ($('#zvmConfigGroups').find('.dataTables_wrapper').length)
return;
else
$('#zvmConfigGroups').append(createLoader(''));
queryGroups('zvmConfigGroups');
});
configAccordion.append(profileLnk, profileSection, imgLnk, imgSection, groupsLnk, groupsSection);
$('#' + tabId).append(configAccordion);
configAccordion.accordion();
profileLnk.trigger('click');
};
/**
* Clone node (service page)
*
* @param node Node to clone
*/
zvmPlugin.prototype.serviceClone = function(node) {
var owner = $.cookie('xcat_username');
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
*/
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
Template
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, template, and image
var zvmCol = $('
');
provRow.append(zvmCol);
var groupCol = $('
');
provRow.append(groupCol);
var tmplCol = $('
');
provRow.append(tmplCol);
var imgCol = $('
');
provRow.append(imgCol);
provRow.children('td').css({
'min-width': '200px'
});
/**
* 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 tmpl = $('#select-table tbody tr:eq(0) td:eq(2) input[name="image"]:checked').val();
var img = $('#select-table tbody tr:eq(0) td:eq(3) input[name="master"]:checked').val();
var owner = $.cookie('xcat_username');
if (img && !group) {
// Show warning message
var warn = createWarnBar('You need to select a group');
warn.prependTo($(this).parent());
} else if (!img && (!hcp || !group || !tmpl)) {
// Show warning message
var warn = createWarnBar('You need to select a zHCP, group, and image');
warn.prependTo($(this).parent());
} else {
if (img) {
// Begin by clonning VM
// Submit request to clone VM
// webportal clonezlinux [src node] [group] [owner]
var iframe = createIFrame('lib/srv_cmd.php?cmd=webportal&tgt=&args=clonezlinux;' + img + ';' + group + ';' + owner + '&msg=&opts=flush');
iframe.prependTo($('#zvmProvisionTab'));
} else {
// Begin by creating VM
createzVM(tabId, group, hcp, tmpl, owner);
}
}
});
provForm.append(provisionBtn);
// Load zVMs, groups, template, and image into their respective columns
loadSrvGroups(groupCol);
loadOSImages(tmplCol);
loadGoldenImages(imgCol);
// Get zVM host names
if (!$.cookie('zvms')){
$.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
*/
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=', '');
// Remove loader
$('#' + tabId).find('img').remove();
// Do not continue if error is found
if (data.rsp[0].indexOf('Error') > -1) {
var warn = createWarnBar(data.rsp[0]);
$('#' + tabId).append(warn);
return;
}
// Get node inventory
var inv = data.rsp[0].split(node + ':');
// Create array of property keys (VM)
var keys = new Array('userId', 'host', 'os', 'arch', 'uptime', 'cpuusedtime', 'hcp', 'priv', 'memory', 'maxmemory', 'proc', 'disk', 'zfcp', 'nic');
// Create hash table for property names (VM)
var attrNames = new Object();
attrNames['userId'] = 'z/VM UserID:';
attrNames['host'] = 'z/VM Host:';
attrNames['os'] = 'Operating System:';
attrNames['arch'] = 'Architecture:';
attrNames['uptime'] = 'Uptime:';
attrNames['cpuusedtime'] = 'CPU Used Time:';
attrNames['hcp'] = 'HCP:';
attrNames['priv'] = 'Privileges:';
attrNames['memory'] = 'Total Memory:';
attrNames['maxmemory'] = 'Max Memory:';
attrNames['proc'] = 'Processors:';
attrNames['disk'] = 'Disks:';
attrNames['zfcp'] = 'zFCP:';
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);
// var info = createInfoBar('No data available');
// fieldSet.append(info.css('width', '300px'));
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 vmLegend = $('');
vmFS.append(vmLegend);
cloneForm.append(vmFS);
var vmAttr = $('');
vmFS.append($(''));
vmFS.append(vmAttr);
// Create hardware fieldset
var storageFS = $('');
var storageLegend = $('');
storageFS.append(storageLegend);
cloneForm.append(storageFS);
var storageAttr = $('');
storageFS.append($(''));
storageFS.append(storageAttr);
vmAttr.append('');
vmAttr.append('');
vmAttr.append('');
vmAttr.append('');
// Create group input
var group = $('');
var groupLabel = $('');
var groupInput = $('');
groupInput.one('focus', function(){
var groupNames = $.cookie('groups');
if (groupNames) {
// Turn on auto complete
$(this).autocomplete({
source: groupNames.split(',')
});
}
});
group.append(groupLabel);
group.append(groupInput);
vmAttr.append(group);
// Create an advanced link to set IP address and hostname
var advancedLnk = $('');
vmAttr.append(advancedLnk);
var advanced = $('').hide();
vmAttr.append(advanced);
var ip = $('');
advanced.append(ip);
var hostname = $('');
advanced.append(hostname);
// Show IP address and hostname inputs on-click
advancedLnk.click(function() {
advanced.toggle();
});
// Get list of disk pools
var temp = hcp.split('.');
var diskPools = $.cookie(temp[0] + 'diskpools');
// Create disk pool input
var poolDiv = $('');
var poolLabel = $('');
var poolInput = $('').autocomplete({
source: diskPools.split(',')
});
poolDiv.append(poolLabel);
poolDiv.append(poolInput);
storageAttr.append(poolDiv);
storageAttr.append('');
// Generate tooltips
cloneForm.find('div input[title]').tooltip({
position : "center right",
offset : [ -2, 10 ],
effect : "fade",
opacity : 0.7,
predelay: 800,
events : {
def : "mouseover,mouseout",
input : "mouseover,mouseout",
widget : "focus mouseover,blur mouseout",
tooltip : "mouseover,mouseout"
}
});
/**
* Clone node
*/
var cloneBtn = createButton('Clone');
cloneBtn.bind('click', function(event) {
// Remove any warning messages
$(this).parents('.ui-tabs-panel').find('.ui-state-error').remove();
var ready = true;
var errMsg = '';
// Check node name, userId, hardware control point, group, and password
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).attr('name') != 'ip'
&& inputs.eq(i).attr('name') != 'hostname') {
inputs.eq(i).css('border', 'solid #FF0000 1px');
ready = false;
} else {
inputs.eq(i).css('border', 'solid #BDBDBD 1px');
}
}
// Write error message
if (!ready) {
errMsg = errMsg + 'Please provide a value for each missing field. ';
}
// Get target node
var nodeRange = $('#' + newTabId + ' input[name=tgtNode]').val();
// Get target user ID
var userIdRange = $('#' + newTabId + ' input[name=tgtUserId]').val();
// Get IP address range
var ipRange = $('#' + newTabId + ' input[name=ip]').val();
// Get hostname range
var hostnameRange = $('#' + newTabId + ' input[name=hostname]').val();
// Check node range and user ID range
if (nodeRange.indexOf('-') > -1 || userIdRange.indexOf('-') > -1 || ipRange.indexOf('-') > -1 || hostnameRange.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+/));
var ipStart = "", ipEnd = "";
if (ipRange) {
tmp = ipRange.split('-');
// Get starting IP address
ipStart = tmp[0].substring(tmp[0].lastIndexOf(".") + 1);
// Get ending IP address
ipEnd = tmp[1].substring(tmp[1].lastIndexOf(".") + 1);
}
var hostnameStart = "", hostnameEnd = "";
if (hostnameRange) {
tmp = hostnameRange.split('-');
// Get starting hostname
hostnameStart = parseInt(tmp[0].substring(0, tmp[0].indexOf(".")).match(/\d+/));
// Get ending hostname
hostnameEnd = parseInt(tmp[1].substring(0, tmp[1].indexOf(".")).match(/\d+/));
}
// If starting and ending index do not match
if (!(nodeStart == userIdStart) || !(nodeEnd == userIdEnd)) {
// Not ready to provision
errMsg = errMsg + 'The node range and user ID range does not match. ';
ready = false;
}
// If an IP address range is given and the starting and ending index do not match
if (ipRange && (!(nodeStart == ipStart) || !(nodeEnd == ipEnd))) {
errMsg = errMsg + 'The node range and IP address range does not match. ';
ready = false;
}
// If a hostname range is given and the starting and ending index do not match
if (hostnameRange && (!(nodeStart == hostnameStart) || !(nodeEnd == hostnameEnd))) {
errMsg = errMsg + 'The node range and hostname range does not match. ';
ready = false;
}
}
}
// Get source node, hardware control point, group, disk pool, and disk password
var srcNode = $('#' + newTabId + ' input[name=srcNode]').val();
var hcp = $('#' + newTabId + ' input[name=newHcp]').val();
var group = $('#' + newTabId + ' input[name=newGroup]').val();
var diskPool = $('#' + newTabId + ' input[name=diskPool]').val();
var diskPw = $('#' + newTabId + ' input[name=diskPw]').val();
// If a value is given for every input
if (ready) {
// Disable all inputs
var inputs = $('#' + newTabId + ' input');
inputs.attr('disabled', 'disabled');
// 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]+/);
// 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]+/);
var ipBase = "";
if (ipRange) {
tmp = ipRange.split('-');
// Get network base
ipBase = tmp[0].substring(0, tmp[0].lastIndexOf(".") + 1);
}
var domain = "";
if (hostnameRange) {
tmp = hostnameRange.split('-');
// Get domain name
domain = tmp[0].substring(tmp[0].indexOf("."));
}
// 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;
var args = node
+ ';zvm.hcp=' + hcp
+ ';zvm.userid=' + userId
+ ';nodehm.mgt=zvm'
+ ';groups=' + group;
if (ipRange) {
var ip = ipBase + i.toString();
args += ';hosts.ip=' + ip;
}
if (hostnameRange) {
var hostname = node + domain;
args += ';hosts.hostnames=' + hostname;
}
/**
* (1) Define node
*/
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'nodeadd',
tgt : '',
args : args,
msg : 'cmd=nodeadd;inst=' + inst
+ ';out=' + statBarId
+ ';node=' + node
},
success : updateZCloneStatus
});
}
} else {
var args = nodeRange
+ ';zvm.hcp=' + hcp
+ ';zvm.userid=' + userIdRange
+ ';nodehm.mgt=zvm'
+ ';groups=' + group;
if (ipRange)
args += ';hosts.ip=' + ipRange;
if (hostnameRange)
args += ';hosts.hostnames=' + hostnameRange;
/**
* (1) Define node
*/
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'nodeadd',
tgt : '',
args : args,
msg : 'cmd=nodeadd;inst=1/1;out=' + statBarId
+ ';node=' + nodeRange
},
success : updateZCloneStatus
});
}
// Create loader
$('#' + statBarId).find('div').append(createLoader());
$('#' + statBarId).show();
// Disable clone button
$(this).attr('disabled', 'true');
} else {
// Show warning message
var warn = createWarnBar(errMsg);
warn.prependTo($(this).parent().parent());
}
});
cloneForm.append(cloneBtn);
// Add clone tab
tab.add(newTabId, 'Clone', cloneForm, true);
}
tab.select(newTabId);
};
/**
* Load node inventory
*
* @param data Data from HTTP request
*/
zvmPlugin.prototype.loadInventory = function(data) {
var args = data.msg.split(',');
// Get tab ID
var tabId = args[0].replace('out=', '');
// Get node
var node = args[1].replace('node=', '');
// Clear any existing cookie
$.cookie(node + 'processes', null);
// Remove loader
$('#' + tabId).find('img').remove();
// Check for error
var error = false;
if (data.rsp.length && data.rsp[0].indexOf('Error') > -1) {
error = true;
var warn = createWarnBar(data.rsp[0]);
$('#' + tabId).append(warn);
}
// Determine the node type
if (data.rsp.length && data.rsp[0].indexOf('Hypervisor OS:') > -1) {
loadHypervisorInventory(data);
return;
}
// Create status bar
var statBarId = node + 'StatusBar';
var statBar = createStatusBar(statBarId);
// Add loader to status bar and hide it
var loader = createLoader(node + 'StatusBarLoader').hide();
statBar.find('div').append(loader);
statBar.hide();
// Create division to hold user entry
var ueDivId = node + 'UserEntry';
var ueDiv = $('');
// Create division to hold inventory
var invDivId = node + 'Inventory';
var invDiv = $('');
/**
* Show user entry
*/
var toggleLinkId = node + 'ToggleLink';
var toggleLink = $('Show directory entry');
toggleLink.one('click', function(event) {
// Toggle inventory division
$('#' + invDivId).toggle();
// Create loader
var loader = createLoader(node + 'TabLoader');
loader = $('
').append(loader);
ueDiv.append(loader);
// Get user entry
var msg = 'out=' + ueDivId + ';node=' + node;
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'lsvm',
tgt : node,
args : '',
msg : msg
},
success : loadUserEntry
});
// Change text
$(this).text('Show inventory');
// Disable toggle link
$(this).unbind(event);
});
// Align toggle link to the right
var toggleLnkDiv = $('').css({
'text-align' : 'right'
});
toggleLnkDiv.append(toggleLink);
// Append to tab
$('#' + tabId).append(statBar);
$('#' + tabId).append(toggleLnkDiv);
$('#' + tabId).append(ueDiv);
$('#' + tabId).append(invDiv);
// Do not load inventory if no inventory is returned
if (data.rsp.length && data.rsp[0].indexOf('z/VM UserID:') > -1) {
// Do nothing
} else {
return;
}
// Create array of property keys (VM)
var keys = new Array('userId', 'host', 'os', 'arch', 'uptime', 'cpuusedtime', 'hcp', 'priv', 'memory', 'maxmemory', 'proc', 'disk', 'zfcp', 'nic');
// Create hash table for property names (VM)
var attrNames = new Object();
attrNames['userId'] = 'z/VM UserID:';
attrNames['host'] = 'z/VM Host:';
attrNames['os'] = 'Operating System:';
attrNames['arch'] = 'Architecture:';
attrNames['uptime'] = 'Uptime:';
attrNames['cpuusedtime'] = 'CPU Used Time:';
attrNames['hcp'] = 'HCP:';
attrNames['priv'] = 'Privileges:';
attrNames['memory'] = 'Total Memory:';
attrNames['maxmemory'] = 'Max Memory:';
attrNames['proc'] = 'Processors:';
attrNames['disk'] = 'Disks:';
attrNames['zfcp'] = 'zFCP:';
attrNames['nic'] = 'NICs:';
// Create hash table for node attributes
var inv = data.rsp[0].split(node + ':');
var attrs;
if (!error) {
attrs = getAttrs(keys, attrNames, inv);
}
// Do not continue if error
if (error) {
return;
}
/**
* 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 < 6; 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 legend = $('');
fieldSet.append(legend);
var oList = $('');
var item, label, args;
// Loop through each property
for (var k = 0; k < 7; 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
*/
zvmPlugin.prototype.loadResources = function() {
// Reset resource table
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
*/
zvmPlugin.prototype.addNode = function() {
// Create form to add node range
var addNodeForm = $('');
var info = createInfoBar('Add a z/VM node range');
addNodeForm.append(info);
// Create provision type drop down
var type = $('');
var typeLabel = $('');
var typeSelect = $('');
typeSelect.append('');
typeSelect.append('');
type.append(typeLabel);
type.append(typeSelect);
addNodeForm.append(type);
addNodeForm.append('');
addNodeForm.append('');
addNodeForm.append('');
addNodeForm.append('');
addNodeForm.append('');
addNodeForm.append('');
addNodeForm.append('');
addNodeForm.append('');
// OS field only required for hosts
addNodeForm.find('input[name=os]').parent().hide();
// Toggle user Id on select
typeSelect.change(function(){
var selected = $(this).val();
if (selected == 'host') {
addNodeForm.find('input[name=userId]').parent().toggle();
addNodeForm.find('input[name=os]').parent().toggle();
} else {
addNodeForm.find('input[name=userId]').parent().toggle();
addNodeForm.find('input[name=os]').parent().toggle();
}
});
// Generate tooltips
addNodeForm.find('div input[title],select[title]').tooltip({
position: "center right",
offset: [-2, 10],
effect: "fade",
opacity: 0.8,
delay: 0,
predelay: 800,
events: {
def: "mouseover,mouseout",
input: "mouseover,mouseout",
widget: "focus mouseover,blur mouseout",
tooltip: "mouseover,mouseout"
},
// Change z index to show tooltip in front
onBeforeShow: function() {
this.getTip().css('z-index', $.topZIndex());
}
});
// 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 type = $(this).find('select[name=type]').val();
var nodeRange = $(this).find('input[name=node]').val();
var ipRange = $(this).find('input[name=ip]').val();
var hostnameRange = $(this).find('input[name=hostname]').val();
var userIdRange = $(this).find('input[name=userId]').val();
var os = $(this).find('input[name=os]').val();
var group = $(this).find('input[name=groups]').val();
var hcp = $(this).find('input[name=hcp]').val();
// Check required fields
if (type == 'host') {
if (!nodeRange || !os || !group || !hcp) {
var warn = createWarnBar('Please provide a value for each missing field!');
warn.prependTo($(this));
return;
}
} else {
if (!nodeRange || !userIdRange || !group || !hcp) {
var warn = createWarnBar('Please provide a value for each missing field!');
warn.prependTo($(this));
return;
}
}
// 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 starting index
var nodeStart = parseInt(tmp[0].match(/\d+/));
// Get ending index
var nodeEnd = parseInt(tmp[1].match(/\d+/));
tmp = userIdRange.split('-');
// Get starting index
var userIdStart = parseInt(tmp[0].match(/\d+/));
// Get ending index
var userIdEnd = parseInt(tmp[1].match(/\d+/));
var ipStart = "", ipEnd = "";
if (ipRange != "" && ipRange != null) {
tmp = ipRange.split('-');
// Get starting IP address
ipStart = tmp[0].substring(tmp[0].lastIndexOf(".") + 1);
// Get ending IP address
ipEnd = tmp[1].substring(tmp[1].lastIndexOf(".") + 1);
}
var hostnameStart = "", hostnameEnd = "";
if (hostnameRange != "" && hostnameRange != null) {
tmp = hostnameRange.split('-');
// Get starting hostname
hostnameStart = parseInt(tmp[0].substring(0, tmp[0].indexOf(".")).match(/\d+/));
// Get ending hostname
hostnameEnd = parseInt(tmp[1].substring(0, tmp[1].indexOf(".")).match(/\d+/));
}
// If starting and ending index do not match
if (!(nodeStart == userIdStart) || !(nodeEnd == userIdEnd)) {
errMsg = errMsg + 'The node range and user ID range does not match. ';
ready = false;
}
// If an IP address range is given and the starting and ending index do not match
if (ipRange != "" && ipRange != null && (!(nodeStart == ipStart) || !(nodeEnd == ipEnd))) {
errMsg = errMsg + 'The node range and IP address range does not match. ';
ready = false;
}
// If a hostname range is given and the starting and ending index do not match
if (hostnameRange != "" && hostnameRange != null && (!(nodeStart == hostnameStart) || !(nodeEnd == hostnameEnd))) {
errMsg = errMsg + 'The node range and hostname range does not match. ';
ready = false;
}
}
}
// If there are no errors
if (ready) {
$('#addZvm').append(createLoader());
// Change dialog buttons
$('#addZvm').dialog('option', 'buttons', {
'Close':function() {
$('#addZvm').dialog('destroy').remove();
}
});
// 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]+/);
var ipBase = "";
if (ipRange != "" && ipRange != null) {
tmp = ipRange.split('-');
// Get network base
ipBase = tmp[0].substring(0, tmp[0].lastIndexOf(".") + 1);
}
var domain = "";
if (hostnameRange != "" && hostnameRange != null) {
tmp = hostnameRange.split('-');
// Get domain name
domain = tmp[0].substring(tmp[0].indexOf("."));
}
// 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;
var args = "";
if (type == 'host') {
args = node + ';zvm.hcp=' + hcp
+ ';nodehm.mgt=zvm;nodetype.arch=s390x;hypervisor.type=zvm;groups=' + group
+ ';nodetype.os=' + os;
} else {
args = node + ';zvm.hcp=' + hcp
+ ';zvm.userid=' + userId
+ ';nodehm.mgt=zvm' + ';nodetype.arch=s390x' + ';groups=' + group;
}
if (ipRange != "" && ipRange != null) {
var ip = ipBase + i.toString();
args += ';hosts.ip=' + ip;
}
if (hostnameRange != "" && hostnameRange != null) {
var hostname = node + domain;
args += ';hosts.hostnames=' + hostname;
}
/**
* (1) Define node
*/
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'nodeadd',
tgt : '',
args : args,
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 instance returned and node range
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]) {
// Update /etc/hosts
$.ajax({
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'makehosts',
tgt : '',
args : '',
msg : ''
}
});
// Remove loader
$('#addZvm img').remove();
// If there was an error, do not continue
if (rsp.length) {
$('#addZvm').prepend(createWarnBar('Failed to create node definitions'));
} else {
$('#addZvm').prepend(createInfoBar('Node definitions created for ' + nodeRange));
}
}
}
});
}
} else {
var args = "";
if (type == 'host') {
args = nodeRange + ';zvm.hcp=' + hcp
+ ';nodehm.mgt=zvm;nodetype.arch=s390x;hypervisor.type=zvm;groups=' + group
+ ';nodetype.os=' + os;
} else {
args = nodeRange + ';zvm.hcp=' + hcp
+ ';zvm.userid=' + userIdRange
+ ';nodehm.mgt=zvm' + ';nodetype.arch=s390x' + ';groups=' + group;
}
if (ipRange)
args += ';hosts.ip=' + ipRange;
if (hostnameRange)
args += ';hosts.hostnames=' + hostnameRange;
// Only one node to add
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'nodeadd',
tgt : '',
args : args,
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(';');
var node = args[1].replace('node=', '');
// Update /etc/hosts
$.ajax({
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'makehosts',
tgt : '',
args : '',
msg : ''
}
});
// Remove loader
$('#addZvm img').remove();
// If there was an error, do not continue
if (rsp.length) {
$('#addZvm').prepend(createWarnBar('Failed to create node definitions'));
} else {
$('#addZvm').prepend(createInfoBar('Node definitions created for ' + node));
}
}
});
}
} else {
// Show warning message
var warn = createWarnBar(errMsg);
warn.prependTo($(this));
}
},
"Cancel": function(){
$(this).dialog('destroy').remove();
}
}
});
};
/**
* Migrate page
*
* @param tgtNode Targets to migrate
*/
zvmPlugin.prototype.loadMigratePage = function(tgtNode) {
var hosts = $.cookie('zvms').split(',');
var radio, zvmBlock, args;
var zvms = new Array();
var hcp = new Object();
// Create a drop-down for z/VM destinations
var destSelect = $('')
destSelect.append($(''));
for (var i in hosts) {
args = hosts[i].split(':');
hcp[args[0]] = args[1];
zvms.push(args[0]);
destSelect.append($(''));
}
// Get nodes tab
var tab = getNodesTab();
// Generate new tab ID
var inst = 0;
var newTabId = 'migrateTab' + inst;
while ($('#' + newTabId).length) {
// If one already exists, generate another one
inst = inst + 1;
newTabId = 'migrateTab' + inst;
}
// Open new tab
// Create remote script form
var migrateForm = $('');
// Create status bar
var barId = 'migrateStatusBar' + inst;
var statBar = createStatusBar(barId);
statBar.hide();
migrateForm.append(statBar);
// Create loader
var loader = createLoader('migrateLoader' + inst);
statBar.find('div').append(loader);
// Create info bar
var infoBar = createInfoBar('Migrate, test relocation eligibility, or cancel the relocation of the specified virtual machine, while it continues to run, to the specified system within the z/VM SSI cluster.');
migrateForm.append(infoBar);
// Virtual machine label
var vmFS = $('');
migrateForm.append(vmFS);
var vmAttr = $('');
vmFS.append($(''));
vmFS.append(vmAttr);
// Target node or group
var tgt = $('');
vmAttr.append(tgt);
// Destination
var dest = $('');
var destInput = $('');
destInput.autocomplete({
source: zvms
});
// Create a drop-down if there are known z/VMs
if (zvms.length) {
dest.append(destSelect);
} else {
dest.append(destInput);
}
vmAttr.append(dest);
// Action Parameter
var actionparam = $('');
vmAttr.append(actionparam);
// Parameters label
var optionalFS = $('').css('margin-top', '20px');
migrateForm.append(optionalFS);
var optAttr = $('');
optionalFS.append($(''));
optionalFS.append(optAttr);
// Immediate Parameter
var immediateparam = $('');
optAttr.append(immediateparam);
immediateparam.change(function() {
if ($('#' + newTabId + ' select[name=immediate]').val() == 'yes') {
$('#' + newTabId + ' input[name=maxQuiesce]').val('0');
} else {
$('#' + newTabId + ' input[name=maxQuiesce]').val('10');
}
});
// Max total
var maxTotalParam = $('');
optAttr.append(maxTotalParam);
// Max quiesce
var maxQuiesceParam = $('');
optAttr.append(maxQuiesceParam);
// Force parameter
var forceParam = $('
ArchitectureDomainStorage
');
optAttr.append(forceParam);
// Generate tooltips
migrateForm.find('div input[title],select[title]').tooltip({
position: "center right",
offset: [-2, 10],
effect: "fade",
opacity: 0.7,
predelay: 800,
events : {
def : "mouseover,mouseout",
input : "mouseover,mouseout",
widget : "focus mouseover,blur mouseout",
tooltip : "mouseover,mouseout"
}
});
/**
* Run
*/
var runBtn = createButton('Run');
runBtn.click(function() {
// Remove any warning messages
$(this).parent().parent().find('.ui-state-error').remove();
var tgt = $('#' + newTabId + ' input[name=target]');
// Drop-down box exists if z/VM systems are known
// Otherwise, only input box exists
var dest = $('#' + newTabId + ' select[name=dest]');
if (!dest.length) {
dest = $('#' + newTabId + ' input[name=dest]');
}
var action = $('#' + newTabId + ' select[name=action]');
var immediate = $('#' + newTabId + ' select[name=immediate]');
var maxTotal = $('#' + newTabId + ' input[name=maxTotal]');
var maxQuiesce = $('#' + newTabId + ' input[name=maxQuiesce]');
var tgts = $('#' + newTabId + ' input[name=target]');
// Change borders color back to normal
var inputs = $('#' + newTabId + ' input').css('border', 'solid #BDBDBD 1px');
var inputs = $('#' + newTabId + ' select').css('border', 'solid #BDBDBD 1px');
// Check if required arguments are given
var message = "";
if (!isInteger(maxTotal.val())) {
message += "Max total time must be an integer. ";
maxTotal.css('border', 'solid #FF0000 1px');
} if (!isInteger(maxQuiesce.val())) {
message += "Max quiesce time must be an integer. ";
maxQuiesce.css('border', 'solid #FF0000 1px');
} if (!tgt.val()) {
message += "Target must be specified. ";
tgt.css('border', 'solid #FF0000 1px');
} if (!dest.val()) {
message += "Destination must be specified. ";
dest.css('border', 'solid #FF0000 1px');
} if (!action.val()) {
message += "Action must be specified. ";
action.css('border', 'solid #FF0000 1px');
}
// Show warning message
if (message) {
var warn = createWarnBar(message);
warn.prependTo($(this).parent().parent());
return;
}
var args = "destination=" + dest.val() + ";action=" + action.val() + ";immediate=" + immediate.val() + ";";
// Append max total argument. Specified <= 0 to accomodate negative values.
if (maxTotal.val() <= 0) {
args = args + "max_total=NOLIMIT;";
} else {
args = args + "max_total=" + maxTotal.val() + ";";
}
// Append max quiesce argument. Specified <= 0 to accomodate negative values.
if (maxQuiesce.val() <= 0) {
args = args + "max_quiesce=NOLIMIT;";
} else {
args = args + "max_quiesce=" + maxQuiesce.val() + ";";
}
// Append force argument
if ($("input[name=force]:checked").length > 0) {
args = args + "'force="
$("input[name=force]:checked").each(function() {
args += $(this).val() + ' ';
});
args += "';";
}
var statBarId = 'migrateStatusBar' + inst;
$('#' + statBarId).show();
// Disable all fields
$('#' + newTabId + ' input').attr('disabled', 'true');
$('#' + newTabId + ' select').attr('disabled', 'true');
// Disable buttons
$('#' + newTabId + ' button').attr('disabled', 'true');
// Run migrate
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'rmigrate',
tgt : tgts.val(),
args : args,
msg : 'out=migrateStatusBar' + inst + ';cmd=rmigrate;tgt=' + tgts.val()
},
success : updateStatusBar
});
});
migrateForm.append(runBtn);
// Append to discover tab
tab.add(newTabId, 'Migrate', migrateForm, true);
// Select new tab
tab.select(newTabId);
};
/**
* Load event log configuration page
*
* @param node Source node to clone
*/
zvmPlugin.prototype.loadLogPage = function(node) {
// Get nodes tab
var tab = getNodesTab();
var newTabId = node + 'LogsTab';
// If there is no existing clone tab
if (!$('#' + newTabId).length) {
// Get table headers
var tableId = $('#' + node).parents('table').attr('id');
var headers = $('#' + tableId).parents('.dataTables_scroll').find('.dataTables_scrollHead thead tr:eq(0) th');
var cols = new Array();
for ( var i = 0; i < headers.length; i++) {
var col = headers.eq(i).text();
cols.push(col);
}
// Get hardware control point column
var hcpCol = $.inArray('hcp', cols);
// Get hardware control point
var nodeRow = $('#' + node).parent().parent();
var datatable = $('#' + getNodesTableId()).dataTable();
var rowPos = datatable.fnGetPosition(nodeRow.get(0));
var aData = datatable.fnGetData(rowPos);
var hcp = aData[hcpCol];
// Create status bar and hide it
var statBarId = node + 'CloneStatusBar';
var statBar = createStatusBar(statBarId).hide();
// Create info bar
var infoBar = createInfoBar('Retrieve, clear, or set options for event logs.');
// Create clone form
var logForm = $('');
logForm.append(statBar);
logForm.append(infoBar);
// Create VM fieldset
var vmFS = $('');
var vmLegend = $('');
vmFS.append(vmLegend);
logForm.append(vmFS);
var vmAttr = $('');
vmFS.append($(''));
vmFS.append(vmAttr);
// Create logs fieldset
var logFS = $('');
var logLegend = $('');
logFS.append(logLegend);
logForm.append(logFS);
var logAttr = $('');
logFS.append($(''));
logFS.append(logAttr);
vmAttr.append('');
logAttr.append('');
var optsLabel = $('');
var optsList = $('
');
logAttr.append(optsLabel);
logAttr.append(optsList);
// Create retrieve log checkbox
var retrieveChkBox = $('');
optsList.append(retrieveChkBox);
retrieveChkBox.append('Retrieve log');
// Create log destination input
var tgtLog = $('');
tgtLog.hide();
optsList.append(tgtLog);
// Create set log checkbox
var setChkBox = $('');
optsList.append(setChkBox);
setChkBox.append('Set options');
// Create log options input
var logOpt = $('');
logOpt.hide();
optsList.append(logOpt);
// Create clear log checkbox
var clearChkBox = $('');
optsList.append(clearChkBox);
clearChkBox.append('Clear log');
retrieveChkBox.bind('click', function(event) {
tgtLog.toggle();
});
setChkBox.find('input').bind('click', function(event) {
logOpt.toggle();
});
// Generate tooltips
logForm.find('div input[title]').tooltip({
position : "center right",
offset : [ -2, 10 ],
effect : "fade",
opacity : 0.7,
predelay: 800,
events : {
def : "mouseover,mouseout",
input : "mouseover,mouseout",
widget : "focus mouseover,blur mouseout",
tooltip : "mouseover,mouseout"
}
});
/**
* Run node
*/
var runBtn = createButton('Run');
runBtn.bind('click', function(event) {
// Remove any warning messages
$(this).parent().parent().find('.ui-state-error').remove();
var ready = true;
var errMsg = '';
// Verify required inputs are provided
var inputs = $('#' + newTabId + ' input');
for ( var i = 0; i < inputs.length; i++) {
if (!inputs.eq(i).val()
&& inputs.eq(i).attr('name') != 'tgtLog'
&& inputs.eq(i).attr('name') != 'logOpt') {
inputs.eq(i).css('border', 'solid #FF0000 1px');
ready = false;
} else {
inputs.eq(i).css('border', 'solid #BDBDBD 1px');
}
}
// Write error message
if (!ready) {
errMsg = errMsg + 'Please provide a value for each missing field. ';
}
var tgts = $('#' + newTabId + ' input[name=tgtNode]').val();
var srcLog = $('#' + newTabId + ' input[name=srcLog]').val();
var chkBoxes = $("#" + newTabId + " input[type='checkbox']:checked");
var optStr = '-s;' + srcLog + ';';
var opt;
for ( var i = 0; i < chkBoxes.length; i++) {
opt = chkBoxes.eq(i).attr('name');
optStr += '-' + opt;
// If it is the retrieve log
if (opt == 't') {
// Append log destination
optStr += ';' + $('#' + newTabId + ' input[name=tgtLog]').val();
}
// If it is set options
if (opt == 'o') {
// Append options
optStr += ';' + $('#' + newTabId + ' textarea[name=logOpt]').val();
}
// Append ; to end of string
if (i < (chkBoxes.length - 1)) {
optStr += ';';
}
}
// If a value is given for every input
if (ready) {
// Disable all inputs
var inputs = $('#' + newTabId + ' input');
inputs.attr('disabled', 'disabled');
/**
* (1) Retrieve, clear, or set options for event logs
*/
$.ajax( {
url : 'lib/cmd.php',
dataType : 'json',
data : {
cmd : 'reventlog',
tgt : tgts,
args : optStr,
msg : 'out=' + statBarId + ';cmd=reventlog;tgt=' + tgts
},
success : updateStatusBar
});
// Create loader
$('#' + statBarId).find('div').append(createLoader());
$('#' + statBarId).show();
// Disable run button
$(this).attr('disabled', 'true');
} else {
// Show warning message
var warn = createWarnBar(errMsg);
warn.prependTo($(this).parent().parent());
}
});
logForm.append(runBtn);
// Add clone tab
tab.add(newTabId, 'Logs', logForm, true);
}
tab.select(newTabId);
};