Skip to content

Commit

Permalink
B #3280: Refactor vCenter CLI host import
Browse files Browse the repository at this point in the history
(cherry picked from commit 78bd769)
  • Loading branch information
tinova committed May 20, 2019
1 parent 6272fb2 commit 14633d9
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/vmm_mad/remotes/lib/vcenter_driver/vcenter_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ def self.import_clusters(con_ops, options)
clusters.each{ |cluster|
one_cluster_id = nil
rpool = nil

# Handle OpenNebula cluster creation or reuse
if !use_defaults
STDOUT.print "\n * vCenter cluster found:\n"\
" - Name : \e[92m#{cluster[:simple_name]}\e[39m\n"\
Expand All @@ -474,27 +476,18 @@ def self.import_clusters(con_ops, options)
STDOUT.print "\n Specify the ID of the cluster or press Enter if you want OpenNebula to create a new cluster for you: "

answer = STDIN.gets.strip

if !answer.empty?
one_cluster_id = answer
else
# Check if the Cluster exists
cluster_list.each do |key, value|
one_cluster_id = key if value == "#{cluster[:cluster_name]}"
end
end
end
end

if !one_cluster_id
one_cluster = VCenterDriver::VIHelper.new_one_item(OpenNebula::Cluster)
rc = one_cluster.allocate("#{cluster[:cluster_name]}")
if ::OpenNebula.is_error?(rc)
STDOUT.puts " Error creating OpenNebula cluster: #{rc.message}\n"
next
end
one_cluster_id = one_cluster.id
end
else
# Defaults, add host to new cluster
# Check if the OpenNebula Cluster exists, and reuse it
one_cluster_id = cluster_list.key(cluster[:cluster_name]) if !one_cluster_id


if !one_cluster_id
one_cluster = VCenterDriver::VIHelper.new_one_item(OpenNebula::Cluster)
rc = one_cluster.allocate("#{cluster[:cluster_name]}")
if ::OpenNebula.is_error?(rc)
Expand All @@ -504,9 +497,7 @@ def self.import_clusters(con_ops, options)
one_cluster_id = one_cluster.id
end



# Generate the template and create the host in the pool
# Generate host template and allocate new host
one_host = VCenterDriver::ClusterComputeResource.to_one(cluster,
con_ops,
rpool,
Expand Down

0 comments on commit 14633d9

Please sign in to comment.