mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
F #1538: create_one_network created, it handles cluster selection
This commit is contained in:
parent
bcc172311d
commit
d845be8d9b
@ -641,9 +641,9 @@ def self.import_networks(con_ops, options)
|
||||
if !use_defaults
|
||||
message = false
|
||||
print_str = "\n * Network found:\n"\
|
||||
" - Name : \e[92m#{n[:name]}\e[39m\n"\
|
||||
" - Type : #{n[:type]}\n"\
|
||||
" - Vcenter Clusters(host id): "
|
||||
" - Name : \e[92m#{n[:name]}\e[39m\n"\
|
||||
" - Type : #{n[:type]}\n"\
|
||||
" - Vcenter Clusters(cluster id): "
|
||||
|
||||
unimported = ""
|
||||
import = false
|
||||
@ -801,32 +801,16 @@ def self.import_networks(con_ops, options)
|
||||
ar_str << ",SIZE = \"#{size}\"]"
|
||||
|
||||
n[:one] << ar_str
|
||||
opts_net = {
|
||||
one_object: n[:one],
|
||||
refs: n[:clusters][:refs],
|
||||
one_ids: n[:clusters][:one_ids]
|
||||
}
|
||||
|
||||
one_vn = VCenterDriver::VIHelper.new_one_item(OpenNebula::VirtualNetwork)
|
||||
if n[:clusters] #Distributed Port Group
|
||||
done = []
|
||||
for i in 0..n[:clusters][:refs].size-1
|
||||
cl_id = n[:clusters][:one_ids][i]
|
||||
next if cl_id == -1 || done.include?(cl_id)
|
||||
one_vn = VCenterDriver::Network.create_one_network(opts_net)
|
||||
|
||||
if done.empty?
|
||||
rc = one_vn.allocate(n[:one],cl_id.to_i)
|
||||
one_vn.info
|
||||
else
|
||||
one_cluster = VCenterDriver::VIHelper.one_item(OpenNebula::Cluster, cl_id, false)
|
||||
rc = one_cluster.addvnet(one_vn['ID'].to_i)
|
||||
end
|
||||
done << cl_id
|
||||
end
|
||||
end
|
||||
|
||||
if ::OpenNebula.is_error?(rc)
|
||||
STDOUT.puts "\n Error creating virtual network: " +
|
||||
" #{rc.message}\n"
|
||||
else
|
||||
STDOUT.puts "\n OpenNebula virtual network \e[92m#{n[:import_name]}\e[39m " +
|
||||
"with ID \e[94m#{one_vn.id}\e[39m created with size #{size}!\n"
|
||||
end
|
||||
STDOUT.puts "\n OpenNebula virtual network \e[92m#{n[:import_name]}\e[39m " +
|
||||
"with ID \e[94m#{one_vn.id}\e[39m !\n"
|
||||
end
|
||||
}
|
||||
rescue Interrupt => e
|
||||
|
@ -157,6 +157,36 @@ class Network
|
||||
return template
|
||||
end
|
||||
|
||||
REQUIRED_ATTRS = [:refs, :one_ids, :one_object]
|
||||
def self.create_one_network(net_config)
|
||||
|
||||
# mandatory parameters:
|
||||
REQUIRED_ATTRS.each do |attr|
|
||||
raise "#{attr} required for importing nics operation!" if net_config[attr].nil?
|
||||
end
|
||||
|
||||
one_vn = VCenterDriver::VIHelper.new_one_item(OpenNebula::VirtualNetwork)
|
||||
|
||||
done = []
|
||||
for i in 0..net_config[:refs].size-1
|
||||
cl_id = net_config[:one_ids][i]
|
||||
next if cl_id == -1 || done.include?(cl_id)
|
||||
|
||||
if done.empty?
|
||||
rc = one_vn.allocate(net_config[:one_object],cl_id.to_i)
|
||||
VCenterDriver::VIHelper.check_error(rc, "create network")
|
||||
one_vn.info
|
||||
else
|
||||
one_cluster = VCenterDriver::VIHelper.one_item(OpenNebula::Cluster, cl_id, false)
|
||||
rc = one_cluster.addvnet(one_vn['ID'].to_i)
|
||||
VCenterDriver::VIHelper.check_error(rc,"addvnet to cluster")
|
||||
end
|
||||
done << cl_id
|
||||
end
|
||||
|
||||
one_vn
|
||||
end
|
||||
|
||||
def self.get_network_type(device)
|
||||
if device.backing.is_a? RbVmomi::VIM::VirtualEthernetCardDistributedVirtualPortBackingInfo
|
||||
return "Distributed Port Group"
|
||||
|
@ -21,6 +21,24 @@ class VIHelper
|
||||
end
|
||||
end
|
||||
|
||||
require 'scripts_common'
|
||||
def self.check_error(rc, message, _exit=false)
|
||||
if OpenNebula::is_error?(rc)
|
||||
OpenNebula::error_message("\n Error #{message}: #{rc.message}\n")
|
||||
exit 1 if (_exit)
|
||||
|
||||
raise rc.message
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_cluster_id(clusters)
|
||||
clusters.each do |id|
|
||||
return id unless id == -1
|
||||
end
|
||||
|
||||
return -1
|
||||
end
|
||||
|
||||
def self.one_item(the_class, id, exit_if_fail = true)
|
||||
item = the_class.new_with_id(id, client)
|
||||
rc = item.info
|
||||
|
@ -413,24 +413,19 @@ class Template
|
||||
nic_info << nic_tmp
|
||||
end
|
||||
else
|
||||
config = {}
|
||||
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)
|
||||
|
||||
# We're importing unmanaged nics
|
||||
unmanaged = true
|
||||
|
||||
# Let's get the OpenNebula host associated to the cluster reference
|
||||
one_host = VCenterDriver::VIHelper.find_by_ref(OpenNebula::HostPool,
|
||||
"TEMPLATE/VCENTER_CCR_REF",
|
||||
ccr_ref,
|
||||
vc_uuid,
|
||||
hpool)
|
||||
|
||||
# Let's get the CLUSTER_ID from the OpenNebula host
|
||||
if !one_host || !one_host['CLUSTER_ID']
|
||||
cluster_id = -1
|
||||
else
|
||||
cluster_id = one_host['CLUSTER_ID']
|
||||
# Let's get the OpenNebula hosts ids associated to the clusters references
|
||||
config[:one_ids] = nic[:refs].map do |ref|
|
||||
VCenterDriver::VIHelper.find_by_ref(OpenNebula::HostPool,
|
||||
"TEMPLATE/VCENTER_CCR_REF",
|
||||
ref,
|
||||
vc_uuid,
|
||||
hpool)["CLUSTER_ID"] rescue -1
|
||||
end
|
||||
|
||||
# We have to know if we're importing nics from a wild vm
|
||||
@ -443,9 +438,6 @@ class Template
|
||||
ar_size = 255
|
||||
end
|
||||
|
||||
net_host = VCenterDriver::ClusterComputeResource.new_from_ref(ccr_ref, @vi_client)
|
||||
location = VCenterDriver::VIHelper.get_location(net_host.item)
|
||||
|
||||
import_opts = {
|
||||
:network_name=> nic[:net_name],
|
||||
:network_ref=> nic[:net_ref],
|
||||
@ -455,8 +447,6 @@ class Template
|
||||
:vcenter_uuid=> vc_uuid,
|
||||
:vcenter_instance_name=> vcenter_instance_name,
|
||||
:dc_name=> dc_name,
|
||||
:cluster_id=> cluster_id,
|
||||
:location=> location,
|
||||
:unmanaged=> unmanaged,
|
||||
:template_ref=> template_ref,
|
||||
:dc_ref=> dc_ref,
|
||||
@ -475,7 +465,9 @@ class Template
|
||||
ar_str << "SIZE=\"#{ar_size}\"\n"
|
||||
ar_str << "]\n"
|
||||
one_vnet[:one] << ar_str
|
||||
config[:one_object] = one_vnet[:one]
|
||||
|
||||
cluster_id = VCenterDriver::VIHelper.get_cluster_id(config[:one_ids])
|
||||
if sunstone
|
||||
if !duplicated_networks.include?(nic[:net_name])
|
||||
sunstone_nic = {}
|
||||
@ -492,16 +484,10 @@ class Template
|
||||
sunstone_nic_info << sunstone_nic
|
||||
end
|
||||
else
|
||||
# Allocate the Virtual Network
|
||||
one_vn = VCenterDriver::Network.create_one_network(config)
|
||||
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"
|
||||
break
|
||||
end
|
||||
|
||||
# Add info for One template
|
||||
one_vn.info
|
||||
nic_info << "NIC=[\n"
|
||||
@ -512,6 +498,7 @@ class Template
|
||||
# Refresh npool
|
||||
npool.info_all
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -614,6 +601,9 @@ class Template
|
||||
else
|
||||
network = device.backing.network
|
||||
end
|
||||
nic[:refs] = network.host.map do |h|
|
||||
h.parent._ref if h.parent
|
||||
end
|
||||
|
||||
nic[:mac] = device.macAddress rescue nil
|
||||
nic[:net_name] = network.name
|
||||
|
Loading…
x
Reference in New Issue
Block a user