mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
vCenter import templates and wild vms where two or more nics share the same port group
This commit is contained in:
parent
6d24617e57
commit
7b390cbc9a
@ -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();
|
||||
|
@ -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.")
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user