rbvmomi2 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -25
  3. data/exe/rbvmomish +50 -48
  4. data/lib/rbvmomi/basic_types.rb +318 -294
  5. data/lib/rbvmomi/connection.rb +221 -216
  6. data/lib/rbvmomi/deserialization.rb +201 -205
  7. data/lib/rbvmomi/fault.rb +10 -9
  8. data/lib/rbvmomi/optimist.rb +51 -50
  9. data/lib/rbvmomi/pbm.rb +52 -50
  10. data/lib/rbvmomi/sms/SmsStorageManager.rb +2 -1
  11. data/lib/rbvmomi/sms.rb +48 -46
  12. data/lib/rbvmomi/sso.rb +13 -18
  13. data/lib/rbvmomi/trivial_soap.rb +9 -8
  14. data/lib/rbvmomi/type_loader.rb +100 -101
  15. data/lib/rbvmomi/utils/admission_control.rb +90 -106
  16. data/lib/rbvmomi/utils/deploy.rb +77 -85
  17. data/lib/rbvmomi/utils/leases.rb +31 -33
  18. data/lib/rbvmomi/utils/perfdump.rb +177 -207
  19. data/lib/rbvmomi/version.rb +2 -1
  20. data/lib/rbvmomi/vim/ComputeResource.rb +17 -15
  21. data/lib/rbvmomi/vim/Datacenter.rb +1 -0
  22. data/lib/rbvmomi/vim/Datastore.rb +18 -15
  23. data/lib/rbvmomi/vim/DynamicTypeMgrAllTypeInfo.rb +7 -6
  24. data/lib/rbvmomi/vim/DynamicTypeMgrDataTypeInfo.rb +3 -2
  25. data/lib/rbvmomi/vim/DynamicTypeMgrManagedTypeInfo.rb +7 -6
  26. data/lib/rbvmomi/vim/Folder.rb +37 -33
  27. data/lib/rbvmomi/vim/HostSystem.rb +139 -136
  28. data/lib/rbvmomi/vim/ManagedEntity.rb +15 -14
  29. data/lib/rbvmomi/vim/ManagedObject.rb +11 -10
  30. data/lib/rbvmomi/vim/ObjectContent.rb +3 -1
  31. data/lib/rbvmomi/vim/ObjectUpdate.rb +3 -1
  32. data/lib/rbvmomi/vim/OvfManager.rb +50 -57
  33. data/lib/rbvmomi/vim/PerfCounterInfo.rb +4 -3
  34. data/lib/rbvmomi/vim/PerformanceManager.rb +28 -31
  35. data/lib/rbvmomi/vim/PropertyCollector.rb +8 -7
  36. data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +22 -21
  37. data/lib/rbvmomi/vim/ResourcePool.rb +19 -18
  38. data/lib/rbvmomi/vim/ServiceInstance.rb +8 -7
  39. data/lib/rbvmomi/vim/Task.rb +6 -5
  40. data/lib/rbvmomi/vim/VirtualMachine.rb +8 -7
  41. data/lib/rbvmomi/vim.rb +112 -129
  42. data/lib/rbvmomi.rb +1 -0
  43. metadata +54 -10
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2012-2017 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
@@ -20,18 +21,18 @@ class RbVmomi::VIM::PerformanceManager
20
21
  def perfcounter_cached
21
22
  @perfcounter ||= perfCounter
22
23
  end
23
-
24
+
24
25
  def perfcounter_hash
25
- @perfcounter_hash ||= Hash[perfcounter_cached.map{|x| [x.name, x]}]
26
+ @perfcounter_hash ||= Hash[perfcounter_cached.map{ |x| [x.name, x] }]
26
27
  end
27
-
28
- def perfcounter_idhash
29
- @perfcounter_idhash ||= Hash[perfcounter_cached.map{|x| [x.key, x]}]
28
+
29
+ def perfcounter_idhash
30
+ @perfcounter_idhash ||= Hash[perfcounter_cached.map{ |x| [x.key, x] }]
30
31
  end
31
-
32
+
32
33
  def provider_summary obj
33
34
  @provider_summary ||= {}
