/** * 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 = $('
'); $('#nodes_page').append(groupDIV); $('#nodes_page').append(nodesDIV); // 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) { var groups = data.rsp; setGroupsCookies(data); // Create a list of groups var ul = $(''); var item = $('
  • Groups

  • '); ul.append(item); var subUL = $(''); item.append(subUL); // Create a link for each group for ( var i = groups.length; i--;) { var subItem = $('
  • '); var link = $('' + groups[i] + ''); subItem.append(link); subUL.append(subItem); } // Turn groups list into a tree $('#groups').append(ul); $('#groups').tree( { callback : { // Open the group onclick onselect : function(node, tree) { var thisGroup = tree.get_text(node); if (thisGroup) { // Clear the nodes DIV $('#nodes').children().remove(); // Create loader var loader = $('
    ').append(createLoader()); // Create a tab for this group var tab = new Tab(); setNodesTab(tab); tab.init(); $('#nodes').append(tab.object()); tab.add('nodesTab', 'Nodes', loader); // Get nodes within selected group $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsdef', tgt : '', args : thisGroup, msg : thisGroup }, success : loadNodes }); } // End of if (thisGroup) } // End of onselect } // End of callback } ); } /** * Load nodes belonging to a given group * * @param data * Data returned from HTTP request * @return Nothing */ function loadNodes(data) { // Data returned var rsp = data.rsp; // Group name var group = data.msg; // Node attributes hash var attrs = new Object(); // Node attributes var headers = new Object(); var node; var args; for ( var i in rsp) { // Get the 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 a 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, node, ping, and power sorted.unshift('', 'node', 'ping', 'power'); // Create a datatable var dTable = new DataTable('nodesDataTable'); 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 = ''; // Open node onclick var nodeLink = $( '' + node + '') .bind('click', loadNode); row.push(checkBx, nodeLink, '', ''); // Go through each header for ( var i = 4; i < sorted.length; i++) { // Add the node attributes to the row var key = sorted[i]; var val = attrs[node][key]; if (val) { row.push(val); } else { row.push(''); } } // Add the row to the table dTable.add(row); } // Clear the tab before inserting the table $('#nodesTab').children().remove(); // Create action buttons var actionBar = $('
    '); /** * The following actions are available to perform against a given node: * power, clone, delete, unlock, and advanced */ /* * Power */ var powerLnk = $('Power'); /* * Power on */ var powerOnLnk = $('Power on'); powerOnLnk.bind('click', function(event) { var tgtNodes = ''; // Get node that was checked var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { tgtNodes += nodes.eq(i).attr('name'); // Add a comma in front of each node if (i < nodes.length - 1) { tgtNodes += ','; } } if (tgtNodes) { powerNode(tgtNodes, 'on'); } } ); /* * Power off */ var powerOffLnk = $('Power off'); powerOffLnk.bind('click', function(event) { var tgtNodes = ''; // Get node that was checked var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { tgtNodes += nodes.eq(i).attr('name'); // Add a comma in front of each node if (i < nodes.length - 1) { tgtNodes += ','; } } if (tgtNodes) { powerNode(tgtNodes, 'off'); } } ); /* * Clone */ var cloneLnk = $('Clone'); cloneLnk.bind('click', function(event) { // Get node that was checked var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { var node = nodes.eq(i).attr('name'); // Load clone page if (node) { var mgt = getNodeMgt(node); if (mgt == 'zvm') { loadZClonePage(node); } else { // TODO: Add clone for other platforms } } } } ); /* * Delete */ var deleteLnk = $('Delete'); deleteLnk.bind('click', function(event) { var tgtNodes = ''; // Get node that was checked var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { tgtNodes += nodes.eq(i).attr('name'); // Add a comma in front of each node if (i < nodes.length - 1) { tgtNodes += ','; } } // Load delete page if (tgtNodes) { deleteNode(tgtNodes); } } ); /* * Unlock */ var unlockLnk = $('Unlock'); unlockLnk.bind('click', function(event) { var tgtNodes = ''; // Get node that was checked var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { tgtNodes += nodes.eq(i).attr('name'); // Add a comma in front of each node if (i < nodes.length - 1) { tgtNodes += ','; } } // Load unlock page if (tgtNodes) { loadUnlockPage(tgtNodes); } } ); /* * Run script */ var scriptLnk = $('Run script'); scriptLnk.bind('click', function(event) { // Get node that was checked var tgtNodes = ''; var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { tgtNodes += nodes.eq(i).attr('name'); // Add a comma in front of each node if (i < nodes.length - 1) { tgtNodes += ','; } } // Load script page if (tgtNodes) { loadScriptPage(tgtNodes); } } ); /* * Update node */ var updateLnk = $('Update'); updateLnk.bind('click', function(event) { // Get node that was checked var tgtNodes = ''; var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { tgtNodes += nodes.eq(i).attr('name'); // Add a comma in front of each node if (i < nodes.length - 1) { tgtNodes += ','; } } // TODO: Load update page if (tgtNodes) { } } ); /* * Set boot state */ var setBootStateLnk = $('Set boot state'); setBootStateLnk.bind('click', function(event) { // Get node that was checked var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { // Get node that was checked var tgtNodes = ''; var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { tgtNodes += nodes.eq(i).attr('name'); // Add a comma in front of each node if (i < nodes.length - 1) { tgtNodes += ','; } } // Load nodeset page if (tgtNodes) { loadNodesetPage(tgtNodes); } } } ); /* * Boot to network */ var boot2NetworkLnk = $('Boot to network'); boot2NetworkLnk.bind('click', function(event) { // Get node that was checked var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { // Get node that was checked var mgt; var tgtNodes = ''; var nodes = $('#nodesDataTable input[type=checkbox]:checked'); for ( var i = 0; i < nodes.length; i++) { tgtNodes += nodes.eq(i).attr('name'); // Add a comma in front of each node if (i < nodes.length - 1) { tgtNodes += ','; } var node = nodes.eq(i).attr('name'); mgt = getNodeMgt(node); } // Load nodeset page if (tgtNodes) { if (mgt == 'zvm') { loadZNetbootPage(tgtNodes); } else { // TODO: Add boot to network for other platforms } } } } ); /* * Advanced */ var advancedLnk = $('Advanced'); // Power actions var powerActions = [ powerOnLnk, powerOffLnk ]; var powerActionMenu = createMenu(powerActions); // Advanced actions var advancedActions = [ boot2NetworkLnk, scriptLnk, setBootStateLnk, updateLnk ]; var advancedActionMenu = createMenu(advancedActions); /** * Create an action menu */ var actionsDIV = $('
    '); var actions = [ [ powerLnk, powerActionMenu ], cloneLnk, deleteLnk, unlockLnk, [ advancedLnk, advancedActionMenu ] ]; var actionMenu = createMenu(actions); actionMenu.superfish(); actionsDIV.append(actionMenu); actionBar.append(actionsDIV); /* * Select all or none */ var selectDIV = $('
    '); actionBar.append(selectDIV); var selectLabel = $('Select: '); var selectAllLnk = $('All'); selectAllLnk.bind('click', function(event) { // Check all nodes var nodes = $('#nodesDataTable input[type=checkbox]'); nodes.attr('checked', true); }); var selectNoneLnk = $('None'); selectNoneLnk.bind('click', function(event) { // Check no nodes var nodes = $('#nodesDataTable input[type=checkbox]'); nodes.attr('checked', false); }); selectDIV.append(selectLabel); selectDIV.append(selectAllLnk); selectDIV.append(selectNoneLnk); $('#nodesTab').append(actionBar); // Insert table $('#nodesTab').append(dTable.object()); // Turn table into a datatable var myDataTable = $('#nodesDataTable').dataTable(); setNodesDataTable(myDataTable); /** * Get power and ping status for each node */ // Get the power status $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'rpower', tgt : group, args : 'stat', msg : '' }, success : loadPowerStatus }); // Get the ping status $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'pping ' + group, msg : '' }, success : loadPingStatus }); /** * Only for zVM */ // Get the index of the HCP column var i = $.inArray('hcp', sorted); if (i) { var rows = dTable.object().find('tbody tr'); // Get HCP var hcps = new Object(); for ( var j = 0; j < rows.length; j++) { var val = rows.eq(j).find('td').eq(i).html(); hcps[val] = 1; } var args; for ( var h in hcps) { // Get node without domain name args = h.split('.'); // Get disk pools $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsvm', tgt : args[0], args : '--diskpoolnames', msg : args[0] }, success : setDiskPoolCookies }); // Get network names $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsvm', tgt : args[0], args : '--getnetworknames', msg : args[0] }, success : setNetworkCookies }); } } } /** * Load the power status for each node * * @param data * Data returned from HTTP request * @return Nothing */ function loadPowerStatus(data) { // Get datatable var dTable = getNodesDataTable(); // Power state of each node // where power[0] = nodeName and power[1] = state var power = data.rsp; var row, rowPos; var node, nodeLink; var status, statusLink; var args; // Get all nodes within the datatable var rows = dTable.fnGetNodes(); for ( var i in power) { args = power[i].split(':'); // Update the power status column node = jQuery.trim(args[0]); status = jQuery.trim(args[1]); // Get the row containing the node row = getNodeRow(node, rows); rowPos = dTable.fnGetPosition(row); dTable.fnUpdate(status, rowPos, 3); } } /** * Load the ping status for each node * * @param data * Data returned from HTTP request * @return Nothing */ function loadPingStatus(data) { // Get data table var dTable = getNodesDataTable(); // Power state of each node // where ping[0] = nodeName ping[1] = state var ping = data.rsp; var row, rowPos; var node, nodeLink; var status, statusLink; var args; // Get all nodes within the datatable var rows = dTable.fnGetNodes(); for ( var i in ping) { args = ping[i][0]; // Update the power status column node = jQuery.trim(ping[i][0]); status = jQuery.trim(ping[i][1]); // Get the row containing the node row = getNodeRow(node, rows); rowPos = dTable.fnGetPosition(row); // Update the power status column status = jQuery.trim(ping[i][1]); dTable.fnUpdate(status, rowPos, 2); } } /** * Load inventory for given node * * @param e * Windows event * @return Nothing */ function loadNode(e) { if (!e) { e = window.event; } // Get node that was clicked var node = (e.target) ? e.target.id : e.srcElement.id; var mgt = getNodeMgt(node); // Get tab area where a new tab will be inserted var myTab = getNodesTab(); var newTabId = node + 'Tab'; /** * Only for zVM */ if (mgt == 'zvm') { // Reset node process $.cookie(node + 'Processes', 0); // Add new tab, only if one does not exist if (!$('#' + newTabId).length) { var loader = createLoader(node + 'TabLoader'); loader = $('
    ').append(loader); myTab.add(newTabId, node, loader); // Get node inventory var msg = 'out=' + newTabId + ',node=' + node; $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'rinv', tgt : node, args : 'all', msg : msg }, success : loadZInventory }); } } else { // Add new tab, only if one does not exist if (!$('#' + newTabId).length) { var p = $('

    No supported

    '); myTab.add(newTabId, node, p); // TODO: Add inventory for other platforms } } // Select new tab myTab.select(newTabId); } /** * Unlock a node by exchanging the SSH keys between the xCAT MN and the target * node * * @param tgtNodes * Nodes to unlock * @return Nothing */ function loadUnlockPage(tgtNodes) { // Get nodes tab var tab = getNodesTab(); // Generate new tab ID var instance = 0; var newTabId = 'UnlockTab' + instance; while ($('#' + newTabId).length) { // If one already exists, generate another one instance = instance + 1; newTabId = 'UnlockTab' + instance; } var unlockForm = $('
    '); // Create status bar, hide on load var statBarId = 'UnlockStatusBar' + instance; var statusBar = createStatusBar(statBarId).hide(); unlockForm.append(statusBar); // Create loader var loader = createLoader(''); statusBar.append(loader); // Create info bar var infoBar = createInfoBar('Give the root password for this node range to exchange its SSH keys'); unlockForm.append(infoBar); unlockForm .append('
    '); unlockForm .append('
    '); /** * Ok */ var okBtn = createButton('Ok'); okBtn.bind('click', function(event) { // If the form is complete var ready = formComplete(newTabId); if (ready) { var password = $('#' + newTabId + ' input[name=password]').val(); // Exchange SSH keys $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'unlock;' + tgtNodes + ';' + password, msg : 'out=' + statBarId + ';cmd=unlock;tgt=' + tgtNodes }, success : updateStatusBar }); // Show status bar statusBar.show(); // Stop this function from executing again // Unbind event $(this).unbind(event); $(this).css( { 'background-color' : '#F2F2F2', 'color' : '#BDBDBD' }); } } ); unlockForm.append(okBtn); tab.add(newTabId, 'Unlock', unlockForm); tab.select(newTabId); } /** * Load script page * * @param tgtNodes * Targets to run script against * @return Nothing */ function loadScriptPage(tgtNodes) { // Get nodes tab var tab = getNodesTab(); // Generate new tab ID var inst = 0; var newTabId = 'scriptTab' + inst; while ($('#' + newTabId).length) { // If one already exists, generate another one inst = inst + 1; newTabId = 'scriptTab' + inst; } // Open new tab // Create remote script form var scriptForm = $('
    '); // Create status bar var barId = 'scriptStatusBar' + inst; var statBar = createStatusBar(barId); statBar.hide(); scriptForm.append(statBar); // Create loader var loader = createLoader('scriptLoader'); statBar.append(loader); // Create info bar var infoBar = createInfoBar('Run a script against this node range'); scriptForm.append(infoBar); // Target node or group var tgt = $('
    '); scriptForm.append(tgt); // Upload file var upload = $('
    '); var label = $(''); var file = $(''); var subBtn = createButton('Load'); upload.append(label); upload.append(file); upload.append(subBtn); scriptForm.append(upload); // Script var script = $('