From bae8998d2daa9938d977f809cc706b8fb748991e Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Mon, 18 Oct 2010 19:09:38 -0700 Subject: [PATCH] new UI - host page - implement update OS action. --- .../classes/resources/resource.properties | 3 + ui/new/jsp/resource.jsp | 19 +++ ui/new/scripts/cloud.core2.resource.js | 142 +++++++++++++----- 3 files changed, 126 insertions(+), 38 deletions(-) diff --git a/client/WEB-INF/classes/resources/resource.properties b/client/WEB-INF/classes/resources/resource.properties index 3c65fda200c..9d678edd428 100644 --- a/client/WEB-INF/classes/resources/resource.properties +++ b/client/WEB-INF/classes/resources/resource.properties @@ -91,6 +91,8 @@ type = Type disk.total = Disk Total disk.allocated = Disk Allocated ip.address.range = IP Range +OS.preference = OS Preference +none = None disk.offering = Disk Offering copy.ISO.to = Copy ISO to @@ -125,3 +127,4 @@ enabling.maintenance.mode.will.cause.a.live.migration.of.all.running.instances.o please.confirm.you.want.to.cancel.maintenance.for.the.host = Please confirm you want to cancel maintenance for the host please.confirm.you.want.to.force.a.reconnection.for.the.host = Please confirm you want to force a reconnection for the host please.confirm.you.want.to.remove.the.host.from.the.management.server = Please confirm you want to remove the host from the management server +Please.choose.a.OS.preference.for.this.host..Virtual.machines.will.always.be.allocated.to.hosts.with.an.OS.preference.that.matches.with.the.OS.type.of.the.template.chosen.for.the.virtual.machine.before.choosing.other.hosts. = Please choose a OS preference for this host. Virtual machines will always be allocated to hosts with an OS preference that matches with the OS type of the template chosen for the virtual machine before choosing other hosts. diff --git a/ui/new/jsp/resource.jsp b/ui/new/jsp/resource.jsp index 124c1c3ecf0..69d74e1d4a5 100644 --- a/ui/new/jsp/resource.jsp +++ b/ui/new/jsp/resource.jsp @@ -1107,3 +1107,22 @@ <%=t.t("please.confirm.you.want.to.remove.the.host.from.the.management.server")%>

