Module: XenApi

Defined in:
lib/xenapi/xenapi/client.rb,
lib/xenapi/xenapi.rb,
lib/xenapi/xenapi/errors.rb,
lib/xenapi/xenapi/dispatcher.rb,
lib/xenapi/xenapi/xmlrpc_client.rb,
lib/xenapi/xenapi/async_dispatcher.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Errors Classes: AsyncDispatcher, Client, Dispatcher, XMLRPCClient

Class Method Summary collapse

Class Method Details

.connect(uris, username, password, options = {}) {|client| ... } ⇒ Object

Perform some action in a session context

Parameters:

  • hosts (String, Array)

    Host or hosts to try to connect to. Pass multiple URLs to allow to find the pool master even if the originally designated host is not reachable.

  • username (String)

    Username used for login

  • password (String)

    Password used for login

  • options (Hash(Symbol => Boolean, String)) (defaults to: {})

    Additional options:

    +:api_version+:: Force the usage of this API version if true
    +:slave_login+:: Authenticate locally against a slave in emergency mode if true.
    +:keep_session+:: Don't logout afterwards to keep the session usable if true
    +:timeout+:: Maximum number of seconds to wait for an API response
    +:ssl_verify+:: SSL certificate verification mode. Can be one of :verify_none or :verify_peer
    

Yields:

  • client

Yield Parameters:

  • client (Client)

    Client instance

Returns:

  • (Object)

    block return value

Raises:

  • (NoHostsAvailable)

    No hosts could be contacted



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/xenapi/xenapi.rb', line 26

def self.connect(uris, username, password, options={})
  uris = uris.respond_to?(:shift) ? uris.dup : [uris]
  method = options[:slave_login] ? :slave_local_login_with_password : :login_with_password

  client = Client.new(uris, options[:timeout] || 10, options[:ssl_verify] || :verify_peer)
  begin
    args = [method, username, password]
    args << options[:api_version] if options.has_key?(:api_version)
    client.send(*args)

    if block_given?
      return yield client
    else
      options[:keep_session] = true
      return client
    end
  ensure
    client.logout unless options[:keep_session] || client.xenapi_session.nil?
  end
end