/** * Execute when the DOM is fully loaded */ $(document).ready(function() { // Load utility scripts }); /** * Constructor * * @return Nothing */ var hmcPlugin = function() { }; /** * Steps for hardware discovery wizard * * @return Discovery steps */ hmcPlugin.prototype.getStep = function() { return [ 'Basic patterns', 'Supernode', 'More patterns', 'Power on hardware', 'Discover frames', 'Management node', 'Discover Rest of Hardware and Update Definitions', 'Create LPARs' ]; }; hmcPlugin.prototype.getInitFunction = function() { return [ powerInitBasicPattern, powerInitSupernode, powerInitSiteTable, powerInitPoweronHardware, powerInitDiscoverFrames, powerInitConfig, powerInitUpdateDefinition, powerInitCreateLpar ]; }; hmcPlugin.prototype.getNextFunction = function() { return [ checkBasicPattern, checkSupernode, checkSiteTable, undefined, checkFrameMtms, undefined, undefined, collectInputValue ]; }; /** * Load node inventory * * @param data Data from HTTP request */ hmcPlugin.prototype.loadInventory = function(data) { // Get arguments var args = data.msg.split(','); // Get tab ID var tabId = args[0].replace('out=', ''); // Get node 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 invDivId = tabId + 'Inventory'; var invDiv = $('
'); // Loop through each line var fieldSet = null; var legend = null; var oList = null; var item = null; for (var k = 0; k < inv.length; k++) { // Remove node name in front var str = inv[k].replace(node + ': ', ''); str = jQuery.trim(str); // If string is a header if (str.indexOf('I/O Bus Information') > -1 || str.indexOf('Machine Configuration Info') > -1) { // Create a fieldset fieldSet = $(''); legend = $(''); fieldSet.append(legend); oList = $('| Frames: | |||
| Name Range: | '; // Use the super node to configure file and calculate the CEC's number showString += ' | ||
| Vlan1 IP Header: | Vlan2 IP Header:' + ' | ||
| Drawers: | |||
| Name Range: | '; showString += ' | Number of LPARs per Drawer: | |
| Lpars: | |||
| Name Range: | Starting IP Adress: | ||
| HMCs: | |||
| Name Range: | '; showString += ' | Number of Frames per HMC: | |
| Starting IP Adress: | '; showString += ' | Hardware Managment: | HMC '; showString += 'DFM | 
| Building Block | |||
| Frame amount per BB:' + ' | ' + ' | CEC amount per BB:' + ' | ' + ' | 
| ' + frameArray[i] + ': | 
| Domain Name: | |
| Name server: | |
| DHCP Dynamic Range: | - | 
| admin password for FRAME and CEC: | |
| general password for FRAME and CEC: | |
| hmc password for FRAME and CEC: | 
'
                            + data.rsp + '');
        }
    });
    createDiscoverButtons();
}
/**
 * Step 4: Check that the inputs are all filled
 */
