Update back-end code fore "Add node" link

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@7583 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
phamt 2010-09-22 16:52:41 +00:00
parent bb4141f57b
commit 8798c04625
7 changed files with 260 additions and 7 deletions

View File

@ -140,4 +140,15 @@ bladePlugin.prototype.loadProvisionPage = function(tabId) {
*/
bladePlugin.prototype.loadResources = function() {
};
/**
* Add node
*
* @param f
* Key/value pairs of the form values
* @return Nothing
*/
bladePlugin.prototype.addNode = function(f) {
};

View File

@ -140,4 +140,15 @@ fspPlugin.prototype.loadProvisionPage = function(tabId) {
*/
fspPlugin.prototype.loadResources = function() {
};
/**
* Add node
*
* @param f
* Key/value pairs of the form values
* @return Nothing
*/
fspPlugin.prototype.addNode = function(f) {
};

View File

@ -193,4 +193,15 @@ hmcPlugin.prototype.loadProvisionPage = function(tabId) {
*/
hmcPlugin.prototype.loadResources = function() {
};
/**
* Add node
*
* @param f
* Key/value pairs of the form values
* @return Nothing
*/
hmcPlugin.prototype.addNode = function(f) {
};

View File

@ -140,4 +140,15 @@ ipmiPlugin.prototype.loadProvisionPage = function(tabId) {
*/
ipmiPlugin.prototype.loadResources = function() {
};
/**
* Add node
*
* @param f
* Key/value pairs of the form values
* @return Nothing
*/
ipmiPlugin.prototype.addNode = function(f) {
};

View File

@ -140,4 +140,15 @@ ivmPlugin.prototype.loadProvisionPage = function(tabId) {
*/
ivmPlugin.prototype.loadResources = function() {
};
/**
* Add node
*
* @param f
* Key/value pairs of the form values
* @return Nothing
*/
ivmPlugin.prototype.addNode = function(f) {
};

View File

@ -1063,4 +1063,184 @@ zvmPlugin.prototype.loadResources = function() {
},
success : getZResources
});
};
/**
* Add node
*
* @param f
* Key/value pairs of the form values
* @return Nothing
*/
zvmPlugin.prototype.addNode = function(f) {
var nodeRange = f.node;
var group = f.group;
var hcp = f.hcp;
var userIdRange = f.userId;
// Check node range and user ID range
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]);
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]);
// 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 catched
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]);
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]);
// 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
var msg;
if (rsp.length) {
msg = '<p>(Error) Failed to create node definition</p>';
} else {
msg = '<p>Node definitions created for ' + nodeRange + '</p>';
}
$.prompt(msg, {
buttons: { Ok: true },
prefix: 'cleanblue'
});
}
}
});
}
} else {
$.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
var msg;
if (rsp.length) {
msg = '<p>(Error) Failed to create node definition</p>';
} else {
msg = '<p>Node definition created for ' + node + '</p>';
}
$.prompt(msg, {
buttons: { Ok: true },
prefix: 'cleanblue'
});
}
});
}
} else {
// Prompt an error message
$.prompt('<p>' + errMsg + '</p>', {
buttons: { Ok: true },
prefix: 'cleanblue'
});
}
};

View File

@ -245,7 +245,6 @@ function loadGroups(data) {
// Show blade form
blade : {
html : bladeForm,
callback : addNode,
buttons : {
Ok : true,
Cancel : false
@ -262,7 +261,6 @@ function loadGroups(data) {
// Show fsp form
fsp : {
html : fspForm,
callback : addNode,
buttons : {
Ok : true,
Cancel : false
@ -279,7 +277,6 @@ function loadGroups(data) {
// Show hmc form
hmc : {
html : hmcForm,
callback : addNode,
buttons : {
Ok : true,
Cancel : false
@ -296,7 +293,6 @@ function loadGroups(data) {
// Show ipmi form
ipmi : {
html : ipmiForm,
callback : addNode,
buttons : {
Ok : true,
Cancel : false
@ -313,7 +309,6 @@ function loadGroups(data) {
// Show ivm form
ivm : {
html : ivmForm,
callback : addNode,
buttons : {
Ok : true,
Cancel : false
@ -330,7 +325,6 @@ function loadGroups(data) {
// Show zvm form
zvm : {
html : zvmForm,
callback : addNode,
buttons : {
Ok : true,
Cancel : false
@ -346,6 +340,7 @@ function loadGroups(data) {
};
$.prompt(states, {
callback : addNode,
prefix : 'cleanblue'
});
@ -1694,6 +1689,29 @@ function loadRconsPage(tgtNodes){
function addNode(v, m, f) {
// If user clicks Ok
if (v) {
var mgt = f.mgt;
var plugin;
switch(mgt) {
case "blade":
plugin = new bladePlugin();
break;
case "fsp":
plugin = new fspPlugin();
break;
case "hmc":
plugin = new hmcPlugin();
break;
case "ipmi":
plugin = new ipmiPlugin();
break;
case "ivm":
plugin = new ivmPlugin();
break;
case "zvm":
plugin = new zvmPlugin();
break;
}
}
plugin.addNode(f);
} // End of if
}