/*associate the step name with step number*/
var steps = ['Discover Hardware',
'Cluster Patterns',
'Switch Ports',
'More Cluster Patterns',
'Prepare Management Node',
'Power On Hardware',
'Discover HW Control Points',
'Update Definitions',
'Configure HW Control Points',
'Create Nodes',
'Complete'];
/*associate the function with step number*/
var initFunctions = [initSelectPlatform,
initBasicPattern,
initSwitch,
initAdvancedPattern];
/*associate the function witch should be called before the page changed(when click next or back)
* if there is no need to call functions, use undefined.*/
var nextFunctions = [undefined,
collectInputValue,
collectInputValue,
collectInputValue];
/*save current step number*/
var currentStep = 0;
/*save user's input*/
var discoverEnv;
/**
* create the discover page
*
* @param
*
* @return
*/
function loadDiscoverPage(){
currentStep = 0;
discoverEnv = new Object();
$('#content').append('
');
updateDiscoverStep();
$('#content').append('
');
initSelectPlatform();
}
/**
* update the step show are on the left side of discover page
*
* @param
*
* @return
*/
function updateDiscoverStep(){
$('#discoverStepDiv').empty();
var showString = '';
for(var index in steps){
showString += '' + steps[index] + ' ';
}
$('#discoverStepDiv').html(showString);
}
/**
* create the navigator buttons on the bottom of discover page
*
* @param
*
* @return
*/
function createDiscoverButtons(){
var buttonDiv = $('');
var backButton = createBackButton();
var nextButton = createNextButton();
var cancelButton = createButton('Cancel');
cancelButton.bind('click', function(){
$('#content').empty();
for (var name in discoverEnv){
delete discoverEnv[name];
}
loadDiscoverPage();
});
if (backButton){
buttonDiv.append(backButton);
}
if(nextButton){
buttonDiv.append(nextButton);
}
buttonDiv.append(cancelButton);
$('#discoverContentDiv').append(buttonDiv);
}
/**
* create the next button base on the currentStep, the last step does not need this button
*
* @param
*
* @return
*/
function createNextButton(){
if ((steps.length - 1) == currentStep){
return undefined;
}
var nextButton = createButton('Next');
nextButton.bind('click', function(){
if (nextFunctions[currentStep]){
nextFunctions[currentStep]();
}
currentStep ++;
updateDiscoverStep();
initFunctions[currentStep]();
});
return nextButton;
}
/**
* create the next button base on the currentStep, the first step does not need this button
*
* @param
*
* @return
*/
function createBackButton(){
if (0 == currentStep){
return undefined;
}
var backButton = createButton('Back');
backButton.bind('click', function(){
if (nextFunctions[currentStep]){
nextFunctions[currentStep]();
}
currentStep--;
updateDiscoverStep();
initFunctions[currentStep]();
});
return backButton;
}
/**
* get the input value on discover page
*
* @param
* envName : value's name(discoverEnv's key)
*
* @return
* if there is assciate value, return the value.
* else return null.
*/
function getDiscoverEnv(envName){
if (discoverEnv[envName]){
return discoverEnv[envName];
}
else{
return '';
}
}
/**
* Expand the noderange into node names.
*
* @param
* nodeRange :
*
* @return
* node names array.
*
*/
function expandNR(nodeRange){
var retArray = new Array();
var tempResult;
if ('' == nodeRange){
return retArray;
}
tempResult = nodeRange.match(/(.*?)\[(.*?)\](.*)/);
if (null != tempResult){
var parts = tempResult[2].split('-');
if (2 > parts.length){
return retArray;
}
var start = Number(parts[0]);
var end = Number(parts[1]);
var len = parts[0].length;
for(var i = parts[0]; i <= parts[1]; i++){
var ts = i.toString();
if (ts.length < len){
ts = "000000".substring(0, (len - ts.length)) + ts;
}
retArray = retArray.concat(expandNR(tempResult[1] + ts + tempResult[3]));
}
return retArray;
}
var tempArray = nodeRange.split('-');
if (2 > tempArray.length){
retArray.push(nodeRange);
return retArray;
}
var begin = tempArray[0].match(/^(\D+)(\d+)$/);
if(2 > begin){
retArray.push(nodeRange);
return retArray;
}
var end = tempArray[1].match(/^(\D+)(\d+)$/);
if(2 > end){
retArray.push(nodeRange);
return retArray;
}
if(begin[1] != end[1]){
retArray.push(nodeRange);
return retArray;
}
var prefix = begin[1];
var len = begin[2].length;
for(var i = begin[2]; i <= end[2]; i++){
var ts = i.toString();
if (ts.length < len){
ts = "000000".substring(0, (len - ts.length)) + ts;
}
retArray.push(prefix + ts);
}
return retArray;
}
/**
* Step 1: show the wizard's function
* platform selector(system P or system X)
*
* @param
*
* @return
*/
function initSelectPlatform(){
var temp = '';
$('#discoverContentDiv').empty();
temp += '
' + steps[currentStep] + '
';
temp += '
This wizard will guide you through the process of defining the naming conventions within' +
'your cluster, discovering the hardware on your network, and automatically defining it in the xCAT' +
'database. Choose which type of hardware you want to discover, and then click Next.
';
temp += ' System x hardware (not implemented yet) ';
temp += ' System p hardware (only partially implemented) ';
temp += '
';
$('#discoverContentDiv').append(temp);
createDiscoverButtons();
}
/**
* Step 2: Cluster basic patterns
* users can input the switches' name range, the number of port, start ip and port prefix
* hmcs' name range, number and start ip
* frames' name range, number and start ip
* drawers' name range, number and start ip
*
* @param
*
* @return
*/
function initBasicPattern(){
$('#discoverContentDiv').empty();
var showString = '
' + steps[currentStep] + '
';
showString += '
';
//switch title
showString += '
Service LAN Switches
';
//switch name
showString += '
Hostname Range:
';
showString += '
';
//switch start ip
showString += '
Starting IP Address:
';
//Number of Ports Per Switch
showString += '
Number of Ports Per Switch:
';
showString += '
';
//ports' name prefix
showString += '
Switch Port Prefix:
';
//hmc title
showString += '
HMCs
';
//hmc name
showString += '
Hostname Range:
';
showString += '
';
//hmc start ip
showString += '
Starting IP Address:
';
//Number of Frames per HMC
showString += '
Number of Frames per HMC:
';
//BPA title
showString += '
Frames (BPAs)
';
//BPA Name
showString += '
Hostname Range:
';
showString += '
';
//BPA start ip
showString += '
Starting IP Address:
';
//Number of Drawers per Frame
showString += '
Number of Drawers per Frame:
';
//FSP title
showString += '
Drawers (FSPs/CECs)
';
//FSP name
showString += '
Hostname Range:
';
showString += '
';
//FSP start ip
showString += '
Starting IP Address:
';
//Number of LPARs per Drawer:
showString += '
Number of LPARs per Drawer:
';
showString += '
';
$('#discoverContentDiv').append(showString);
$('#discoverContentDiv input[type=text][title]').tooltip({
position: "center right",
offset: [-2, 10],
effect: "fade",
opacity: 1
});
createDiscoverButtons();
}
/**
* Step 2: Cluster basic patterns
* save all of users' input into the global object discoverEnv
*
* @param
*
* @return
*/
function collectInputValue(){
$('#discoverContentDiv input[type=text]').each(function(){
var name = $(this).attr('name');
var value = $(this).attr('value');
if('' != value){
discoverEnv[name] = value;
}
else{
if(discoverEnv[name]){
delete discoverEnv[name];
}
}
});
return;
}
/**
* Step 3: define switch ports
*
* @param
*
* @return
*/
function initSwitch(){
$('#discoverContentDiv').empty();
var showString = '
' + steps[currentStep] + '
';
showString += '
';
//Discovery Information title
showString += '
Switch Port Assignments
';
//Dynamic IP Range for DHCP
showString += '
Dynamic IP Range for DHCP:
';
showString += '
';
//IP Address to Broadcast
showString += '
IP Address to Broadcast From:
';
showString += '
';
$('#discoverContentDiv').append(showString);
createDiscoverButtons();
}
function initAdvancedPattern(){
$('#discoverContentDiv').empty();
var showString = '
' + steps[currentStep] + '
';
showString += '
';
showString += '
Building Blocks
';
//Starting Subnet IP for Cluster Mgmt LAN:
showString += '