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

F #1408: Centralize credentials for vCenter (#3226)

This commit is contained in:
sergiojvg 2019-04-25 03:28:38 -05:00 committed by Tino Vázquez
parent 3c4629953a
commit 2aa4710713
2 changed files with 19 additions and 4 deletions

View File

@ -778,8 +778,6 @@ class DsImporter < VCenterDriver::VcImporter
inner = ->(object, auth) {
one = ""
one << "VCENTER_HOST=\"#{auth[:host]}\"\n"
one << "VCENTER_USER=\"#{auth[:user]}\"\n"
one << "VCENTER_PASSWORD=\"#{auth[:pass]}\"\n"
rc = object.update(one, true)
}

View File

@ -164,8 +164,25 @@ class VIClient
if OpenNebula.is_error?(rc)
raise "Could not get datastore info for ID: #{datastore_id} - #{rc.message}"
end
vcenter_id = datastore["TEMPLATE/VCENTER_INSTANCE_ID"]
password = datastore["TEMPLATE/VCENTER_PASSWORD"]
host_pool = OpenNebula::HostPool.new(client)
rc = host_pool.info
if OpenNebula.is_error?(rc)
raise "Could not get hosts information - #{rc.message}"
end
user = ""
password = ""
host_pool.each do |host|
if host["TEMPLATE/VCENTER_INSTANCE_ID"] == vcenter_id
user = host["TEMPLATE/VCENTER_USER"]
password = host["TEMPLATE/VCENTER_PASSWORD"]
end
end
if password.empty? or user.empty?
raise "Error getting credentials for datastore #{datastore_id}"
end
system = OpenNebula::System.new(client)
config = system.get_configuration
@ -179,7 +196,7 @@ class VIClient
connection = {
:host => datastore["TEMPLATE/VCENTER_HOST"],
:user => datastore["TEMPLATE/VCENTER_USER"],
:user => user,
:password => password
}