From b699c9b3f7583479e3d00ab690822aa90e9a5385 Mon Sep 17 00:00:00 2001 From: phamt Date: Thu, 24 Nov 2011 04:18:38 +0000 Subject: [PATCH] Finished KVM provision page. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@11047 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/js/custom/kvm.js | 219 ++++++++++++++++++++---------- xCAT-UI/js/provision/provision.js | 86 ++++++------ 2 files changed, 193 insertions(+), 112 deletions(-) diff --git a/xCAT-UI/js/custom/kvm.js b/xCAT-UI/js/custom/kvm.js index 62f330c6d..4276ce400 100644 --- a/xCAT-UI/js/custom/kvm.js +++ b/xCAT-UI/js/custom/kvm.js @@ -159,9 +159,6 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { success : setGroupsCookies }); - // Get provision tab instance - var inst = tabId.replace('kvmProvisionTab', ''); - // Create provision form var provForm = $('
'); @@ -187,31 +184,12 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { provForm.append(vmFS, hwFS, imgFS); // Create hypervisor input - var hypervisor = $('
'); - var hypervisorLabel = $(''); - hypervisor.append(hypervisorLabel); - - // Turn on auto complete for group - var hypervisorNames = $.cookie(''); - if (hypervisorNames) { - // Split group names into an array - var tmp = groupNames.split(','); - - // Create drop down for groups - var hypervisorSelect = $(''); - hypervisorSelect.append(''); - for ( var i in tmp) { - // Add group into drop down - var opt = $(''); - hypervisorSelect.append(opt); - } - hypervisor.append(groupSelect); - } else { - // If no groups are cookied - var hypervisorInput = $(''); - hypervisor.append(hypervisorInput); - } - vmFS.append(hypervisor); + var host = $('
'); + var hostLabel = $(''); + host.append(hostLabel); + var hostInput = $(''); + host.append(hostInput); + vmFS.append(host); // Create group input var group = $('
'); @@ -225,7 +203,7 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { var tmp = groupNames.split(','); // Create drop down for groups - var groupSelect = $(''); + var groupSelect = $(''); groupSelect.append(''); for ( var i in tmp) { // Add group into drop down @@ -251,7 +229,7 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { // Create memory input var memory = $('
'); var memoryLabel = $(''); - var memoryInput = $(''); + var memoryInput = $(''); memory.append(memoryLabel); memory.append(memoryInput); hwFS.append(memory); @@ -276,34 +254,33 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { // Create NIC dropdown var nic = $('
'); var nicLabel = $(''); - var nicSelect = $(''); - nicSelect.append('' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - ); + var nicInput = $(''); nic.append(nicLabel); - nic.append(nicSelect); + nic.append(nicInput); hwFS.append(nic); // Create disk input var disk = $('
'); var diskLabel = $(''); - var diskInput = $(''); - var diskSizeSelect = $(''); - diskSizeSelect.append('' - + '' + var diskInput = $(''); + var diskSizeSelect = $(''); + diskSizeSelect.append('' + + '' ); disk.append(diskLabel, diskInput, diskSizeSelect); hwFS.append(disk); + // Create disk storage input + var storage = $('
'); + var storageLabel = $(''); + var storageInput = $(''); + storage.append(storageLabel); + storage.append(storageInput); + hwFS.append(storage); + // Create operating system input var os = $('
'); - var osLabel = $(''); + var osLabel = $(''); var osInput = $(''); osInput.one('focus', function() { var tmp = $.cookie('osvers'); @@ -320,7 +297,7 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { // Create architecture input var arch = $('
'); - var archLabel = $(''); + var archLabel = $(''); var archInput = $(''); archInput.one('focus', function() { var tmp = $.cookie('osarchs'); @@ -337,7 +314,7 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { // Create profile input var profile = $('
'); - var profileLabel = $(''); + var profileLabel = $(''); var profileInput = $(''); profileInput.one('focus', function() { var tmp = $.cookie('profiles'); @@ -354,7 +331,7 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { // Create boot method dropdown var method = $('
'); - var methodLabel = $(''); + var methodLabel = $(''); var methodSelect = $(''); methodSelect.append('' + '' @@ -375,15 +352,14 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { // Remove any warning messages $(this).parents('.ui-tabs-panel').find('.ui-state-error').remove(); var ready = true; - var errorMessage = ''; // Get tab ID - var thisTabId = $(this).parents('.ui-tabs-panel').attr('id'); - + var tabId = $(this).parents('.ui-tabs-panel').attr('id'); + // Check if fields are properly filled in - var inputs = $('#' + thisTabId + ' input:visible'); + var inputs = $('#' + tabId + ' input:visible'); for ( var i = 0; i < inputs.length; i++) { - if (!inputs.eq(i).val()) { + if (!inputs.eq(i).val() && inputs.eq(i).attr('name') != 'storage') { inputs.eq(i).css('border', 'solid #FF0000 1px'); ready = false; } else { @@ -391,7 +367,7 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { } } - var selects = $('#' + thisTabId + ' select:visible'); + var selects = $('#' + tabId + ' select:visible'); for ( var i = 0; i < selects.length; i++) { if (!selects.eq(i).val()) { selects.eq(i).css('border', 'solid #FF0000 1px'); @@ -400,6 +376,65 @@ kvmPlugin.prototype.loadProvisionPage = function(tabId) { selects.eq(i).css('border', 'solid #BDBDBD 1px'); } } + + if (ready) { + var inst = tabId.replace('kvmProvisionTab', ''); + + // Prepend status bar + var statBar = createStatusBar('kvmProvisionStatBar' + inst); + statBar.append(createLoader('')); + statBar.prependTo($('#' + tabId)); + + var host = $('#' + tabId + ' input[name=host]').val(); + var group = $('#' + tabId + ' select[name=group]').val(); + var node = $('#' + tabId + ' input[name=node]').val(); + + var memory = $('#' + tabId + ' input[name=memory]').val(); + var cpu = $('#' + tabId + ' select[name=cpu]').val(); + var nic = $('#' + tabId + ' input[name=nic]').val(); + var disk = $('#' + tabId + ' input[name=disk]').val() + $('#' + tabId + ' select[name=diskUnit]').val(); + var storage = $('#' + tabId + ' input[name=storage]').val(); + + var os = $('#' + tabId + ' input[name=os]').val(); + var arch = $('#' + tabId + ' input[name=arch]').val(); + var profile = $('#' + tabId + ' input[name=profile]').val(); + var boot = $('#' + tabId + ' select[name=bootMethod]').val(); + + /** + * (1) Define node + */ + var args = '-t;node;-o;' + node + + ';vmhost=' + host + + ';groups=' + group + + ';vmmemory=' + memory + + ';vmcpus=' + cpu + + ';vmnics=' + nic + + ';vmstorage=' + storage + + ';os=' + os + + ';arch=' + arch + + ';profile=' + profile + + ';netboot=xnba' + + ';nodetype=osi' + + ';serialport=0' + + ';serialspeed=115200' + + ';mgt=kvm'; + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'chdef', + tgt : '', + args : args, + msg : 'cmd=chdef;out=' + inst + }, + + success : updateKVMProvisionStatus + }); + } else { + // Show warning message + var warn = createWarnBar('Please provide a value for each missing field.'); + warn.prependTo($(this).parent().parent()); + } }); provForm.append(provisionBtn); }; @@ -571,32 +606,28 @@ function updateKVMProvisionStatus(data) { var statBarId = 'kvmProvisionStatBar' + inst; var tabId = 'kvmProvisionTab' + inst; + var node = $('#' + tabId + ' input[name=node]').val(); + /** - * (2) Remote install + * (2) Create virtual machine */ - if (cmd == 'nodeadd') { + if (cmd == 'chdef') { // Write ajax response to status bar var prg = writeRsp(rsp, ''); $('#' + statBarId).find('div').append(prg); // Get parameters - var os = $('#' + tabId + ' input[name="os"]').val(); - var profile = $('#' + tabId + ' input[name="profile"]').val(); - var arch = $('#' + tabId + ' input[name="arch"]').val(); - - // Get nodes that were checked - var dTableId = 'kvmNodesDatatable' + inst; - var tgts = getNodesChecked(dTableId); + var disk = $('#' + tabId + ' input[name=disk]').val() + $('#' + tabId + ' select[name=diskUnit]').val(); // Begin installation $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { - cmd : 'webrun', + cmd : 'mkvm', tgt : '', - args : 'rinstall;' + os + ';' + profile + ';' + arch + ';' + tgts, - msg : 'cmd=rinstall;out=' + inst + args : node + ';-s;' + disk, + msg : 'cmd=mkvm;out=' + inst }, success : updateKVMProvisionStatus @@ -604,9 +635,57 @@ function updateKVMProvisionStatus(data) { } /** - * (3) Done + * (3) Prepare node for boot */ - else if (cmd == 'rinstall') { + if (cmd == 'mkvm') { + // Write ajax response to status bar + var prg = writeRsp(rsp, ''); + $('#' + statBarId).find('div').append(prg); + + // Get provision method + var boot = $('#' + tabId + ' select[name=bootMethod]').val(); + + // Prepare node for boot + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'nodeset', + tgt : node, + args : boot, + msg : 'cmd=nodeset;out=' + inst + }, + + success : updateKVMProvisionStatus + }); + } + + /** + * (4) Power on node + */ + if (cmd == 'nodeset') { + var prg = writeRsp(rsp, ''); + $('#' + statBarId).find('div').append(prg); + + // Prepare node for boot + $.ajax( { + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'rpower', + tgt : node, + args : 'on', + msg : 'cmd=rpower;out=' + inst + }, + + success : updateKVMProvisionStatus + }); + } + + /** + * (5) Done + */ + else if (cmd == 'rpower') { // Write ajax response to status bar var prg = writeRsp(rsp, ''); $('#' + statBarId).find('div').append(prg); @@ -614,7 +693,7 @@ function updateKVMProvisionStatus(data) { // If installation was successful if (prg.html().indexOf('Error') == -1) { - $('#' + statBarId).find('div').append('
It will take several minutes before the nodes are up and ready. Use nodestat to check the status of the install.
'); + $('#' + statBarId).find('div').append('
It will take several minutes before the nodes are up and ready. Use rcons to monitor the status of the install.
'); } } } \ No newline at end of file diff --git a/xCAT-UI/js/provision/provision.js b/xCAT-UI/js/provision/provision.js index bee828b28..b505d6fdb 100644 --- a/xCAT-UI/js/provision/provision.js +++ b/xCAT-UI/js/provision/provision.js @@ -83,9 +83,9 @@ function loadProvisionPage() { // Create radio buttons for platforms var hwList = $('
    Platforms available:
