/** * Execute when the DOM is fully loaded */ $(document).ready(function() { // Load utility scripts includeJs("js/custom/zvmUtils.js"); }); /** * Constructor * * @return Nothing */ var zvmPlugin = function() { }; /** * Load clone page * * @param node * Source node to clone * @return Nothing */ zvmPlugin.prototype.loadClonePage = function(node) { // Get nodes tab var tab = getNodesTab(); var newTabId = node + 'CloneTab'; // If there is no existing clone tab if (!$('#' + newTabId).length) { // Get table headers var table = $('#' + node).parent().parent().parent().parent(); var headers = table.find('thead th'); var cols = new Array(); for ( var i = 0; i < headers.length; i++) { var col = headers.eq(i).text(); cols.push(col); } // Get hardware control point column var hcpCol = $.inArray('hcp', cols); // Get hardware control point var nodeRow = $('#' + node).parent().parent(); var dTable = getNodesDataTable(); var rowPos = dTable.fnGetPosition(nodeRow.get(0)); var aData = dTable.fnGetData(rowPos); var hcp = aData[hcpCol]; // Create status bar and hide it var statBarId = node + 'CloneStatusBar'; var statBar = $('
') .hide(); // Create info bar var infoBar = createInfoBar('Clone a node'); // Create clone form var cloneForm = $(''); cloneForm.append(statBar); cloneForm.append(infoBar); // Create target node range input cloneForm.append(''); // Create target user ID range input cloneForm.append(''); // Create clone source and hardware control point inputs cloneForm.append(''); cloneForm.append(''); // Create group input var group = $(''); var groupLabel = $(''); var groupInput = $(''); groupInput.one('focus', function(){ var groupNames = $.cookie('Groups'); if (groupNames) { // Turn on auto complete $(this).autocomplete(groupNames.split(',')); } }); group.append(groupLabel); group.append(groupInput); cloneForm.append(group); // Get list of disk pools var temp = hcp.split('.'); var diskPools = $.cookie(temp[0] + 'DiskPools'); // Create disk pool input var poolDiv = $(''); var poolLabel = $(''); var poolInput = $('').autocomplete(diskPools.split(',')); poolDiv.append(poolLabel); poolDiv.append(poolInput); cloneForm.append(poolDiv); // Create disk password input cloneForm.append(''); /** * Clone node */ var cloneBtn = createButton('Clone'); cloneBtn.bind('click', function(event) { var ready = true; var errMsg = ''; // Check node name, userId, hardware control point, group, and password var inputs = $('#' + newTabId + ' input'); for ( var i = 0; i < inputs.length; i++) { if (!inputs.eq(i).val() && inputs.eq(i).attr('name') != 'diskPw' && inputs.eq(i).attr('name') != 'diskPool') { inputs.eq(i).css('border', 'solid #FF0000 1px'); ready = false; } else { inputs.eq(i).css('border', 'solid #BDBDBD 1px'); } } // Write error message if (!ready) { errMsg = errMsg + 'You are missing some inputs. '; } // Get target node var nodeRange = $('#' + newTabId + ' input[name=tgtNode]').val(); // Get target user ID var userIdRange = $('#' + newTabId + ' input[name=tgtUserId]').val(); // Check node range and user ID range if (nodeRange.indexOf('-') > -1 || userIdRange.indexOf('-') > -1) { if (nodeRange.indexOf('-') < 0 || userIdRange.indexOf('-') < 0) { errMsg = errMsg + 'A user ID range and node range needs to be given. '; ready = false; } else { var tmp = nodeRange.split('-'); // Get node base name var nodeBase = tmp[0].match(/[a-zA-Z]+/); // Get starting index var nodeStart = parseInt(tmp[0].match(/\d+/)); // Get ending index var nodeEnd = parseInt(tmp[1]); tmp = userIdRange.split('-'); // Get user ID base name var userIdBase = tmp[0].match(/[a-zA-Z]+/); // Get starting index var userIdStart = parseInt(tmp[0].match(/\d+/)); // Get ending index var userIdEnd = parseInt(tmp[1]); // If starting and ending index do not match if (!(nodeStart == userIdStart) || !(nodeEnd == userIdEnd)) { // Not ready to provision errMsg = errMsg + 'The node range and user ID range does not match. '; ready = false; } } } // Get source node, hardware control point, group, disk pool, and disk password var srcNode = $('#' + newTabId + ' input[name=srcNode]').val(); var hcp = $('#' + newTabId + ' input[name=newHcp]').val(); var group = $('#' + newTabId + ' input[name=newGroup]').val(); var diskPool = $('#' + newTabId + ' input[name=diskPool]').val(); var diskPw = $('#' + newTabId + ' input[name=diskPw]').val(); // If a value is given for every input if (ready) { // Disable all inputs var inputs = $('#' + newTabId + ' input'); inputs.attr('disabled', 'disabled'); // If a node range is given if (nodeRange.indexOf('-') > -1) { var tmp = nodeRange.split('-'); // Get node base name var nodeBase = tmp[0].match(/[a-zA-Z]+/); // Get starting index var nodeStart = parseInt(tmp[0].match(/\d+/)); // Get ending index var nodeEnd = parseInt(tmp[1]); tmp = userIdRange.split('-'); // Get user ID base name var userIdBase = tmp[0].match(/[a-zA-Z]+/); // Get starting index var userIdStart = parseInt(tmp[0].match(/\d+/)); // Get ending index var userIdEnd = parseInt(tmp[1]); // Loop through each node in the node range for ( var i = nodeStart; i <= nodeEnd; i++) { var node = nodeBase + i.toString(); var userId = userIdBase + i.toString(); var inst = i + '/' + nodeEnd; /** * (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;inst=' + inst + ';out=' + statBarId + ';node=' + node }, success : updateZCloneStatus }); } } else { /** * (1) Define node */ $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'nodeadd', tgt : '', args : nodeRange + ';zvm.hcp=' + hcp + ';zvm.userid=' + userIdRange + ';nodehm.mgt=zvm' + ';groups=' + group, msg : 'cmd=nodeadd;inst=1/1;out=' + statBarId + ';node=' + nodeRange }, success : updateZCloneStatus }); } // Create loader var loader = createLoader(''); $('#' + statBarId).append(loader); $('#' + statBarId).show(); // Disable clone button $(this).unbind(event); $(this).css( { 'background-color' : '#F2F2F2', 'color' : '#BDBDBD' }); } else { alert('(Error) ' + errMsg); } }); cloneForm.append(cloneBtn); // Add clone tab tab.add(newTabId, 'Clone', cloneForm, true); } tab.select(newTabId); }; /** * Load node inventory * * @param data * Data from HTTP request * @return Nothing */ zvmPlugin.prototype.loadInventory = function(data) { 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[0].split(node + ':'); // Remove loader var loaderId = tabId + 'TabLoader'; $('#' + loaderId).remove(); // Create status bar var statBarId = node + 'StatusBar'; var statBar = createStatusBar(statBarId); // Add loader to status bar and hide it loaderId = node + 'StatusBarLoader'; var loader = createLoader(loaderId); statBar.append(loader); loader.hide(); statBar.hide(); // Create array of property keys var keys = new Array('userId', 'host', 'os', 'arch', 'hcp', 'priv', 'memory', 'proc', 'disk', 'nic'); // Create hash table for property names var attrNames = new Object(); attrNames['userId'] = 'z/VM UserID:'; attrNames['host'] = 'z/VM Host:'; attrNames['os'] = 'Operating System:'; attrNames['arch'] = 'Architecture:'; attrNames['hcp'] = 'HCP:'; attrNames['priv'] = 'Privileges:'; attrNames['memory'] = 'Total Memory:'; attrNames['proc'] = 'Processors:'; attrNames['disk'] = 'Disks:'; attrNames['nic'] = 'NICs:'; // Create hash table for node attributes var attrs = getAttrs(keys, attrNames, inv); // Create division to hold user entry var ueDivId = node + 'UserEntry'; var ueDiv = $(''); // Create division to hold inventory var invDivId = node + 'Inventory'; var invDiv = $(''); /** * Show user entry */ var toggleLinkId = node + 'ToggleLink'; var toggleLink = $('Show user entry'); toggleLink.one('click', function(event) { // Toggle inventory division $('#' + invDivId).toggle(); // Create loader var loader = createLoader(node + 'TabLoader'); loader = $('