Class: RbVmomi::VIM

Inherits:
Connection
  • Object
show all
Defined in:
lib/rbvmomi/vim.rb

Overview

A connection to one vSphere SDK endpoint.

See Also:

Defined Under Namespace

Classes: ComputeResource, Datacenter, Datastore, Folder, ManagedEntity, ManagedObject, ObjectContent, ObjectUpdate, OvfManager, PropertyCollector, ResourcePool, ServiceInstance, Task, VirtualMachine

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.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.

  • :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.



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

def self.connect opts
  fail unless opts.is_a? Hash
  fail "host option required" unless opts[:host]
  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|
    vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password]
    unless rev_given
      rev = vim.serviceContent.about.apiVersion
      vim.rev = [rev, '5.0'].min
    end
  end
end

.extension_dirsObject

Directories to search for extensions



107
108
109
# File 'lib/rbvmomi/vim.rb', line 107

def self.extension_dirs
  @extension_dirs
end

.finalizer(cookie, opts) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/rbvmomi/vim.rb', line 54

def self.finalizer cookie, opts
  proc do |object_id|
    new(opts).tap do |vim|
      vim.instance_variable_set :@cookie, cookie
      vim.close
    end
    nil
  end
end

Instance Method Details

#closeObject



43
44
45
46
# File 'lib/rbvmomi/vim.rb', line 43

def close
  VIM::SessionManager(self, 'SessionManager').Logout
  super
end

#cookie=(cookie) ⇒ Object



48
49
50
51
52
# File 'lib/rbvmomi/vim.rb', line 48

def cookie= cookie
  super
  ObjectSpace.undefine_finalizer self
  ObjectSpace.define_finalizer(self, self.class.finalizer(cookie,@opts))
end

#propertyCollectorObject

Alias to serviceContent.propertyCollector



90
91
92
# File 'lib/rbvmomi/vim.rb', line 90

def propertyCollector
  serviceContent.propertyCollector
end

#rev=(x) ⇒ Object



64
65
66
67
# File 'lib/rbvmomi/vim.rb', line 64

def rev= x
  super
  @serviceContent = nil
end

#rootFolderObject Also known as: root

Alias to serviceContent.rootFolder



83
84
85
# File 'lib/rbvmomi/vim.rb', line 83

def rootFolder
  serviceContent.rootFolder
end

#searchIndexObject

Alias to serviceContent.searchIndex



95
96
97
# File 'lib/rbvmomi/vim.rb', line 95

def searchIndex
  serviceContent.searchIndex
end

#serviceContentObject

Alias to serviceInstance.RetrieveServiceContent



78
79
80
# File 'lib/rbvmomi/vim.rb', line 78

def serviceContent
  @serviceContent ||= serviceInstance.RetrieveServiceContent
end

#serviceInstanceObject

Return the ServiceInstance

The ServiceInstance is the root of the vSphere inventory.



73
74
75
# File 'lib/rbvmomi/vim.rb', line 73

def serviceInstance
  VIM::ServiceInstance self, 'ServiceInstance'
end