rbvmomi2 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2016-2020 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
4
5
  module RbVmomi
5
- VERSION = '3.0.0'.freeze
6
+ VERSION = '3.0.1'.freeze
6
7
  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
 
@@ -12,37 +13,38 @@ class RbVmomi::VIM::ComputeResource
12
13
  # @return [MB] usedMem: Used RAM.
13
14
  def stats
14
15
  filterSpec = RbVmomi::VIM.PropertyFilterSpec(
15
- :objectSet => [{
16
- :obj => self,
17
- :selectSet => [
16
+ objectSet: [{
17
+ obj: self,
18
+ selectSet: [
18
19
  RbVmomi::VIM.TraversalSpec(
19
- :name => 'tsHosts',
20
- :type => 'ComputeResource',
21
- :path => 'host',
22
- :skip => false
20
+ name: 'tsHosts',
21
+ type: 'ComputeResource',
22
+ path: 'host',
23
+ skip: false
23
24
  )
24
25
  ]
25
26
  }],
26
- :propSet => [{
27
- :pathSet => %w(name overallStatus summary.hardware.cpuMhz
27
+ propSet: [{
28
+ pathSet: %w(name overallStatus summary.hardware.cpuMhz
28
29
  summary.hardware.numCpuCores summary.hardware.memorySize
29
30
  summary.quickStats.overallCpuUsage
30
31
  summary.quickStats.overallMemoryUsage),
31
- :type => 'HostSystem'
32
+ type: 'HostSystem'
32
33
  }]
33
34
  )
34
35
 
35
- result = _connection.propertyCollector.RetrieveProperties(:specSet => [filterSpec])
36
+ result = _connection.propertyCollector.RetrieveProperties(specSet: [filterSpec])
36
37
 
37
38
  stats = {
38
- :totalCPU => 0,
39
- :totalMem => 0,
40
- :usedCPU => 0,
41
- :usedMem => 0,
39
+ totalCPU: 0,
40
+ totalMem: 0,
41
+ usedCPU: 0,
42
+ usedMem: 0,
42
43
  }
43
44
 
44
45
  result.each do |x|
45
46
  next if x['overallStatus'] == 'red'
47
+
46
48
  stats[:totalCPU] += x['summary.hardware.cpuMhz'] * x['summary.hardware.numCpuCores']
47
49
  stats[:totalMem] += x['summary.hardware.memorySize'] / (1024*1024)
48
50
  stats[:usedCPU] += x['summary.quickStats.overallCpuUsage'] || 0
@@ -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
 
@@ -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,7 +6,7 @@
5
6
  # then set the +CURL+ environment variable to point to it.
6
7
  # @todo Use an HTTP library instead of executing +curl+.
7
8
  class RbVmomi::VIM::Datastore
8
- CURLBIN = ENV['CURL'] || "curl" #@private
9
+ CURLBIN = ENV['CURL'] || 'curl' #@private
9
10
 
10
11
  # Check whether a file exists on this datastore.
11
12
  # @param path [String] Path on the datastore.
@@ -19,7 +20,7 @@ class RbVmomi::VIM::Datastore
19
20
  when Net::HTTPNotFound
20
21
  false
21
22
  else
22
- fail resp.inspect
23
+ raise resp.inspect
23
24
  end
24
25
  end
25
26
 
@@ -29,13 +30,13 @@ class RbVmomi::VIM::Datastore
29
30
  # @return [void]
30
31
  def download remote_path, local_path
31
32
  url = "http#{_connection.http.use_ssl? ? 's' : ''}://#{_connection.http.address}:#{_connection.http.port}#{mkuripath(remote_path)}"
32
- pid = spawn CURLBIN, "-k", '--noproxy', '*', '-f',
33
- "-o", local_path,
34
- "-b", _connection.cookie,
33
+ pid = spawn CURLBIN, '-k', '--noproxy', '*', '-f',
34
+ '-o', local_path,
35
+ '-b', _connection.cookie,
35
36
  url,
36
- :out => '/dev/null'
37
+ out: '/dev/null'
37
38
  Process.waitpid(pid, 0)
38
- fail "download failed" unless $?.success?
39
+ raise 'download failed' unless $?.success?
39
40
  end
40
41
 
41
42
  # Upload a file to this datastore.
@@ -44,29 +45,31 @@ class RbVmomi::VIM::Datastore
44
45
  # @return [void]
45
46
  def upload remote_path, local_path
46
47
  url = "http#{_connection.http.use_ssl? ? 's' : ''}://#{_connection.http.address}:#{_connection.http.port}#{mkuripath(remote_path)}"
47
- pid = spawn CURLBIN, "-k", '--noproxy', '*', '-f',
48
- "-T", local_path,
49
- "-b", _connection.cookie,
48
+ pid = spawn CURLBIN, '-k', '--noproxy', '*', '-f',
49
+ '-T', local_path,
50
+ '-b', _connection.cookie,
50
51
  url,
51
- :out => '/dev/null'
52
+ out: '/dev/null'
52
53
  Process.waitpid(pid, 0)
53
- fail "upload failed" unless $?.success?
54
+ raise 'upload failed' unless $?.success?
54
55
  end
55
56
 
56
57
  private
57
58
 
58
59
  def datacenter
59
60
  return @datacenter if @datacenter
61
+
60
62
  x = parent
61
63
  while not x.is_a? RbVmomi::VIM::Datacenter
62
64
  x = x.parent
63
65
  end
64
- fail unless x.is_a? RbVmomi::VIM::Datacenter
66
+ raise unless x.is_a? RbVmomi::VIM::Datacenter
67
+
65
68
  @datacenter = x
66
69
  end
67
70
 
68
71
  def mkuripath path
69
- datacenter_path_str = datacenter.path[1..-1].map{|elem| elem[1]}.join('/')
70
- "/folder/#{URI.escape path}?dcPath=#{URI.escape datacenter_path_str }&dsName=#{URI.escape name}"
72
+ datacenter_path_str = datacenter.path[1..-1].map{ |elem| elem[1] }.join('/')
73
+ "/folder/#{URI.encode_www_form_component path}?dcPath=#{URI.encode_www_form_component datacenter_path_str }&dsName=#{URI.encode_www_form_component name}"
71
74
  end
72
75
  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
 
@@ -34,14 +35,14 @@ class RbVmomi::VIM::DynamicTypeMgrAllTypeInfo
34
35
  end
35
36
 
36
37
  types = {}
37
- self.managedTypeInfo.each{|x| types.merge!(x.toRbvmomiTypeHash) }
38
- self.dataTypeInfo.each{|x| types.merge!(x.toRbvmomiTypeHash) }
38
+ self.managedTypeInfo.each{ |x| types.merge!(x.toRbvmomiTypeHash) }
39
+ self.dataTypeInfo.each{ |x| types.merge!(x.toRbvmomiTypeHash) }
39
40
 
40
- types.each do |k,t|
41
+ types.each do |k, t|
41
42
  id2name[t['type-id']] = k
42
43
  end
43
44
 
44
- types = Hash[types.map do |k,t|
45
+ types = Hash[types.map do |k, t|
45
46
  case t['kind']
46
47
  when 'data'
47
48
  t['wsdl_base'] = t['base-type-id'] ? id2name[t['base-type-id']] : 'DataObject'
@@ -57,7 +58,7 @@ class RbVmomi::VIM::DynamicTypeMgrAllTypeInfo
57
58
  x['wsdl_type'] = id2name[x['type-id-ref']]
58
59
  x.delete 'type-id-ref'
59
60
  end
60
- t['methods'].each do |mName,x|
61
+ t['methods'].each do |mName, x|
61
62
  if y = x['result']
62
63
  y['wsdl_type'] = id2name[y['type-id-ref']]
63
64
  #y.delete 'type-id-ref'
@@ -68,7 +69,7 @@ class RbVmomi::VIM::DynamicTypeMgrAllTypeInfo
68
69
  end
69
70
  end
70
71
  when 'enum'
71
- else fail
72
+ else raise
72
73
  end
73
74
  [k, t]
74
75
  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
 
@@ -11,9 +12,9 @@ class RbVmomi::VIM::DynamicTypeMgrDataTypeInfo
11
12
  'props' => self.property.map do |prop|
12
13
  {
13
14
  'name' => prop.name,
14
- 'type-id-ref' => prop.type.gsub("[]", ""),
15
+ 'type-id-ref' => prop.type.gsub('[]', ''),
15
16
  'is-array' => (prop.type =~ /\[\]$/) ? true : false,
16
- 'is-optional' => prop.annotation.find{|a| a.name == "optional"} ? true : false,
17
+ 'is-optional' => prop.annotation.find{ |a| a.name == 'optional' } ? true : false,
17
18
  'version-id-ref' => prop.version,
18
19
  }
19
20
  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
 
@@ -11,9 +12,9 @@ class RbVmomi::VIM::DynamicTypeMgrManagedTypeInfo
11
12
  'props' => self.property.map do |prop|
12
13
  {
13
14
  'name' => prop.name,
14
- 'type-id-ref' => prop.type.gsub("[]", ""),
15
+ 'type-id-ref' => prop.type.gsub('[]', ''),
15
16
  'is-array' => (prop.type =~ /\[\]$/) ? true : false,
16
- 'is-optional' => prop.annotation.find{|a| a.name == "optional"} ? true : false,
17
+ 'is-optional' => prop.annotation.find{ |a| a.name == 'optional' } ? true : false,
17
18
  'version-id-ref' => prop.version,
18
19
  }
19
20
  end,
@@ -26,9 +27,9 @@ class RbVmomi::VIM::DynamicTypeMgrManagedTypeInfo
26
27
  'params' => method.paramTypeInfo.map do |param|
27
28
  {
28
29
  'name' => param.name,
29
- 'type-id-ref' => param.type.gsub("[]", ""),
30
+ 'type-id-ref' => param.type.gsub('[]', ''),
30
31
  'is-array' => (param.type =~ /\[\]$/) ? true : false,
31
- 'is-optional' => param.annotation.find{|a| a.name == "optional"} ? true : false,
32
+ 'is-optional' => param.annotation.find{ |a| a.name == 'optional' } ? true : false,
32
33
  'version-id-ref' => param.version,
33
34
  }
34
35
  end,
@@ -38,9 +39,9 @@ class RbVmomi::VIM::DynamicTypeMgrManagedTypeInfo
38
39
  else
39
40
  {
40
41
  'name' => result.name,
41
- 'type-id-ref' => result.type.gsub("[]", ""),
42
+ 'type-id-ref' => result.type.gsub('[]', ''),
42
43
  'is-array' => (result.type =~ /\[\]$/) ? true : false,
43
- 'is-optional' => result.annotation.find{|a| a.name == "optional"} ? true : false,
44
+ 'is-optional' => result.annotation.find{ |a| a.name == 'optional' } ? true : false,
44
45
  'version-id-ref' => result.version,
45
46
  }
46
47
  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
 
@@ -7,7 +8,7 @@ class RbVmomi::VIM::Folder
7
8
  # @param type [Class] Return nil unless the found entity <tt>is_a? type</tt>.
8
9
  # @return [VIM::ManagedEntity]
9
10
  def find name, type=Object
10
- x = _connection.searchIndex.FindChild(:entity => self, :name => name)
11
+ x = _connection.searchIndex.FindChild(entity: self, name: name)
11
12
  x if x.is_a? type
12
13
  end
13
14
 
@@ -18,8 +19,8 @@ class RbVmomi::VIM::Folder
18
19
  # @return [VIM::ManagedEntity]
19
20
  def findByDnsName name, type=RbVmomi::VIM::VirtualMachine, dc=nil
20
21
  propSpecs = {
21
- :entity => self, :dnsName => name,
22
- :vmSearch => type == RbVmomi::VIM::VirtualMachine
22
+ entity: self, dnsName: name,
23
+ vmSearch: type == RbVmomi::VIM::VirtualMachine
23
24
  }
24
25
  propSpecs[:datacenter] = dc if dc
25
26
  x = _connection.searchIndex.FindByDnsName(propSpecs)
@@ -33,8 +34,8 @@ class RbVmomi::VIM::Folder
33
34
  # @return [VIM::ManagedEntity]
34
35
  def findByIp ip, type=RbVmomi::VIM::VirtualMachine, dc=nil
35
36
  propSpecs = {
36
- :entity => self, :ip => ip,
37
- :vmSearch => type == RbVmomi::VIM::VirtualMachine
37
+ entity: self, ip: ip,
38
+ vmSearch: type == RbVmomi::VIM::VirtualMachine
38
39
  }
39
40
  propSpecs[:datacenter] = dc if dc
40
41
  x = _connection.searchIndex.FindByIp(propSpecs)
@@ -50,10 +51,10 @@ class RbVmomi::VIM::Folder
50
51
  # @return [VIM::ManagedEntity]
51
52
  def findByUuid(uuid, type = RbVmomi::VIM::VirtualMachine, dc = nil, instance_uuid = false)
52
53
  prop_specs = {
53
- :entity => self,
54
- :instanceUuid => instance_uuid,
55
- :uuid => uuid,
56
- :vmSearch => type == RbVmomi::VIM::VirtualMachine
54
+ entity: self,
55
+ instanceUuid: instance_uuid,
56
+ uuid: uuid,
57
+ vmSearch: type == RbVmomi::VIM::VirtualMachine
57
58
  }
58
59
  prop_specs[:datacenter] = dc if dc
59
60
  x = _connection.searchIndex.FindByUuid(prop_specs)
@@ -65,7 +66,7 @@ class RbVmomi::VIM::Folder
65
66
  # @return [VIM::ManagedEntity]
66
67
  def findByInventoryPath path
67
68
  propSpecs = {
68
- :entity => self, :inventoryPath => path
69
+ entity: self, inventoryPath: path
69
70
  }
70
71
  _connection.searchIndex.FindByInventoryPath(propSpecs)
71
72
  end
@@ -88,21 +89,22 @@ class RbVmomi::VIM::Folder
88
89
  elsif path.is_a? Enumerable
89
90
  es = path
90
91
  else
91
- fail "unexpected path class #{path.class}"
92
+ raise "unexpected path class #{path.class}"
92
93
  end
93
94
  return self if es.empty?
95
+
94
96
  final = es.pop
95
97
 
96
- p = es.inject(self) do |f,e|
97
- f.find(e, RbVmomi::VIM::Folder) || (create && f.CreateFolder(:name => e)) || return
98
+ p = es.inject(self) do |f, e|
99
+ f.find(e, RbVmomi::VIM::Folder) || (create && f.CreateFolder(name: e)) || return
98
100
  end
99
101
 
100
102
  if x = p.find(final, type)
101
103
  x
102
104
  elsif create and type == RbVmomi::VIM::Folder
103
- p.CreateFolder(:name => final)
105
+ p.CreateFolder(name: final)
104
106
  elsif create and type == RbVmomi::VIM::Datacenter
105
- p.CreateDatacenter(:name => final)
107
+ p.CreateDatacenter(name: final)
106
108
  else
107
109
  nil
108
110
  end
@@ -123,48 +125,49 @@ class RbVmomi::VIM::Folder
123
125
  #
124
126
  # @return [Hash] Hash of ManagedObjects to properties.
125
127
  def inventory_flat propSpecs={}
126
- propSet = [{ :type => 'Folder', :pathSet => ['name', 'parent', 'childEntity'] }]
127
- propSpecs.each do |k,v|
128
+ propSet = [{ type: 'Folder', pathSet: ['name', 'parent', 'childEntity'] }]
129
+ propSpecs.each do |k, v|
128
130
  case k
129
131
  when Class
130
- fail "key must be a subclass of ManagedEntity" unless k < RbVmomi::VIM::ManagedEntity
132
+ raise 'key must be a subclass of ManagedEntity' unless k < RbVmomi::VIM::ManagedEntity
133
+
131
134
  k = k.wsdl_name
132
135
  when Symbol, String
133
136
  k = k.to_s
134
137
  else
135
- fail "invalid key"
138
+ raise 'invalid key'
136
139
  end
137
140
 
138
- h = { :type => k }
141
+ h = { type: k }
139
142
  if v == :all
140
143
  h[:all] = true
141
144
  elsif v.is_a? Array
142
145
  h[:pathSet] = v + %w(parent)
143
146
  else
144
- fail "value must be an array of property paths or :all"
147
+ raise 'value must be an array of property paths or :all'
145
148
  end
146
149
  propSet << h
147
150
  end
148
151
 
149
152
  filterSpec = RbVmomi::VIM.PropertyFilterSpec(
150
- :objectSet => [
151
- :obj => self,
152
- :selectSet => [
153
+ objectSet: [
154
+ obj: self,
155
+ selectSet: [
153
156
  RbVmomi::VIM.TraversalSpec(
154
- :name => 'tsFolder',
155
- :type => 'Folder',
156
- :path => 'childEntity',
157
- :skip => false,
158
- :selectSet => [
159
- RbVmomi::VIM.SelectionSpec(:name => 'tsFolder')
157
+ name: 'tsFolder',
158
+ type: 'Folder',
159
+ path: 'childEntity',
160
+ skip: false,
161
+ selectSet: [
162
+ RbVmomi::VIM.SelectionSpec(name: 'tsFolder')
160
163
  ]
161
164
  )
162
165
  ]
163
166
  ],
164
- :propSet => propSet
167
+ propSet: propSet
165
168
  )
166
169
 
167
- result = _connection.propertyCollector.RetrieveProperties(:specSet => [filterSpec])
170
+ result = _connection.propertyCollector.RetrieveProperties(specSet: [filterSpec])
168
171
  {}.tap do |h|
169
172
  result.each { |r| h[r.obj] = r }
170
173
  end
@@ -203,8 +206,9 @@ class RbVmomi::VIM::Folder
203
206
  def inventory propSpecs={}
204
207
  inv = inventory_flat propSpecs
205
208
  tree = { self => {} }
206
- inv.each do |obj,x|
209
+ inv.each do |obj, x|
207
210
  next if obj == self
211
+
208
212
  h = Hash[x.propSet.map { |y| [y.name, y.val] }]
209
213
  tree[h['parent']][h['name']] = [obj, h]
210
214
  tree[obj] = {} if obj.is_a? RbVmomi::VIM::Folder