diff --git a/xCAT-UI/css/style.css b/xCAT-UI/css/style.css index 4aeeaee79..d86bdf98b 100644 --- a/xCAT-UI/css/style.css +++ b/xCAT-UI/css/style.css @@ -543,6 +543,10 @@ div.cleanblue button:hover { display: block; } +.form .indent { + display: inline-table; +} + .form input { font: 12px verdana, arial, helvetica, sans-serif; border: solid 1px #BDBDBD; diff --git a/xCAT-UI/js/custom/blade.js b/xCAT-UI/js/custom/blade.js index 941cf4669..2716a6f1a 100644 --- a/xCAT-UI/js/custom/blade.js +++ b/xCAT-UI/js/custom/blade.js @@ -106,7 +106,7 @@ bladePlugin.prototype.loadProvisionPage = function(tabId) { var groupInput = $(''); // Get the groups on-focus - groupInput.focus(function() { + groupInput.one('focus', function(){ var groupNames = $.cookie('Groups'); // If there are groups, turn on auto-complete @@ -150,7 +150,7 @@ bladePlugin.prototype.loadProvisionPage = function(tabId) { // Get the OS versions on-focus var tmp; - osInput.focus(function() { + osInput.one('focus', function(){ tmp = $.cookie('OSVers'); // If there are any, turn on auto-complete @@ -168,7 +168,7 @@ bladePlugin.prototype.loadProvisionPage = function(tabId) { var archInput = $(''); // Get the OS architectures on-focus - archInput.focus(function() { + archInput.one('focus', function(){ tmp = $.cookie('OSArchs'); // If there are any, turn on auto-complete @@ -186,7 +186,7 @@ bladePlugin.prototype.loadProvisionPage = function(tabId) { var profileInput = $(''); // Get the profiles on-focus - profileInput.focus(function() { + profileInput.one('focus', function(){ tmp = $.cookie('Profiles'); // If there are any, turn on auto-complete diff --git a/xCAT-UI/js/custom/fsp.js b/xCAT-UI/js/custom/fsp.js index b8ebc9a4b..fe14ba61b 100644 --- a/xCAT-UI/js/custom/fsp.js +++ b/xCAT-UI/js/custom/fsp.js @@ -106,7 +106,7 @@ fspPlugin.prototype.loadProvisionPage = function(tabId) { var groupInput = $(''); // Get the groups on-focus - groupInput.focus(function() { + groupInput.one('focus', function(){ var groupNames = $.cookie('Groups'); // If there are groups, turn on auto-complete @@ -150,7 +150,7 @@ fspPlugin.prototype.loadProvisionPage = function(tabId) { // Get the OS versions on-focus var tmp; - osInput.focus(function() { + osInput.one('focus', function(){ tmp = $.cookie('OSVers'); // If there are any, turn on auto-complete @@ -168,7 +168,7 @@ fspPlugin.prototype.loadProvisionPage = function(tabId) { var archInput = $(''); // Get the OS architectures on-focus - archInput.focus(function() { + archInput.one('focus', function(){ tmp = $.cookie('OSArchs'); // If there are any, turn on auto-complete @@ -186,7 +186,7 @@ fspPlugin.prototype.loadProvisionPage = function(tabId) { var profileInput = $(''); // Get the profiles on-focus - profileInput.focus(function() { + profileInput.one('focus', function(){ tmp = $.cookie('Profiles'); // If there are any, turn on auto-complete diff --git a/xCAT-UI/js/custom/hmc.js b/xCAT-UI/js/custom/hmc.js index 2d2f1e2cb..66467c668 100644 --- a/xCAT-UI/js/custom/hmc.js +++ b/xCAT-UI/js/custom/hmc.js @@ -159,7 +159,7 @@ hmcPlugin.prototype.loadProvisionPage = function(tabId) { var groupInput = $(''); // Get the groups on-focus - groupInput.focus(function() { + groupInput.one('focus', function(){ var groupNames = $.cookie('Groups'); // If there are groups, turn on auto-complete @@ -203,7 +203,7 @@ hmcPlugin.prototype.loadProvisionPage = function(tabId) { // Get the OS versions on-focus var tmp; - osInput.focus(function() { + osInput.one('focus', function(){ tmp = $.cookie('OSVers'); // If there are any, turn on auto-complete @@ -221,7 +221,7 @@ hmcPlugin.prototype.loadProvisionPage = function(tabId) { var archInput = $(''); // Get the OS architectures on-focus - archInput.focus(function() { + archInput.one('focus', function(){ tmp = $.cookie('OSArchs'); // If there are any, turn on auto-complete @@ -239,7 +239,7 @@ hmcPlugin.prototype.loadProvisionPage = function(tabId) { var profileInput = $(''); // Get the profiles on-focus - profileInput.focus(function() { + profileInput.one('focus', function(){ tmp = $.cookie('Profiles'); // If there are any, turn on auto-complete diff --git a/xCAT-UI/js/custom/ipmi.js b/xCAT-UI/js/custom/ipmi.js index f8f065bee..9f935dc8c 100644 --- a/xCAT-UI/js/custom/ipmi.js +++ b/xCAT-UI/js/custom/ipmi.js @@ -106,7 +106,7 @@ ipmiPlugin.prototype.loadProvisionPage = function(tabId) { var groupInput = $(''); // Get the groups on-focus - groupInput.focus(function() { + groupInput.one('focus', function(){ var groupNames = $.cookie('Groups'); // If there are groups, turn on auto-complete @@ -150,7 +150,7 @@ ipmiPlugin.prototype.loadProvisionPage = function(tabId) { // Get the OS versions on-focus var tmp; - osInput.focus(function() { + osInput.one('focus', function(){ tmp = $.cookie('OSVers'); // If there are any, turn on auto-complete @@ -168,7 +168,7 @@ ipmiPlugin.prototype.loadProvisionPage = function(tabId) { var archInput = $(''); // Get the OS architectures on-focus - archInput.focus(function() { + archInput.one('focus', function(){ tmp = $.cookie('OSArchs'); // If there are any, turn on auto-complete @@ -186,7 +186,7 @@ ipmiPlugin.prototype.loadProvisionPage = function(tabId) { var profileInput = $(''); // Get the profiles on-focus - profileInput.focus(function() { + profileInput.one('focus', function(){ tmp = $.cookie('Profiles'); // If there are any, turn on auto-complete diff --git a/xCAT-UI/js/custom/ivm.js b/xCAT-UI/js/custom/ivm.js index 6e6fd1e00..e77b00ce4 100644 --- a/xCAT-UI/js/custom/ivm.js +++ b/xCAT-UI/js/custom/ivm.js @@ -106,7 +106,7 @@ ivmPlugin.prototype.loadProvisionPage = function(tabId) { var groupInput = $(''); // Get the groups on-focus - groupInput.focus(function() { + groupInput.one('focus', function(){ var groupNames = $.cookie('Groups'); // If there are groups, turn on auto-complete @@ -150,7 +150,7 @@ ivmPlugin.prototype.loadProvisionPage = function(tabId) { // Get the OS versions on-focus var tmp; - osInput.focus(function() { + osInput.one('focus', function(){ tmp = $.cookie('OSVers'); // If there are any, turn on auto-complete @@ -168,7 +168,7 @@ ivmPlugin.prototype.loadProvisionPage = function(tabId) { var archInput = $(''); // Get the OS architectures on-focus - archInput.focus(function() { + archInput.one('focus', function(){ tmp = $.cookie('OSArchs'); // If there are any, turn on auto-complete @@ -186,7 +186,7 @@ ivmPlugin.prototype.loadProvisionPage = function(tabId) { var profileInput = $(''); // Get the profiles on-focus - profileInput.focus(function() { + profileInput.one('focus', function(){ tmp = $.cookie('Profiles'); // If there are any, turn on auto-complete diff --git a/xCAT-UI/js/custom/zvm.js b/xCAT-UI/js/custom/zvm.js index 79e237387..6be75b72e 100644 --- a/xCAT-UI/js/custom/zvm.js +++ b/xCAT-UI/js/custom/zvm.js @@ -75,7 +75,7 @@ zvmPlugin.prototype.loadClonePage = function(node) { var groupInput = $(''); // Get the groups on-focus - groupInput.focus(function() { + groupInput.one('focus', function(){ var groupNames = $.cookie('Groups'); // If there are groups, turn on auto-complete @@ -908,9 +908,7 @@ zvmPlugin.prototype.loadInventory = function(data) { * @return Nothing */ zvmPlugin.prototype.loadProvisionPage = function(tabId) { - var errMsg; - - // Get the OS image names + // Get OS image names $.ajax( { url : 'lib/cmd.php', dataType : 'json', @@ -938,16 +936,18 @@ zvmPlugin.prototype.loadProvisionPage = function(tabId) { success : setGroupsCookies }); - // Generate new tab ID + // Error message string + var errMsg; + + // zVM provision tab instance var inst = tabId.replace('zvmProvisionTab', ''); - // Open new tab // Create provision form var provForm = $('
'); // Create status bar - var barId = 'zProvisionStatBar' + inst; - var statBar = createStatusBar(barId); + var statBarId = 'zProvisionStatBar' + inst; + var statBar = createStatusBar(statBarId); statBar.hide(); provForm.append(statBar); @@ -963,444 +963,33 @@ zvmPlugin.prototype.loadProvisionPage = function(tabId) { // Append to provision tab $('#' + tabId).append(provForm); - /* - * Begin creating the form - */ - - // Create drop-down menu for provision type + // Create provision type drop down var provType = $('
'); - var label = $(''); - var type = $(''); - var newNode = $(''); - var existNode = $(''); - type.append(newNode); - type.append(existNode); - provType.append(label); - provType.append(type); + var typeLabel = $(''); + var typeSelect = $(''); + var provNewNode = $(''); + var provExistNode = $(''); + typeSelect.append(provNewNode); + typeSelect.append(provExistNode); + provType.append(typeLabel); + provType.append(typeSelect); provForm.append(provType); - /* - * Create provision new node DIV + /** + * Create provision new node division */ - var provNew = $('
'); + var provNew = createZProvisionNew(inst); provForm.append(provNew); - - // Group - var group = $('
'); - var groupLabel = $(''); - var groupInput = $(''); - - // Get the groups on-focus - groupInput.focus(function() { - var groupNames = $.cookie('Groups'); - - // If there are groups, turn on auto-complete - if (groupNames) { - $(this).autocomplete(groupNames.split(',')); - } - }); - - group.append(groupLabel); - group.append(groupInput); - provNew.append(group); - // Node name - var nodeName = $('
'); - var nodeLabel = $(''); - var nodeInput = $(''); - nodeName.append(nodeLabel); - nodeName.append(nodeInput); - provNew.append(nodeName); - - // User ID - var userId = $('
'); - provNew.append(userId); - - // Hardware control point - var hcpDiv = $('
'); - var hcpLabel = $(''); - hcpDiv.append(hcpLabel); - - var hcpInput = $(''); - hcpInput.blur(function() { - // If there is a HCP - if (hcpInput.val()) { - var args = hcpInput.val().split('.'); - - // Get disk pools - $.ajax( { - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'lsvm', - tgt : args[0], - args : '--diskpoolnames', - msg : args[0] - }, - - success : setDiskPoolCookies - }); - } - }); - hcpDiv.append(hcpInput); - provNew.append(hcpDiv); - - // Operating system image - var os = $('
'); - var osLabel = $(''); - var osInput = $(''); - - // Get the image names on-focus - osInput.focus(function() { - var imageNames = $.cookie('ImageNames'); - - // If there are image names, turn on auto-complete - if (imageNames) { - $(this).autocomplete(imageNames.split(',')); - } - }); - - os.append(osLabel); - os.append(osInput); - provNew.append(os); - - // User entry - var userEntry = $('
'); - provNew.append(userEntry); - - // Create disk table - var diskDiv = $('
'); - var diskLabel = $(''); - diskDiv.append(diskLabel); - var diskTable = $('
'); - var diskHeader = $(' Type Address Size Pool Password '); - diskHeader.find('th').css( { - 'width' : '80px' - }); - diskHeader.find('th').eq(0).css( { - 'width' : '20px' - }); - var diskBody = $(''); - var diskFooter = $(''); - /** - * Add disks + * Create provision existing node division */ - var addDiskLink = $('Add disk'); - addDiskLink.bind('click', function(event) { - var diskRow = $(''); - - // Remove button - var removeBtn = $(''); - removeBtn.bind('click', function(event) { - diskRow.remove(); - }); - var col = $('').append(removeBtn); - diskRow.append(col); - - // Disk type - var diskType = $(''); - var diskTypeSelect = $(''); - var diskType3390 = $(''); - diskTypeSelect.append(diskType3390); - diskType.append(diskTypeSelect); - diskRow.append(diskType); - - // Disk address - var diskAddr = $(''); - diskRow.append(diskAddr); - - // Disk size - var diskSize = $(''); - diskRow.append(diskSize); - - // Get list of disk pools - var thisTabId = $(this).parent().parent().parent().parent().parent().parent().attr('id'); - var thisHcp = $('#' + thisTabId + ' input[name=hcp]').val(); - var definedPools; - if (thisHcp) { - // Get node without domain - var temp = thisHcp.split('.'); - definedPools = $.cookie(temp[0] + 'DiskPools'); - } - - // Set auto-complete for disk pool - var diskPoolInput = $('').autocomplete( - definedPools.split(',')); - var diskPool = $('').append(diskPoolInput); - diskRow.append(diskPool); - - // Disk password - var diskPw = $(''); - diskRow.append(diskPw); - - diskBody.append(diskRow); - }); - diskFooter.append(addDiskLink); - - diskTable.append(diskHeader); - diskTable.append(diskBody); - diskTable.append(diskFooter); - diskDiv.append(diskTable); - provNew.append(diskDiv); - - /** - * Provision - */ - var provisionBtn = createButton('Provision'); - provisionBtn.bind('click', function(event) { - var ready = true; - errMsg = ''; - - // Get the tab ID - var thisTabId = $(this).parent().parent().parent().attr('id'); - var out2Id = thisTabId.replace('zvmProvisionTab', ''); - - // Check node name, userId, hardware control point, and group - var inputs = $('#' + thisTabId + ' input'); - for ( var i = 0; i < inputs.length; i++) { - // Do not check OS or disk password - if (!inputs.eq(i).val() && inputs.eq(i).attr('name') != 'os' - && inputs.eq(i).attr('type') != 'password') { - inputs.eq(i).css('border', 'solid #FF0000 1px'); - ready = false; - } else { - inputs.eq(i).css('border', 'solid #BDBDBD 1px'); - } - } - - // Check user entry - var thisUserEntry = $('#' + thisTabId + ' textarea'); - thisUserEntry.val(thisUserEntry.val().toUpperCase()); - if (!thisUserEntry.val()) { - thisUserEntry.css('border', 'solid #FF0000 1px'); - ready = false; - } else { - thisUserEntry.css('border', 'solid #BDBDBD 1px'); - } - - // Check if user entry contains user ID - var thisUserId = $('#' + thisTabId + ' input[name=userId]'); - var pos = thisUserEntry.val().indexOf( - 'USER ' + thisUserId.val().toUpperCase()); - if (pos < 0) { - errMsg = errMsg + 'The user entry does not contain the correct user ID. '; - ready = false; - } - - // If no operating system is specified, create only user entry - os = $('#' + thisTabId + ' input[name=os]'); - - // Check number of disks - var diskRows = $('#' + thisTabId + ' table tr'); - // If an OS is given, disks are needed - if (os.val() && (diskRows.length < 1)) { - errMsg = errMsg + 'You need to add at some disks. '; - ready = false; - } - - // Check address, size, pool, and password - var diskArgs = $('#' + thisTabId + ' table input'); - for ( var i = 0; i < diskArgs.length; i++) { - if (!diskArgs.eq(i).val() - && diskArgs.eq(i).attr('type') != 'password') { - diskArgs.eq(i).css('border', 'solid #FF0000 1px'); - ready = false; - } else { - diskArgs.eq(i).css('border', 'solid #BDBDBD 1px'); - } - } - - if (ready) { - if (!os.val()) { - /* - * If no OS is given, create a virtual server - */ - var msg = ''; - if (diskRows.length > 0) { - msg = 'Do you want to create virtual server(s) without an operating system ?'; - } - - // If no disks are given, create a virtual server (no disk) - else { - msg = 'Do you want to create virtual server(s) without an operating system or disk(s) ?'; - } - - // If the user clicks Ok - if (confirm(msg)) { - // Stop this function from executing again - // Unbind event - provisionBtn.unbind('click'); - provisionBtn.css( { - 'background-color' : '#F2F2F2', - 'color' : '#BDBDBD' - }); - - // Show loader - $('#zProvisionStatBar' + out2Id).show(); - $('#zProvisionLoader' + out2Id).show(); - - // Stop this function from executing again - // Unbind event - addDiskLink.unbind('click'); - addDiskLink.css( { - 'color' : '#BDBDBD' - }); - - // Disable close button on disk table - $('#' + thisTabId + ' table span').unbind('click'); - - // Disable all fields - var inputs = $('#' + thisTabId + ' input'); - inputs.attr('disabled', 'disabled'); - inputs.css( { - 'background-color' : '#F2F2F2' - }); - - var selects = $('#' + thisTabId + ' select'); - selects.attr('disabled', 'disabled'); - selects.css( { - 'background-color' : '#F2F2F2' - }); - - var textarea = $('#' + thisTabId + ' textarea'); - - // Add a new line at the end of the user entry - var tmp = jQuery.trim(textarea.val()); - textarea.val(tmp + '\n'); - - textarea.attr('readonly', 'readonly'); - textarea.css( { - 'background-color' : '#F2F2F2' - }); - - // Get node name - var node = $('#' + thisTabId + ' input[name=nodeName]') - .val(); - // Get userId - var userId = $('#' + thisTabId + ' input[name=userId]') - .val(); - // Get hardware control point - var hcp = $('#' + thisTabId + ' input[name=hcp]').val(); - // Get group - var group = $('#' + thisTabId + ' input[name=group]') - .val(); - - /** - * (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=nodeadd;out=' + out2Id - }, - - success : updateProvisionStatus - }); - } - } else { - /** - * Create a virtual server and install OS - */ - - // Stop this function from executing again - // Unbind event - $(this).unbind(event); - $(this).css( { - 'background-color' : '#F2F2F2', - 'color' : '#BDBDBD' - }); - - // Show loader - $('#zProvisionStatBar' + out2Id).show(); - $('#zProvisionLoader' + out2Id).show(); - - // Stop this function from executing again - // Unbind event - addDiskLink.unbind('click'); - addDiskLink.css( { - 'color' : '#BDBDBD' - }); - - // Disable close button on disk table - $('#' + thisTabId + ' table span').unbind('click'); - - // Disable all fields - var inputs = $('#' + thisTabId + ' input'); - inputs.attr('disabled', 'disabled'); - inputs.css( { - 'background-color' : '#F2F2F2' - }); - - var selects = $('#' + thisTabId + ' select'); - selects.attr('disabled', 'disabled'); - selects.css( { - 'background-color' : '#F2F2F2' - }); - - var textarea = $('#' + thisTabId + ' textarea'); - - // Add a new line at the end of the user entry - var tmp = jQuery.trim(textarea.val()); - textarea.val(tmp + '\n'); - - textarea.attr('readonly', 'readonly'); - textarea.css( { - 'background-color' : '#F2F2F2' - }); - - // Get node name - var node = $('#' + thisTabId + ' input[name=nodeName]') - .val(); - // Get userId - var userId = $('#' + thisTabId + ' input[name=userId]') - .val(); - // Get hardware control point - var hcp = $('#' + thisTabId + ' input[name=hcp]').val(); - // Get group - var group = $('#' + thisTabId + ' input[name=group]').val(); - - /** - * (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=nodeadd;out=' + out2Id - }, - - success : updateProvisionStatus - }); - } - } else { - alert('(Error) ' + errMsg); - } - }); - provNew.append(provisionBtn); - - /* - * Create provision existing node DIV - */ - var provExisting = $('
').hide(); + var provExisting = createZProvisionExisting(inst); provForm.append(provExisting); - - // Toogle provision forms on select of provision type - type.change(function(){ + + // Toggle provision new/existing on select + typeSelect.change(function(){ var selected = $(this).val(); - - // If the user wants to provision a new node if (selected == 'new') { provNew.toggle(); provExisting.toggle(); diff --git a/xCAT-UI/js/custom/zvmUtils.js b/xCAT-UI/js/custom/zvmUtils.js index cc9f1dd30..096a6f7c4 100644 --- a/xCAT-UI/js/custom/zvmUtils.js +++ b/xCAT-UI/js/custom/zvmUtils.js @@ -205,13 +205,13 @@ function incrementNodeProcess(node) { } /** - * Update the provision status + * Update the provision new node status * * @param data * Data returned from HTTP request * @return Nothing */ -function updateProvisionStatus(data) { +function updateProvisionNewStatus(data) { var rsp = data.rsp; var args = data.msg.split(';'); @@ -262,7 +262,7 @@ function updateProvisionStatus(data) { msg : 'cmd=makehosts;out=' + out2Id }, - success : updateProvisionStatus + success : updateProvisionNewStatus }); } @@ -289,7 +289,7 @@ function updateProvisionStatus(data) { msg : 'cmd=makedns;out=' + out2Id }, - success : updateProvisionStatus + success : updateProvisionNewStatus }); } @@ -323,7 +323,7 @@ function updateProvisionStatus(data) { msg : 'cmd=mkvm;out=' + out2Id }, - success : updateProvisionStatus + success : updateProvisionNewStatus }); } @@ -376,7 +376,7 @@ function updateProvisionStatus(data) { msg : 'cmd=mkvm;out=' + out2Id }, - success : updateProvisionStatus + success : updateProvisionNewStatus }); } else { // Failed - Do not continue @@ -415,7 +415,7 @@ function updateProvisionStatus(data) { msg : 'cmd=chvm;out=' + out2Id }, - success : updateProvisionStatus + success : updateProvisionNewStatus }); } else { // Virtual server created @@ -492,7 +492,7 @@ function updateProvisionStatus(data) { msg : 'cmd=chvm;out=' + out2Id }, - success : updateProvisionStatus + success : updateProvisionNewStatus }); } } else { @@ -539,7 +539,7 @@ function updateProvisionStatus(data) { msg : 'cmd=noderes;out=' + out2Id }, - success : updateProvisionStatus + success : updateProvisionNewStatus }); } } else { @@ -574,7 +574,7 @@ function updateProvisionStatus(data) { msg : 'cmd=makedhcp;out=' + out2Id }, - success : updateProvisionStatus + success : updateProvisionNewStatus }); } @@ -615,7 +615,7 @@ function updateProvisionStatus(data) { msg : 'cmd=nodeset;out=' + out2Id }, - success : updateProvisionStatus + success : updateProvisionNewStatus }); } @@ -662,7 +662,7 @@ function updateProvisionStatus(data) { msg : 'cmd=rnetboot;out=' + out2Id }, - success : updateProvisionStatus + success : updateProvisionNewStatus }); } } @@ -705,6 +705,100 @@ function updateProvisionStatus(data) { } } +/** + * Update the provision existing node status + * + * @param data + * Data returned from HTTP request + * @return Nothing + */ +function updateProvisionExistingStatus(data) { + // Get ajax response + var rsp = data.rsp; + var args = data.msg.split(';'); + + // Get command invoked + var cmd = args[0].replace('cmd=', ''); + // Get provision tab instance + var inst = args[1].replace('out=', ''); + + // Get provision tab and status bar ID + var statBarId = 'zProvisionStatBar' + inst; + var tabId = 'zvmProvisionTab' + inst; + + /** + * (2) Prepare node for boot + */ + if (cmd == 'chtab') { + // Get operating system + var bootMethod = $('#' + tabId + ' select[name=bootMethod]').val(); + + // Get nodes that were checked + var dTableId = 'nodesDatatable' + inst; + var tgts = getNodesChecked(dTableId); + + // Prepare node for boot + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'nodeset', + tgt : tgts, + args : bootMethod, + msg : 'cmd=nodeset;out=' + inst + }, + + success : updateProvisionExistingStatus + }); + } + + /** + * (3) Boot node from network + */ + else if (cmd == 'nodeset') { + // Write ajax response to status bar + var prg = writeRsp(rsp); + $('#' + statBarId).append(prg); + + // If there was an error + // Do not continue + if (prg.html().indexOf('Error') > -1) { + var loaderId = 'zProvisionLoader' + inst; + $('#' + loaderId).remove(); + } + + // Get nodes that were checked + var dTableId = 'nodesDatatable' + inst; + var tgts = getNodesChecked(dTableId); + + // Boot node from network + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'rnetboot', + tgt : tgts, + args : 'ipl=000C', + msg : 'cmd=rnetboot;out=' + inst + }, + + success : updateProvisionExistingStatus + }); + } + + /** + * (4) Done + */ + else if (cmd == 'rnetboot') { + // Write ajax response to status bar + var prg = writeRsp(rsp); + $('#' + statBarId).append(prg); + + var loaderId = 'zProvisionLoader' + inst; + $('#' + loaderId).remove(); + } +} + /** * Update zVM node status * @@ -1649,4 +1743,674 @@ function connect2VSwitch(data) { success : updateZNodeStatus }); +} + +/** + * Create provision existing node division + * + * @param inst + * Provision tab instance + * @return Provision existing node division + */ +function createZProvisionExisting(inst) { + // Create provision existing and hide it + var provExisting = $('
').hide(); + + // Create group input + var group = $('
'); + var groupLabel = $(''); + group.append(groupLabel); + + // Turn on auto complete for group + var groupNames = $.cookie('Groups'); + if (groupNames) { + // Split group names into an array + var tmp = groupNames.split(','); + + // Create drop down for groups + var groupSelect = $(''); + groupSelect.append(''); + for (var i in tmp) { + // Add group into drop down + var opt = $(''); + groupSelect.append(opt); + } + group.append(groupSelect); + + // Create node datatable + groupSelect.change(function(){ + // Create loader + var loader = createLoader(''); + $('nodesDatatableDIV' + inst).append(loader); + + // Get group selected + var thisGroup = $(this).val(); + // If a valid group is selected + if (thisGroup) { + // Get group nodes + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'lsdef', + tgt : '', + args : thisGroup, + msg : 'nodesDatatableDIV' + inst + }, + + /** + * Load nodes datatable + * + * @param data + * Data returned from HTTP request + * @return Nothing + */ + success : function(data) { + // Data returned + var rsp = data.rsp; + // Output ID + var outId = data.msg; + // Datatable ID + var dTableId = outId.replace('nodesDatatableDIV', 'nodesDatatable'); + // Node attributes hash + var attrs = new Object(); + // Node attributes + var headers = new Object(); + + // Remove loader + $('#' + outId).find('img').remove(); + + // Clear nodes datatable division + $('#' + outId).children().remove(); + + // Create nodes datatable + var node, args; + for ( var i in rsp) { + // Get node + var pos = rsp[i].indexOf('Object name:'); + if (pos > -1) { + var temp = rsp[i].split(': '); + node = jQuery.trim(temp[1]); + + // Create a hash for the node attributes + attrs[node] = new Object(); + i++; + } + + // Get key and value + args = rsp[i].split('='); + var key = jQuery.trim(args[0]); + var val = jQuery.trim(args[1]); + + // Create hash table + attrs[node][key] = val; + headers[key] = 1; + } + + // Sort headers + var sorted = new Array(); + for ( var key in headers) { + sorted.push(key); + } + sorted.sort(); + + // Add column for check box and node + sorted.unshift('Select', 'node'); + + // Create nodes datatable + var dTable = new DataTable(dTableId); + dTable.init(sorted); + + // Go through each node + for ( var node in attrs) { + // Create a row + var row = new Array(); + // Create a check box + var checkBx = ''; + row.push(checkBx, node); + + // Go through each header + for ( var i = 2; i < sorted.length; i++) { + // Add node attributes to the row + var key = sorted[i]; + var val = attrs[node][key]; + if (val) { + row.push(val); + } else { + row.push(''); + } + } + + // Add row to table + dTable.add(row); + } + + $('#' + outId).append(dTable.object()); + $('#' + dTableId).dataTable(); + } // End of function(data) + }); + } // End of if (thisGroup) + }); + } else { + // If no groups are cookied + var groupInput = $(''); + group.append(groupInput); + } + provExisting.append(group); + + // Create node input + var node = $('
'); + var nodeLabel = $(''); + var nodeDatatable = $('
'); + node.append(nodeLabel); + node.append(nodeDatatable); + provExisting.append(node); + + // Create operating system image input + var os = $('
'); + var osLabel = $(''); + var osInput = $(''); + // Get image names on focus + osInput.one('focus', function(){ + var imageNames = $.cookie('ImageNames'); + if (imageNames) { + // Turn on auto complete + $(this).autocomplete(imageNames.split(',')); + } + }); + os.append(osLabel); + os.append(osInput); + provExisting.append(os); + + // Create boot method drop down + var bootMethod = $('
'); + var methoddLabel = $(''); + var methodSelect = $(''); + methodSelect.append(''); + methodSelect.append(''); + methodSelect.append(''); + methodSelect.append(''); + methodSelect.append(''); + bootMethod.append(methoddLabel); + bootMethod.append(methodSelect); + provExisting.append(bootMethod); + + /** + * Provision existing + */ + var provisionBtn = createButton('Provision'); + provisionBtn.bind('click', function(event) { + var ready = true; + var errMsg = ''; + + // Get provision tab ID + var thisTabId = $(this).parent().parent().parent().attr('id'); + // Get provision tab instance + var inst = thisTabId.replace('zvmProvisionTab', ''); + + // Get nodes that were checked + var dTableId = 'nodesDatatable' + inst; + var tgts = getNodesChecked(dTableId); + if (!tgts) { + errMsg = 'You need to select a node.'; + ready = false; + } + + // Check operating system image + var os = $('#' + thisTabId + ' input[name=os]:visible'); + if (!os.val()) { + os.css('border', 'solid #FF0000 1px'); + ready = false; + } else { + os.css('border', 'solid #BDBDBD 1px'); + } + + // If all inputs are valid, ready to provision + if (ready) { + // Disable provision button + $(this).unbind(event); + $(this).css( { + 'background-color' : '#F2F2F2', + 'color' : '#BDBDBD' + }); + + // Show loader + $('#zProvisionStatBar' + inst).show(); + $('#zProvisionLoader' + inst).show(); + + // Disable all inputs + var inputs = $('#' + thisTabId + ' input'); + inputs.attr('disabled', 'disabled'); + + // Disable all selects + var selects = $('#' + thisTabId + ' select'); + selects.attr('disabled', 'disabled'); + + // Get operating system image + var osImage = $('#' + thisTabId + ' input[name=os]:visible').val(); + var tmp = osImage.split('-'); + var os = tmp[0]; + var arch = tmp[1]; + var profile = tmp[3]; + + /** + * (1) Set operating system + */ + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'nodeadd', + tgt : tgts, + args : 'noderes.netboot=zvm;nodetype.os=' + os + ';nodetype.arch=' + arch + ';nodetype.profile=' + profile, + msg : 'cmd=chtab;out=' + inst + }, + + success : updateProvisionExistingStatus + }); + } else { + alert('(Error) ' + errMsg); + } + }); + provExisting.append(provisionBtn); + + return provExisting; +} + +/** + * Create provision new node division + * + * @param inst + * Provision tab instance + * @return Provision new node division + */ +function createZProvisionNew(inst) { + // Create provision new node division + var provNew = $('
'); + + // Create group input + var group = $('
'); + var groupLabel = $(''); + var groupInput = $(''); + // Get groups on-focus + groupInput.one('focus', function(){ + var groupNames = $.cookie('Groups'); + if (groupNames) { + // Turn on auto complete + $(this).autocomplete(groupNames.split(',')); + } + }); + group.append(groupLabel); + group.append(groupInput); + provNew.append(group); + + // Create node input + var nodeName = $('
'); + var nodeLabel = $(''); + var nodeInput = $(''); + nodeName.append(nodeLabel); + nodeName.append(nodeInput); + provNew.append(nodeName); + + // Create user ID input + var userId = $('
'); + provNew.append(userId); + + // Create hardware control point input + var hcpDiv = $('
'); + var hcpLabel = $(''); + var hcpInput = $(''); + hcpInput.blur(function() { + if ($(this).val()) { + var args = $(this).val().split('.'); + + // Get disk pools + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'lsvm', + tgt : args[0], + args : '--diskpoolnames', + msg : args[0] + }, + + success : setDiskPoolCookies + }); + } + }); + hcpDiv.append(hcpLabel); + hcpDiv.append(hcpInput); + provNew.append(hcpDiv); + + // Create operating system image input + var os = $('
'); + var osLabel = $(''); + var osInput = $(''); + // Get image names on focus + osInput.one('focus', function(){ + var imageNames = $.cookie('ImageNames'); + if (imageNames) { + // Turn on auto complete + $(this).autocomplete(imageNames.split(',')); + } + }); + os.append(osLabel); + os.append(osInput); + provNew.append(os); + + // Create user entry input + var userEntry = $('
'); + provNew.append(userEntry); + + // Create disk table + var diskDiv = $('
'); + var diskLabel = $(''); + var diskTable = $('
'); + var diskHeader = $(' Type Address Size Pool Password '); + // Adjust header width + diskHeader.find('th').css( { + 'width' : '80px' + }); + diskHeader.find('th').eq(0).css( { + 'width' : '20px' + }); + var diskBody = $(''); + var diskFooter = $(''); + + /** + * Add disks + */ + var addDiskLink = $('Add disk'); + addDiskLink.bind('click', function(event) { + // Create a row + var diskRow = $(''); + + // Add remove button + var removeBtn = $(''); + var col = $('').append(removeBtn); + removeBtn.bind('click', function(event) { + diskRow.remove(); + }); + diskRow.append(col); + + // Create disk type drop down + var diskType = $(''); + var diskTypeSelect = $(''); + var diskType3390 = $(''); + diskTypeSelect.append(diskType3390); + diskType.append(diskTypeSelect); + diskRow.append(diskType); + + // Create disk address input + var diskAddr = $(''); + diskRow.append(diskAddr); + + // Create disk size input + var diskSize = $(''); + diskRow.append(diskSize); + + // Get list of disk pools + var thisTabId = $(this).parent().parent().parent().parent().parent().parent().attr('id'); + var thisHcp = $('#' + thisTabId + ' input[name=hcp]').val(); + var definedPools; + if (thisHcp) { + // Get node without domain name + var temp = thisHcp.split('.'); + definedPools = $.cookie(temp[0] + 'DiskPools'); + } + + // Create disk pool input + // Turn on auto complete for disk pool + var diskPoolInput = $('').autocomplete(definedPools.split(',')); + var diskPool = $('').append(diskPoolInput); + diskRow.append(diskPool); + + // Create disk password input + var diskPw = $(''); + diskRow.append(diskPw); + + diskBody.append(diskRow); + }); + + // Create disk table + diskFooter.append(addDiskLink); + diskTable.append(diskHeader); + diskTable.append(diskBody); + diskTable.append(diskFooter); + + diskDiv.append(diskLabel); + diskDiv.append(diskTable); + provNew.append(diskDiv); + + /** + * Provision new + */ + var provisionBtn = createButton('Provision'); + provisionBtn.bind('click', function(event) { + var ready = true; + var errMsg = ''; + + // Get tab ID + var thisTabId = $(this).parent().parent().parent().attr('id'); + // Get provision tab instance + var inst = thisTabId.replace('zvmProvisionTab', ''); + + // Check node name, userId, hardware control point, and group + var inputs = $('#' + thisTabId + ' input'); + for ( var i = 0; i < inputs.length; i++) { + // Do not check OS or disk password + if (!inputs.eq(i).val() + && inputs.eq(i).attr('name') != 'os' + && inputs.eq(i).attr('type') != 'password') { + inputs.eq(i).css('border', 'solid #FF0000 1px'); + ready = false; + } else { + inputs.eq(i).css('border', 'solid #BDBDBD 1px'); + } + } + + // Check user entry + var thisUserEntry = $('#' + thisTabId + ' textarea:visible'); + thisUserEntry.val(thisUserEntry.val().toUpperCase()); + if (!thisUserEntry.val()) { + thisUserEntry.css('border', 'solid #FF0000 1px'); + ready = false; + } else { + thisUserEntry.css('border', 'solid #BDBDBD 1px'); + } + + // Check if user entry contains user ID + var thisUserId = $('#' + thisTabId + ' input[name=userId]:visible'); + var pos = thisUserEntry.val().indexOf('USER ' + thisUserId.val().toUpperCase()); + if (pos < 0) { + errMsg = errMsg + 'The user entry does not contain the correct user ID. '; + ready = false; + } + + // If no operating system is specified, create only user entry + os = $('#' + thisTabId + ' input[name=os]:visible'); + + // Check number of disks + var diskRows = $('#' + thisTabId + ' table tr'); + // If an OS is given, disks are needed + if (os.val() && (diskRows.length < 1)) { + errMsg = errMsg + 'You need to add at some disks. '; + ready = false; + } + + // Check address, size, pool, and password + var diskArgs = $('#' + thisTabId + ' table input:visible'); + for ( var i = 0; i < diskArgs.length; i++) { + if (!diskArgs.eq(i).val() + && diskArgs.eq(i).attr('type') != 'password') { + diskArgs.eq(i).css('border', 'solid #FF0000 1px'); + ready = false; + } else { + diskArgs.eq(i).css('border', 'solid #BDBDBD 1px'); + } + } + + // If inputs are valid, ready to provision + if (ready) { + if (!os.val()) { + // If no OS is given, create a virtual server + var msg = ''; + if (diskRows.length > 0) { + msg = 'Do you want to create a virtual server without an operating system ?'; + } + + // If no disks are given, create a virtual server (no disk) + else { + msg = 'Do you want to create a virtual server without an operating system or disks ?'; + } + + // If user clicks Ok + if (confirm(msg)) { + // Disable provision button + $(this).unbind('click'); + $(this).css( { + 'background-color' : '#F2F2F2', + 'color' : '#BDBDBD' + }); + + // Show loader + $('#zProvisionStatBar' + inst).show(); + $('#zProvisionLoader' + inst).show(); + + // Disable add disk button + addDiskLink.unbind('click'); + addDiskLink.css( { + 'color' : '#BDBDBD' + }); + + // Disable close button on disk table + $('#' + thisTabId + ' table span').unbind('click'); + + // Disable all inputs + var inputs = $('#' + thisTabId + ' input'); + inputs.attr('disabled', 'disabled'); + + // Disable all selects + var selects = $('#' + thisTabId + ' select'); + selects.attr('disabled', 'disabled'); + + // Add a new line at the end of the user entry + var textarea = $('#' + thisTabId + ' textarea'); + var tmp = jQuery.trim(textarea.val()); + textarea.val(tmp + '\n'); + textarea.attr('readonly', 'readonly'); + textarea.css( { + 'background-color' : '#F2F2F2' + }); + + // Get node name + var node = $('#' + thisTabId + ' input[name=nodeName]').val(); + // Get userId + var userId = $('#' + thisTabId + ' input[name=userId]').val(); + // Get hardware control point + var hcp = $('#' + thisTabId + ' input[name=hcp]').val(); + // Get group + var group = $('#' + thisTabId + ' input[name=group]').val(); + + /** + * (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=nodeadd;out=' + inst + }, + + success : updateProvisionNewStatus + }); + } + } else { + /** + * Create a virtual server and install OS + */ + + // Disable provision button + $(this).unbind(event); + $(this).css( { + 'background-color' : '#F2F2F2', + 'color' : '#BDBDBD' + }); + + // Show loader + $('#zProvisionStatBar' + inst).show(); + $('#zProvisionLoader' + inst).show(); + + // Disable add disk button + addDiskLink.unbind('click'); + addDiskLink.css( { + 'color' : '#BDBDBD' + }); + + // Disable close button on disk table + $('#' + thisTabId + ' table span').unbind('click'); + + // Disable all inputs + var inputs = $('#' + thisTabId + ' input'); + inputs.attr('disabled', 'disabled'); + inputs.css( { + 'background-color' : '#F2F2F2' + }); + + // Disable all selects + var selects = $('#' + thisTabId + ' select'); + selects.attr('disabled', 'disabled'); + selects.css( { + 'background-color' : '#F2F2F2' + }); + + // Add a new line at the end of the user entry + var textarea = $('#' + thisTabId + ' textarea'); + var tmp = jQuery.trim(textarea.val()); + textarea.val(tmp + '\n'); + textarea.attr('readonly', 'readonly'); + textarea.css( { + 'background-color' : '#F2F2F2' + }); + + // Get node name + var node = $('#' + thisTabId + ' input[name=nodeName]').val(); + // Get userId + var userId = $('#' + thisTabId + ' input[name=userId]').val(); + // Get hardware control point + var hcp = $('#' + thisTabId + ' input[name=hcp]').val(); + // Get group + var group = $('#' + thisTabId + ' input[name=group]').val(); + + /** + * (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=nodeadd;out=' + inst + }, + + success : updateProvisionNewStatus + }); + } + } else { + alert('(Error) ' + errMsg); + } + }); + provNew.append(provisionBtn); + + return provNew; } \ No newline at end of file diff --git a/xCAT-UI/js/nodes/nodes.js b/xCAT-UI/js/nodes/nodes.js index bea3f0028..b8029e1f7 100644 --- a/xCAT-UI/js/nodes/nodes.js +++ b/xCAT-UI/js/nodes/nodes.js @@ -258,7 +258,7 @@ function loadNodes(data) { */ var powerOnLnk = $('Power on'); powerOnLnk.bind('click', function(event) { - var tgtNodes = getNodesChecked(); + var tgtNodes = getNodesChecked('nodesDataTable'); if (tgtNodes) { powerNode(tgtNodes, 'on'); } @@ -269,7 +269,7 @@ function loadNodes(data) { */ var powerOffLnk = $('Power off'); powerOffLnk.bind('click', function(event) { - var tgtNodes = getNodesChecked(); + var tgtNodes = getNodesChecked('nodesDataTable'); if (tgtNodes) { powerNode(tgtNodes, 'off'); } @@ -280,7 +280,7 @@ function loadNodes(data) { */ var cloneLnk = $('Clone'); cloneLnk.bind('click', function(event) { - var tgtNodes = getNodesChecked().split(','); + var tgtNodes = getNodesChecked('nodesDataTable').split(','); for ( var i = 0; i < tgtNodes.length; i++) { var mgt = getNodeMgt(tgtNodes[i]); @@ -316,7 +316,7 @@ function loadNodes(data) { */ var deleteLnk = $('Delete'); deleteLnk.bind('click', function(event) { - var tgtNodes = getNodesChecked(); + var tgtNodes = getNodesChecked('nodesDataTable'); if (tgtNodes) { deleteNode(tgtNodes); } @@ -327,7 +327,7 @@ function loadNodes(data) { */ var unlockLnk = $('Unlock'); unlockLnk.bind('click', function(event) { - var tgtNodes = getNodesChecked(); + var tgtNodes = getNodesChecked('nodesDataTable'); if (tgtNodes) { loadUnlockPage(tgtNodes); } @@ -338,7 +338,7 @@ function loadNodes(data) { */ var scriptLnk = $('Run script'); scriptLnk.bind('click', function(event) { - var tgtNodes = getNodesChecked(); + var tgtNodes = getNodesChecked('nodesDataTable'); if (tgtNodes) { loadScriptPage(tgtNodes); } @@ -349,7 +349,7 @@ function loadNodes(data) { */ var updateLnk = $('Update'); updateLnk.bind('click', function(event) { - var tgtNodes = getNodesChecked(); + var tgtNodes = getNodesChecked('nodesDataTable'); if (tgtNodes) { loadUpdatenodePage(tgtNodes); } @@ -360,7 +360,7 @@ function loadNodes(data) { */ var setBootStateLnk = $('Set boot state'); setBootStateLnk.bind('click', function(event) { - var tgtNodes = getNodesChecked(); + var tgtNodes = getNodesChecked('nodesDataTable'); if (tgtNodes) { loadNodesetPage(tgtNodes); } @@ -372,7 +372,7 @@ function loadNodes(data) { */ var boot2NetworkLnk = $('Boot to network'); boot2NetworkLnk.bind('click', function(event) { - var tgtNodes = getNodesChecked(); + var tgtNodes = getNodesChecked('nodesDataTable'); if (tgtNodes) { loadNetbootPage(tgtNodes); } @@ -926,7 +926,7 @@ function loadNodesetPage(trgtNodes) { // Get the OS versions on-focus var tmp; - osInput.focus(function() { + osInput.one('focus', function(){ tmp = $.cookie('OSVers'); // If there are any, turn on auto-complete @@ -944,7 +944,7 @@ function loadNodesetPage(trgtNodes) { var archInput = $(''); // Get the OS architectures on-focus - archInput.focus(function() { + archInput.one('focus', function(){ tmp = $.cookie('OSArchs'); // If there are any, turn on auto-complete @@ -962,7 +962,7 @@ function loadNodesetPage(trgtNodes) { var profileInput = $(''); // Get the profiles on-focus - profileInput.focus(function() { + profileInput.one('focus', function(){ tmp = $.cookie('Profiles'); // If there are any, turn on auto-complete @@ -2161,29 +2161,31 @@ function getNodeRow(tgtNode, rows) { } /** - * Get the nodes that were checked in the nodes datatable + * Get the nodes that are checked in a given datatable * + * @param datatableId + * The datatable ID * @return Nodes that were checked */ -function getNodesChecked() { - var tgtNodes = ''; +function getNodesChecked(datatableId) { + var tgts = ''; // Get nodes that were checked - var nodes = $('#nodesDataTable input[type=checkbox]:checked'); + var nodes = $('#' + datatableId + ' input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { - tgtNodes += nodes.eq(i).attr('name'); + var tgtNode = nodes.eq(i).attr('name'); - if ("" == tgtNodes){ - continue; - } - - // Add a comma in front of each node - if (i < nodes.length - 1) { - tgtNodes += ','; + if (tgtNode){ + tgts += tgtNode; + + // Add a comma at the end + if (i < nodes.length - 1) { + tgts += ','; + } } } - return tgtNodes; + return tgts; } function getColNum(colName){ diff --git a/xCAT-UI/js/ui.js b/xCAT-UI/js/ui.js index 9a413baa3..2e91d17ae 100644 --- a/xCAT-UI/js/ui.js +++ b/xCAT-UI/js/ui.js @@ -464,4 +464,26 @@ function includeJs(file) { $('head').append(script); } +} + +/** + * Write ajax response to a paragraph + * + * @param rsp + * Ajax response + * @param replace + * Boolean to replace the node name in front of each line + * @return Paragraph containing ajax response + */ +function writeRsp(rsp) { + // Create paragraph to hold ajax response + var prg = $('

'); + for ( var i in rsp) { + if (rsp[i]) { + prg.append(rsp[i]); + prg.append('
'); + } + } + + return prg; } \ No newline at end of file