From 8798c04625caf8e16ec6712947a4f9f455205e2f Mon Sep 17 00:00:00 2001 From: phamt Date: Wed, 22 Sep 2010 16:52:41 +0000 Subject: [PATCH] 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 --- xCAT-UI/js/custom/blade.js | 11 +++ xCAT-UI/js/custom/fsp.js | 11 +++ xCAT-UI/js/custom/hmc.js | 11 +++ xCAT-UI/js/custom/ipmi.js | 11 +++ xCAT-UI/js/custom/ivm.js | 11 +++ xCAT-UI/js/custom/zvm.js | 180 +++++++++++++++++++++++++++++++++++++ xCAT-UI/js/nodes/nodes.js | 32 +++++-- 7 files changed, 260 insertions(+), 7 deletions(-) diff --git a/xCAT-UI/js/custom/blade.js b/xCAT-UI/js/custom/blade.js index 851f7745e..f0d0867f8 100644 --- a/xCAT-UI/js/custom/blade.js +++ b/xCAT-UI/js/custom/blade.js @@ -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) { + }; \ No newline at end of file diff --git a/xCAT-UI/js/custom/fsp.js b/xCAT-UI/js/custom/fsp.js index 508084ea0..fa3b50034 100644 --- a/xCAT-UI/js/custom/fsp.js +++ b/xCAT-UI/js/custom/fsp.js @@ -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) { + }; \ No newline at end of file diff --git a/xCAT-UI/js/custom/hmc.js b/xCAT-UI/js/custom/hmc.js index 8cd08217a..ffb986a63 100644 --- a/xCAT-UI/js/custom/hmc.js +++ b/xCAT-UI/js/custom/hmc.js @@ -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) { + }; \ No newline at end of file diff --git a/xCAT-UI/js/custom/ipmi.js b/xCAT-UI/js/custom/ipmi.js index f4187f4f4..5a959567e 100644 --- a/xCAT-UI/js/custom/ipmi.js +++ b/xCAT-UI/js/custom/ipmi.js @@ -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) { + }; \ No newline at end of file diff --git a/xCAT-UI/js/custom/ivm.js b/xCAT-UI/js/custom/ivm.js index bfe5d2c2b..70852ab09 100644 --- a/xCAT-UI/js/custom/ivm.js +++ b/xCAT-UI/js/custom/ivm.js @@ -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) { + }; \ No newline at end of file diff --git a/xCAT-UI/js/custom/zvm.js b/xCAT-UI/js/custom/zvm.js index 00063fa30..74259de7d 100644 --- a/xCAT-UI/js/custom/zvm.js +++ b/xCAT-UI/js/custom/zvm.js @@ -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 = '

(Error) Failed to create node definition

'; + } else { + msg = '

Node definitions created for ' + nodeRange + '

'; + } + + $.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 = '

(Error) Failed to create node definition

'; + } else { + msg = '

Node definition created for ' + node + '

'; + } + + $.prompt(msg, { + buttons: { Ok: true }, + prefix: 'cleanblue' + }); + } + }); + } + } else { + // Prompt an error message + $.prompt('

' + errMsg + '

', { + buttons: { Ok: true }, + prefix: 'cleanblue' + }); + } }; \ No newline at end of file diff --git a/xCAT-UI/js/nodes/nodes.js b/xCAT-UI/js/nodes/nodes.js index 4c5315507..ec24a4f91 100644 --- a/xCAT-UI/js/nodes/nodes.js +++ b/xCAT-UI/js/nodes/nodes.js @@ -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 } \ No newline at end of file