function checkSiteTable(operType) {
    $('#discoverContentDiv input[name=ipStart]').trigger('change');
    collectInputValue();
    if ('back' == operType) {
        return true;
    }
    $('#discoverContentDiv .ui-state-error').remove();
    var errMessage = '';
    if (!getDiscoverEnv('domainname')) {
        errMessage += 'Input the domain name.| ' + ' | 
' + frameArray[i] + '
'); } for (var i in mtmsArray) { $('#mtmsTd').append( '' + mtmsArray[i] + '
'); } createDiscoverButtons(); } }); } function parseMtmsMap(responseText){ var frameArray = expandNR(getDiscoverEnv('frameName')); var lines = responseText.split("\n"); var temphash = new Object(); var nulldefine = ''; for(var i in lines){ var temparray = lines[i].split(" "); var tempname = temparray[0]; var tempmtm = temparray[1]; var tempserial = temparray[2]; temphash[tempname] = tempmtm + '-' + tempserial; } for (var i in frameArray){ var tempname = frameArray[i]; if (!temphash[tempname]){ if (!nulldefine){ nulldefine += 'tempname'; } else{ nulldefine += ', tempname'; } } } if (nulldefine){ $('#framedisc div').html( 'Error: ' + nulldefine + ' was not defined in the map file, please check!'); return; } else{ for (var i in temphash){ showMap(i, temphash[i], 0); } } createDiscoverButtons(); } function createMap(obj) { var fname = ''; var mname = ''; if ($('#discoverShow :checked').size() < 2) { return; } if ('frameradio' == $(obj).attr('name')) { fname = $(obj).next().html(); mname = $('#discoverShow input[name=mtmsradio]:checked').next().html(); } else { fname = $('#discoverShow input[name=frameradio]:checked').next().html(); mname = $(obj).next().html(); } $('#discoverShow :checked').parent().remove(); showMap(fname, mname, 1); } function showMap(fname, mname, deleteflag) { var rowClass = ''; var deleteicon = ''; if ($('#discoverShow fieldset').size() < 1) { $('#discoverShow') .append( ''); } if (0 == $('#discoverShow fieldset tr').size() % 2) { rowClass = 'odd'; } else { rowClass = 'even'; } if (deleteflag){ deleteicon = '' + fname + '
'); $('#mtmsTd').append( '' + mname + '
'); } /** * Step 6: Write the frame and MTMs map file */ function checkFrameMtms(operType) { // Check the number of radio button var vpdFileCon = ''; $('#discoverShow .ui-state-error').remove(); if (0 < $('#discoverShow :radio').size()) { var warnBar = createWarnBar('Map all of the frame with mtms.'); $('#discoverContentDiv #discoverShow').prepend(warnBar); return false; } // Find out all maps var maps = ''; $('#discoverShow fieldset tr').each( function() { var fname = $(this).children().eq(0).html(); var mtms = $(this).children().eq(2).html(); var pos = mtms.lastIndexOf('-'); var startpos = mtms.indexOf(':'); maps += (fname + ',' + mtms + ';'); vpdFileCon += fname + ':\n'; vpdFileCon += ' objtype=node\n serial=' + mtms.substring(pos + 1) + '\n'; vpdFileCon += ' mtm=' + mtms.substring(startpos + 1, pos) + '\n side=A\n'; }); maps = maps.substr(0, maps.length - 1); setDiscoverEnv('framemtmsmap', maps); if ('back' == operType) { return true; } // Write the maps into vpd table $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'writeconfigfile;/tmp/webvpd.stanza;' + vpdFileCon, msg : '' } }); return true; } /** * Step 7: Create the xcatsetup configure file and run xcatsetup to define all * objects in xcat database. */ function powerInitConfig(operType) { $('#discoverContentDiv').empty(); $('.tooltip').remove(); var showStr = '' + mapstring + '
'); // Write MTMs and HMC name pair into vpd table $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'updatevpd;' + tempPar, msg : '' }, success : function() { $('#returninfo div').append('Add the discovered HMCs into xCAT database.
'); var cmklink2 = 'lib/cmd.php?cmd=lsslp&tgt=&args=-w;-s;HMC&msg=&opts=flush'; var hmciframe2 = $('').attr('src', cmdlink).css({ 'display': 'block', 'border': '0px', 'margin': '10px', 'width': '100%', 'overflow': 'visible' }); $('#returninfo div').append(hmciframe2); hmciframe2.load(function() { $('#hmcLine2 img').remove(); var tempSpan = $('#hmcLine2').find('span'); tempSpan.removeClass('ui-icon-gear'); tempSpan.addClass('ui-icon-check'); lsslpWriteFrame(); }); } }); }); $('#returninfo div').append(hmciframe1); } /** * Step 8: Write all lsslp frame info into the database */ function lsslpWriteFrame() { $('#frameLine1').append(createLoader()); $('#returninfo div').append('Write the discovered FRAMES into xCAT Database.
'); var cmdlink = 'lib/cmd.php?cmd=lsslp&tgt=&args=-w;-s;FRAME&msg=&opts=flush';; var frameiframe1 = $('').attr('src', cmdlink).css({ 'display': 'block', 'border': '0px', 'margin': '10px', 'width': '100%', 'overflow': 'visible' }); $('#returninfo div').append(frameiframe1); frameiframe1.load(function(data) { $('#frameLine1 img').remove(); var tempSpan = $('#frameLine1').find('span'); tempSpan.removeClass('ui-icon-gear'); tempSpan.addClass('ui-icon-check'); frameSetup(); }); } /** * Step 8: config the frame dhcp and dns */ function frameSetup() { $('#frameLine2').append(createLoader()); var tempargs = getDiscoverEnv('adminpasswd') + ';' + getDiscoverEnv('generalpasswd') + ';' + getDiscoverEnv('hmcpasswd'); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'framesetup;' + tempargs + ';1', msg : '' }, success : function(data) { $('#frameLine2 img').remove(); var tempSpan = $('#frameLine2').find('span'); tempSpan.removeClass('ui-icon-gear'); tempSpan.addClass('ui-icon-check'); $('#returninfo div').append('' + data.rsp.join("\n") + '');
            frameReset();
        }
    });
}
/**
 * Step 8: reset the networks for frames
 */
