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

B#5019: allow remote sunstone with vCenter (#402)

This commit is contained in:
Carlos J. Herrera 2020-11-12 04:50:23 -05:00 committed by GitHub
parent dfab1440a1
commit 9d6d90b486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 52 additions and 26 deletions

View File

@ -540,8 +540,12 @@ EOT
@translation_hash = nil
end
def set_client(options)
@client=OpenNebulaHelper::OneHelper.get_client(options, true)
def set_client(options, client=nil)
if client.nil?
@client=OpenNebulaHelper::OneHelper.get_client(options, true)
else
@client = client
end
end
def create_resource(options, &block)

View File

@ -21,7 +21,7 @@ require 'webauthn'
module SunstoneWebAuthn
def self.configure(conf)
@client = OpenNebula::Client.new
@client = OpenNebula::Client.new(nil, conf[:one_xmlrpc])
@challenges = Hash.new
WebAuthn.configure do |config|
if !conf.include?(:webauthn_origin) || conf[:webauthn_origin] == ''

View File

@ -361,7 +361,7 @@ class SunstoneServer < CloudServer
exit -1
end
return vmrc.proxy(resource)
return vmrc.proxy(resource, client)
end
########################################################################

View File

@ -126,7 +126,7 @@ class OpenNebulaVMRC
ticket
end
def proxy(vm_resource)
def proxy(vm_resource, client=nil)
# Check configurations and VM attributes
unless VMRC_STATES.include?(vm_resource['LCM_STATE'])
error_message = "Wrong state (#{vm_resource['LCM_STATE']}) to
@ -154,7 +154,7 @@ class OpenNebulaVMRC
host_id = one_vm['HISTORY_RECORDS/HISTORY[last()]/HID'].to_i
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vi_client = VCenterDriver::VIClient.new_from_host(host_id, client)
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vm_id)

View File

@ -62,7 +62,7 @@ helpers do
if vpass.size > MAX_VCENTER_PASSWORD_LENGTH
begin
client = OpenNebula::Client.new(token, $conf[:one_xmlrpc])
client = OpenNebula::Client.new(nil, $conf[:one_xmlrpc])
system = OpenNebula::System.new(client)
config = system.get_configuration
token = config["ONE_KEY"]
@ -96,16 +96,16 @@ helpers do
error code, error.to_json
end
def viclient_from_host
def viclient_from_host(client)
host_id = params["host"]
VCenterDriver::VIClient.new_from_host(host_id) if host_id
VCenterDriver::VIClient.new_from_host(host_id, client) if host_id
end
def new_vcenter_importer(type)
def new_vcenter_importer(type, one_client=nil)
host_id = params["host"]
vi_client = VCenterDriver::VIClient.new_from_host(host_id) if host_id
one_client = OpenNebula::Client.new
one_client = OpenNebula::Client.new(nil, $conf[:one_xmlrpc]) if one_client.nil?
vi_client = VCenterDriver::VIClient.new_from_host(host_id, one_client) if host_id
$importer = VCenterDriver::VcImporter.new_child(one_client, vi_client, type)
end
@ -115,6 +115,9 @@ get '/vcenter/hosts' do
begin
dc_folder = VCenterDriver::DatacenterFolder.new(vcenter_client)
client = OpenNebula::Client.new(nil, $conf[:one_xmlrpc])
VCenterDriver::VIHelper.set_client(nil, client)
hpool = VCenterDriver::VIHelper.one_pool(OpenNebula::HostPool, false)
if hpool.respond_to?(:message)
@ -137,7 +140,8 @@ end
get '/vcenter/datastores' do
begin
new_vcenter_importer("datastores")
client = OpenNebula::Client.new(nil, $conf[:one_xmlrpc])
new_vcenter_importer("datastores", client)
[200, $importer.retrieve_resources.to_json]
rescue Exception => e
@ -161,7 +165,8 @@ end
get '/vcenter/templates' do
begin
new_vcenter_importer("templates")
client = OpenNebula::Client.new(nil, $conf[:one_xmlrpc])
new_vcenter_importer("templates", client)
[200, $importer.retrieve_resources.to_json]
rescue Exception => e
@ -185,7 +190,8 @@ end
get '/vcenter/networks' do
begin
new_vcenter_importer("networks")
client = OpenNebula::Client.new(nil, $conf[:one_xmlrpc])
new_vcenter_importer("networks", client)
opts = {:host => params["host"], :filter => true}
[200, $importer.retrieve_resources(opts).to_json]
rescue Exception => e
@ -209,8 +215,10 @@ end
get '/vcenter/images' do
begin
new_vcenter_importer("images")
client = OpenNebula::Client.new(nil, $conf[:one_xmlrpc])
new_vcenter_importer("images", client)
VCenterDriver::VIHelper.set_client(nil, client)
ds = VCenterDriver::VIHelper.one_item(OpenNebula::Datastore, params["ds"])
opts = {
@ -240,8 +248,8 @@ end
post '/vcenter/wild' do
begin
client = OpenNebula::Client.new
vi_client = viclient_from_host
client = OpenNebula::Client.new(nil, $conf[:one_xmlrpc])
vi_client = viclient_from_host(client)
importer = VCenterDriver::VmmImporter.new(client, vi_client).tap do |im|
im.list(params["host"], params["opts"])
end

View File

@ -705,7 +705,8 @@ module VCenterDriver
networks = {}
# Selected host in OpenNebula
one_client = OpenNebula::Client.new
one_client = OpenNebula::Client.new(nil, $conf[:one_xmlrpc])
one_host = OpenNebula::Host.new_with_id(args[:host], one_client)
rc = one_host.info
raise rc.message if OpenNebula.is_error? rc

View File

@ -952,7 +952,12 @@ module VCenterDriver
add_clusters(id, clusters)
inner.call(one_object, @vi_client.host_credentials)
inner.call(
one_object,
@vi_client.host_credentials(
@one_client
)
)
end
end

View File

@ -63,19 +63,19 @@ module VCenterDriver
!!@rp
end
def host_credentials
def host_credentials(one_client)
raise 'no host id defined!' if @host_id == -1
host =
OpenNebula::Host
.new_with_id(
@host_id,
OpenNebula::Client.new
one_client
)
rc = host.info
if OpenNebula.is_error?(rc)
raise "Could not get host info \
for ID: #{host_id} - #{rc.message}"
for ID: #{@host_id} - #{rc.message}"
end
{ :pass => host['TEMPLATE/VCENTER_PASSWORD'],
@ -139,9 +139,9 @@ module VCenterDriver
entities
end
def self.new_from_host(host_id)
def self.new_from_host(host_id, client=nil)
begin
client = OpenNebula::Client.new
client = OpenNebula::Client.new if client.nil?
host = OpenNebula::Host.new_with_id(host_id, client)
rc = host.info(true)
if OpenNebula.is_error?(rc)

View File

@ -29,7 +29,15 @@ module VCenterDriver
VM_PREFIX_DEFAULT = 'one-$i-'
def self.client
@@client ||= OpenNebula::Client.new # rubocop:disable Style/ClassVars
@@client ||= OpenNebula::Client.new(nil, $conf[:one_xmlrpc]) # rubocop:disable Style/ClassVars
end
def self.set_client(options, client=nil)
if client.nil?
@@client=OpenNebulaHelper::OneHelper.get_client(options, true)
else
@@client = client
end
end
def self.return_if_error(rc, item, exit_if_fail)