diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js index a393b09ecf..6ffdbe1ff7 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js @@ -129,6 +129,7 @@ define(function(require) { var index = 0; var template = ""; var rollback = []; + var duplicated_nics = {}; function getNext() { @@ -200,7 +201,6 @@ define(function(require) { } if (disks_and_nets[index].type === "EXISTING_DISK") { - template += disks_and_nets[index].image_tmpl; ++index; getNext(); } @@ -222,6 +222,8 @@ define(function(require) { var network_id = response.VNET.ID; if (one_cluster_id != -1) { Sunstone.runAction("Cluster.addvnet",one_cluster_id,response.VNET.ID); + // Remove vnet from cluster default 0 + Sunstone.runAction("Cluster.delvnet",0,response.VNET.ID); } ++index; var rollback_info = { type: "NETWORK", id: network_id}; @@ -241,11 +243,14 @@ define(function(require) { } if (disks_and_nets[index].type == "EXISTING_NIC") { - template += disks_and_nets[index].network_tmpl; ++index; getNext(); } + if (disks_and_nets[index].type === "DUPLICATED_NIC") { + ++index; + getNext(); + } } } getNext(); diff --git a/src/sunstone/public/app/utils/vcenter/templates.js b/src/sunstone/public/app/utils/vcenter/templates.js index a8e90f0796..b3eded515e 100644 --- a/src/sunstone/public/app/utils/vcenter/templates.js +++ b/src/sunstone/public/app/utils/vcenter/templates.js @@ -245,6 +245,7 @@ define(function(require) { var index = 0; var template = ""; var rollback = []; + var duplicated_nics = {}; function getNext() { @@ -263,7 +264,7 @@ define(function(require) { } else { - if (disks_and_nets[index].type === "NEW_DISK") { + if (disks_and_nets[index].type === "NEW_DISK") { var image_json = { "image": { @@ -281,7 +282,6 @@ define(function(require) { ++index; template += "DISK=[\n"; template += "IMAGE_ID=\"" + image_id + "\",\n"; - template += "IMAGE_UNAME=\"" + image_uname + "\",\n"; template += "OPENNEBULA_MANAGED=\"NO\"\n"; template += "]\n"; @@ -326,12 +326,17 @@ define(function(require) { var network_id = response.VNET.ID; if (one_cluster_id != -1) { Sunstone.runAction("Cluster.addvnet",one_cluster_id,response.VNET.ID); + //Remove bnet from default datastore + Sunstone.runAction("Cluster.delvnet",0,response.VNET.ID); } + duplicated_nics[disks_and_nets[index].network_name]=network_id; + ++index; template += "NIC=[\n"; template += "NETWORK_ID=\"" + network_id + "\",\n"; template += "OPENNEBULA_MANAGED=\"NO\"\n"; template += "]\n"; + var rollback_info = { type: "NETWORK", id: network_id}; rollback.push(rollback_info); getNext(); @@ -354,6 +359,18 @@ define(function(require) { getNext(); } + if (disks_and_nets[index].type === "DUPLICATED_NIC") { + var network_id = duplicated_nics[disks_and_nets[index].network_name]; + + template += "NIC=[\n"; + template += "NETWORK_ID=\"" + network_id + "\",\n"; + template += "OPENNEBULA_MANAGED=\"NO\"\n"; + template += "]\n"; + ++index; + getNext(); + } + + } } getNext(); @@ -445,6 +462,24 @@ define(function(require) { message : OpenNebulaError(response).error.message }); Notifier.onError({}, OpenNebulaError(response)); + + // Remove template - Rollback + var path = '/vcenter/template_rollback/' + template_id; + $.ajax({ + url: path, + type: "POST", + data: {timeout: false}, + dataType: "json", + success: function(response){ + // Do nothing + }, + error: function(response){ + VCenterCommon.importFailure({ + context : row_context, + message : Locale.tr("Could not delete the template " + template_id + " due to " + OpenNebulaError(response).error.message + ". Please remote it manually before importing this template again.") + }); + } + }); } }); }, diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb index fbafd0d890..b7b40a3571 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb @@ -295,7 +295,6 @@ class Template one_i.info disk_info << "DISK=[\n" disk_info << "IMAGE_ID=\"#{one_i["ID"]}\",\n" - disk_info << "IMAGE_UNAME=\"#{one_i["UNAME"]}\",\n" disk_info << "OPENNEBULA_MANAGED=\"NO\"\n" disk_info << "]\n" end @@ -344,6 +343,9 @@ class Template # Track allocated networks for rollback allocated_networks = [] + # Track port groups duplicated in this VM + duplicated_networks = [] + vc_nics.each do |nic| # Check if the network already exists network_found = VCenterDriver::Network.get_unmanaged_vnet_by_ref(nic[:net_ref], @@ -423,11 +425,20 @@ class Template one_vnet[:one] << ar_str if sunstone - sunstone_nic = {} - sunstone_nic[:type] = "NEW_NIC" - sunstone_nic[:network_tmpl] = one_vnet[:one] - sunstone_nic[:one_cluster_id] = cluster_id.to_i - sunstone_nic_info << sunstone_nic + if !duplicated_networks.include?(nic[:net_name]) + sunstone_nic = {} + sunstone_nic[:type] = "NEW_NIC" + sunstone_nic[:network_name] = nic[:net_name] + sunstone_nic[:network_tmpl] = one_vnet[:one] + sunstone_nic[:one_cluster_id] = cluster_id.to_i + sunstone_nic_info << sunstone_nic + duplicated_networks << nic[:net_name] + else + sunstone_nic = {} + sunstone_nic[:type] = "DUPLICATED_NIC" + sunstone_nic[:network_name] = nic[:net_name] + sunstone_nic_info << sunstone_nic + end else # Allocate the Virtual Network allocated_networks << one_vn @@ -444,6 +455,9 @@ class Template nic_info << "NETWORK_ID=\"#{one_vn["ID"]}\",\n" nic_info << "OPENNEBULA_MANAGED=\"NO\"\n" nic_info << "]\n" + + # Refresh npool + npool.info_all end end end