1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-25 23:21:29 +03:00

F #4386: Further refactor

This commit is contained in:
Tino Vazquez 2020-09-09 17:12:58 +02:00
parent 230c8441ca
commit 8a674b92ff
No known key found for this signature in database
GPG Key ID: 2FE9C32E94AEABBE

View File

@ -532,6 +532,11 @@ module VCenterDriver
nic_tmp nic_tmp
end end
# Creates an OpenNebula Virtual Network as part of the VM Template
# import process. This only need to happen if no VNET in OpenNebula
# is present that refers to the network where the NIC of the VM Template
# is hooked to.
def create_network_for_import( def create_network_for_import(
nic, nic,
ccr_ref, ccr_ref,
@ -546,14 +551,6 @@ module VCenterDriver
config = {} config = {}
config[:refs] = nic[:refs] config[:refs] = nic[:refs]
# # Then the network has to be created
# # as it's not in OpenNebula
# one_vn =
# VCenterDriver::VIHelper
# .new_one_item(
# OpenNebula::VirtualNetwork
# )
# Let's get the OpenNebula hosts ids # Let's get the OpenNebula hosts ids
# associated to the clusters references # associated to the clusters references
config[:one_ids] = nic[:refs].map do |ref| config[:one_ids] = nic[:refs].map do |ref|
@ -651,11 +648,7 @@ module VCenterDriver
host_id = vi_client.instance_variable_get '@host_id' host_id = vi_client.instance_variable_get '@host_id'
begin begin
nsx_client = nsx_client = NSXDriver::NSXClient.new_from_id(host_id)
NSXDriver::NSXClient
.new_from_id(
host_id
)
rescue StandardError rescue StandardError
nsx_client = nil nsx_client = nil
end end
@ -711,11 +704,7 @@ module VCenterDriver
end end
# Prepare the Virtual Network template # Prepare the Virtual Network template
one_vnet = one_vnet = VCenterDriver::Network.to_one_template(import_opts)
VCenterDriver::Network
.to_one_template(
import_opts
)
# always has to be created because of # always has to be created because of
# templates when they are instantiated # templates when they are instantiated
@ -731,26 +720,17 @@ module VCenterDriver
one_vnet[:one] << ar_tmp one_vnet[:one] << ar_tmp
config[:one_object] = one_vnet[:one] config[:one_object] = one_vnet[:one]
_cluster_id = _cluster_id = VCenterDriver::VIHelper
VCenterDriver::VIHelper .get_cluster_id(config[:one_ids])
.get_cluster_id(
config[:one_ids]
)
one_vn = one_vn = VCenterDriver::Network.create_one_network(config)
VCenterDriver::Network
.create_one_network(
config
)
allocated_networks << one_vn allocated_networks << one_vn
VCenterDriver::VIHelper.clean_ref_hash VCenterDriver::VIHelper.clean_ref_hash
one_vn.info one_vn.info
nic_info << nic_from_network_created(one_vn, nic) one_vn
# Refresh npool end
npool.info_all
end
def import_vcenter_nics( def import_vcenter_nics(
vi_client, vi_client,
@ -793,18 +773,26 @@ module VCenterDriver
npool) npool)
# Network is already in OpenNebula # Network is already in OpenNebula
if network_found if network_found
nic_info << nic_from_network_found(network_found, vm_object, nic, ar_ids) nic_info << nic_from_network_found(network_found,
vm_object,
nic,
ar_ids)
# Network not found # Network not found
else else
create_network_for_import(nic, one_vn = create_network_for_import(nic,
ccr_ref, ccr_ref,
ccr_name, ccr_name,
vc_uuid, vc_uuid,
vcenter_instance_name, vcenter_instance_name,
dc_name, dc_name,
template_ref, template_ref,
dc_ref, dc_ref,
vm_id) vm_id)
nic_info << nic_from_network_created(one_vn, nic)
# Refresh npool
npool.info_all
end end
end end
rescue StandardError => e rescue StandardError => e