mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-23 22:50:09 +03:00
* B #5286: import wilds works with known networks * B #5286: New AR is created when existing network detected * B #5286: imported vms with existing networks chooses their own AR
This commit is contained in:
parent
36cb9acb33
commit
773a4cb29b
@ -441,7 +441,8 @@ class DatacenterFolder
|
||||
"TEMPLATE/VCENTER_NET_REF",
|
||||
network_ref,
|
||||
vcenter_uuid,
|
||||
npool)
|
||||
npool,
|
||||
false)
|
||||
next if one_network #If the network has been already imported
|
||||
|
||||
one_vnet = VCenterDriver::Network.to_one_template(network_name,
|
||||
|
@ -71,14 +71,31 @@ class VIHelper
|
||||
hash
|
||||
end
|
||||
|
||||
def self.find_by_ref(the_class, attribute, ref, vcenter_uuid, pool = nil)
|
||||
def self.clean_ref_hash(attr = nil)
|
||||
if attr.nil?
|
||||
@ref_hash = {}
|
||||
else
|
||||
@ref_hash[attr] = {}
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_by_ref(the_class, attribute, ref, vcenter_uuid, pool = nil, one_managed = nil)
|
||||
one_managed = one_managed.nil? || one_managed
|
||||
pool = one_pool(the_class, false) if pool.nil?
|
||||
@ref_hash ||= {}
|
||||
@ref_hash[attribute] ||= create_ref_hash(attribute, pool)
|
||||
|
||||
e = @ref_hash[attribute][ref]
|
||||
|
||||
if e && (!e[:opennebula_managed] || e[:opennebula_managed] != "NO") &&
|
||||
return nil if e.nil?
|
||||
|
||||
if one_managed
|
||||
one_managed_test = (!e[:opennebula_managed] || e[:opennebula_managed] != "NO")
|
||||
else
|
||||
one_managed_test = (!e[:opennebula_managed] || e[:opennebula_managed] != "YES")
|
||||
end
|
||||
|
||||
if one_managed_test &&
|
||||
(e[:tvcenter_instance_id] == vcenter_uuid ||
|
||||
e[:uvcenter_instance_id] == vcenter_uuid)
|
||||
return e[:opennebula_object]
|
||||
|
@ -368,23 +368,33 @@ class Template
|
||||
|
||||
vc_nics.each do |nic|
|
||||
# Check if the network already exists
|
||||
if wild
|
||||
network_found = false
|
||||
else
|
||||
network_found = VCenterDriver::VIHelper.find_by_ref(OpenNebula::VirtualNetworkPool,
|
||||
"TEMPLATE/VCENTER_NET_REF",
|
||||
nic[:net_ref],
|
||||
vc_uuid,
|
||||
npool)
|
||||
end
|
||||
network_found = VCenterDriver::VIHelper.find_by_ref(OpenNebula::VirtualNetworkPool,
|
||||
"TEMPLATE/VCENTER_NET_REF",
|
||||
nic[:net_ref],
|
||||
vc_uuid,
|
||||
npool, false)
|
||||
|
||||
#Network is already in OpenNebula
|
||||
if network_found
|
||||
|
||||
# Create the new size 1 AR
|
||||
ar_tmp = ""
|
||||
ar_tmp << "AR=[\n"
|
||||
ar_tmp << "TYPE=\"ETHER\",\n"
|
||||
if wild && nic[:mac]
|
||||
ar_tmp << "MAC=\"#{nic[:mac]}\",\n"
|
||||
ar_tmp << "SIZE=\"1\"\n"
|
||||
else
|
||||
ar_tmp << "SIZE=\"255\"\n"
|
||||
end
|
||||
ar_tmp << "]\n"
|
||||
network_found.add_ar(ar_tmp)
|
||||
|
||||
# This is the existing nic info
|
||||
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"
|
||||
|
||||
@ -472,6 +482,7 @@ class Template
|
||||
# Allocate the Virtual Network
|
||||
allocated_networks << one_vn
|
||||
rc = one_vn.allocate(one_vnet[:one], cluster_id.to_i)
|
||||
VCenterDriver::VIHelper.clean_ref_hash()
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
error = "\n ERROR: Could not allocate virtual network due to #{rc.message}\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user