/** * Create nodes datatable for a given group * * @param group * Group name * @param outId * Division ID to append datatable * @return Nodes datatable */ function createNodesDatatable(group, outId) { // Get group nodes $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsdef', tgt : '', args : group, msg : outId }, /** * Create nodes datatable * * @param data * Data returned from HTTP request * @return Nothing */ success : function(data) { // Data returned var rsp = data.rsp; // Get output ID var outId = data.msg; // Get datatable ID var dTableId = outId.replace('DIV', ''); // Node attributes hash var attrs = new Object(); // Node attributes var headers = new Object(); // Clear nodes datatable division $('#' + outId).empty(); // Create nodes datatable var node, args; for ( var i in rsp) { // Get 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 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 and node sorted.unshift('', 'node'); // Create nodes datatable var dTable = new DataTable(dTableId); 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 = ''; row.push(checkBx, node); // Go through each header for ( var i = 2; i < sorted.length; i++) { // Add node attributes to the row var key = sorted[i]; var val = attrs[node][key]; if (val) { row.push(val); } else { row.push(''); } } // Add row to table dTable.add(row); } $('#' + outId).append(dTable.object()); $('#' + dTableId).dataTable(); } // End of function(data) }); } /** * Create provision existing node division * * @param plugin * Plugin name to create division for * @param inst * Provision tab instance * @return Provision existing node division */ function createProvisionExisting(plugin, inst) { // Create provision existing division and hide it var provExisting = $('
').hide(); // Create group input var group = $('
'); var groupLabel = $(''); group.append(groupLabel); // Turn on auto complete for group var dTableDivId = plugin + 'NodesDatatableDIV' + 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); } provExisting.append(group); // Create node input var node = $('
'); var nodeLabel = $(''); var nodeDatatable = $('

Select a group to view its nodes

'); node.append(nodeLabel); node.append(nodeDatatable); provExisting.append(node); // Create boot method drop down var method = $('
'); var methodLabel = $(''); var methodSelect = $(''); methodSelect.append('' + '' + '' + '' + '' ); method.append(methodLabel); method.append(methodSelect); provExisting.append(method); // Create boot type drop down var type = $('
'); var typeLabel = $(''); var typeSelect = $(''); typeSelect.append('' + '' + '' ); type.append(typeLabel); type.append(typeSelect); provExisting.append(type); // 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); provExisting.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); provExisting.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); provExisting.append(profile); /** * Provision existing */ var provisionBtn = createButton('Provision'); provisionBtn.bind('click', function(event) { // TODO Insert provision code here openDialog('info', 'Not yet supported'); }); provExisting.append(provisionBtn); return provExisting; } /** * Create provision new node division * * @param inst * Provision tab instance * @return Provision new node division */ function createProvisionNew(plugin, inst) { // Create provision new node division var provNew = $('
'); // Create node input var nodeName = $('
'); provNew.append(nodeName); // 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({ source: groupNames.split(',') }); } }); group.append(groupLabel); group.append(groupInput); provNew.append(group); // Create boot method drop down var method = $('
'); var methodLabel = $(''); var methodSelect = $(''); methodSelect.append('' + '' + '' + '' + '' ); method.append(methodLabel); method.append(methodSelect); provNew.append(method); // Create boot type drop down var type = $('
'); var typeLabel = $(''); var typeSelect = $(''); typeSelect.append('' + '' + '' ); type.append(typeLabel); type.append(typeSelect); provNew.append(type); // 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); provNew.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); provNew.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); provNew.append(profile); /** * Provision new node */ var provisionBtn = createButton('Provision'); provisionBtn.bind('click', function(event) { // TODO Insert provision code here openDialog('info', 'Not yet supported'); }); provNew.append(provisionBtn); return provNew; } /** * Create section to provision node * * @param plugin * Plugin name * @param container * Container to hold provision section * @return Nothing */ function appendProvisionSection(plugin, container) { // Get provision tab ID var tabId = container.parents('.tab').attr('id'); if (plugin == 'quick') appendProvision4Url(container); // For provisioning based on argmunents found in URL else appendProvision4NoUrl(plugin, container); // Add provision button var provisionBtn = createButton('Provision'); provisionBtn.bind('click', function(){ provisionNode(tabId); }); container.append(provisionBtn); // Bind image select to change event container.find('select[name=image]').bind('change', function() { createAdvancedOptions($(this).val(), tabId); }); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsdef', tgt : '', args : '-t;osimage', msg : tabId }, success : function(data){ var tabId = data.msg; var i = 0; var imageName = 0; var position = 0; if (!data.rsp.length) { $('#' + tabId).prepend(createWarnBar('Please run copycds and genimage in provision page before continuing!')); return; } for (i in data.rsp) { imageName = data.rsp[i]; position = imageName.indexOf(' '); imageName = imageName.substr(0, position); $('#' + tabId + ' select[name=image]').append($('')); } // Trigger select change event $('#' + tabId + ' select[name=image]').trigger('change'); // Show provision button $('#' + tabId + ' button').show(); } }); } /** * Create provision node section using URL * * @param container * Container to hold provision section * @returns Nothing */ function appendProvision4Url(container){ // Get provision tab ID var tabId = container.parents('.tab').attr('id'); // Create node fieldset var nodeFS = $('
'); var nodeLegend = $('Node'); nodeFS.append(nodeLegend); container.append(nodeFS); var nodeAttr = $('
'); nodeFS.append($('
')); nodeFS.append(nodeAttr); // Create image fieldset var imgFS = $('
'); var imgLegend = $('Image'); imgFS.append(imgLegend); container.append(imgFS); var imgAttr = $('
'); imgFS.append($('
')); imgFS.append(imgAttr); var query = window.location.search; var args = query.substr(1).split('&'); var parms = new Object(); var tmp; // Turn URL arguments into hash array for (var i = 0; i < args.length; i++) { tmp = args[i].split('='); parms[tmp[0]] = tmp[1]; } var master = ''; if (parms['master']) master = parms['master']; var nfsserver = ''; if (parms['nfsserver']) nfsserver = parms['nfsserver']; var tftpserver = ''; if (parms['tftpserver']) tftpserver = parms['tftpserver']; nodeAttr.append('
'); imgAttr.append('
'); imgAttr.append('
'); imgAttr.append( '
'); imgAttr.append('
'); imgAttr.append('
'); imgAttr.append('
'); imgAttr.append('
'); return; } /** * Create section to provision node using no URL * * @param plugin * Create provision section for given plugin * @param container * Container to hold provision section * @returns Nothing */ function appendProvision4NoUrl(plugin, container){ // Get provision tab ID var tabId = container.parents('.tab').attr('id'); // Create node fieldset var nodeFS = $('
'); var nodeLegend = $('Node'); nodeFS.append(nodeLegend); container.append(nodeFS); var nodeAttr = $('
'); nodeFS.append($('
')); nodeFS.append(nodeAttr); // Create image fieldset var imgFS = $('
'); var imgLegend = $('Image'); imgFS.append(imgLegend); container.append(imgFS); var imgAttr = $('
'); imgFS.append($('
')); imgFS.append(imgAttr); // Select group name var group = $('
').append(''); var groupSelect = $(''); group.append(groupSelect); var groupNames = $.cookie('groups'); if (groupNames) { var tmp = groupNames.split(','); groupSelect.append(''); // Append empty group name for (var i in tmp) groupSelect.append(''); } nodeAttr.append(group); // Select node from table var nodes = $('
'); var nodesTable = $('

Select a group to view its nodes

'); nodes.append(nodesTable); nodeAttr.append(nodes); // Select architecture var arch = $('
').append(''); var archName = $.cookie('osarchs'); if (archName) { var archSelect = $(''); arch.append(archSelect); var tmp = archName.split(','); for (var i in tmp) archSelect.append(''); } else { arch.append(''); } imgAttr.append(arch); imgAttr.append('
'); imgAttr.append('
'); imgAttr.append('
'); imgAttr.append('
'); imgAttr.append('
'); imgAttr.append('
'); // When a group is selected, show the nodes belonging to that group groupSelect.bind('change', function() { var nodesTableId = '#' + tabId + ' #nodesTable'; $(nodesTableId).append(createLoader()); createNodesTable($(this).val(), nodesTableId); }); return; } /** * Provision node * * @param tabId * Provision tab ID * @return Nothing */ function provisionNode(tabId) { var plugin = tabId; var errorMessage = ""; var args = new Array(); var node = ""; // Delete any existing warnings $('#' + tabId + ' .ui-state-error').remove(); // Go through each input $('#' + tabId + ' input[type!="checkbox"]').each(function() { if (!$(this).val()) { errorMessage = 'Please provide a value for each missing field!'; return false; } else { args.push($(this).val()); } }); // Do not continue if error was found if (errorMessage) { $('#' + tabId).prepend(createWarnBar(errorMessage)); return; } // If jumped from nodes page, get node name if (tabId == 'quick') { node = args.shift(); } else { // Select platform, get node names from table checkbox args.unshift($('#' + tabId + ' input[name=arch]').val()); node = getCheckedByObj($('#' + tabId + ' #nodesTable')); } // Do not continue if a node is not given if (!node) { $('#' + tabId).prepend(createWarnBar('Please select a node!')); return; } var software = getCheckedByObj($('#' + tabId + ' #advanced')); var imageName = $('#' + tabId + ' select[name=image]').val(); var provision = args.join(','); var url = 'lib/cmd.php?cmd=webrun&tgt=&args=provision;' + node + ';' + imageName + ';' + provision + ';' + software + '&msg=&opts=flush'; $('#' + tabId).prepend(createIFrame(url)); } /** * Create advance option * * @param imagename * Image name * @param outId * Output area ID * @return Nothing */ function createAdvancedOptions(image, outId) { $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'lsdef', tgt : '', args : '-t;osimage;' + image + ';-i;osname,provmethod', msg : outId }, success : function(data) { var outId = data.msg; var osName = ''; var provMethod = ''; var tmpStr = ''; var position = 0; for (var i = 0; i < data.rsp.length; i++) { tmpStr = data.rsp[i]; if (tmpStr.indexOf('osname') != -1) { position = tmpStr.indexOf('='); osName = tmpStr.substr(position + 1); } if (tmpStr.indexOf('provmethod') != -1) { position = tmpStr.indexOf('='); provMethod = tmpStr.substr(position + 1); } } $('#' + outId + ' #advanced').remove(); if (osName.toLowerCase() == 'aix') return; if (provMethod == 'install') { // Create advanced fieldset var advancedFS = $('
').append($('Advanced')); $('#' + outId + ' div.form fieldset:eq(1)').after(advancedFS); advancedFS.append('
Install Ganglia monitoring
'); } } }); } /** * Create nodes table * * @param group * Group name * @param outId * Output section ID * @return Nothing */ function createNodesTable(group, outId) { // Get group nodes $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'nodels', tgt : group, args : '', msg : outId }, success : function(data) { var outId = $(data.msg); var nodes = data.rsp; // Create table to hold nodes var nTable = $('
'); var tHead = $(' Node '); nTable.append(tHead); var tBody = $(''); nTable.append(tBody); for (var i in nodes) { var node = nodes[i][0]; // Go to next node if there is nothing here if (!node) continue; // Insert node into table tBody.append('' + node + ''); } outId.empty().append(nTable); if (nodes.length > 10) outId.css('height', '300px'); else outId.css('height', 'auto'); } }); } /** * Get select element names * * @param obj * Object to get selected element names * @return Nodes name seperate by a comma */ function getCheckedByObj(obj) { var str = ''; // Get nodes that were checked obj.find('input:checked').each(function() { if ($(this).attr('name')) { str += $(this).attr('name') + ','; } }); if (str) { str = str.substr(0, str.length - 1); } return str; } /** * Select all checkboxes in the table * * @param event * Event on element * @param obj * Object triggering event * @return Nothing */ function selectAll4Table(event, obj) { // Get datatable ID // This will ascend from var tableObj = obj.parents('table').find('tbody'); var status = obj.attr('checked'); tableObj.find(' :checkbox').attr('checked', status); event.stopPropagation(); }