' +
- '
' +
+ '
' +
'
' +
+ '
'+
+ '
'+
'
' +
+ '
'+
+ '
'+
'
'+
'
'+
'
'+
@@ -1064,67 +1073,186 @@ function setupCreateHostDialog(){
$(".cluster_name", row).data("cluster_name", cluster_name)
$(".cluster_name", row).data("datacenter_name", datacenter_name)
$(".cluster_name", row).on("change", function(){
- var path = '/vcenter/' + $(this).data("datacenter_name") + '/cluster/' + $(this).data("cluster_name");
- var templates_container = $(".vcenter_templates", $(this).closest(".vcenter_cluster"))
- templates_container.html(generateAdvancedSection({
- html_id: path,
- title: tr("Templates"),
- content: '
'+
- ''+
- ''+
- ''
- }))
+ var templates_container = $(".vcenter_templates", $(this).closest(".vcenter_cluster"));
+ if ($(this).is(":checked")) {
+ var path = '/vcenter/' + $(this).data("datacenter_name") + '/cluster/' + $(this).data("cluster_name");
+ templates_container.html(generateAdvancedSection({
+ html_id: path,
+ title: tr("Templates"),
+ content: '
'+
+ ''+
+ ''+
+ ''
+ }))
- $('a', templates_container).trigger("click")
+ $('a', templates_container).trigger("click")
- $.ajax({
- url: path,
- type: "GET",
- //data: {timeout: timeout},
- dataType: "json",
- headers: {
- "X_VCENTER_USER": $("#vcenter_user", $create_host_dialog).val(),
- "X_VCENTER_PASSWORD": $("#vcenter_password", $create_host_dialog).val(),
- "X_VCENTER_HOST": $("#vcenter_host", $create_host_dialog).val()
- },
- success: function(response){
- $(".content", templates_container).html("");
- console.log(response);
- $.each(response, function(id, template){
- var trow = $('
' +
- '
' +
- '
' +
- '' +
- '
' +
- '
'+
- '
'+
- '
'+
- '
').appendTo($(".content", templates_container))
+ $.ajax({
+ url: path,
+ type: "GET",
+ data: {timeout: false},
+ dataType: "json",
+ headers: {
+ "X_VCENTER_USER": $("#vcenter_user", $create_host_dialog).val(),
+ "X_VCENTER_PASSWORD": $("#vcenter_password", $create_host_dialog).val(),
+ "X_VCENTER_HOST": $("#vcenter_host", $create_host_dialog).val()
+ },
+ success: function(response){
+ $(".content", templates_container).html("");
+ console.log(response);
+ $.each(response, function(id, template){
+ var trow = $('
' +
+ '
' +
+ '
' +
+ '
' +
+ '
'+
+ '
'+
+ '
' +
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
').appendTo($(".content", templates_container))
- $(".template_name", trow).data("template_name", template.name)
- $(".template_name", trow).data("one_template", template.one)
- });
- },
- error: function(response){
+ $(".template_name", trow).data("template_name", template.name)
+ $(".template_name", trow).data("one_template", template.one)
+ });
+ },
+ error: function(response){
+ templates_container.html("");
onError({}, OpenNebula.Error(response));
- }
- });
+ }
+ });
+ } else {
+ templates_container.html("");
+ }
})
});
}
});
},
error: function(response){
- onError({}, OpenNebula.Error(response));
+ $(".vcenter_clusters", $create_host_dialog).html('')
+ onError({}, OpenNebula.Error(response));
}
});
return false;
})
+
+ $("#import_vcenter_clusters", $create_host_dialog).on("click", function(){
+ $(this).hide();
+
+ var cluster_id = $('#host_cluster_id .resource_list_select', $create_host_dialog).val();
+ if (!cluster_id) cluster_id = "-1";
+
+ $.each($(".cluster_name:checked", $create_host_dialog), function(){
+ console.log($(this).data("cluster_name"));
+
+ var context = $(this).closest(".vcenter_cluster");
+ $(".vcenter_host_result:not(.success)", context).html('
'+
+ ''+
+ ''+
+ '');
+
+ var host_json = {
+ "host": {
+ "name": $(this).data("cluster_name"),
+ "vm_mad": "vcenter",
+ "vnm_mad": "dummy",
+ "im_mad": "vcenter",
+ "cluster_id": cluster_id
+ }
+ };
+
+ OpenNebula.Host.create({
+ timeout: true,
+ data: host_json,
+ success: function (cluster_context){
+ return function(request, response) {
+ $(".vcenter_host_result", cluster_context).addClass("success").html(
+ '
'+
+ ''+
+ ''+
+ '');
+
+ $(".vcenter_host_response", cluster_context).html('
'+
+ tr("Host created successfully")+' ID:'+response.HOST.ID+
+ '
');
+
+ var template_raw =
+ "VCENTER_USER=\"" + $("#vcenter_user", $create_host_dialog).val() + "\"\n" +
+ "VCENTER_PASSWORD=\"" + $("#vcenter_password", $create_host_dialog).val() + "\"\n" +
+ "VCENTER_HOST=\"" + $("#vcenter_host", $create_host_dialog).val() + "\"\n";
+
+ Sunstone.runAction("Host.update_template", response.HOST.ID, template_raw);
+
+ $.each($(".template_name:checked", cluster_context), function(){
+ console.log($(this).data("one_template"));
+
+ var template_context = $(this).closest(".vcenter_template");
+
+ $(".vcenter_template_result:not(.success)", template_context).html(
+ '
'+
+ ''+
+ ''+
+ '');
+
+ var template_json = {
+ "vmtemplate": {
+ "template_raw": $(this).data("one_template")
+ }
+ };
+
+ OpenNebula.Template.create({
+ timeout: true,
+ data: template_json,
+ success: function(request, response) {
+ $(".vcenter_template_result", template_context).addClass("success").html(
+ '
'+
+ ''+
+ ''+
+ '');
+
+ $(".vcenter_template_response", template_context).html('
'+
+ tr("Template created successfully")+' ID:'+response.VMTEMPLATE.ID+
+ '
');
+ },
+ error: function (request, error_json){
+ $(".vcenter_template_result", template_context).html('
'+
+ ''+
+ ''+
+ '');
+
+ $(".vcenter_template_response", template_context).html('
'+
+ (error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+
+ '
');
+ }
+ });
+ })
+ };
+ }(context),
+ error: function (request, error_json){
+ $(".vcenter_host_result", context).html('
'+
+ ''+
+ ''+
+ '');
+
+ $(".vcenter_host_response", context).html('
'+
+ (error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+
+ '
');
+ }
+ });
+ })
+
+ return false
+ });
+
// Show custom driver input only when custom is selected in selects
$('input[name="custom_vmm_mad"],'+
'input[name="custom_im_mad"],'+