/** * Execute when the DOM is fully loaded */ $(document).ready(function() { // Load utility scripts (if any) }); /** * Constructor * * @return Nothing */ var ipmiPlugin = function() { }; /** * Steps for hardware discovery wizard * * @return Discovery steps */ ipmiPlugin.prototype.getStep = function(){ return ['Basic patterns', 'Switches', 'Network', 'Services', 'Power on hardware']; }; /** * return steps's init function for hardware discovery wizard * * @return Nothing */ ipmiPlugin.prototype.getInitFunction = function(){ return [idataplexInitBasic, idataplexInitSwitch, idataplexInitNetwork, idataplexInitService, idataplexInitPowerOn]; }; ipmiPlugin.prototype.getNextFunction = function(){ return [idataplexCheckBasic, undefined, idataplexCheckNetwork, undefined, undefined]; }; /** * Clone node (service page) * * @param node * Node to clone * @return Nothing */ ipmiPlugin.prototype.serviceClone = function(node) { }; /** * Load provision page (service page) * * @param tabId * Tab ID where page will reside * @return Nothing */ ipmiPlugin.prototype.loadServiceProvisionPage = function(tabId) { }; /** * Show node inventory (service page) * * @param data * Data from HTTP request * @return Nothing */ ipmiPlugin.prototype.loadServiceInventory = function(data) { }; /** * Load node inventory * * @param data * Data from HTTP request * @return Nothing */ ipmiPlugin.prototype.loadInventory = function(data) { var args = data.msg.split(','); var tabId = args[0].replace('out=', ''); var node = args[1].replace('node=', ''); // Get node inventory var inv = data.rsp; // Remove loader $('#' + tabId).find('img').remove(); // Create division to hold inventory var invDiv = $('
'); // Create a fieldset var fieldSet = $('
'); var legend = $('Hardware'); fieldSet.append(legend); var oList = $('
    '); fieldSet.append(oList); invDiv.append(fieldSet); // Loop through each line var item; for (var k = 0; k < inv.length; k++) { // Remove node name var attr = inv[k].replace(node + ': ', ''); attr = jQuery.trim(attr); // Append attribute to list item = $('
  1. '); item.append(attr); oList.append(item); } // Append to inventory form $('#' + tabId).append(invDiv); }; /** * Load clone page * * @param node * Source node to clone * @return Nothing */ ipmiPlugin.prototype.loadClonePage = function(node) { // Get nodes tab var tab = getNodesTab(); var newTabId = node + 'CloneTab'; // If there is no existing clone tab if (!$('#' + newTabId).length) { // Create info bar var infoBar = createInfoBar('Not supported'); // Create clone form var cloneForm = $('
    '); cloneForm.append(infoBar); // Add clone tab tab.add(newTabId, 'Clone', cloneForm, true); } tab.select(newTabId); }; /** * Load provision page * * @param tabId * The provision tab ID * @return Nothing */ ipmiPlugin.prototype.loadProvisionPage = function(tabId) { // Get OS image names $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'tabdump', tgt : '', args : 'osimage', msg : '' }, success : setOSImageCookies }); // Get groups $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'extnoderange', tgt : '/.*', args : 'subgroups', msg : '' }, success : setGroupsCookies }); // Get provision tab instance var inst = tabId.replace('ipmiProvisionTab', ''); // Create provision form var provForm = $('
    '); // Create info bar var infoBar = createInfoBar('Provision an iDataPlex. This will install an operating system onto the iDataPlex.'); provForm.append(infoBar); // Append to provision tab $('#' + tabId).append(provForm); // Create provision existing node division var provExisting = createIpmiProvisionExisting(inst); provForm.append(provExisting); }; /** * Load resources */ ipmiPlugin.prototype.loadResources = function() { // Get resource tab ID var tabId = 'ipmiResourceTab'; // Remove loader $('#' + tabId).find('img').remove(); // Create info bar var infoBar = createInfoBar('Under construction'); // Create resource form var resrcForm = $('
    '); resrcForm.append(infoBar); $('#' + tabId).append(resrcForm); }; /** * Add node range */ ipmiPlugin.prototype.addNode = function() { var dialog = $('
    '); var info = createInfoBar('Add a iDataPlex node'); dialog.append(info); // Create node inputs dialog.append($('
    ')); dialog.append($('
    ')); dialog.append($('
    ')); dialog.append($('
    ')); dialog.dialog({ title: 'Add node', modal: true, width: 400, close: function(){$(this).remove();}, buttons: { "OK" : function(){addIdataplex();}, "Cancel": function(){$(this).dialog('close');} } }); }; /** * Add iDataPlex node range */ function addIdataplex(){ var attr, args; var errorMessage = ''; // Remove existing warnings $('#addIdplx .ui-state-error').remove(); // Return input border colors to normal $('#addIdplx input').css('border', 'solid #BDBDBD 1px'); // Check node attributes $('#addIdplx input').each(function(){ attr = $(this).val(); if (!attr) { errorMessage = "Please provide a value for each missing field!"; $(this).css('border', 'solid #FF0000 1px'); } }); // Show error message (if any) if (errorMessage) { $('#addIdplx').prepend(createWarnBar(errorMessage)); return; } // Create loader $('#addIdplx').append(createLoader()); // Change dialog buttons $('#addIdplx').dialog('option', 'buttons', { 'Close':function(){ $('#addIdplx').dialog('close'); } }); // Generate chdef arguments args = '-t;node;-o;' + $('#addIdplx input[name="node"]').val() + ';ip=' + $('#addIdplx input[name="ip"]').val() + ';mac=' + $('#addIdplx input[name="mac"]').val() + ';groups=' + $('#addIdplx input[name="groups"]').val() + ';mgt=ipmi;netboot=xnba;nodetype=osi;profile=compute'; $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'chdef', tgt : '', args : args, msg : '' }, success: function(data) { // Update /etc/hosts $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'makehosts', tgt : '', args : '', msg : '' }, }); // Remove loader $('#addIdplx img').remove(); // Get return message var message = ''; for (var i in data.rsp) { message += data.rsp[i] + '
    '; } // Show return message if (message) $('#addIdplx').prepend(createInfoBar(message)); } }); } /** * Create provision existing node division * * @param inst * Provision tab instance * @return Provision existing node division */ function createIpmiProvisionExisting(inst) { // Create provision existing division var provExisting = $('
    '); // Create VM fieldset var nodeFS = $('
    '); var nodeLegend = $('Node'); nodeFS.append(nodeLegend); var nodeAttr = $('
    '); nodeFS.append($('
    ')); nodeFS.append(nodeAttr); // Create image fieldset var imgFS = $('
    '); var imgLegend = $('Image'); imgFS.append(imgLegend); var imgAttr = $('
    '); imgFS.append($('
    ')); imgFS.append(imgAttr); provExisting.append(nodeFS, imgFS); // Create group input var group = $('
    '); var groupLabel = $(''); group.append(groupLabel); // Turn on auto complete for group var dTableDivId = 'ipmiNodesDatatableDIV' + inst; // Division ID where nodes datatable will be appended 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() { // Get group selected var thisGroup = $(this).val(); // If a valid group is selected if (thisGroup) { createNodesDatatable(thisGroup, dTableDivId); } // End of if (thisGroup) }); } else { // If no groups are cookied var groupInput = $(''); group.append(groupInput); } nodeAttr.append(group); // Create node input var node = $('
    '); var nodeLabel = $(''); var nodeDatatable = $('

    Select a group to view its nodes

    '); node.append(nodeLabel); node.append(nodeDatatable); nodeAttr.append(node); // Create boot method drop down var method = $('
    '); var methodLabel = $(''); var methodSelect = $(''); methodSelect.append('' + '' + '' + '' + '' + '' ); method.append(methodLabel); method.append(methodSelect); imgAttr.append(method); // Create operating system input var os = $('
    '); var osLabel = $(''); var osInput = $(''); osInput.one('focus', function() { var tmp = $.cookie('osvers'); if (tmp) { // Turn on auto complete $(this).autocomplete({ source: tmp.split(',') }); } }); os.append(osLabel); os.append(osInput); imgAttr.append(os); // Create architecture input var arch = $('
    '); var archLabel = $(''); var archInput = $(''); archInput.one('focus', function() { var tmp = $.cookie('osarchs'); if (tmp) { // Turn on auto complete $(this).autocomplete({ source: tmp.split(',') }); } }); arch.append(archLabel); arch.append(archInput); imgAttr.append(arch); // Create profile input var profile = $('
    '); var profileLabel = $(''); var profileInput = $(''); profileInput.one('focus', function() { var tmp = $.cookie('profiles'); if (tmp) { // Turn on auto complete $(this).autocomplete({ source: tmp.split(',') }); } }); profile.append(profileLabel); profile.append(profileInput); imgAttr.append(profile); /** * Provision existing */ var provisionBtn = createButton('Provision'); provisionBtn.bind('click', function(event) { // Remove any warning messages $(this).parents('.ui-tabs-panel').find('.ui-state-error').remove(); var ready = true; var errorMessage = ''; // Get provision tab ID var thisTabId = 'ipmiProvisionTab' + inst; // Get nodes that were checked var dTableId = 'ipmiNodesDatatable' + inst; var tgts = getNodesChecked(dTableId); if (!tgts) { errorMessage += 'You need to select a node. '; ready = false; } // Check booth method var boot = $('#' + thisTabId + ' select[name=bootMethod]'); if (!boot.val()) { errorMessage += 'You need to select a boot method. '; boot.css('border', 'solid #FF0000 1px'); ready = false; } else { boot.css('border', 'solid #BDBDBD 1px'); } // Check operating system image var os = $('#' + thisTabId + ' input[name=os]'); if (!os.val()) { errorMessage += 'You need to select a operating system image. '; os.css('border', 'solid #FF0000 1px'); ready = false; } else { os.css('border', 'solid #BDBDBD 1px'); } // Check architecture var arch = $('#' + thisTabId + ' input[name=arch]'); if (!arch.val()) { errorMessage += 'You need to select an architecture. '; arch.css('border', 'solid #FF0000 1px'); ready = false; } else { arch.css('border', 'solid #BDBDBD 1px'); } // Check profile var profile = $('#' + thisTabId + ' input[name=profile]'); if (!profile.val()) { errorMessage += 'You need to select a profile. '; profile.css('border', 'solid #FF0000 1px'); ready = false; } else { profile.css('border', 'solid #BDBDBD 1px'); } // If all inputs are valid, ready to provision if (ready) { // Disable provision button $(this).attr('disabled', 'true'); // Prepend status bar var statBar = createStatusBar('ipmiProvisionStatBar' + inst); statBar.append(createLoader('')); statBar.prependTo($('#' + thisTabId)); // Disable all inputs var inputs = $('#' + thisTabId + ' input'); inputs.attr('disabled', 'disabled'); // Disable all selects var selects = $('#' + thisTabId + ' select'); selects.attr('disabled', 'disabled'); /** * (1) Set operating system */ $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'nodeadd', tgt : '', args : tgts + ';noderes.netboot=xnba;nodetype.os=' + os.val() + ';nodetype.arch=' + arch.val() + ';nodetype.profile=' + profile.val() + ';nodetype.provmethod=' + boot.val(), msg : 'cmd=nodeadd;out=' + inst }, success : updateIpmiProvisionExistingStatus }); } else { // Show warning message var warn = createWarnBar(errorMessage); warn.prependTo($(this).parent().parent()); } }); provExisting.append(provisionBtn); return provExisting; } /** * Update the provision existing node status * * @param data * Data returned from HTTP request * @return Nothing */ function updateIpmiProvisionExistingStatus(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 = 'ipmiProvisionStatBar' + inst; var tabId = 'ipmiProvisionTab' + inst; /** * (2) Remote install */ if (cmd == 'nodeadd') { // Write ajax response to status bar var prg = writeRsp(rsp, ''); $('#' + statBarId).find('div').append(prg); // Get parameters var os = $('#' + tabId + ' input[name="os"]').val(); var profile = $('#' + tabId + ' input[name="profile"]').val(); var arch = $('#' + tabId + ' input[name="arch"]').val(); // Get nodes that were checked var dTableId = 'ipmiNodesDatatable' + inst; var tgts = getNodesChecked(dTableId); // Begin installation $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'rinstall;' + os + ';' + profile + ';' + arch + ';' + tgts, msg : 'cmd=rinstall;out=' + inst }, success : updateIpmiProvisionExistingStatus }); } /** * (3) Done */ else if (cmd == 'rinstall') { // Write ajax response to status bar var prg = writeRsp(rsp, ''); $('#' + statBarId).find('div').append(prg); $('#' + statBarId).find('img').remove(); // If installation was successful if (prg.html().indexOf('Error') == -1) { $('#' + statBarId).find('div').append('
    It will take several minutes before the nodes are up and ready. Use nodestat to check the status of the install.
    '); } } } /** * step 2: init the idataplex basic pattern * * @param * * @return */ function idataplexInitBasic(){ var tempip = ''; $('#discoverContentDiv').empty(); $('.tooltip').remove(); var showString = '

    ' + steps[currentStep] + '

    '; showString += ''; //nodes title showString += ''; //nodes name range showString += ''; //nodes start ip if (getDiscoverEnv('idataplexnodeip')){ tempip = getDiscoverEnv('idataplexnodeip'); } else{ tempip = '172.30.20.1'; } showString += ''; //num-nodes-per-frame showString += ''; //bmc title showString += ''; //bmc name range showString += ''; //bmc start ip if (getDiscoverEnv('idataplexbmcip')){ tempip = getDiscoverEnv('idataplexbmcip'); } else{ tempip = '172.30.120.1'; } showString += ''; //switches title showString += ''; //switches name range showString += ''; //switches start ip if (getDiscoverEnv('idataplexswitchip')){ tempip = getDiscoverEnv('idataplexswitchip'); } else{ tempip = '172.30.10.1'; } showString += ''; //nodes per switch showString += ''; showString += '

    Nodes:

    Name Range:Start IP:
    Nodes number
    per Frame:

    BMCs:

    Name Range:Start IP:

    Switches:

    Name Range:Start IP:
    Nodes number
    per Switch:
    '; $('#discoverContentDiv').append(showString); $('#discoverContentDiv [title]').tooltip({ position: "center right", offset: [-2, 10], effect: "fade", opacity: 1 }); createDiscoverButtons(); } /** * step 2: collect and check the basic pattern input on page. * * @param * * @return false: the input contains error, can not go to next step * true : the input are correct, go to the next step */ function idataplexCheckBasic(operType){ collectInputValue(); //click back button, do not need check, only collect input value is ok. if ('back' == operType){ return true; } $('#patternDiv .ui-state-error').remove(); var errMessage = ''; var nodename = getDiscoverEnv('idataplexnodename'); var nodeip = getDiscoverEnv('idataplexnodeip'); var bmcname = getDiscoverEnv('idataplexbmcname'); var bmcip = getDiscoverEnv('idataplexbmcip'); var switchname = getDiscoverEnv('idataplexswitchname'); var switchip = getDiscoverEnv('idataplexswitchip'); var nodesperswitch = getDiscoverEnv('idataplexperswitch'); var nodesperframe = getDiscoverEnv('idataplexperframe'); //all fields should input if (!nodename){ errMessage += 'Input the Nodes name.
    '; } if (!verifyIp(nodeip)){ errMessage += 'Input valid Nodes start ip.
    '; } if (!bmcname){ errMessage += 'Input the BMC name.
    '; } if (!verifyIp(bmcip)){ errMessage += 'Input valid BMC start ip.
    '; } if (!switchname){ errMessage += 'Input the switch name.
    '; } if (!verifyIp(switchip)){ errMessage += 'Input valid switch start ip.
    '; } if (!nodesperswitch){ errMessage += 'Input the nodes number per switch.
    '; } if (!nodesperframe){ errMessage += 'Input the nodes number per frame.
    '; } if ('' != errMessage){ var warnBar = createWarnBar(errMessage); $('#patternDiv').prepend(warnBar); return false; } //check the relations among nodes, bmcs and switches var nodeNum = expandNR(nodename).length; var bmcNum = expandNR(bmcname).length; var switchNum = expandNR(switchname).length; var tempNumber = 0; //nodes number and bmc number if (nodeNum != bmcNum){ errMessage += 'The number of Node must equal the number of BMC.
    '; } //nodes' number calculate by switches tempNumber += Number(nodesperswitch) * switchNum; if (tempNumber < nodeNum){ errMessage += 'Input the node number per switch correctly.
    '; } if ('' != errMessage){ var warnBar = createWarnBar(errMessage); $('#patternDiv').prepend(warnBar); return false; } return true; } /** * step 3: tell users to configure the switches. * * @param * * @return */ function idataplexInitSwitch(){ $('#discoverContentDiv').empty(); $('.tooltip').remove(); var switchArray = expandNR(getDiscoverEnv('idataplexswitchname')); var switchIp = getDiscoverEnv('idataplexswitchip'); var showString = '

    ' + steps[currentStep] + '

    '; showString += '

    You defined ' + switchArray.length +' switches in last step. Configure them manually please:
    '; showString += '