34
- @provider_summary[obj.class] ||= QueryPerfProviderSummary(:entity => obj)
35
+ @provider_summary[obj.class] ||= QueryPerfProviderSummary(entity: obj)
35
36
  end
36
37
 
37
38
  def retrieve_stats objects, metrics, opts = {}
@@ -44,45 +45,41 @@ class RbVmomi::VIM::PerformanceManager
44
45
  realtime = true
45
46
  else
46
47
  provider = provider_summary objects.first
47
- if opts[:interval] == provider.refreshRate
48
- realtime = true
49
- end
48
+ realtime = true if opts[:interval] == provider.refreshRate
50
49
  end
51
-
50
+
52
51
  instances = opts[:instance] || '*'
53
- if !instances.is_a?(Array)
54
- instances = [instances]
55
- end
52
+ instances = [instances] if !instances.is_a?(Array)
56
53
  metric_ids = []
57
- metrics.each do |x|
54
+ metrics.each do |x|
58
55
  counter = perfcounter_hash[x]
59
56
  if !counter
60
57
  pp perfcounter_hash.keys
61
- fail "Counter for #{x} couldn't be found"
58
+ raise "Counter for #{x} couldn't be found"
62
59
  end
63
60
  instances.each do |instance|
64
- metric_ids << RbVmomi::VIM::PerfMetricId(:counterId => counter.key,
65
- :instance => instance)
61
+ metric_ids << RbVmomi::VIM::PerfMetricId(counterId: counter.key,
62
+ instance: instance)
66
63
  end
67
64
  end
68
65
  query_specs = objects.map do |obj|
69
66
  RbVmomi::VIM::PerfQuerySpec({
70
- :maxSample => max_samples,
71
- :entity => obj,
72
- :metricId => metric_ids,
73
- :intervalId => opts[:interval],
74
- :startTime => (realtime == false ? opts[:start_time].to_datetime : nil),
67
+ maxSample: max_samples,
68
+ entity: obj,
69
+ metricId: metric_ids,
70
+ intervalId: opts[:interval],
71
+ startTime: (realtime == false ? opts[:start_time].to_datetime : nil),
75
72
  })
76
73
  end
77
- stats = QueryPerf(:querySpec => query_specs)
78
-
74
+ stats = QueryPerf(querySpec: query_specs)
75
+
79
76
  if !opts[:multi_instance]