+ + + diff --git a/ui/new/scripts/cloud.core2.resource.js b/ui/new/scripts/cloud.core2.resource.js index 091bf56b33c..b0513c68abd 100644 --- a/ui/new/scripts/cloud.core2.resource.js +++ b/ui/new/scripts/cloud.core2.resource.js @@ -373,6 +373,8 @@ function hostJsonToDetailsTab(jsonObj) { $detailsTab.find("#oscategoryname").text(fromdb(jsonObj.oscategoryname)); $detailsTab.find("#disconnected").text(fromdb(jsonObj.disconnected)); + populateForUpdateOSDialog(jsonObj.oscategoryid); + //actions *** var $actionLink = $detailsTab.find("#action_link"); $actionLink.bind("mouseover", function(event) { @@ -405,6 +407,7 @@ function hostJsonToDetailsTab(jsonObj) { buildActionLinkForDetailsTab("Cancel Maintenance Mode", hostActionMap, $actionMenu, midmenuItemId, $detailsTab); //when right panel has more than 1 details tab, we need to specify which one it is building action to. buildActionLinkForDetailsTab("Force Reconnect", hostActionMap, $actionMenu, midmenuItemId, $detailsTab); //when right panel has more than 1 details tab, we need to specify which one it is building action to. buildActionLinkForDetailsTab("Remove Host", hostActionMap, $actionMenu, midmenuItemId, $detailsTab); //when right panel has more than 1 details tab, we need to specify which one it is building action to. + buildActionLinkForDetailsTab("Update OS Preference", hostActionMap, $actionMenu, midmenuItemId, $detailsTab); //when right panel has more than 1 details tab, we need to specify which one it is building action to. //temporary for testing (begin) ***** @@ -740,6 +743,7 @@ function afterLoadResourceJSP() { initDialog("dialog_confirmation_cancel_maintenance"); initDialog("dialog_confirmation_force_reconnect"); initDialog("dialog_confirmation_remove_host"); + initDialog("dialog_update_os"); // if hypervisor is KVM, limit the server option to NFS for now if (getHypervisorType() == 'kvm') @@ -750,11 +754,32 @@ function afterLoadResourceJSP() { if (getNetworkType() == "vnet") $("#dialog_add_vlan_for_zone").attr("title", "Add Public IP Range"); bindEventHandlerToDialogAddVlanForZone(); - + //initialize Add Zone button initAddZoneButton($("#midmenu_add_link")); } +function populateForUpdateOSDialog(oscategoryid) { + $.ajax({ + data: createURL("command=listOsCategories"+maxPageSize), + dataType: "json", + success: function(json) { + var categories = json.listoscategoriesresponse.oscategory; + var select = $("#dialog_update_os #host_os"); + if (categories != null && categories.length > 0) { + for (var i = 0; i < categories.length; i++) { + if(categories[i].id == oscategoryid) { + select.append(""); + } + else { + select.append(""); + } + } + } + } + }); +} + function nfsURL(server, path) { var url; if(server.indexOf("://")==-1) @@ -1300,7 +1325,24 @@ var hostActionMap = { clearRightPanel(); hostClearRightPanel(); } - }, + }, + "Update OS Preference": { + isAsyncJob: false, + dialogBeforeActionFn : doUpdateOSPreference, + inProcessText: "Updating OS Preference....", + afterActionSeccessFn: function(json, id, midmenuItemId) { + //call listHosts API before bug 6650 ("updateHost API should return an embedded object like what listHosts API does") is fixed. + $.ajax({ + data: createURL("command=listHosts&id="+id), + dataType: "json", + success: function(json) { + $midmenuItem1 = $("#"+midmenuItemId); + hostToMidmenu(json.listhostsresponse.host[0], $midmenuItem1); + hostToRigntPanel($midmenuItem1) + } + }); + } + }, } function doEnableMaintenanceMode($actionLink, $detailsTab, midmenuItemId){ @@ -1308,15 +1350,15 @@ function doEnableMaintenanceMode($actionLink, $detailsTab, midmenuItemId){ $("#dialog_confirmation_enable_maintenance") .dialog("option", "buttons", { - "OK": function() { - $(this).dialog("close"); - var id = jsonObj.id; - var apiCommand = "command=prepareHostForMaintenance&id="+id; - doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId); - }, - "Cancel": function() { - $(this).dialog("close"); - } + "OK": function() { + $(this).dialog("close"); + var id = jsonObj.id; + var apiCommand = "command=prepareHostForMaintenance&id="+id; + doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId); + }, + "Cancel": function() { + $(this).dialog("close"); + } }).dialog("open"); } @@ -1325,15 +1367,15 @@ function doCancelMaintenanceMode($actionLink, $detailsTab, midmenuItemId){ $("#dialog_confirmation_cancel_maintenance") .dialog("option", "buttons", { - "OK": function() { - $(this).dialog("close"); - var id = jsonObj.id; - var apiCommand = "command=cancelHostMaintenance&id="+id; - doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId); - }, - "Cancel": function() { - $(this).dialog("close"); - } + "OK": function() { + $(this).dialog("close"); + var id = jsonObj.id; + var apiCommand = "command=cancelHostMaintenance&id="+id; + doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId); + }, + "Cancel": function() { + $(this).dialog("close"); + } }).dialog("open"); } @@ -1342,15 +1384,15 @@ function doForceReconnect($actionLink, $detailsTab, midmenuItemId){ $("#dialog_confirmation_force_reconnect") .dialog("option", "buttons", { - "OK": function() { - $(this).dialog("close"); - var id = jsonObj.id; - var apiCommand = "command=reconnectHost&id="+id; - doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId); - }, - "Cancel": function() { - $(this).dialog("close"); - } + "OK": function() { + $(this).dialog("close"); + var id = jsonObj.id; + var apiCommand = "command=reconnectHost&id="+id; + doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId); + }, + "Cancel": function() { + $(this).dialog("close"); + } }).dialog("open"); } @@ -1359,14 +1401,38 @@ function doRemoveHost($actionLink, $detailsTab, midmenuItemId){ $("#dialog_confirmation_remove_host") .dialog("option", "buttons", { - "OK": function() { - $(this).dialog("close"); - var id = jsonObj.id; - var apiCommand = "command=deleteHost&id="+id; - doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId); - }, - "Cancel": function() { - $(this).dialog("close"); - } + "OK": function() { + $(this).dialog("close"); + var id = jsonObj.id; + var apiCommand = "command=deleteHost&id="+id; + doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId); + }, + "Cancel": function() { + $(this).dialog("close"); + } + }).dialog("open"); +} + +function doUpdateOSPreference($actionLink, $detailsTab, midmenuItemId){ + var jsonObj = $detailsTab.data("jsonObj"); + + $("#dialog_update_os") + .dialog("option", "buttons", { + "Update": function() { + $(this).dialog("close"); + var osId = $("#dialog_update_os #host_os").val(); + var osName = $("#dialog_update_os #host_os option:selected").text(); + var category = ""; + if (osId.length > 0) { + category = "&osCategoryId="+osId; + } + var id = jsonObj.id; + + var apiCommand = "command=updateHost&id="+id+category; + doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId); + }, + "Cancel": function() { + $(this).dialog("close"); + } }).dialog("open"); } \ No newline at end of file