(1) When hypervisor.type is kvm, allow option to add host in UI.

(2) When when hypervisor.type is kvm, hide cluster section in add host dialog.
This commit is contained in:
Jessica Wang 2010-08-13 18:12:50 -07:00
parent 7cf14dcffa
commit 66ccd6f7ad
2 changed files with 165 additions and 161 deletions

View File

@ -277,10 +277,10 @@
<input class="text" type="password" name="host_password" id="host_password" AUTOCOMPLETE="off" /> <input class="text" type="password" name="host_password" id="host_password" AUTOCOMPLETE="off" />
<div id="host_password_errormsg" class="dialog_formcontent_errormsg" style="display:none;" ></div> <div id="host_password_errormsg" class="dialog_formcontent_errormsg" style="display:none;" ></div>
</li> </li>
<li> <li id="cluster_options_container">
<label>&nbsp;</label><span><u>Cluster Options</u></span> <label>&nbsp;</label><span><u>Cluster Options</u></span>
</li> </li>
<li> <li id="new_cluster_radio_container">
<label><input type="radio" name="cluster" value="new_cluster_radio" checked />&nbsp;New cluster:</label> <label><input type="radio" name="cluster" value="new_cluster_radio" checked />&nbsp;New cluster:</label>
<input class="text" type="text" id="new_cluster_name"/> <input class="text" type="text" id="new_cluster_name"/>
<div id="new_cluster_name_errormsg" class="dialog_formcontent_errormsg" style="display:none;" ></div> <div id="new_cluster_name_errormsg" class="dialog_formcontent_errormsg" style="display:none;" ></div>

View File