80
77
  Hash[stats.map do |res|
81
78
  [
82
- res.entity,
79
+ res.entity,
83
80
  {
84
- :sampleInfo => res.sampleInfo,
85
- :metrics => Hash[res.value.map do |metric|
81
+ sampleInfo: res.sampleInfo,
82
+ metrics: Hash[res.value.map do |metric|
86
83
  metric_name = perfcounter_idhash[metric.id.counterId].name
87
84
  [metric_name, metric.value]
88
85
  end]
@@ -92,10 +89,10 @@ class RbVmomi::VIM::PerformanceManager
92
89
  else
93
90
  Hash[stats.map do |res|
94
91
  [
95
- res.entity,
92
+ res.entity,
96
93
  {
97
- :sampleInfo => res.sampleInfo,
98
- :metrics => Hash[res.value.map do |metric|
94
+ sampleInfo: res.sampleInfo,
95
+ metrics: Hash[res.value.map do |metric|
99
96
  metric_name = perfcounter_idhash[metric.id.counterId].name
100
97
  [[metric_name, metric.id.instance], metric.value]
101
98
  end]
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
@@ -5,22 +6,22 @@ class RbVmomi::VIM::PropertyCollector
5
6
  def collectMultiple objs, *pathSet
6
7
  return {} if objs.empty?
7
8
 
8
- klasses = objs.map{|x| x.class}.uniq
9
+ klasses = objs.map{ |x| x.class }.uniq
9
10
  klass = if klasses.length > 1
10
11
  # common superclass
11
- klasses.map(&:ancestors).inject(&:&)[0]
12
+ klasses.map(&:ancestors).inject(&:&)[0]
12
13
  else
13
14
  klasses.first
14
15
  end
15
16
 
16
17
  spec = {
17
- :objectSet => objs.map{|x| { :obj => x }},
18
- :propSet => [{
19
- :pathSet => pathSet,
20
- :type => klass.wsdl_name
18
+ objectSet: objs.map{ |x| { obj: x } },
19
+ propSet: [{
20
+ pathSet: pathSet,
21
+ type: klass.wsdl_name
21
22
  }]
22
23
  }
23
- res = RetrieveProperties(:specSet => [spec])
24
+ res = RetrieveProperties(specSet: [spec])
24
25
  Hash[res.map do |x|
25
26
  [x.obj, x.to_hash]
26
27
  end]
@@ -1,33 +1,34 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
4
5
  module RbVmomi
5
6
 
6
- class VIM::ReflectManagedMethodExecuter
7
- def fetch moid, prop
8
- result = FetchSoap(:moid => moid, :version => 'urn:vim25/6.5', :prop => prop)
9
- xml = Nokogiri(result.response)
10
- _connection.deserializer.deserialize xml.root, nil
11
- end
7
+ class VIM::ReflectManagedMethodExecuter
8
+ def fetch moid, prop
9
+ result = FetchSoap(moid: moid, version: 'urn:vim25/6.5', prop: prop)
10
+ xml = Nokogiri(result.response)
11
+ _connection.deserializer.deserialize xml.root, nil
12
+ end
12
13
 
13
- def execute moid, method, args
14
- soap_args = args.map do |k,v|
15
- VIM::ReflectManagedMethodExecuterSoapArgument.new.tap do |soap_arg|
16
- soap_arg.name = k
17
- xml = Builder::XmlMarkup.new :indent => 0
18
- _connection.obj2xml xml, k, :anyType, false, v
19
- soap_arg.val = xml.target!
14
+ def execute moid, method, args
15
+ soap_args = args.map do |k, v|
16
+ VIM::ReflectManagedMethodExecuterSoapArgument.new.tap do |soap_arg|
17
+ soap_arg.name = k
18
+ xml = Builder::XmlMarkup.new indent: 0
19
+ _connection.obj2xml xml, k, :anyType, false, v
20
+ soap_arg.val = xml.target!
21
+ end
22
+ end
23
+ result = ExecuteSoap(moid: moid, version: 'urn:vim25/6.5',
24
+ method: method, argument: soap_args)
25
+ if result
26
+ _connection.deserializer.deserialize Nokogiri(result.response).root, nil
27
+ else
28
+ nil
20
29
  end
21
- end
22
- result = ExecuteSoap(:moid => moid, :version => 'urn:vim25/6.5',
23
- :method => method, :argument => soap_args)
24
- if result
25
- _connection.deserializer.deserialize Nokogiri(result.response).root, nil
26
- else
27
- nil
28
30
  end
29
31
  end
30
- end
31
32
 
32
33
  end
33
34
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
@@ -6,7 +7,7 @@ class RbVmomi::VIM::ResourcePool
6
7
  # @param name [String] Name of the child.
7
8
  # @return [VIM::ResourcePool]
8
9
  def find name
9
- _connection.searchIndex.FindChild(:entity => self, :name => name)
10
+ _connection.searchIndex.FindChild(entity: self, name: name)
10
11
  end
11
12
 
12
13
  # Retrieve a descendant of this ResourcePool.
@@ -14,7 +15,7 @@ class RbVmomi::VIM::ResourcePool
14
15
  # @return [VIM::ResourcePool]
15
16
  def traverse path
16
17
  es = path.split('/').reject(&:empty?)
17
- es.inject(self) do |f,e|
18
+ es.inject(self) do |f, e|
18
19
  f.find(e) || return
19
20
  end
20
21
  end
@@ -22,35 +23,35 @@ class RbVmomi::VIM::ResourcePool
22
23
  def resourcePoolSubTree fields = []
23
24
  self.class.resourcePoolSubTree [self], fields
24
25
  end
25
-
26
+
26
27
  def self.resourcePoolSubTree objs, fields = []
27
28
  fields = (fields + ['name', 'resourcePool']).uniq
28
29
  filterSpec = RbVmomi::VIM.PropertyFilterSpec(
29
- :objectSet => objs.map do |obj|
30
+ objectSet: objs.map do |obj|
30
31
  RbVmomi::VIM.ObjectSpec(
31
- :obj => obj,
32
- :selectSet => [
32
+ obj: obj,
33
+ selectSet: [
33
34
  RbVmomi::VIM.TraversalSpec(
34
- :name => "tsRP",
35
- :type => 'ResourcePool',
36
- :path => 'resourcePool',
37
- :skip => false,
38
- :selectSet => [
39
- RbVmomi::VIM.SelectionSpec(:name => "tsRP")
35
+ name: 'tsRP',
36
+ type: 'ResourcePool',
37
+ path: 'resourcePool',
38
+ skip: false,
39
+ selectSet: [
40
+ RbVmomi::VIM.SelectionSpec(name: 'tsRP')
40
41
  ]
41
42
  )
42
43
  ]
43
44
  )
44
45
  end,
45
- :propSet => [{
46
- :pathSet => fields,
47
- :type => 'ResourcePool'
46
+ propSet: [{
47
+ pathSet: fields,
48
+ type: 'ResourcePool'
48
49
  }]
49
50
  )
50
-
51
+
51
52
  propCollector = objs.first._connection.propertyCollector
52
- result = propCollector.RetrieveProperties(:specSet => [filterSpec])
53
-
53
+ result = propCollector.RetrieveProperties(specSet: [filterSpec])
54
+
54
55
  Hash[result.map do |x|
55
56
  [x.obj, x.to_hash]
56
57
  end]
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
@@ -24,16 +25,16 @@ class RbVmomi::VIM::ServiceInstance
24
25
  def wait_for_multiple_tasks interested, tasks
25
26
  version = ''
26
27
  interested = (interested + ['info.state']).uniq
27
- task_props = Hash.new { |h,k| h[k] = {} }
28
+ task_props = Hash.new { |h, k| h[k] = {} }
28
29
 
29
- filter = _connection.propertyCollector.CreateFilter :spec => {
30
- :propSet => [{ :type => 'Task', :all => false, :pathSet => interested }],
31
- :objectSet => tasks.map { |x| { :obj => x } },
32
- }, :partialUpdates => false
30
+ filter = _connection.propertyCollector.CreateFilter spec: {
31
+ propSet: [{ type: 'Task', all: false, pathSet: interested }],
32
+ objectSet: tasks.map { |x| { obj: x } },
33
+ }, partialUpdates: false
33
34
 
34
35
  begin
35
- until task_props.size == tasks.size and task_props.all? { |k,h| %w(success error).member? h['info.state'] }
36
- result = _connection.propertyCollector.WaitForUpdates(:version => version)
36
+ until task_props.size == tasks.size and task_props.all? { |k, h| %w(success error).member? h['info.state'] }
37
+ result = _connection.propertyCollector.WaitForUpdates(version: version)
37
38
  version = result.version
38
39
  os = result.filterSet[0].objectSet
39
40
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
@@ -14,7 +15,7 @@ class RbVmomi::VIM::Task
14
15
  raise info.error
15
16
  end
16
17
  end
17
-
18
+
18
19
  # Wait for all child tasks to finish. If any one child task failed,
19
20
  # the exception of the first failing task is thrown.
20
21
  # @return [Hash] Map of tasks to their +info.result+ on success.
@@ -51,17 +52,17 @@ class RbVmomi::VIM::Task
51
52
  raise info.error
52
53
  end
53
54
  end
54
-
55
+
55
56
  # Get child tasks of this task.
56
57
  # @return [Array] List of VIM::Task objects
57
58
  def child_tasks
58
59
  tm = _connection.serviceContent.taskManager
59
- col = tm.CreateCollectorForTasks(:filter => {
60
- :rootTaskKey => [self.info.key],
60
+ col = tm.CreateCollectorForTasks(filter: {
61
+ rootTaskKey: [self.info.key],
61
62
  })
62
63
  # XXX: Likely this is not enough and we need to collect pages other
63
64
  # than the latest.
64
- tasks = col.latestPage.map{|x| x.task}
65
+ tasks = col.latestPage.map{ |x| x.task }
65
66
  col.DestroyCollector()
66
67
  tasks
67
68
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
@@ -18,7 +19,7 @@ class RbVmomi::VIM::VirtualMachine
18
19
  # @return [String] Current IP reported (as per VMware Tools) or nil
19
20
  def guest_ip
20
21
  g = self.guest
21
- if g.ipAddress && (g.toolsStatus == "toolsOk" || g.toolsStatus == "toolsOld")
22
+ if g.ipAddress && (g.toolsStatus == 'toolsOk' || g.toolsStatus == 'toolsOld')
22
23
  g.ipAddress
23
24
  else
24
25
  nil
@@ -36,7 +37,7 @@ class RbVmomi::VIM::VirtualMachine
36
37
  # share the base disk.
37
38
  def add_delta_disk_layer_on_all_disks
38
39
  spec = update_spec_add_delta_disk_layer_on_all_disks
39
- self.ReconfigVM_Task(:spec => spec).wait_for_completion
40
+ self.ReconfigVM_Task(spec: spec).wait_for_completion
40
41
  end
41
42
 
42
43
  # Updates a passed in spec to perform the task of adding a delta disk layer
@@ -50,13 +51,13 @@ class RbVmomi::VIM::VirtualMachine
50
51
  device_change = []
51
52
  disks.each do |disk|
52
53
  device_change << {
53
- :operation => :remove,
54
- :device => disk
54
+ operation: :remove,
55
+ device: disk
55
56
  }
56
57
  device_change << {
57
- :operation => :add,
58
- :fileOperation => :create,
59
- :device => disk.dup.tap { |x|
58
+ operation: :add,
59
+ fileOperation: :create,
60
+ device: disk.dup.tap { |x|
60
61
  x.backing = x.backing.dup
61
62
  x.backing.fileName = "[#{disk.backing.datastore.name}]"
62
63
  x.backing.parent = disk.backing
data/lib/rbvmomi/vim.rb CHANGED
@@ -1,157 +1,140 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
4
- # Win32::SSPI is part of core on Windows
5
- begin
6
- require 'win32/sspi'
7
- rescue LoadError
8
- end
9
- WIN32 = (defined? Win32::SSPI)
10
-
11
5
  module RbVmomi
12
6
 
13
7
  # A connection to one vSphere SDK endpoint.
14
8
  # @see #serviceInstance
15
- class VIM < Connection
16
- # Connect to a vSphere SDK endpoint
17
- #
18
- # @param [Hash] opts The options hash.
19
- # @option opts [String] :host Host to connect to.
20
- # @option opts [Numeric] :port (443) Port to connect to.
21
- # @option opts [Boolean] :ssl (true) Whether to use SSL.
22
- # @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors.
23
- # @option opts [String] :cookie If set, use cookie to connect instead of user/password
24
- # @option opts [String] :user (root) Username.
25
- # @option opts [String] :password Password.
26
- # @option opts [String] :path (/sdk) SDK endpoint path.
27
- # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
28
- # @option opts [String] :operation_id If set, use for operationID
29
- # @option opts [Boolean] :close_on_exit (true) If true, will close connection with at_exit
30
- # @option opts [RbVmomi::SSO] :sso (nil) Use SSO token to login if set
31
- def self.connect opts
32
- fail unless opts.is_a? Hash
33
- fail "host option required" unless opts[:host]
34
- opts[:cookie] ||= nil
35
- opts[:user] ||= (WIN32 ? ENV['USERNAME'].dup : 'root')
36
- opts[:password] ||= ''
37
- opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
38
- opts[:insecure] ||= false
39
- opts[:port] ||= (opts[:ssl] ? 443 : 80)
40
- opts[:path] ||= '/sdk'
41
- opts[:ns] ||= 'urn:vim25'
42
- opts[:rev] = '6.7' if opts[:rev].nil?
43
- opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
44
-
45
- conn = new(opts).tap do |vim|
46
- unless opts[:cookie]
47
- if WIN32 && opts[:password] == ''
48
- # Attempt login by SSPI if no password specified on Windows
49
- negotiation = Win32::SSPI::NegotiateAuth.new opts[:user], ENV['USERDOMAIN'].dup
50
- begin
51
- vim.serviceContent.sessionManager.LoginBySSPI :base64Token => negotiation.get_initial_token
52
- rescue RbVmomi::Fault => fault
53
- if !fault.fault.is_a?(RbVmomi::VIM::SSPIChallenge)
54
- raise
55
- else
56
- vim.serviceContent.sessionManager.LoginBySSPI :base64Token => negotiation.complete_authentication(fault.base64Token)
57
- end
58
- end
59
- elsif opts[:sso]
60
- vim.serviceContent.sessionManager.LoginByToken
61
- else
62
- vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password]
9
+ class VIM < Connection
10
+ # Connect to a vSphere SDK endpoint
11
+ #
12
+ # @param [Hash] opts The options hash.
13
+ # @option opts [String] :host Host to connect to.
14
+ # @option opts [Numeric] :port (443) Port to connect to.
15
+ # @option opts [Boolean] :ssl (true) Whether to use SSL.
16
+ # @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors.
17
+ # @option opts [String] :cookie If set, use cookie to connect instead of user/password
18
+ # @option opts [String] :user (root) Username.
19
+ # @option opts [String] :password Password.
20
+ # @option opts [String] :path (/sdk) SDK endpoint path.
21
+ # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
22
+ # @option opts [String] :operation_id If set, use for operationID
23
+ # @option opts [Boolean] :close_on_exit (true) If true, will close connection with at_exit
24
+ # @option opts [RbVmomi::SSO] :sso (nil) Use SSO token to login if set
25
+ def self.connect opts
26
+ raise unless opts.is_a? Hash
27
+ raise 'host option required' unless opts[:host]
28
+
29
+ opts[:cookie] ||= nil
30
+ opts[:user] ||= 'root'
31
+ opts[:password] ||= ''
32
+ opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
33
+ opts[:insecure] ||= false
34
+ opts[:port] ||= (opts[:ssl] ? 443 : 80)
35
+ opts[:path] ||= '/sdk'
36
+ opts[:ns] ||= 'urn:vim25'
37
+ opts[:rev] = '6.7' if opts[:rev].nil?
38
+ opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
39
+
40
+ conn = new(opts).tap do |vim|
41
+ unless opts[:cookie]
42
+ if opts[:sso]
43
+ vim.serviceContent.sessionManager.LoginByToken
44
+ else
45
+ vim.serviceContent.sessionManager.Login userName: opts[:user], password: opts[:password]
46
+ end
63
47
  end
48
+ rev = vim.serviceContent.about.apiVersion
49
+ vim.rev = [rev, opts[:rev]].min { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }
64
50
  end
65
- rev = vim.serviceContent.about.apiVersion
66
- vim.rev = [rev, opts[:rev]].min { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }
67
- end
68
51
 
69
- at_exit { conn.close } if opts.fetch(:close_on_exit, true)
70
- conn
71
- end
52
+ at_exit { conn.close } if opts.fetch(:close_on_exit, true)
53
+ conn
54
+ end
72
55
 
73
- def close
74
- serviceContent.sessionManager.Logout
75
- rescue RbVmomi::Fault => e
76
- $stderr.puts(e.message) if debug
77
- ensure
78
- self.cookie = nil
79
- super
80
- end
56
+ def close
57
+ serviceContent.sessionManager.Logout
58
+ rescue RbVmomi::Fault => e
59
+ $stderr.puts(e.message) if debug
60
+ ensure
61
+ self.cookie = nil
62
+ super
63
+ end
81
64
 
82
- def rev= x
83
- super
84
- @serviceContent = nil
85
- end
65
+ def rev= x
66
+ super
67
+ @serviceContent = nil
68
+ end
86
69
 
87
- # Return the ServiceInstance
88
- #
89
- # The ServiceInstance is the root of the vSphere inventory.
90
- # @see http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.ServiceInstance.html
91
- def serviceInstance
92
- VIM::ServiceInstance self, 'ServiceInstance'
93
- end
70
+ # Return the ServiceInstance
71
+ #
72
+ # The ServiceInstance is the root of the vSphere inventory.
73
+ # @see http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.ServiceInstance.html
74
+ def serviceInstance
75
+ VIM::ServiceInstance self, 'ServiceInstance'
76
+ end
94
77
 
95
- # Alias to serviceInstance.RetrieveServiceContent
96
- def serviceContent
97
- @serviceContent ||= serviceInstance.RetrieveServiceContent
98
- end
78
+ # Alias to serviceInstance.RetrieveServiceContent
79
+ def serviceContent
80
+ @serviceContent ||= serviceInstance.RetrieveServiceContent
81
+ end
99
82
 
100
- # Alias to serviceContent.rootFolder
101
- def rootFolder
102
- serviceContent.rootFolder
103
- end
83
+ # Alias to serviceContent.rootFolder
84
+ def rootFolder
85
+ serviceContent.rootFolder
86
+ end
104
87
 
105
- alias root rootFolder
88
+ alias root rootFolder
106
89
 
107
- # Alias to serviceContent.propertyCollector
108
- def propertyCollector
109
- serviceContent.propertyCollector
110
- end
111
-
112
- # Alias to serviceContent.searchIndex
113
- def searchIndex
114
- serviceContent.searchIndex
115
- end
90
+ # Alias to serviceContent.propertyCollector
91
+ def propertyCollector
92
+ serviceContent.propertyCollector
93
+ end
116
94
 
117
- # @private
118
- def pretty_print pp
119
- pp.text "VIM(#{@opts[:host]})"
120
- end
95
+ # Alias to serviceContent.searchIndex
96
+ def searchIndex
97
+ serviceContent.searchIndex
98
+ end
121
99
 
122
- def instanceUuid
123
- serviceContent.about.instanceUuid
124
- end
100
+ # @private
101
+ def pretty_print pp
102
+ pp.text "VIM(#{@opts[:host]})"
103
+ end
125
104
 
126
- def get_log_lines logKey, lines=5, start=nil, host=nil
127
- diagMgr = self.serviceContent.diagnosticManager
128
- if !start
129
- log = diagMgr.BrowseDiagnosticLog(:host => host, :key => logKey, :start => 999999999)
130
- lineEnd = log.lineEnd
131
- start = lineEnd - lines
105
+ def instanceUuid
106
+ serviceContent.about.instanceUuid
132
107
  end
133
- start = start < 0 ? 0 : start
134
- log = diagMgr.BrowseDiagnosticLog(:host => host, :key => logKey, :start => start)
135
- if log.lineText.size > 0
136
- [log.lineText.slice(-lines, log.lineText.size), log.lineEnd]
137
- else
138
- [log.lineText, log.lineEnd]
108
+
109
+ def get_log_lines logKey, lines=5, start=nil, host=nil
110
+ diagMgr = self.serviceContent.diagnosticManager
111
+ if !start
112
+ log = diagMgr.BrowseDiagnosticLog(host: host, key: logKey, start: 999999999)
113
+ lineEnd = log.lineEnd
114
+ start = lineEnd - lines
115
+ end
116
+ start = start < 0 ? 0 : start
117
+ log = diagMgr.BrowseDiagnosticLog(host: host, key: logKey, start: start)
118
+ if log.lineText.size > 0
119
+ [log.lineText.slice(-lines, log.lineText.size), log.lineEnd]
120
+ else
121
+ [log.lineText, log.lineEnd]
122
+ end
139
123
  end
140
- end
141
124
 
142
- def get_log_keys host=nil
143
- diagMgr = self.serviceContent.diagnosticManager
144
- keys = []
145
- diagMgr.QueryDescriptions(:host => host).each do |desc|
146
- keys << "#{desc.key}"
125
+ def get_log_keys host=nil
126
+ diagMgr = self.serviceContent.diagnosticManager
127
+ keys = []
128
+ diagMgr.QueryDescriptions(host: host).each do |desc|
129
+ keys << "#{desc.key}"
130
+ end
131
+ keys
147
132
  end
148
- keys
149
- end
150
133
 
151
- add_extension_dir File.join(File.dirname(__FILE__), "vim")
152
- (ENV['RBVMOMI_VIM_EXTENSION_PATH']||'').split(':').each { |dir| add_extension_dir dir }
134
+ add_extension_dir File.join(File.dirname(__FILE__), 'vim')
135
+ (ENV['RBVMOMI_VIM_EXTENSION_PATH']||'').split(':').each { |dir| add_extension_dir dir }
153
136
 
154
- load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.db"))
155
- end
137
+ load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), '../../vmodl.db'))
138
+ end
156
139
 
157
140
  end
data/lib/rbvmomi.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2010-2019 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4