From 0445358321052e4a4d389adbbdbb644be643b758 Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Mon, 27 Dec 2010 17:50:03 -0800 Subject: [PATCH] Bug 7709: let addPrimaryStorage be aware of hypervisors and do it smartly --- ui/jsp/pod.jsp | 24 ++++++++-- ui/jsp/resource.jsp | 20 ++++++-- ui/jsp/zone.jsp | 20 ++++++-- ui/scripts/cloud.core.pod.js | 79 ++++++++++++++++++++++++++----- ui/scripts/cloud.core.resource.js | 57 ++++++++++++++++++---- ui/scripts/cloud.core.zone.js | 59 +++++++++++++++++++---- 6 files changed, 215 insertions(+), 44 deletions(-) diff --git a/ui/jsp/pod.jsp b/ui/jsp/pod.jsp index 7885ff3fff6..5e0db0e9433 100644 --- a/ui/jsp/pod.jsp +++ b/ui/jsp/pod.jsp @@ -496,34 +496,48 @@ -
  • -
  • +
  • -
  • +
  • - - +
  • + + + +
  • +
  • + + + +
  • diff --git a/ui/jsp/resource.jsp b/ui/jsp/resource.jsp index da3611c3871..7fdfdd628b7 100644 --- a/ui/jsp/resource.jsp +++ b/ui/jsp/resource.jsp @@ -724,27 +724,41 @@
  • -
  • +
  • - - +
  • + + + +
  • +
  • + + + +
  • diff --git a/ui/jsp/zone.jsp b/ui/jsp/zone.jsp index 320bb677737..52674346461 100644 --- a/ui/jsp/zone.jsp +++ b/ui/jsp/zone.jsp @@ -832,27 +832,41 @@
  • -
  • +
  • - - +
  • + + + +
  • +
  • + + + +
  • diff --git a/ui/scripts/cloud.core.pod.js b/ui/scripts/cloud.core.pod.js index e118d370e81..de0bf1dc029 100644 --- a/ui/scripts/cloud.core.pod.js +++ b/ui/scripts/cloud.core.pod.js @@ -628,23 +628,53 @@ function bindAddPrimaryStorageButton($button, currentPageInRightPanel, $leftmenu dialogAddPool.find("#pod_name").text(fromdb(primarystorageObj.podname)); } - var clusterSelect = $("#dialog_add_pool").find("#pool_cluster").empty(); + var clusterSelect = $("#dialog_add_pool").find("#pool_cluster").empty(); + var mapClusters = {}; $.ajax({ data: createURL("command=listClusters&podid=" + podId), - dataType: "json", + async: false, + dataType: "json", success: function(json) { - var items = json.listclustersresponse.cluster; - if(items != null && items.length > 0) { - for(var i=0; i 0) { + mapClusters = {}; + for(var i=0; i" + fromdb(items[i].name) + ""); else clusterSelect.append(""); - } + } + if(!clusterSelect.val()) + $("option", clusterSelect)[0].attr("selected", "selected"); } } - }); - + }); + + $("#pool_cluster", dialogAddPool).change(function() { + var curOption = $(this).val(); + if(!curOption) + return false; + + var $protocolSelector = $("#add_pool_protocol", dialogAddPool); + var objCluster = mapClusters['cluster_'+curOption]; + + if(objCluster.hypervisortype == "KVM") { + $protocolSelector.empty(); + $protocolSelector.append(''); + } else if(objCluster.hypervisortype == "XenServer") { + $protocolSelector.empty(); + $protocolSelector.append(''); + $protocolSelector.append(''); + } else if(objCluster.hypervisortype == "VmWare") { + $protocolSelector.empty(); + $protocolSelector.append(''); + $protocolSelector.append(''); + } + + $protocolSelector.change(); + }).change(); + $("#dialog_add_pool") .dialog('option', 'buttons', { "Add": function() { @@ -657,11 +687,14 @@ function bindAddPrimaryStorageButton($button, currentPageInRightPanel, $leftmenu isValid &= validateDropDownBox("Cluster", $thisDialog.find("#pool_cluster"), $thisDialog.find("#pool_cluster_errormsg"), false); //required, reset error text isValid &= validateString("Name", $thisDialog.find("#add_pool_name"), $thisDialog.find("#add_pool_name_errormsg")); isValid &= validateString("Server", $thisDialog.find("#add_pool_nfs_server"), $thisDialog.find("#add_pool_nfs_server_errormsg")); - if (protocol == "nfs" || protocol == "vmfs") { + if (protocol == "nfs") { isValid &= validateString("Path", $thisDialog.find("#add_pool_path"), $thisDialog.find("#add_pool_path_errormsg")); - } else { + } else if(protocol == "iscsi") { isValid &= validateString("Target IQN", $thisDialog.find("#add_pool_iqn"), $thisDialog.find("#add_pool_iqn_errormsg")); isValid &= validateString("LUN #", $thisDialog.find("#add_pool_lun"), $thisDialog.find("#add_pool_lun_errormsg")); + } else if(protocol == "vmfs") { + isValid &= validateString("vCenter Datacenter", $thisDialog.find("#add_pool_vmfs_dc"), $thisDialog.find("#add_pool_vmfs_dc_errormsg")); + isValid &= validateString("vCenter Datastore", $thisDialog.find("#add_pool_vmfs_ds"), $thisDialog.find("#add_pool_vmfs_ds_errormsg")); } isValid &= validateString("Tags", $thisDialog.find("#add_pool_tags"), $thisDialog.find("#add_pool_tags_errormsg"), true); //optional if (!isValid) @@ -688,10 +721,11 @@ function bindAddPrimaryStorageButton($button, currentPageInRightPanel, $leftmenu path = "/" + path; url = nfsURL(server, path); } else if (protocol == "vmfs") { - var path = trim($thisDialog.find("#add_pool_path").val()); + var path = trim($thisDialog.find("#add_pool_vmfs_dc").val()); if(path.substring(0,1)!="/") path = "/" + path; - url = vmfsURL(server, path); + path += "/" + trim($thisDialog.find("#add_pool_vmfs_ds").val()) + url = vmfsURL("dummy", path); } else { var iqn = trim($thisDialog.find("#add_pool_iqn").val()); if(iqn.substring(0,1)!="/") @@ -837,7 +871,25 @@ function iscsiURL(server, iqn, lun) { } function bindEventHandlerToDialogAddPool($dialogAddPool) { - $dialogAddPool.find("#add_pool_protocol").change(function(event) { + $dialogAddPool.find("#add_pool_protocol").change(function(event) { + if($(this).val() == "nfs") { + $("#add_pool_server_container", $dialogAddPool).show(); + $('li[input_group="nfs"]', $dialogAddPool).show(); + $('li[input_group="iscsi"]', $dialogAddPool).hide(); + $('li[input_group="vmfs"]', $dialogAddPool).hide(); + } else if($(this).val() == "iscsi") { + $("#add_pool_server_container", $dialogAddPool).show(); + $('li[input_group="nfs"]', $dialogAddPool).hide(); + $('li[input_group="iscsi"]', $dialogAddPool).show(); + $('li[input_group="vmfs"]', $dialogAddPool).hide(); + } else if($(this).val() == "vmfs") { + $("#add_pool_server_container", $dialogAddPool).hide(); + $('li[input_group="nfs"]', $dialogAddPool).hide(); + $('li[input_group="iscsi"]', $dialogAddPool).hide(); + $('li[input_group="vmfs"]', $dialogAddPool).show(); + } + +/* if ($(this).val() == "iscsi") { $dialogAddPool.find("#add_pool_path_container").hide(); $dialogAddPool.find("#add_pool_iqn_container,#add_pool_lun_container").show(); @@ -850,6 +902,7 @@ function bindEventHandlerToDialogAddPool($dialogAddPool) { $dialogAddPool.find("#add_pool_path_container").show(); $dialogAddPool.find("#add_pool_iqn_container,#add_pool_lun_container").hide(); } +*/ }); } diff --git a/ui/scripts/cloud.core.resource.js b/ui/scripts/cloud.core.resource.js index 5c93053e7e7..6b4fb82a043 100644 --- a/ui/scripts/cloud.core.resource.js +++ b/ui/scripts/cloud.core.resource.js @@ -1132,7 +1132,8 @@ function initAddPrimaryStorageShortcut($midmenuAddLink2, currentPageInRightPanel } }); }); - + + var mapClusters = {}; $dialogAddPool.find("#pod_dropdown").bind("change", function(event) { var podId = $(this).val(); if(podId == null || podId.length == 0) @@ -1141,11 +1142,19 @@ function initAddPrimaryStorageShortcut($midmenuAddLink2, currentPageInRightPanel $.ajax({ data: createURL("command=listClusters&podid=" + podId), dataType: "json", - success: function(json) { + async: false, + success: function(json) { + mapClusters = {}; var items = json.listclustersresponse.cluster; if(items != null && items.length > 0) { - for(var i=0; i" + fromdb(items[i].name) + ""); + for(var i=0; i" + fromdb(items[i].name) + ""); + } + + if(!$clusterSelect.val()) + $("option", $clusterSelect)[0].attr("selected", "selected"); + $dialogAddPool.find("input[value=existing_cluster_radio]").attr("checked", true); } else { @@ -1155,6 +1164,30 @@ function initAddPrimaryStorageShortcut($midmenuAddLink2, currentPageInRightPanel } }); }); + + $dialogAddPool.find("#cluster_select").change(function() { + var curOption = $(this).val(); + if(!curOption) + return false; + + var $protocolSelector = $("#add_pool_protocol", $dialogAddPool); + var objCluster = mapClusters['cluster_'+curOption]; + + if(objCluster.hypervisortype == "KVM") { + $protocolSelector.empty(); + $protocolSelector.append(''); + } else if(objCluster.hypervisortype == "XenServer") { + $protocolSelector.empty(); + $protocolSelector.append(''); + $protocolSelector.append(''); + } else if(objCluster.hypervisortype == "VmWare") { + $protocolSelector.empty(); + $protocolSelector.append(''); + $protocolSelector.append(''); + } + + $protocolSelector.change(); + }).change(); $("#add_primarystorage_shortcut").unbind("click").bind("click", function(event) { @@ -1175,11 +1208,14 @@ function initAddPrimaryStorageShortcut($midmenuAddLink2, currentPageInRightPanel isValid &= validateDropDownBox("Cluster", $thisDialog.find("#cluster_select"), $thisDialog.find("#cluster_select_errormsg"), false); //required, reset error text isValid &= validateString("Name", $thisDialog.find("#add_pool_name"), $thisDialog.find("#add_pool_name_errormsg")); isValid &= validateString("Server", $thisDialog.find("#add_pool_nfs_server"), $thisDialog.find("#add_pool_nfs_server_errormsg")); - if (protocol == "nfs" || protocol == "vmfs") { + if (protocol == "nfs") { isValid &= validateString("Path", $thisDialog.find("#add_pool_path"), $thisDialog.find("#add_pool_path_errormsg")); - } else { - isValid &= validateString("Target IQN", $thisDialog.find("#add_pool_iqn"), $thisDialog.find("#add_pool_iqn_errormsg")); - isValid &= validateString("LUN #", $thisDialog.find("#add_pool_lun"), $thisDialog.find("#add_pool_lun_errormsg")); + } else if(protocol == "iscsi") { + isValid &= validateString("Target IQN", $thisDialog.find("#add_pool_iqn"), $thisDialog.find("#add_pool_iqn_errormsg")); + isValid &= validateString("LUN #", $thisDialog.find("#add_pool_lun"), $thisDialog.find("#add_pool_lun_errormsg")); + } else if(protocol == "vmfs") { + isValid &= validateString("vCenter Datacenter", $thisDialog.find("#add_pool_vmfs_dc"), $thisDialog.find("#add_pool_vmfs_dc_errormsg")); + isValid &= validateString("vCenter Datastore", $thisDialog.find("#add_pool_vmfs_ds"), $thisDialog.find("#add_pool_vmfs_ds_errormsg")); } isValid &= validateString("Tags", $thisDialog.find("#add_pool_tags"), $thisDialog.find("#add_pool_tags_errormsg"), true); //optional if (!isValid) @@ -1215,10 +1251,11 @@ function initAddPrimaryStorageShortcut($midmenuAddLink2, currentPageInRightPanel path = "/" + path; url = nfsURL(server, path); } else if(protocol == "vmfs") { - var path = trim($thisDialog.find("#add_pool_path").val()); + var path = trim($thisDialog.find("#add_pool_vmfs_dc").val()); if(path.substring(0,1)!="/") path = "/" + path; - url = vmfsURL(server, path); + path += "/" + trim($thisDialog.find("#add_pool_vmfs_ds").val()) + url = vmfsURL("dummy", path); } else { var iqn = trim($thisDialog.find("#add_pool_iqn").val()); if(iqn.substring(0,1)!="/") diff --git a/ui/scripts/cloud.core.zone.js b/ui/scripts/cloud.core.zone.js index e55be6c4ae2..f88a854f7c9 100644 --- a/ui/scripts/cloud.core.zone.js +++ b/ui/scripts/cloud.core.zone.js @@ -1360,6 +1360,7 @@ function bindAddPrimaryStorageButtonOnZonePage($button, zoneId, zoneName) { bindEventHandlerToDialogAddPool($dialogAddPool); var $podSelect = $dialogAddPool.find("#pod_dropdown"); + var mapClusters = {}; $podSelect.bind("change", function(event) { var podId = $(this).val(); @@ -1369,11 +1370,19 @@ function bindAddPrimaryStorageButtonOnZonePage($button, zoneId, zoneName) { $.ajax({ data: createURL("command=listClusters&podid=" + podId), dataType: "json", + async: false, success: function(json) { var items = json.listclustersresponse.cluster; - if(items != null && items.length > 0) { - for(var i=0; i" + fromdb(items[i].name) + ""); + if(items != null && items.length > 0) { + mapClusters = {}; + for(var i=0; i" + fromdb(items[i].name) + ""); + } + + if(!$clusterSelect.val()) + $("option", $clusterSelect)[0].attr("selected", "selected"); + $dialogAddPool.find("input[value=existing_cluster_radio]").attr("checked", true); } else { @@ -1382,7 +1391,33 @@ function bindAddPrimaryStorageButtonOnZonePage($button, zoneId, zoneName) { } } }); - }); + }); + + $("#cluster_select", $dialogAddPool).change(function() { + + var curOption = $(this).val(); + if(!curOption) + return false; + + var $protocolSelector = $("#add_pool_protocol", $dialogAddPool); + var objCluster = mapClusters['cluster_'+curOption]; + + if(objCluster.hypervisortype == "KVM") { + $protocolSelector.empty(); + $protocolSelector.append(''); + } else if(objCluster.hypervisortype == "XenServer") { + $protocolSelector.empty(); + $protocolSelector.append(''); + $protocolSelector.append(''); + } else if(objCluster.hypervisortype == "VmWare") { + $protocolSelector.empty(); + $protocolSelector.append(''); + $protocolSelector.append(''); + } + + $protocolSelector.change(); + }).change(); + $button.unbind("click").bind("click", function(event) { $dialogAddPool.find("#zone_name").text(zoneName); @@ -1417,11 +1452,14 @@ function bindAddPrimaryStorageButtonOnZonePage($button, zoneId, zoneName) { isValid &= validateDropDownBox("Cluster", $thisDialog.find("#cluster_select"), $thisDialog.find("#cluster_select_errormsg"), false); //required, reset error text isValid &= validateString("Name", $thisDialog.find("#add_pool_name"), $thisDialog.find("#add_pool_name_errormsg")); isValid &= validateString("Server", $thisDialog.find("#add_pool_nfs_server"), $thisDialog.find("#add_pool_nfs_server_errormsg")); - if (protocol == "nfs" || protocol == "vmfs") { + if (protocol == "nfs") { isValid &= validateString("Path", $thisDialog.find("#add_pool_path"), $thisDialog.find("#add_pool_path_errormsg")); - } else { - isValid &= validateString("Target IQN", $thisDialog.find("#add_pool_iqn"), $thisDialog.find("#add_pool_iqn_errormsg")); - isValid &= validateString("LUN #", $thisDialog.find("#add_pool_lun"), $thisDialog.find("#add_pool_lun_errormsg")); + } else if(protocol == "iscsi") { + isValid &= validateString("Target IQN", $thisDialog.find("#add_pool_iqn"), $thisDialog.find("#add_pool_iqn_errormsg")); + isValid &= validateString("LUN #", $thisDialog.find("#add_pool_lun"), $thisDialog.find("#add_pool_lun_errormsg")); + } else if(protocol == "vmfs") { + isValid &= validateString("vCenter Datacenter", $thisDialog.find("#add_pool_vmfs_dc"), $thisDialog.find("#add_pool_vmfs_dc_errormsg")); + isValid &= validateString("vCenter Datastore", $thisDialog.find("#add_pool_vmfs_ds"), $thisDialog.find("#add_pool_vmfs_ds_errormsg")); } isValid &= validateString("Tags", $thisDialog.find("#add_pool_tags"), $thisDialog.find("#add_pool_tags_errormsg"), true); //optional if (!isValid) @@ -1456,10 +1494,11 @@ function bindAddPrimaryStorageButtonOnZonePage($button, zoneId, zoneName) { path = "/" + path; url = nfsURL(server, path); } else if (protocol == "vmfs") { - var path = trim($thisDialog.find("#add_pool_path").val()); + var path = trim($thisDialog.find("#add_pool_vmfs_dc").val()); if(path.substring(0,1)!="/") path = "/" + path; - url = vmfsURL(server, path); + path += "/" + trim($thisDialog.find("#add_pool_vmfs_ds").val()) + url = vmfsURL("dummy", path); } else { var iqn = trim($thisDialog.find("#add_pool_iqn").val()); if(iqn.substring(0,1)!="/")