/** * Global variables */ var nodesTabs; // Node tabs var nodesDataTable; // Datatable containing all nodes within a group /** * Set the nodes tab * * @param obj * Tab object * @return Nothing */ function setNodesTab(obj) { nodesTabs = obj; } /** * Get the nodes tab * * @param Nothing * @return Tab object */ function getNodesTab() { return nodesTabs; } /** * Get the nodes datatable * * @param Nothing * @return Data table object */ function getNodesDataTable() { return nodesDataTable; } /** * Set the nodes datatable * * @param table * Data table object * @return Nothing */ function setNodesDataTable(table) { nodesDataTable = table; } /** * Load nodes page * * @return Nothing */ function loadNodesPage() { // If groups are not already loaded if (!$('#groups').length) { // Create a groups division groupDIV = $('
'); nodesDIV = $(''); $('#content').append(groupDIV); $('#content').append(nodesDIV); // Create loader var loader = createLoader(); groupDIV.append(loader); // Create info bar var info = createInfoBar('Select a group to view its nodes'); $('#nodes').append(info); // Get groups $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'extnoderange', tgt : '/.*', args : 'subgroups', msg : '' }, success : loadGroups }); } } /** * Load groups * * @param data * Data returned from HTTP request * @return */ function loadGroups(data) { // Remove loader $('#groups').find('img').remove(); var groups = data.rsp; setGroupsCookies(data); // Create a list of groups var ul = $('Do you want to delete ' + tgtNodesStr + '?
').css('word-wrap', 'break-word'); deleteForm.append(instr); /** * Delete */ var deleteBtn = createButton('Delete'); deleteBtn.bind('click', function(event) { // Delete the virtual server $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'rmvm', tgt : tgtNodes, args : '', msg : 'out=' + statBarId + ';cmd=rmvm;tgt=' + tgtNodes }, success : updateStatusBar }); // Show status bar loader statBar.show(); // Disable delete button $(this).unbind(event); $(this).css( { 'background-color' : '#F2F2F2', 'color' : '#BDBDBD' }); }); var cancelBtn = createButton('Cancel'); cancelBtn.bind('click', function(){ myTab.remove($(this).parent().parent().attr('id')); }); deleteForm.append(deleteBtn); deleteForm.append(cancelBtn); myTab.add(newTabId, 'Delete', deleteForm, true); myTab.select(newTabId); } /** * Update status bar of a given tab * * @param data * Data returned from HTTP request * @return Nothing */ function updateStatusBar(data) { // Get ajax response var rsp = data.rsp; var args = data.msg.split(';'); var statBarId = args[0].replace('out=', ''); var cmd = args[1].replace('cmd=', ''); var tgts = args[2].replace('tgt=', '').split(','); if (cmd == 'unlock' || cmd == 'updatenode') { // Hide loader $('#' + statBarId).find('img').hide(); // Write ajax response to status bar var prg = writeRsp(rsp, ''); $('#' + statBarId).append(prg); } else if (cmd == 'rmvm') { // Get data table var dTable = getNodesDataTable(); var failed = false; // Hide loader $('#' + statBarId).find('img').hide(); // 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) { failed = true; } // Update data table var rows = dTable.fnGetNodes(); for ( var i = 0; i < tgts.length; i++) { if (!failed) { // Get the row containing the node link and delete it var row = getNodeRow(tgts[i], rows); var rowPos = dTable.fnGetPosition(row); dTable.fnDeleteRow(rowPos); } } } else { // Hide loader $('#' + statBarId).find('img').hide(); // Write ajax response to status bar var prg = writeRsp(rsp, '[A-Za-z0-9._-]+:'); $('#' + statBarId).append(prg); } } /** * Check if the form is complete * * @param tabId * Tab ID containing form * @return True: If the form is complete, False: Otherwise */ function formComplete(tabId) { var ready = true; // Check all inputs within the form var inputs = $('#' + tabId + ' input'); for ( var i = 0; i < inputs.length; i++) { // If there is no value given in the input if (!inputs.eq(i).val()) { inputs.eq(i).css('border', 'solid #FF0000 1px'); // It is not complete ready = false; } else { inputs.eq(i).css('border', 'solid #BDBDBD 1px'); } } return ready; } /** * Update power status of a node in the datatable * * @param data * Data from HTTP request * @return Nothing */ function updatePowerStatus(data) { // Get datatable var dTable = getNodesDataTable(); // Get all nodes within the datatable var rows = dTable.fnGetNodes(); // Get xCAT response var rsp = data.rsp; // Loop through each line for ( var i = 0; i < rsp.length; i++) { // Get the node var node = rsp[i].split(":")[0]; // If there is no error var status; if (rsp[i].indexOf("Error") < 0 || rsp[i].indexOf("Failed") < 0) { // Get the row containing the node link var row = getNodeRow(node, rows); var rowPos = dTable.fnGetPosition(row); // If it was power on, then the data return would contain "Starting" var strPos = rsp[i].indexOf("Starting"); if (strPos > -1) { status = 'on'; } else { status = 'off'; } // Update the power status column dTable.fnUpdate(status, rowPos, 3); } else { // Power on/off failed alert(rsp[i]); } } } /** * Run a script * * @param inst * Remote script tab instance * @return Nothing */ function runScript(inst) { var tabId = 'scriptTab' + inst; // Get node name var tgts = $('#' + tabId + ' input[name=target]').val(); // Get script var script = $('#' + tabId + ' textarea').val(); // Disable all fields $('#' + tabId + ' input').attr('readonly', 'readonly'); $('#' + tabId + ' input').css( { 'background-color' : '#F2F2F2' }); $('#' + tabId + ' textarea').attr('readonly', 'readonly'); $('#' + tabId + ' textarea').css( { 'background-color' : '#F2F2F2' }); // Run script $.ajax( { url : 'lib/zCmd.php', dataType : 'json', data : { cmd : 'xdsh', tgt : tgts, args : '-e', att : script, msg : 'out=scriptStatusBar' + inst + ';cmd=xdsh;tgt=' + tgts }, success : updateStatusBar }); } /** * Get an attribute of a given node * * @param node * The node * @param attrName * The attribute * @return The attribute of the node */ function getNodeAttr(node, attrName) { // Get the row var row = $('[id=' + node + ']').parent().parent(); // Search for the column containing the attribute var attrCol; var cols = row.parent().parent().find('th:contains("' + attrName + '")'); // Loop through each column for (var i in cols) { // Find column that matches the attribute if (cols.eq(i).html() == attrName) { attrCol = cols.eq(i); break; } } // If the column containing the attribute is found if (attrCol) { // Get the attribute column index var attrIndex = attrCol.index(); // Get the attribute for the given node var attr = row.find('td:eq(' + attrIndex + ')'); return attr.text(); } else { return ''; } } /** * Set a cookie for the OS images * * @param data * Data from HTTP request * @return Nothing */ function setOSImageCookies(data) { var rsp = data.rsp; var imageNames = new Array; var profilesHash = new Object(); var osVersHash = new Object(); var osArchsHash = new Object(); for ( var i = 1; i < rsp.length; i++) { // osimage table columns: imagename, profile, imagetype, provmethod, // osname, osvers, osdistro, osarch, synclists, comments, disable // e.g. sles11.1-s390x-statelite-compute, compute, linux, statelite, // Linux, sles11.1, , s390x, , s, // Get the image name var cols = rsp[i].split(','); var osImage = cols[0].replace(new RegExp('"', 'g'), ''); var profile = cols[1].replace(new RegExp('"', 'g'), ''); var osVer = cols[5].replace(new RegExp('"', 'g'), ''); var osArch = cols[7].replace(new RegExp('"', 'g'), ''); imageNames.push(osImage); profilesHash[profile] = 1; osVersHash[osVer] = 1; osArchsHash[osArch] = 1; } // Save image names in a cookie $.cookie('ImageNames', imageNames); // Save profiles in a cookie var tmp = new Array; for ( var key in profilesHash) { tmp.push(key); } $.cookie('Profiles', tmp); // Save OS versions in a cookie tmp = []; for ( var key in osVersHash) { tmp.push(key); } $.cookie('OSVers', tmp); // Save OS architectures in a cookie tmp = []; for ( var key in osArchsHash) { tmp.push(key); } $.cookie('OSArchs', tmp); } /** * Set a cookie for the groups * * @param data * Data from HTTP request * @return Nothing */ function setGroupsCookies(data) { var rsp = data.rsp; $.cookie('Groups', rsp); } /** * Get row element that contains given node * * @param tgtNode * Node to find * @param rows * Rows within the datatable * @return Row element */ function getNodeRow(tgtNode, rows) { // Find the row for ( var i in rows) { // Get all columns within the row var cols = rows[i].children; // Get the 1st column (node name) var cont = cols[1].children; var node = cont[0].innerHTML; // If the node matches the target node if (node == tgtNode) { // Return the row return rows[i]; } } return; } /** * Get nodes that are checked in a given datatable * * @param datatableId * The datatable ID * @return Nodes that were checked */ function getNodesChecked(datatableId) { var tgts = ''; // Get nodes that were checked var nodes = $('#' + datatableId + ' input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { var tgtNode = nodes.eq(i).attr('name'); if (tgtNode){ tgts += tgtNode; // Add a comma at the end if (i < nodes.length - 1) { tgts += ','; } } } return tgts; } function getColNum(colName){ var temp; var columns = $('table thead tr').children(); for(temp = 1; temp < columns.length; temp++){ if (colName == columns[temp].innerHTML){ return temp; } } return -1; } function getRowNum(nodeName){ // Get datatable var dTable = getNodesDataTable(); // Get all data from datatable var data = dTable.fnGetData(); var temp; var nodeItem; for(temp = 0; temp < data.length; temp++){ nodeItem = data[temp][1]; if(nodeItem.indexOf('>' + nodeName + '<') > -1){ return temp; } } return -1; } /** * Select all checkboxes in a given datatable * * @param event * Event on element * @param obj * Object triggering event * @return Nothing */ function selectAllCheckbox(event, obj) { // Get datatable ID // This will ascend from