1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-25 02:50:08 +03:00

F #4913: Add resource pool confinement option when a cluster is imported

This commit is contained in:
mcabrerizo 2017-04-05 09:46:49 +02:00
parent 8e460d9bd3
commit 18494e421b
4 changed files with 44 additions and 12 deletions

View File

@ -103,20 +103,24 @@ class DatacenterFolder
host_folder = dc.host_folder
host_folder.fetch_clusters!
host_folder.items.values.each do |host|
host_folder.items.values.each do |ccr|
one_host = VCenterDriver::VIHelper.find_by_ref(OpenNebula::HostPool,
"TEMPLATE/VCENTER_CCR_REF",
host['_ref'],
ccr['_ref'],
vcenter_uuid,
hpool)
next if one_host #If the host has been already imported
cluster = VCenterDriver::ClusterComputeResource.new_from_ref(ccr['_ref'], @vi_client)
rpools = cluster.get_resource_pool_list.select {|rp| !rp[:name].empty?}
host_info = {}
host_info[:cluster_name] = host['name'].tr(" ", "_")
host_info[:cluster_ref] = host['_ref']
host_info[:cluster_name] = ccr['name'].tr(" ", "_")
host_info[:cluster_ref] = ccr['_ref']
host_info[:vcenter_uuid] = vcenter_uuid
host_info[:vcenter_version] = vcenter_version
host_info[:rp_list] = rpools
host_objects[dc_name] << host_info
end

View File

@ -318,7 +318,7 @@ class ClusterComputeResource
Datacenter.new(item)
end
def self.to_one(cluster, con_ops)
def self.to_one(cluster, con_ops, rp)
one_host = VCenterDriver::VIHelper.new_one_item(OpenNebula::Host)
@ -340,6 +340,8 @@ class ClusterComputeResource
"VCENTER_INSTANCE_ID=\"#{cluster[:vcenter_uuid]}\"\n"\
"VCENTER_VERSION=\"#{cluster[:vcenter_version]}\"\n"\
template << "VCENTER_RESOURCE_POOL=\"#{rp}\"" if rp
rc = one_host.update(template, false)
if OpenNebula.is_error?(rc)

View File

@ -41,20 +41,46 @@ def self.import_clusters(con_ops, options)
end
if clusters.empty?
STDOUT.puts " No new clusters found in #{dc}..."
STDOUT.puts "\n No new clusters found in #{dc}..."
next
end
clusters.each{ |cluster|
rpool = nil
if !use_defaults
STDOUT.print " * Import cluster #{cluster[:cluster_name]} (y/[n])? "
STDOUT.print "\n * Import cluster #{cluster[:cluster_name]} (y/[n])? "
next if STDIN.gets.strip.downcase != 'y'
rpools = cluster[:rp_list]
if !rpools.empty?
STDOUT.print "\n Do you want to confine this cluster in "\
"a resource pool (y/[n])? "
if STDIN.gets.strip.downcase == 'y'
rpool_list = ""
rpools.each do |rp|
rpool_list << " - " << rp[:name] << "\n"
end
STDOUT.print "\n Please specify one resource pool from "\
"the following list:\n\n#{rpool_list}"
STDOUT.print "\n Your resource pool choice: "
answer = STDIN.gets.strip
rpool = answer if !answer.empty?
end
end
end
one_host = VCenterDriver::ClusterComputeResource.to_one(cluster,
con_ops)
con_ops,
rpool)
STDOUT.puts " OpenNebula host #{cluster[:cluster_name]} with"\
STDOUT.puts "\n OpenNebula host #{cluster[:cluster_name]} with"\
" id #{one_host.id} successfully created."
STDOUT.puts
}

View File

@ -20,7 +20,7 @@ class VIClient
if ccr
rp = opts.delete(:rp)
if rp
rp_list = get_resource_pool_list(ccr)
rp_list = get_resource_pools(ccr)
rp_ref = rp_list.select { |r| r[:name] == rp }.first._ref rescue nil
@rp = RbVmomi::VIM::ResourcePool(@vim, rp_ref) if rp_ref
end
@ -32,7 +32,7 @@ class VIClient
!!@rp
end
def get_resource_pool_list(ccr, rp = nil, parent_prefix = "", rp_array = [])
def get_resource_pools(ccr, rp = nil, parent_prefix = "", rp_array = [])
current_rp = ""
@ -53,7 +53,7 @@ class VIClient
rp_array << rp_info
else
rp.resourcePool.each do |child_rp|
get_resource_pool_list(ccr, child_rp, current_rp, rp_array)
get_resource_pools(ccr, child_rp, current_rp, rp_array)
end
rp_info = {}
rp_info[:name] = current_rp