vagrant-rbvmomi 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +6 -0
  3. data/LICENSE +19 -0
  4. data/README.rdoc +78 -0
  5. data/Rakefile +31 -0
  6. data/VERSION +1 -0
  7. data/bin/rbvmomish +138 -0
  8. data/devel/analyze-vim-declarations.rb +213 -0
  9. data/devel/analyze-xml.rb +46 -0
  10. data/devel/benchmark.rb +117 -0
  11. data/devel/collisions.rb +18 -0
  12. data/devel/merge-internal-vmodl.rb +59 -0
  13. data/devel/merge-manual-vmodl.rb +32 -0
  14. data/examples/annotate.rb +54 -0
  15. data/examples/cached_ovf_deploy.rb +120 -0
  16. data/examples/clone_vm.rb +84 -0
  17. data/examples/create_vm-1.9.rb +93 -0
  18. data/examples/create_vm.rb +93 -0
  19. data/examples/extraConfig.rb +54 -0
  20. data/examples/lease_tool.rb +102 -0
  21. data/examples/logbundle.rb +63 -0
  22. data/examples/logtail.rb +60 -0
  23. data/examples/nfs_datastore.rb +95 -0
  24. data/examples/power.rb +59 -0
  25. data/examples/readme-1.rb +35 -0
  26. data/examples/readme-2.rb +51 -0
  27. data/examples/run.sh +41 -0
  28. data/examples/screenshot.rb +48 -0
  29. data/examples/vdf.rb +81 -0
  30. data/examples/vm_drs_behavior.rb +76 -0
  31. data/lib/rbvmomi.rb +12 -0
  32. data/lib/rbvmomi/basic_types.rb +375 -0
  33. data/lib/rbvmomi/connection.rb +270 -0
  34. data/lib/rbvmomi/deserialization.rb +248 -0
  35. data/lib/rbvmomi/fault.rb +17 -0
  36. data/lib/rbvmomi/pbm.rb +66 -0
  37. data/lib/rbvmomi/sms.rb +61 -0
  38. data/lib/rbvmomi/sms/SmsStorageManager.rb +7 -0
  39. data/lib/rbvmomi/trivial_soap.rb +114 -0
  40. data/lib/rbvmomi/trollop.rb +70 -0
  41. data/lib/rbvmomi/type_loader.rb +136 -0
  42. data/lib/rbvmomi/utils/admission_control.rb +398 -0
  43. data/lib/rbvmomi/utils/deploy.rb +336 -0
  44. data/lib/rbvmomi/utils/leases.rb +142 -0
  45. data/lib/rbvmomi/utils/perfdump.rb +628 -0
  46. data/lib/rbvmomi/vim.rb +128 -0
  47. data/lib/rbvmomi/vim/ComputeResource.rb +51 -0
  48. data/lib/rbvmomi/vim/Datacenter.rb +17 -0
  49. data/lib/rbvmomi/vim/Datastore.rb +68 -0
  50. data/lib/rbvmomi/vim/DynamicTypeMgrAllTypeInfo.rb +75 -0
  51. data/lib/rbvmomi/vim/DynamicTypeMgrDataTypeInfo.rb +20 -0
  52. data/lib/rbvmomi/vim/DynamicTypeMgrManagedTypeInfo.rb +46 -0
  53. data/lib/rbvmomi/vim/Folder.rb +207 -0
  54. data/lib/rbvmomi/vim/HostSystem.rb +174 -0
  55. data/lib/rbvmomi/vim/ManagedEntity.rb +57 -0
  56. data/lib/rbvmomi/vim/ManagedObject.rb +60 -0
  57. data/lib/rbvmomi/vim/ObjectContent.rb +23 -0
  58. data/lib/rbvmomi/vim/ObjectUpdate.rb +23 -0
  59. data/lib/rbvmomi/vim/OvfManager.rb +200 -0
  60. data/lib/rbvmomi/vim/PerfCounterInfo.rb +26 -0
  61. data/lib/rbvmomi/vim/PerformanceManager.rb +110 -0
  62. data/lib/rbvmomi/vim/PropertyCollector.rb +25 -0
  63. data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +30 -0
  64. data/lib/rbvmomi/vim/ResourcePool.rb +55 -0
  65. data/lib/rbvmomi/vim/ServiceInstance.rb +55 -0
  66. data/lib/rbvmomi/vim/Task.rb +65 -0
  67. data/lib/rbvmomi/vim/VirtualMachine.rb +74 -0
  68. data/test/test_deserialization.rb +383 -0
  69. data/test/test_emit_request.rb +128 -0
  70. data/test/test_exceptions.rb +14 -0
  71. data/test/test_helper.rb +14 -0
  72. data/test/test_misc.rb +24 -0
  73. data/test/test_parse_response.rb +69 -0
  74. data/test/test_serialization.rb +311 -0
  75. data/vmodl.db +0 -0
  76. metadata +163 -0
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ require 'trollop'
3
+ require 'rbvmomi'
4
+ require 'rbvmomi/trollop'
5
+
6
+ VIM = RbVmomi::VIM
7
+ CMDS = %w(get set)
8
+ BEHAVIOR = %w(fullyAutomated manual partiallyAutomated default)
9
+
10
+ opts = Trollop.options do
11
+ banner <<-EOS
12
+ Configure VM DRS behavior.
13
+
14
+ Usage:
15
+ vm_drs_behavior.rb [options] VM get
16
+ vm_drs_behavior.rb [options] VM set #{BEHAVIOR.join('|')}
17
+
18
+ Commands: #{CMDS * ' '}
19
+
20
+ VIM connection options:
21
+ EOS
22
+
23
+ rbvmomi_connection_opts
24
+
25
+ text <<-EOS
26
+
27
+ VM location options:
28
+ EOS
29
+
30
+ rbvmomi_datacenter_opt
31
+
32
+ text <<-EOS
33
+
34
+ Other options:
35
+ EOS
36
+
37
+ stop_on CMDS
38
+ end
39
+
40
+ Trollop.die("must specify host") unless opts[:host]
41
+
42
+ vm_name = ARGV[0] or Trollop.die("no VM name given")
43
+ cmd = ARGV[1] or Trollop.die("no command given")
44
+ abort "invalid command" unless CMDS.member? cmd
45
+
46
+ vim = VIM.connect opts
47
+ dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
48
+ vm = dc.find_vm(vm_name) or abort "VM not found"
49
+
50
+ cluster = vm.runtime.host.parent
51
+ config = cluster.configurationEx.drsVmConfig.select {|c| c.key.name == vm.name }.first
52
+ default = cluster.configurationEx.drsConfig.defaultVmBehavior
53
+
54
+ case cmd
55
+ when 'get'
56
+ if config
57
+ behavior = config.behavior
58
+ else
59
+ behavior = "#{default} (default)"
60
+ end
61
+ puts "#{vm.name} is #{behavior}"
62
+ when 'set'
63
+ behavior = ARGV[2] or Trollop.die("no behavior given")
64
+ abort "invalid behavior" unless BEHAVIOR.member? behavior
65
+
66
+ if behavior == "default"
67
+ behavior = default
68
+ end
69
+ vm_spec =
70
+ VIM.ClusterDrsVmConfigSpec(:operation => VIM.ArrayUpdateOperation(config ? "edit" : "add"),
71
+ :info => VIM.ClusterDrsVmConfigInfo(:key => vm,
72
+ :behavior => VIM.DrsBehavior(behavior)))
73
+ spec = VIM.ClusterConfigSpecEx(:drsVmConfigSpec => [vm_spec])
74
+ cluster.ReconfigureComputeResource_Task(:spec => spec, :modify => true).wait_for_completion
75
+ end
76
+
@@ -0,0 +1,12 @@
1
+ # Copyright (c) 2010 VMware, Inc. All Rights Reserved.
2
+ module RbVmomi
3
+
4
+ # @private
5
+ # @deprecated Use +RbVmomi::VIM.connect+.
6
+ def self.connect opts
7
+ VIM.connect opts
8
+ end
9
+
10
+ end
11
+ require 'rbvmomi/connection'
12
+ require 'rbvmomi/vim'
@@ -0,0 +1,375 @@
1
+ # Copyright (c) 2010 VMware, Inc. All Rights Reserved.
2
+ require 'pp'
3
+ require 'set'
4
+
5
+ module RbVmomi
6
+ module BasicTypes
7
+
8
+ BUILTIN = Set.new %w(ManagedObject DataObject TypeName PropertyPath ManagedObjectReference MethodName MethodFault LocalizedMethodFault KeyValue)
9
+
10
+ class Base
11
+ class << self
12
+ attr_accessor :wsdl_name
13
+
14
+ def init wsdl_name=self.name
15
+ @wsdl_name = wsdl_name
16
+ end
17
+
18
+ def to_s
19
+ @wsdl_name
20
+ end
21
+ end
22
+
23
+ init
24
+ end
25
+
26
+ class ObjectWithProperties < Base
27
+ class << self
28
+ attr_accessor :props_desc
29
+
30
+ def init name=self.name, props=[]
31
+ super name
32
+ @props_desc = props
33
+ @props_desc.each do |d|
34
+ sym = d['name'].to_sym
35
+ define_method(sym) { _get_property sym }
36
+ define_method(:"#{sym}=") { |x| _set_property sym, x }
37
+ end
38
+ end
39
+
40
+ def full_props_set
41
+ @full_props_set ||= Set.new(full_props_desc.map { |x| x['name'] })
42
+ end
43
+
44
+ def full_props_desc
45
+ @full_props_desc ||= (self == ObjectWithProperties ? [] : superclass.full_props_desc) + props_desc
46
+ end
47
+
48
+ def find_prop_desc name
49
+ full_props_desc.find { |x| x['name'] == name.to_s }
50
+ end
51
+ end
52
+
53
+ def _get_property sym
54
+ fail 'unimplemented'
55
+ end
56
+
57
+ def _set_property sym, val
58
+ fail 'unimplemented'
59
+ end
60
+
61
+ init
62
+ end
63
+
64
+ class ObjectWithMethods < ObjectWithProperties
65
+ class << self
66
+ attr_accessor :methods_desc
67
+
68
+ def init name=self.name, props=[], methods={}
69
+ super name, props
70
+ @methods_desc = methods
71
+
72
+ @methods_desc.each do |k,d|
73
+ sym = k.to_sym
74
+ define_method(sym) { |*args| _call sym, *args }
75
+ define_method(:"#{sym}!") { |*args| _call sym, *args }
76
+ end
77
+ end
78
+
79
+ # XXX cache
80
+ def full_methods_desc
81
+ (self == ObjectWithMethods ? {} : superclass.full_methods_desc).merge methods_desc
82
+ end
83
+ end
84
+
85
+ init
86
+ end
87
+
88
+ class DataObject < ObjectWithProperties
89
+ attr_reader :props
90
+
91
+ def self.kind; :data end
92
+
93
+ def initialize props={}
94
+ # Deserialization fast path
95
+ if props == nil
96
+ @props = {}
97
+ return
98
+ end
99
+
100
+ @props = Hash[props.map { |k,v| [k.to_sym, v] }]
101
+ #self.class.full_props_desc.each do |desc|
102
+ #fail "missing required property #{desc['name'].inspect} of #{self.class.wsdl_name}" if @props[desc['name'].to_sym].nil? and not desc['is-optional']
103
+ #end
104
+ @props.each do |k,v|
105
+ fail "unexpected property name #{k}" unless self.class.find_prop_desc(k)
106
+ end
107
+ end
108
+
109
+ def initialize_copy(source)
110
+ super
111
+ @props = @props.dup
112
+ end
113
+
114
+ def _get_property sym
115
+ @props[sym]
116
+ end
117
+
118
+ def [] sym
119
+ _get_property sym
120
+ end
121
+
122
+ def _set_property sym, val
123
+ @props[sym] = val
124
+ end
125
+
126
+ def []= sym, val
127
+ _set_property sym, val
128
+ end
129
+
130
+ def == o
131
+ return false unless o.class == self.class
132
+ keys = (props.keys + o.props.keys).uniq
133
+ keys.all? { |k| props[k] == o.props[k] }
134
+ end
135
+
136
+ alias eql? ==
137
+
138
+ def hash
139
+ props.hash
140
+ end
141
+
142
+ def pretty_print q
143
+ q.text self.class.wsdl_name
144
+ q.group 2 do
145
+ q.text '('
146
+ q.breakable
147
+ props = @props.sort_by { |k,v| k.to_s }
148
+ q.seplist props, nil, :each do |e|
149
+ k, v = e
150
+ q.group do
151
+ q.text k.to_s
152
+ q.text ': '
153
+ q.pp v
154
+ end
155
+ end
156
+ end
157
+ q.breakable
158
+ q.text ')'
159
+ end
160
+
161
+ init
162
+ end
163
+
164
+ class ManagedObject < ObjectWithMethods
165
+ def self.kind; :managed end
166
+
167
+ def initialize connection, ref
168
+ super()
169
+ @connection = connection
170
+ @soap = @connection # XXX deprecated
171
+ @ref = ref
172
+ end
173
+
174
+ def _connection
175
+ @connection
176
+ end
177
+
178
+ def _ref
179
+ @ref
180
+ end
181
+
182
+ def _get_property sym
183
+ ret = @connection.propertyCollector.RetrieveProperties(:specSet => [{
184
+ :propSet => [{ :type => self.class.wsdl_name, :pathSet => [sym.to_s] }],
185
+ :objectSet => [{ :obj => self }],
186
+ }])[0]
187
+
188
+ if !ret
189
+ return nil
190
+ elsif ret.propSet.empty?
191
+ return nil if ret.missingSet.empty?
192
+ raise ret.missingSet[0].fault
193
+ else
194
+ ret.propSet[0].val
195
+ end
196
+ end
197
+
198
+ def _set_property sym, val
199
+ fail 'unimplemented'
200
+ end
201
+
202
+ def _call method, o={}
203
+ fail "parameters must be passed as a hash" unless o.is_a? Hash
204
+ desc = self.class.full_methods_desc[method.to_s] or fail "unknown method"
205
+ @connection.call method, desc, self, o
206
+ end
207
+
208
+ def to_s
209
+ "#{self.class.wsdl_name}(#{@ref.inspect})"
210
+ end
211
+
212
+ def pretty_print pp
213
+ pp.text to_s
214
+ end
215
+
216
+ def [] k
217
+ _get_property k
218
+ end
219
+
220
+ def == x
221
+ out = (x.class == self.class && x._ref == @ref)
222
+ out = (x._connection.instanceUuid == self._connection.instanceUuid) if out && x._connection.host
223
+ out
224
+ end
225
+
226
+ alias eql? ==
227
+
228
+ def hash
229
+ [self.class, @ref].hash
230
+ end
231
+
232
+ init 'ManagedObject'
233
+ end
234
+
235
+ class Enum < Base
236
+ class << self
237
+ attr_accessor :values
238
+
239
+ def init name=self.name, values=[]
240
+ super name
241
+ @values = values
242
+ end
243
+ end
244
+
245
+ def self.kind; :enum end
246
+
247
+ attr_reader :value
248
+
249
+ def initialize value
250
+ @value = value
251
+ end
252
+
253
+ init
254
+ end
255
+
256
+ class MethodFault < DataObject
257
+ init 'MethodFault', [
258
+ {
259
+ 'name' => 'faultCause',
260
+ 'wsdl_type' => 'LocalizedMethodFault',
261
+ 'is-array' => false,
262
+ 'is-optional' => true,
263
+ }, {
264
+ 'name' => 'faultMessage',
265
+ 'wsdl_type' => 'LocalizableMessage',
266
+ 'is-array' => true,
267
+ 'is-optional' => true,
268
+ },
269
+ ]
270
+
271
+ def self.=== exn
272
+ exn.class == RbVmomi::Fault and self <= exn.fault.class
273
+ end
274
+ end
275
+
276
+ class LocalizedMethodFault < DataObject
277
+ init 'LocalizedMethodFault', [
278
+ {
279
+ 'name' => 'fault',
280
+ 'wsdl_type' => 'MethodFault',
281
+ 'is-array' => false,
282
+ 'is-optional' => false,
283
+ }, {
284
+ 'name' => 'localizedMessage',
285
+ 'wsdl_type' => 'xsd:string',
286
+ 'is-array' => false,
287
+ 'is-optional' => true,
288
+ },
289
+ ]
290
+
291
+ def exception
292
+ RbVmomi::Fault.new(self.localizedMessage, self.fault)
293
+ end
294
+ end
295
+
296
+ class RuntimeFault < MethodFault
297
+ init
298
+ end
299
+
300
+ class MethodName < String
301
+ def self.wsdl_name; 'MethodName' end
302
+ end
303
+
304
+ class PropertyPath < String
305
+ def self.wsdl_name; 'PropertyPath' end
306
+ end
307
+
308
+ class TypeName < String
309
+ def self.wsdl_name; 'TypeName' end
310
+ end
311
+
312
+ class ManagedObjectReference
313
+ def self.wsdl_name; 'ManagedObjectReference' end
314
+ end
315
+
316
+ class Boolean
317
+ def self.wsdl_name; 'xsd:boolean' end
318
+ end
319
+
320
+ class AnyType
321
+ def self.wsdl_name; 'xsd:anyType' end
322
+ end
323
+
324
+ class Binary
325
+ def self.wsdl_name; 'xsd:base64Binary' end
326
+ end
327
+
328
+ class ::Class
329
+ def wsdl_name; self.class.name end
330
+ end
331
+
332
+ class ::String
333
+ def self.wsdl_name; 'xsd:string' end
334
+ end
335
+
336
+ class ::Integer
337
+ def self.wsdl_name; 'xsd:int' end
338
+ end
339
+
340
+ class ::Float
341
+ def self.wsdl_name; 'xsd:float' end
342
+ end
343
+
344
+ class Int
345
+ def self.wsdl_name; 'xsd:int' end
346
+
347
+ def initialize x
348
+ @val = x
349
+ end
350
+
351
+ def to_s
352
+ @val.to_s
353
+ end
354
+ end
355
+
356
+ class KeyValue
357
+ def self.wsdl_name; 'KeyValue' end
358
+ attr_accessor :key, :value
359
+
360
+ def initialize k, v
361
+ @key = k
362
+ @value = v
363
+ end
364
+
365
+ def [] i
366
+ if i == 0 then @key
367
+ elsif i == 1 then @value
368
+ else fail "invalid index #{i.inspect}"
369
+ end
370
+ end
371
+ end
372
+
373
+
374
+ end
375
+ end