function frameReset(){
	$('#frameLine3').append(createLoader());
	$('#returninfo div').append('Reset network on FRAMES to get persistent IP.
'); var cmdlink = 'lib/cmd.php?cmd=rspconfig&tgt=frame&args=--resetnet&msg=&opts=flush';; var frameiframe2 = $('').attr('src', cmdlink).css({ 'display': 'block', 'border': '0px', 'margin': '10px', 'width': '100%', 'overflow': 'visible' }); $('#returninfo div').append(frameiframe2); frameiframe2.load(function() { $('#frameLine3 img').remove(); var tempSpan = $('#frameLine3').find('span'); tempSpan.removeClass('ui-icon-gear'); tempSpan.addClass('ui-icon-check'); frameHwconn(); }); } /** * Step 8: create hardware connection for frames */ function frameHwconn(){ $('#frameLine4').append(createLoader()); var tempargs = getDiscoverEnv('adminpasswd') + ';' + getDiscoverEnv('generalpasswd') + ';' + getDiscoverEnv('hmcpasswd'); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'framesetup;' + tempargs + ';2', msg : '' }, success : function(data) { $('#frameLine4 img').remove(); var tempSpan = $('#frameLine4').find('span'); tempSpan.removeClass('ui-icon-gear'); tempSpan.addClass('ui-icon-check'); $('#returninfo div').append('' + data.rsp.join("\n") + '');
            lsslpWriteCec();
        }
    });
}
/**
 * Step 8: Write all the lsslp cec info into database
 */