'); - var esx = $('
  • ESX
  • '); + var esx = $('
  • ESX
  • '); var kvm = $('
  • KVM
  • '); - var ipmi = $('
  • iDataPlex
  • '); + var ipmi = $('
  • iDataPlex
  • '); var blade = $('
  • BladeCenter
  • '); var hmc = $('
  • System p
  • '); var zvm = $('
  • System z
  • '); @@ -105,47 +105,49 @@ function loadProvisionPage() { okBtn.bind('click', function(event) { // Get hardware that was selected var hw = $(this).parent().find('input[name="hw"]:checked').val(); - var newTabId = hw + 'ProvisionTab'; + + var inst = 0; + var newTabId = hw + 'ProvisionTab' + inst; + while ($('#' + newTabId).length) { + // If one already exists, generate another one + inst = inst + 1; + newTabId = hw + 'ProvisionTab' + inst; + } + + // Create an instance of the plugin + var title = ''; + var plugin; + switch (hw) { + case "kvm": + plugin = new kvmPlugin(); + title = 'KVM'; + break; + case "esx": + plugin = new esxPlugin(); + title = 'ESX'; + break; + case "blade": + plugin = new bladePlugin(); + title = 'BladeCenter'; + break; + case "hmc": + plugin = new hmcPlugin(); + title = 'System p'; + break; + case "ipmi": + plugin = new ipmiPlugin(); + title = 'iDataPlex'; + break; + case "zvm": + plugin = new zvmPlugin(); + title = 'System z'; + break; + } - if ($('#' + newTabId).size() > 0){ - tab.select(newTabId); - } else { - var title = ''; - - // Create an instance of the plugin - var plugin; - switch (hw) { - case "kvm": - plugin = new kvmPlugin(); - title = 'KVM'; - break; - case "esx": - plugin = new esxPlugin(); - title = 'ESX'; - break; - case "blade": - plugin = new bladePlugin(); - title = 'BladeCenter'; - break; - case "hmc": - plugin = new hmcPlugin(); - title = 'System p'; - break; - case "ipmi": - plugin = new ipmiPlugin(); - title = 'iDataPlex'; - break; - case "zvm": - plugin = new zvmPlugin(); - title = 'System z'; - break; - } - - // Select tab - tab.add(newTabId, title, '', true); - tab.select(newTabId); - plugin.loadProvisionPage(newTabId); - } + // Select tab + tab.add(newTabId, title, '', true); + tab.select(newTabId); + plugin.loadProvisionPage(newTabId); }); provPg.append(okBtn);