Method: RbVmomi::VIM.connect

Defined in:
lib/rbvmomi/vim.rb

.connect(opts) ⇒ Object

Connect to a vSphere SDK endpoint

Parameters:

  • opts (Hash)

    The options hash.

Options Hash (opts):

  • :host (String)

    Host to connect to.

  • :port (Numeric) — default: 443

    Port to connect to.

  • :ssl (Boolean) — default: true

    Whether to use SSL.

  • :insecure (Boolean) — default: false

    If true, ignore SSL certificate errors.

  • :cookie (String)

    If set, use cookie to connect instead of user/password

  • :user (String) — default: root

    Username.

  • :password (String)

    Password.

  • :path (String) — default: /sdk

    SDK endpoint path.

  • :debug (Boolean) — default: false

    If true, print SOAP traffic to stderr.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rbvmomi/vim.rb', line 21

def self.connect opts
  fail unless opts.is_a? Hash
  fail "host option required" unless opts[:host]
  opts[:cookie] ||= nil
  opts[:user] ||= 'root'
  opts[:password] ||= ''
  opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
  opts[:insecure] ||= false
  opts[:port] ||= (opts[:ssl] ? 443 : 80)
  opts[:path] ||= '/sdk'
  opts[:ns] ||= 'urn:vim25'
  rev_given = opts[:rev] != nil
  opts[:rev] = '4.0' unless rev_given
  opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug

  new(opts).tap do |vim|
    unless opts[:cookie]
      vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password]
    end
    unless rev_given
      rev = vim.serviceContent.about.apiVersion
      vim.rev = [rev, '5.5'].min
    end
  end
end