function lsslpWriteCec() {
    $('#cecLine').append(createLoader());
    $('#returninfo div').append('Discover and write CECs into xCAT Database.
');
    var cmdlink = 'lib/cmd.php?cmd=lsslp&tgt=&args=-s;CEC;-w&msg=&opts=flush';;
    var ceciframe1 = $('').attr('src', cmdlink).css({
    	'display': 'block',
        'border': '0px',
        'margin': '10px',
        'width': '100%',
        'overflow': 'visible'
    });
	$('#returninfo div').append(ceciframe1);
	ceciframe1.load(function() {
        $('#cecLine img').remove();
        var tempSpan = $('#cecLine').find('span');
        tempSpan.removeClass('ui-icon-gear');
        tempSpan.addClass('ui-icon-check');
        cecsetup();
    });
}
/**
 * Step 8: config the cec dhcp and dns
 */
function cecsetup(){
	$('#cecLine2').append(createLoader());
	var tempargs = getDiscoverEnv('adminpasswd') + ';' + getDiscoverEnv('generalpasswd') + ';' 
                   + getDiscoverEnv('hmcpasswd');
    $.ajax({
        url : 'lib/cmd.php',
        dataType : 'json',
        data : {
            cmd : 'webrun',
            tgt : '',
            args : 'cecsetup;' + tempargs + ';1',
            msg : ''
        },
        success : function(data) {
            $('#cecLine2 img').remove();
            var tempSpan = $('#cecLine2').find('span');
            tempSpan.removeClass('ui-icon-gear');
            tempSpan.addClass('ui-icon-check');
            $('#returninfo div').append('' + data.rsp.join("\n") + '');
            cecReset();
        }
    });
}
/**
 * Step 8: reset the networks for cecs
 */
function cecReset(){
	$('#cecLine3').append(createLoader());
	$('#returninfo div').append('Reset network on CECs to get persistent IP.
');
    var cmdlink = 'lib/cmd.php?cmd=rspconfig&tgt=cec&args=--resetnet&msg=&opts=flush';;
    var ceciframe2 = $('').attr('src', cmdlink).css({
    	'display': 'block',
        'border': '0px',
        'margin': '10px',
        'width': '100%',
        'overflow': 'visible'
    });
	$('#returninfo div').append(ceciframe2);
	ceciframe2.load(function() {
        $('#cecLine3 img').remove();
        var tempSpan = $('#cecLine3').find('span');
        tempSpan.removeClass('ui-icon-gear');
        tempSpan.addClass('ui-icon-check');
        cecHwconn();
    });
}
/**
 * Step 8: config the cec
 */
function cecHwconn(){
	$('#cecLine4').append(createLoader());
	var tempargs = getDiscoverEnv('adminpasswd') + ';' + getDiscoverEnv('generalpasswd') + ';' 
                   + getDiscoverEnv('hmcpasswd');
    $.ajax({
        url : 'lib/cmd.php',
        dataType : 'json',
        data : {
            cmd : 'webrun',
            tgt : '',
            args : 'cecsetup;' + tempargs + ';2',
            msg : ''
        },
        success : function(data) {
            $('#cecLine4 img').remove();
            var tempSpan = $('#cecLine4').find('span');
            tempSpan.removeClass('ui-icon-gear');
            tempSpan.addClass('ui-icon-check');
            $('#returninfo div').append('' + data.rsp.join("\n") + '');
            createDiscoverButtons();
        }
    });
}
/**
 * Step 9: Create LPARs
 */
function powerInitCreateLpar() {
    $('#discoverContentDiv').empty();
    $('.tooltip').remove();
    var showDiv = $(''
            + steps[currentStep] + '
');
    switch (getDiscoverEnv('machineType')) {
        case 'ih':
            ihCreateLpar(showDiv);
            break;
        case 'nonih':
            nonihCreateLpar(showDiv);
            break;
        default:
            break;
    }
    
    $('#discoverContentDiv').append(showDiv);
    createDiscoverButtons();
}
function ihCreateLpar(parentDiv) {
    var showStr = 'Partition Rule:
'
            + 'If all the octants configuration value are same in one CEC,  it will be  " -r  0-7:value".
'
            + 'If the octants use the different configuration value in one cec, it will be "-r 0:value1,1:value2,...7:value7", or "-r 0:value1,1-7:value2".
'
            + 'The octants configuration value for one Octant could be  1, 2, 3, 4, 5 . The meanings of the octants configuration value  are as following:
'
            + '1 - 1 partition with all cpus and memory of the octant
'
            + '2 - 2 partitions with a 50/50 split of cpus and memory
'
            + '3 - 3 partitions with a 25/25/50 split of cpus and memory
'
            + '4 - 4 partitions with a 25/25/25/25 split of cpus and memory
'
            + '5 - 2 partitions with a 25/75 split of cpus and memory
'
            + 'Define the configuration rule for one CEC, and create all Lpars on all CECs by this rule. Or ignore this step.';
    parentDiv.append(createInfoBar(showStr));
    parentDiv.append('Partition Configuration: '
        + '
');
            diaDiv.append(createLoader());
            diaDiv.dialog({
                modal : true,
                width : 600,
                title : 'Creating Lpars...'
            });
            $('.ui-dialog-titlebar-close').hide();
            var cecArray = expandNR(getDiscoverEnv('cecName'));
            for (var i in cecArray) {
                $.ajax({
                    url : 'lib/cmd.php',
                    dataType : 'json',
                    data : {
                        cmd : 'mkvm',
                        tgt : cecArray[i] + 'nodes',
                        args : '-i;1;-m;non-interleaved;-r;'
                                + inputStr,
                        msg : cecArray[i] + ';' + cecArray.length
                    },
                    success : function(data) {
                        // update the dialogure
                        var tempArray = data.msg.split(';');
                        updateCreateLparDia(tempArray[0],
                                Number(tempArray[1]));
                    }
                });
            }
        });
}
function updateCreateLparDia(cecname, cecNum) {
    $('#createLparDiv ul').append('Creating lpars on ' + cecname + ' competed. ');
    if (cecNum != $('#createLparDiv li').size()) {
        return;
    }
    $('#createLparDiv').empty();
    $('#createLparDiv').append('All lpars are created. You must:
1. reboot the all CECS. 
'
            + '2.use chvm to assign the I/O slots to the new LPAR.
');
    var chvmButton = createButton('OK');
    $('#createLparDiv').append(chvmButton);
    chvmButton.bind('click', function() {
        $('#createLparDiv').dialog('destroy');
        $('#createLparDiv').remove();
    });
}
function nonihCreateLpar(parentDiv) {
    var showStr = 'The machine type is not P7 IH, so you had to create lpars by command line manually.';
    parentDiv.append(createInfoBar(showStr));
    return;
}