mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-27 13:57:23 +03:00
* Added rollback for ARs when fails importation process * Fix feature when import wild vm form vcenter
This commit is contained in:
parent
c4dc65f994
commit
adb08d9ec4
@ -40,7 +40,7 @@ def self.import_wild(host_id, vm_ref, one_vm, template)
|
||||
template << template_disks
|
||||
|
||||
# Create images or get nics information for template
|
||||
error, template_nics = vcenter_vm.import_vcenter_nics(vc_uuid,
|
||||
error, template_nics, ar_ids = vcenter_vm.import_vcenter_nics(vc_uuid,
|
||||
npool,
|
||||
hpool,
|
||||
vc_name,
|
||||
@ -49,7 +49,17 @@ def self.import_wild(host_id, vm_ref, one_vm, template)
|
||||
sunstone,
|
||||
vm_name)
|
||||
|
||||
return OpenNebula::Error.new(error) if !error.empty?
|
||||
if !error.empty?
|
||||
if !ar_ids.nil?
|
||||
ar_ids.each do |key, value|
|
||||
network = VCenterDriver::VIHelper.find_by_ref(OpenNebula::VirtualNetworkPool,"TEMPLATE/VCENTER_NET_REF", key, vc_uuid, npool)
|
||||
value.each do |ar|
|
||||
network.rm_ar(ar)
|
||||
end
|
||||
end
|
||||
end
|
||||
return OpenNebula::Error.new(error) if !error.empty?
|
||||
end
|
||||
|
||||
template << template_nics
|
||||
|
||||
@ -64,13 +74,43 @@ def self.import_wild(host_id, vm_ref, one_vm, template)
|
||||
e["TEMPLATE/VCENTER_INSTANCE_ID"] == vc_uuid
|
||||
end.first
|
||||
|
||||
return OpenNebula::Error.new("DS with ref #{ds_ref} is not imported in OpenNebula, aborting Wild VM import.") if !ds_one
|
||||
if !ds_one
|
||||
if !ar_ids.nil?
|
||||
ar_ids.each do |key, value|
|
||||
network = VCenterDriver::VIHelper.find_by_ref(OpenNebula::VirtualNetworkPool,"TEMPLATE/VCENTER_NET_REF", key, vc_uuid, npool)
|
||||
value.each do |ar|
|
||||
network.rm_ar(ar)
|
||||
end
|
||||
end
|
||||
end
|
||||
return OpenNebula::Error.new("DS with ref #{ds_ref} is not imported in OpenNebula, aborting Wild VM import.")
|
||||
end
|
||||
|
||||
rc = one_vm.allocate(template)
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
if OpenNebula.is_error?(rc)
|
||||
if !ar_ids.nil?
|
||||
ar_ids.each do |key, value|
|
||||
network = VCenterDriver::VIHelper.find_by_ref(OpenNebula::VirtualNetworkPool,"TEMPLATE/VCENTER_NET_REF", key, vc_uuid, npool)
|
||||
value.each do |ar|
|
||||
network.rm_ar(ar)
|
||||
end
|
||||
end
|
||||
end
|
||||
return rc
|
||||
end
|
||||
|
||||
rc = one_vm.deploy(host_id, false, ds_one.id)
|
||||
return rc if OpenNebula.is_error?(rc)
|
||||
if OpenNebula.is_error?(rc)
|
||||
if !ar_ids.nil?
|
||||
ar_ids.each do |key, value|
|
||||
network = VCenterDriver::VIHelper.find_by_ref(OpenNebula::VirtualNetworkPool,"TEMPLATE/VCENTER_NET_REF", key, vc_uuid, npool)
|
||||
value.each do |ar|
|
||||
network.rm_ar(ar)
|
||||
end
|
||||
end
|
||||
end
|
||||
return rc
|
||||
end
|
||||
|
||||
# Set reference to template disks and nics in VM template
|
||||
vcenter_vm.one_item = one_vm
|
||||
|
@ -356,7 +356,7 @@ class Template
|
||||
nic_info = ""
|
||||
error = ""
|
||||
sunstone_nic_info = []
|
||||
|
||||
ar_ids = {}
|
||||
begin
|
||||
lock #Lock import operation, to avoid concurrent creation of networks
|
||||
|
||||
@ -389,7 +389,6 @@ class Template
|
||||
#Network is already in OpenNebula
|
||||
if network_found
|
||||
|
||||
# Create the new size 1 AR
|
||||
ar_tmp = ""
|
||||
if wild
|
||||
if nic[:mac] && nic[:ipv4] && nic[:ipv6]
|
||||
@ -425,14 +424,28 @@ class Template
|
||||
end
|
||||
network_found.add_ar(ar_tmp)
|
||||
network_found.info
|
||||
last_id = network_found.to_hash["VNET"]["AR_POOL"]["AR"].last["AR_ID"]
|
||||
value = []
|
||||
arsNew = network_found.to_hash["VNET"]["AR_POOL"]["AR"]
|
||||
arsNew = [arsNew] if arsNew.class.to_s.eql? "Hash"
|
||||
last_id = arsNew.last["AR_ID"]
|
||||
if ar_ids.has_key?(nic[:net_ref])
|
||||
ref = nic[:net_ref]
|
||||
value = ar_ids[ref.to_s]
|
||||
value.insert(value.length, arsNew.last["AR_ID"])
|
||||
ar_ids.store(nic[:net_ref], value)
|
||||
else
|
||||
value.insert(value.length , arsNew.last["AR_ID"])
|
||||
ar_ids.store(nic[:net_ref], [arsNew.last["AR_ID"]])
|
||||
end
|
||||
arsNew.clear
|
||||
arsNew = nil
|
||||
|
||||
# This is the existing nic info
|
||||
nic_tmp = ""
|
||||
nic_tmp << "NIC=[\n"
|
||||
nic_tmp << "AR_ID=\"#{last_id}\",\n"
|
||||
nic_tmp << "NETWORK_ID=\"#{network_found["ID"]}\",\n"
|
||||
nic_tmp << "MAC=\"#{nic[:mac]}\",\n" if nic[:mac]
|
||||
nic_tmp << "VCENTER_IP=\"#{nic[:ipv4]}\",\n" if nic[:ipv4]
|
||||
nic_tmp << "VCENTER_ADDITIONALS_IP4=\"#{nic[:ipv4_additionals]}\",\n" if nic[:ipv4_additionals]
|
||||
nic_tmp << "VCENTER_IP6=\"#{nic[:ipv6]}\",\n" if nic[:ipv6]
|
||||
nic_tmp << "IP6_GLOBAL=\"#{nic[:ipv6_global]}\",\n" if nic[:ipv6_global]
|
||||
@ -441,16 +454,16 @@ class Template
|
||||
nic_tmp << "OPENNEBULA_MANAGED=\"NO\"\n"
|
||||
nic_tmp << "]\n"
|
||||
else
|
||||
ar_tmp << "AR=[\n"
|
||||
ar_tmp << "SIZE=\"255\"\n"
|
||||
ar_tmp << "]\n"
|
||||
network_found.add_ar(ar_tmp)
|
||||
nic_tmp = ""
|
||||
nic_tmp << "NIC=[\n"
|
||||
nic_tmp << "NETWORK_ID=\"#{network_found["ID"]}\",\n"
|
||||
nic_tmp << "MAC=\"#{nic[:mac]}\",\n" if wild && nic[:mac]
|
||||
nic_tmp << "OPENNEBULA_MANAGED=\"NO\"\n"
|
||||
nic_tmp << "]\n"
|
||||
ar_tmp << "AR=[\n"
|
||||
ar_tmp << "SIZE=\"255\"\n"
|
||||
ar_tmp << "]\n"
|
||||
network_found.add_ar(ar_tmp)
|
||||
nic_tmp = ""
|
||||
nic_tmp << "NIC=[\n"
|
||||
nic_tmp << "NETWORK_ID=\"#{network_found["ID"]}\",\n"
|
||||
nic_tmp << "MAC=\"#{nic[:mac]}\",\n" if nic[:mac]
|
||||
nic_tmp << "OPENNEBULA_MANAGED=\"NO\"\n"
|
||||
nic_tmp << "]\n"
|
||||
end
|
||||
if sunstone
|
||||
sunstone_nic = {}
|
||||
@ -654,52 +667,55 @@ class Template
|
||||
h.parent._ref if h.parent
|
||||
end
|
||||
if wild
|
||||
ipAddresses = @item["guest.net"][num_device].ipConfig.ipAddress
|
||||
if !ipAddresses.empty?
|
||||
nic[:ipv4], nic[:ipv4_additionals] = nil
|
||||
nic[:ipv6], nic[:ipv6_ula], nic[:ipv6_global], nic[:ipv6_additionals] = nil
|
||||
index = 0
|
||||
while index < ipAddresses.length
|
||||
ip = ipAddresses[index].ipAddress
|
||||
if ip =~ Resolv::IPv4::Regex
|
||||
if nic[:ipv4]
|
||||
if nic[:ipv4_additionals]
|
||||
nic[:ipv4_additionals] += ',' + ip
|
||||
else
|
||||
nic[:ipv4_additionals] = ip
|
||||
end
|
||||
else
|
||||
nic[:ipv4] = ip
|
||||
end
|
||||
elsif ipAddresses[index].ipAddress =~ Resolv::IPv6::Regex
|
||||
if get_ipv6_prefix(ip, 3) == "2000"
|
||||
if nic[:ipv6_global]
|
||||
if nic[:ipv6_additionals]
|
||||
nic[:ipv6_additionals] += ',' + ip
|
||||
if !@item["guest.net"].empty?
|
||||
ipAddresses = @item["guest.net"][num_device].ipConfig.ipAddress
|
||||
if !ipAddresses.nil? && !ipAddresses.empty?
|
||||
nic[:ipv4], nic[:ipv4_additionals] = nil
|
||||
nic[:ipv6], nic[:ipv6_ula], nic[:ipv6_global], nic[:ipv6_additionals] = nil
|
||||
index = 0
|
||||
while index < ipAddresses.length
|
||||
ip = ipAddresses[index].ipAddress
|
||||
if ip =~ Resolv::IPv4::Regex
|
||||
if nic[:ipv4]
|
||||
if nic[:ipv4_additionals]
|
||||
nic[:ipv4_additionals] += ',' + ip
|
||||
else
|
||||
nic[:ipv6_additionals] = ip
|
||||
nic[:ipv4_additionals] = ip
|
||||
end
|
||||
else
|
||||
nic[:ipv6_global] = ip
|
||||
nic[:ipv4] = ip
|
||||
end
|
||||
elsif get_ipv6_prefix(ip, 10) == "fe80"
|
||||
nic[:ipv6] = ip
|
||||
elsif get_ipv6_prefix(ip, 7) == "fc00"
|
||||
if nic[:ipv6_ula]
|
||||
if nic[:ipv6_additionals]
|
||||
nic[:ipv6_additionals] += ',' + ip
|
||||
else
|
||||
nic[:ipv6_additionals] = ip
|
||||
elsif ipAddresses[index].ipAddress =~ Resolv::IPv6::Regex
|
||||
if get_ipv6_prefix(ip, 3) == "2000"
|
||||
if nic[:ipv6_global]
|
||||
if nic[:ipv6_additionals]
|
||||
nic[:ipv6_additionals] += ',' + ip
|
||||
else
|
||||
nic[:ipv6_additionals] = ip
|
||||
end
|
||||
else
|
||||
nic[:ipv6_global] = ip
|
||||
end
|
||||
elsif get_ipv6_prefix(ip, 10) == "fe80"
|
||||
nic[:ipv6] = ip
|
||||
elsif get_ipv6_prefix(ip, 7) == "fc00"
|
||||
if nic[:ipv6_ula]
|
||||
if nic[:ipv6_additionals]
|
||||
nic[:ipv6_additionals] += ',' + ip
|
||||
else
|
||||
nic[:ipv6_additionals] = ip
|
||||
end
|
||||
else
|
||||
nic[:ipv6_ula] = ip
|
||||
end
|
||||
else
|
||||
nic[:ipv6_ula] = ip
|
||||
end
|
||||
end
|
||||
index += 1
|
||||
end
|
||||
index += 1
|
||||
end
|
||||
nic[:mac] = @item["guest.net"][num_device].macAddress rescue nil
|
||||
num_device += 1
|
||||
end
|
||||
nic[:mac] = @item["guest.net"][num_device].macAddress rescue nil
|
||||
else
|
||||
nic[:mac] = device.macAddress rescue nil
|
||||
end
|
||||
@ -708,7 +724,6 @@ class Template
|
||||
nic[:pg_type] = VCenterDriver::Network.get_network_type(device)
|
||||
|
||||
nics << nic
|
||||
num_device += 1
|
||||
end
|
||||
end
|
||||
return nics
|
||||
|
Loading…
x
Reference in New Issue
Block a user