@ -23,73 +23,76 @@ function showHostsTab() {
var sIndex = 0; var sIndex = 0;
var pIndex = 0; var pIndex = 0;
// Dialog Setup // Dialog Setup
if (getHypervisorType() != "kvm") { //"xenserver" $("#host_action_new_routing").show();
$("#host_action_new_routing").show(); activateDialog($("#dialog_add_routing").dialog({
activateDialog($("#dialog_add_routing").dialog({ autoOpen: false,
autoOpen: false, modal: true,
modal: true, zIndex: 2000
zIndex: 2000 }));
}));
var dialogAddRouting = $("#dialog_add_routing");
var dialogAddRouting = $("#dialog_add_routing");
//xenserver supports cluster. kvm doesn't support cluster.
if (getHypervisorType() == "kvm")
dialogAddRouting.find("#cluster_options_container, #new_cluster_radio_container, #existing_cluster_radio_container, #no_cluster_radio_container").hide();
$.ajax({
data: createURL("command=listZones&available=true&response=json"+maxPageSize),
dataType: "json",
success: function(json) {
var zones = json.listzonesresponse.zone;
var zoneSelect = dialogAddRouting.find("#host_zone").empty();
if (zones != null && zones.length > 0) {
for (var i = 0; i < zones.length; i++)
zoneSelect.append("<option value='" + zones[i].id + "'>" + sanitizeXSS(zones[i].name) + "</option>");
}
//dialogAddRouting.find("#host_zone").change();
}
});
dialogAddRouting.find("#host_zone").bind("change", function(event) {
var zoneId = $(this).val();
$.ajax({ $.ajax({
data: createURL("command=listZones&available=true&response=json"+maxPageSize), data: createURL("command=listPods&zoneId="+zoneId+"&response=json"+maxPageSize),
dataType: "json", dataType: "json",
async: false,
success: function(json) { success: function(json) {
var zones = json.listzonesresponse.zone; var pods = json.listpodsresponse.pod;
var zoneSelect = dialogAddRouting.find("#host_zone").empty(); var podSelect = dialogAddRouting.find("#host_pod").empty();
if (zones != null && zones.length > 0) { if (pods != null && pods.length > 0) {
for (var i = 0; i < zones.length; i++) for (var i = 0; i < pods.length; i++) {
zoneSelect.append("<option value='" + zones[i].id + "'>" + sanitizeXSS(zones[i].name) + "</option>"); podSelect.append("<option value='" + pods[i].id + "'>" + sanitizeXSS(pods[i].name) + "</option>");
}
} }
//dialogAddRouting.find("#host_zone").change(); dialogAddRouting.find("#host_pod").change();
} }
}); });
});
dialogAddRouting.find("#host_zone").bind("change", function(event) {
var zoneId = $(this).val(); dialogAddRouting.find("#host_pod").bind("change", function(event) {
$.ajax({ var podId = $(this).val();
data: createURL("command=listPods&zoneId="+zoneId+"&response=json"+maxPageSize), if(podId == null || podId.length == 0)
dataType: "json", return;
async: false, var clusterSelect = dialogAddRouting.find("#cluster_select").empty();
success: function(json) { $.ajax({
var pods = json.listpodsresponse.pod; data: createURL("command=listClusters&response=json&podid=" + podId+maxPageSize),
var podSelect = dialogAddRouting.find("#host_pod").empty(); dataType: "json",
if (pods != null && pods.length > 0) { success: function(json) {
for (var i = 0; i < pods.length; i++) { var items = json.listclustersresponse.cluster;
podSelect.append("<option value='" + pods[i].id + "'>" + sanitizeXSS(pods[i].name) + "</option>"); if(items != null && items.length > 0) {
} for(var i=0; i<items.length; i++)
} clusterSelect.append("<option value='" + items[i].id + "'>" + items[i].name + "</option>");
dialogAddRouting.find("#host_pod").change(); dialogAddRouting.find("input[value=existing_cluster_radio]").attr("checked", true);
} }
}); else {
}); clusterSelect.append("<option value='-1'>None Available</option>");
dialogAddRouting.find("input[value=new_cluster_radio]").attr("checked", true);
dialogAddRouting.find("#host_pod").bind("change", function(event) { }
var podId = $(this).val(); }
if(podId == null || podId.length == 0) });
return; });
var clusterSelect = dialogAddRouting.find("#cluster_select").empty();
$.ajax({
data: createURL("command=listClusters&response=json&podid=" + podId+maxPageSize),
dataType: "json",
success: function(json) {
var items = json.listclustersresponse.cluster;
if(items != null && items.length > 0) {
for(var i=0; i<items.length; i++)
clusterSelect.append("<option value='" + items[i].id + "'>" + items[i].name + "</option>");
dialogAddRouting.find("input[value=existing_cluster_radio]").attr("checked", true);
}
else {
clusterSelect.append("<option value='-1'>None Available</option>");
dialogAddRouting.find("input[value=new_cluster_radio]").attr("checked", true);
}
}
});
});
}
activateDialog($("#dialog_update_os").dialog({ activateDialog($("#dialog_update_os").dialog({
autoOpen: false, autoOpen: false,
modal: true, modal: true,
@ -575,105 +578,106 @@ function showHostsTab() {
var submenuContent = $("#submenu_content_routing"); var submenuContent = $("#submenu_content_routing");
// Add New Routing Host // Add New Routing Host
if (getHypervisorType() != "kvm") { $("#host_action_new_routing").bind("click", function(event) {
$("#host_action_new_routing").bind("click", function(event) { dialogAddRouting.find("#new_cluster_name").val("");
dialogAddRouting.find("#new_cluster_name").val(""); dialogAddRouting.find("#host_zone").change(); //refresh cluster dropdown
dialogAddRouting.find("#host_zone").change(); //refresh cluster dropdown
dialogAddRouting
dialogAddRouting .dialog('option', 'buttons', {
.dialog('option', 'buttons', { "Add": function() {
"Add": function() { var dialogBox = $(this);
var dialogBox = $(this); var clusterRadio = dialogBox.find("input[name=cluster]:checked").val();
var clusterRadio = dialogBox.find("input[name=cluster]:checked").val();
// validate values
var isValid = true;
isValid &= validateString("Host name", dialogBox.find("#host_hostname"), dialogBox.find("#host_hostname_errormsg"));
isValid &= validateString("User name", dialogBox.find("#host_username"), dialogBox.find("#host_username_errormsg"));
isValid &= validateString("Password", dialogBox.find("#host_password"), dialogBox.find("#host_password_errormsg"));
if(clusterRadio == "new_cluster_radio")
isValid &= validateString("Cluster name", dialogBox.find("#new_cluster_name"), dialogBox.find("#new_cluster_name_errormsg"));
if (!isValid) return;
// validate values var array1 = [];
var isValid = true;
isValid &= validateString("Host name", dialogBox.find("#host_hostname"), dialogBox.find("#host_hostname_errormsg")); var zoneId = dialogBox.find("#host_zone").val();
isValid &= validateString("User name", dialogBox.find("#host_username"), dialogBox.find("#host_username_errormsg")); array1.push("&zoneId="+zoneId);
isValid &= validateString("Password", dialogBox.find("#host_password"), dialogBox.find("#host_password_errormsg"));
if(clusterRadio == "new_cluster_radio") var podId = dialogBox.find("#host_pod").val();
isValid &= validateString("Cluster name", dialogBox.find("#new_cluster_name"), dialogBox.find("#new_cluster_name_errormsg")); array1.push("&podId="+podId);
if (!isValid) return;
var username = trim(dialogBox.find("#host_username").val());
var array1 = []; array1.push("&username="+encodeURIComponent(username));
var zoneId = dialogBox.find("#host_zone").val(); var password = trim(dialogBox.find("#host_password").val());
array1.push("&zoneId="+zoneId); array1.push("&password="+encodeURIComponent(password));
var podId = dialogBox.find("#host_pod").val(); //xenserver supports cluster. kvm doesn't support cluster.
array1.push("&podId="+podId); if (getHypervisorType() != "kvm") {
if(clusterRadio == "new_cluster_radio") {
var username = trim(dialogBox.find("#host_username").val()); var newClusterName = trim(dialogBox.find("#new_cluster_name").val());
array1.push("&username="+encodeURIComponent(username)); array1.push("&clustername="+encodeURIComponent(newClusterName));
}
var password = trim(dialogBox.find("#host_password").val()); else if(clusterRadio == "existing_cluster_radio") {
array1.push("&password="+encodeURIComponent(password)); var clusterId = dialogBox.find("#cluster_select").val();
// We will default to no cluster if someone selects Join Cluster with no cluster available.
if(clusterRadio == "new_cluster_radio") { if (clusterId != '-1') {
var newClusterName = trim(dialogBox.find("#new_cluster_name").val()); array1.push("&clusterid="+clusterId);
array1.push("&clustername="+encodeURIComponent(newClusterName)); }
} }
else if(clusterRadio == "existing_cluster_radio") { }
var clusterId = dialogBox.find("#cluster_select").val();
// We will default to no cluster if someone selects Join Cluster with no cluster available. var hostname = trim(dialogBox.find("#host_hostname").val());
if (clusterId != '-1') { var url;
array1.push("&clusterid="+clusterId); if(hostname.indexOf("http://")==-1)
} url = "http://" + hostname;
} else
url = hostname;
var hostname = trim(dialogBox.find("#host_hostname").val()); array1.push("&url="+encodeURIComponent(url));
var url;
if(hostname.indexOf("http://")==-1) var template = $("#routing_template").clone(true);
url = "http://" + hostname; var loadingImg = template.find(".adding_loading");
else var rowContainer = template.find("#row_container");
url = hostname; loadingImg.find(".adding_text").text("Adding....");
array1.push("&url="+encodeURIComponent(url)); loadingImg.show();
rowContainer.hide();
var template = $("#routing_template").clone(true); submenuContent.find("#grid_content").append(template.fadeIn("slow"));
var loadingImg = template.find(".adding_loading");
var rowContainer = template.find("#row_container"); dialogBox.dialog("close");
loadingImg.find(".adding_text").text("Adding...."); $.ajax({
loadingImg.show(); data: createURL("command=addHost&response=json" + array1.join("")),
rowContainer.hide(); dataType: "json",
submenuContent.find("#grid_content").append(template.fadeIn("slow")); success: function(json) {
var items = json.addhostresponse.host;
dialogBox.dialog("close"); routingJSONToTemplate(items[0], template);
$.ajax({ loadingImg.hide();
data: createURL("command=addHost&response=json" + array1.join("")), rowContainer.show();
dataType: "json", changeGridRowsTotal(submenuContent.find("#grid_rows_total"), 1);
success: function(json) {
var items = json.addhostresponse.host; if(items.length > 1) {
routingJSONToTemplate(items[0], template); for(var i=1; i<items.length; i++) {
loadingImg.hide(); var anotherNewTemplate = $("#routing_template").clone(true);
rowContainer.show(); routingJSONToTemplate(items[i], anotherNewTemplate);
changeGridRowsTotal(submenuContent.find("#grid_rows_total"), 1); submenuContent.find("#grid_content").append(anotherNewTemplate.fadeIn("slow"));
changeGridRowsTotal(submenuContent.find("#grid_rows_total"), 1);
if(items.length > 1) { }
for(var i=1; i<items.length; i++) { }
var anotherNewTemplate = $("#routing_template").clone(true);
routingJSONToTemplate(items[i], anotherNewTemplate); if(clusterRadio == "new_cluster_radio")
submenuContent.find("#grid_content").append(anotherNewTemplate.fadeIn("slow")); dialogBox.find("#new_cluster_name").val("");
changeGridRowsTotal(submenuContent.find("#grid_rows_total"), 1); },
} error: function(XMLHttpResponse) {
} handleError(XMLHttpResponse);
template.slideUp("slow", function(){ $(this).remove(); } );
if(clusterRadio == "new_cluster_radio") }
dialogBox.find("#new_cluster_name").val(""); });
}, },
error: function(XMLHttpResponse) { "Cancel": function() {
handleError(XMLHttpResponse); $(this).dialog("close");
template.slideUp("slow", function(){ $(this).remove(); } ); }
} }).dialog("open");
}); return false;
}, });
"Cancel": function() {
$(this).dialog("close");
}
}).dialog("open");
return false;
});
}
function listHosts() { function listHosts() {
var submenuContent = $("#submenu_content_routing"); var submenuContent = $("#submenu_content_routing");