rbvmomi 1.6.0 → 1.8.0

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.
data/Rakefile CHANGED
@@ -30,16 +30,16 @@ end
30
30
 
31
31
  YARD::Rake::YardocTask.new
32
32
 
33
- begin
34
- require 'rcov/rcovtask'
35
- desc 'Measures test coverage using rcov'
36
- Rcov::RcovTask.new do |rcov|
37
- rcov.pattern = 'test/test_*.rb'
38
- rcov.output_dir = 'coverage'
39
- rcov.verbose = true
40
- rcov.libs << "test"
41
- rcov.rcov_opts << '--exclude "gems/*"'
42
- end
43
- rescue LoadError
44
- puts "Rcov not available. Install it with: gem install rcov"
45
- end
33
+ #begin
34
+ # require 'rcov/rcovtask'
35
+ # desc 'Measures test coverage using rcov'
36
+ # Rcov::RcovTask.new do |rcov|
37
+ # rcov.pattern = 'test/test_*.rb'
38
+ # rcov.output_dir = 'coverage'
39
+ # rcov.verbose = true
40
+ # rcov.libs << "test"
41
+ # rcov.rcov_opts << '--exclude "gems/*"'
42
+ # end
43
+ #rescue LoadError
44
+ # puts "Rcov not available. Install it with: gem install rcov"
45
+ #end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.0
1
+ 1.8.0
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'nokogiri'
3
-
3
+ require 'pp'
4
4
  # :usage => analyze-vim-declarations.rb vim-declarations.xml foo-declarations.xml vmodl.db
5
5
 
6
6
  XML_FNS = ARGV[0...-1]
@@ -28,6 +28,7 @@ ID2NAME.merge!({
28
28
  'vmodl.DateTime' => 'xsd:dateTime',
29
29
  'vmodl.Binary' => 'xsd:base64Binary',
30
30
  'vmodl.Any' => 'xsd:anyType',
31
+ 'vmodl.URI' => 'xsd:anyURI',
31
32
  'void' => nil,
32
33
  })
33
34
 
@@ -129,7 +130,9 @@ end
129
130
 
130
131
  XML_FNS.each do |fn|
131
132
  puts "parsing #{fn} ..."
132
- xml = Nokogiri.parse(File.read(fn), nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS)
133
+ xml_str = File.read(fn)
134
+ xml_str = xml_str.gsub(/\<description-html\>(.*?)\<\/description-html\>/m, "")
135
+ xml = Nokogiri.parse(xml_str, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS)
133
136
  xml.root.at('enums').children.each { |x| handle_enum x }
134
137
  xml.root.at('managed-objects').children.each { |x| handle_managed_object x }
135
138
  xml.root.at('data-objects').children.each { |x| handle_data_object x }
@@ -137,6 +140,8 @@ XML_FNS.each do |fn|
137
140
  #xml.root.at('definitions').at('version-types').children.each { |x| handle_version x }
138
141
  end
139
142
 
143
+ #pp ID2NAME
144
+
140
145
  munge_fault = lambda { |x| true }
141
146
 
142
147
  TYPES.each do |k,t|
@@ -159,12 +164,20 @@ TYPES.each do |k,t|
159
164
  end
160
165
  t['methods'].each do |mName,x|
161
166
  if y = x['result']
162
- y['wsdl_type'] = ID2NAME[y['type-id-ref']]
167
+ begin
168
+ y['wsdl_type'] = ID2NAME[y['type-id-ref']]
169
+ rescue Exception => ex
170
+ pp ex
171
+ end
163
172
  y.delete 'type-id-ref'
164
173
  munge_fault[y]
165
174
  end
166
175
  x['params'].each do |r|
167
- r['wsdl_type'] = ID2NAME[r['type-id-ref']]
176
+ begin
177
+ r['wsdl_type'] = ID2NAME[r['type-id-ref']]
178
+ rescue Exception => ex
179
+ pp ex
180
+ end
168
181
  r.delete 'type-id-ref'
169
182
  munge_fault[r]
170
183
  end
@@ -46,7 +46,7 @@ internal_vmodl = File.open(internal_vmodl_filename, 'r') { |io| Marshal.load io
46
46
 
47
47
  TYPES.each do |k|
48
48
  puts "Merging in #{k}"
49
- fail unless internal_vmodl.member? k
49
+ fail "Couldn't find type #{k} in internal VMODL" unless internal_vmodl.member? k
50
50
  public_vmodl[k] = internal_vmodl[k]
51
51
  end
52
52
 
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ # Manually merge two versions of vmodl.db
3
+
4
+ public_vmodl_filename = ARGV[0] or abort "public vmodl filename required"
5
+ internal_vmodl_filename = ARGV[1] or abort "internal vmodl filename required"
6
+ output_vmodl_filename = ARGV[2] or abort "output vmodl filename required"
7
+
8
+ public_vmodl = File.open(public_vmodl_filename, 'r') { |io| Marshal.load io }
9
+ internal_vmodl = File.open(internal_vmodl_filename, 'r') { |io| Marshal.load io }
10
+
11
+ db = {}
12
+ tn = {}
13
+ public_vmodl.each do |k,v|
14
+ unless k == '_typenames'
15
+ db[k] = v
16
+ else
17
+ tn['_typenames'] = v
18
+ end
19
+ end
20
+
21
+ internal_vmodl.each do |k, v|
22
+ unless k == '_typenames'
23
+ db[k] = v unless db[k]
24
+ else
25
+ tn['_typenames'] = tn['_typenames'] + v
26
+ end
27
+ end
28
+
29
+ db['_typenames'] = tn
30
+
31
+
32
+ File.open(output_vmodl_filename, 'w') { |io| Marshal.dump db, io }
@@ -9,7 +9,7 @@ BUILTIN = Set.new %w(ManagedObject DataObject TypeName PropertyPath ManagedObjec
9
9
 
10
10
  class Base
11
11
  class << self
12
- attr_reader :wsdl_name
12
+ attr_accessor :wsdl_name
13
13
 
14
14
  def init wsdl_name=self.name
15
15
  @wsdl_name = wsdl_name
@@ -185,7 +185,9 @@ class ManagedObject < ObjectWithMethods
185
185
  :objectSet => [{ :obj => self }],
186
186
  }])[0]
187
187
 
188
- if ret.propSet.empty?
188
+ if !ret
189
+ return nil
190
+ elsif ret.propSet.empty?
189
191
  return nil if ret.missingSet.empty?
190
192
  raise ret.missingSet[0].fault
191
193
  else
@@ -216,7 +218,9 @@ class ManagedObject < ObjectWithMethods
216
218
  end
217
219
 
218
220
  def == x
219
- x.class == self.class and x._ref == @ref
221
+ out = (x.class == self.class && x._ref == @ref)
222
+ out = (x._connection.instanceUuid == self._connection.instanceUuid) if out && x._connection.host
223
+ out
220
224
  end
221
225
 
222
226
  alias eql? ==
@@ -337,6 +341,18 @@ class ::Float
337
341
  def self.wsdl_name; 'xsd:float' end
338
342
  end
339
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
+
340
356
  class KeyValue
341
357
  def self.wsdl_name; 'KeyValue' end
342
358
  attr_accessor :key, :value
@@ -115,27 +115,29 @@ class Connection < TrivialSoap
115
115
  # hic sunt dracones
116
116
  def obj2xml xml, name, type, is_array, o, attrs={}
117
117
  expected = type(type)
118
- fail "expected array, got #{o.class.wsdl_name}" if is_array and not (o.is_a? Array or (o.is_a? Hash and expected == BasicTypes::KeyValue))
118
+ fail "expected array for '#{name}', got #{o.class.wsdl_name}" if is_array and not (o.is_a? Array or (o.is_a? Hash and expected == BasicTypes::KeyValue))
119
119
  case o
120
120
  when Array, BasicTypes::KeyValue
121
121
  if o.is_a? BasicTypes::KeyValue and expected != BasicTypes::KeyValue
122
- fail "expected #{expected.wsdl_name}, got KeyValue"
122
+ fail "expected #{expected.wsdl_name} for '#{name}', got KeyValue"
123
123
  elsif expected == BasicTypes::KeyValue and not is_array
124
124
  xml.tag! name, attrs do
125
125
  xml.tag! 'key', o[0].to_s
126
126
  xml.tag! 'value', o[1].to_s
127
127
  end
128
128
  else
129
- fail "expected #{expected.wsdl_name}, got array" unless is_array
129
+ fail "expected #{expected.wsdl_name} for '#{name}', got array" unless is_array
130
130
  o.each do |e|
131
131
  obj2xml xml, name, expected.wsdl_name, false, e, attrs
132
132
  end
133
133
  end
134
134
  when BasicTypes::ManagedObject
135
- fail "expected #{expected.wsdl_name}, got #{o.class.wsdl_name} for field #{name.inspect}" if expected and not expected >= o.class and not expected == BasicTypes::AnyType
135
+ fail "expected #{expected.wsdl_name} for '#{name}', got #{o.class.wsdl_name} for field #{name.inspect}" if expected and not expected >= o.class and not expected == BasicTypes::AnyType
136
136
  xml.tag! name, o._ref, :type => o.class.wsdl_name
137
137
  when BasicTypes::DataObject
138
- fail "expected #{expected.wsdl_name}, got #{o.class.wsdl_name} for field #{name.inspect}" if expected and not expected >= o.class and not expected == BasicTypes::AnyType
138
+ if expected and not expected >= o.class and not expected == BasicTypes::AnyType
139
+ fail "expected #{expected.wsdl_name} for '#{name}', got #{o.class.wsdl_name} for field #{name.inspect}"
140
+ end
139
141
  xml.tag! name, attrs.merge("xsi:type" => o.class.wsdl_name) do
140
142
  o.class.full_props_desc.each do |desc|
141
143
  if o.props.member? desc['name'].to_sym
@@ -151,11 +153,11 @@ class Connection < TrivialSoap
151
153
  if expected == BasicTypes::KeyValue and is_array
152
154
  obj2xml xml, name, type, is_array, o.to_a, attrs
153
155
  else
154
- fail "expected #{expected.wsdl_name}, got a hash" unless expected <= BasicTypes::DataObject
156
+ fail "expected #{expected.wsdl_name} for '#{name}', got a hash" unless expected <= BasicTypes::DataObject
155
157
  obj2xml xml, name, type, false, expected.new(o), attrs
156
158
  end
157
159
  when true, false
158
- fail "expected #{expected.wsdl_name}, got a boolean" unless [BasicTypes::Boolean, BasicTypes::AnyType].member? expected
160
+ fail "expected #{expected.wsdl_name} for '#{name}', got a boolean" unless [BasicTypes::Boolean, BasicTypes::AnyType].member? expected
159
161
  attrs['xsi:type'] = 'xsd:boolean' if expected == BasicTypes::AnyType
160
162
  xml.tag! name, (o ? '1' : '0'), attrs
161
163
  when Symbol, String
@@ -178,7 +180,10 @@ class Connection < TrivialSoap
178
180
  when Time
179
181
  attrs['xsi:type'] = 'xsd:dateTime' if expected == BasicTypes::AnyType
180
182
  xml.tag! name, o.iso8601, attrs
181
- else fail "unexpected object class #{o.class}"
183
+ when BasicTypes::Int
184
+ attrs['xsi:type'] = 'xsd:int'
185
+ xml.tag! name, o.to_s, attrs
186
+ else fail "unexpected object class #{o.class} for '#{name}'"
182
187
  end
183
188
  xml
184
189
  rescue
@@ -200,6 +205,11 @@ class Connection < TrivialSoap
200
205
  when :base64Binary then BasicTypes::Binary
201
206
  when :KeyValue then BasicTypes::KeyValue
202
207
  else
208
+ first_char = name[0].chr
209
+ if first_char.downcase == first_char
210
+ name = "%s%s" % [first_char.upcase, name[1..-1]]
211
+ end
212
+
203
213
  if @loader.has? name
204
214
  const_get(name)
205
215
  else
@@ -211,6 +221,10 @@ class Connection < TrivialSoap
211
221
  def type name
212
222
  self.class.type name
213
223
  end
224
+
225
+ def instanceUuid
226
+ nil
227
+ end
214
228
 
215
229
  def self.extension_dirs
216
230
  @extension_dirs ||= []
@@ -64,12 +64,18 @@ class NewDeserializer
64
64
  else fail
65
65
  end
66
66
  else
67
+ if type =~ /:/
68
+ type = type.split(":", 2)[1]
69
+ end
67
70
  if type =~ /^ArrayOf/
68
71
  type = DEMANGLED_ARRAY_TYPES[$'] || $'
69
72
  return node.children.select(&:element?).map { |c| deserialize c, type }
70
73
  end
74
+ if type =~ /:/
75
+ type = type.split(":", 2)[1]
76
+ end
71
77
 
72
- klass = @loader.get(type) or fail "no such type #{type}"
78
+ klass = @loader.get(type) or fail "no such type '#{type}'"
73
79
  case klass.kind
74
80
  when :data
75
81
  traverse_data node, klass
@@ -226,7 +232,7 @@ class OldDeserializer
226
232
  end
227
233
  end
228
234
 
229
- if ENV['RBVMOMI_NEW_DESERIALIZER'] == '1'
235
+ if ENV['RBVMOMI_NEW_DESERIALIZER'] == '1' || true # Always use new one now
230
236
  Deserializer = NewDeserializer
231
237
  else
232
238
  Deserializer = OldDeserializer
@@ -0,0 +1,66 @@
1
+ # Copyright (c) 2012 VMware, Inc. All Rights Reserved.
2
+ require 'rbvmomi'
3
+
4
+ module RbVmomi
5
+
6
+ # A connection to one vSphere ProfileBasedManagement endpoint.
7
+ # @see #serviceInstance
8
+ class PBM < Connection
9
+ # Connect to a vSphere ProfileBasedManagement endpoint
10
+ #
11
+ # @param [VIM] Connection to main vSphere API endpoint
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] :path (/pbm/sdk) SDK endpoint path.
18
+ # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
19
+ def self.connect vim, opts = {}
20
+ fail unless opts.is_a? Hash
21
+ opts[:host] = vim.host
22
+ opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
23
+ opts[:insecure] ||= false
24
+ opts[:port] ||= (opts[:ssl] ? 443 : 80)
25
+ opts[:path] ||= '/pbm/sdk'
26
+ opts[:ns] ||= 'urn:pbm'
27
+ rev_given = opts[:rev] != nil
28
+ opts[:rev] = '1.0' unless rev_given
29
+ opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
30
+
31
+ new(opts).tap do |pbm|
32
+ pbm.vcSessionCookie = vim.cookie.split('"')[1]
33
+ end
34
+ end
35
+
36
+ def vcSessionCookie= cookie
37
+ @vcSessionCookie = cookie
38
+ end
39
+
40
+ def rev= x
41
+ super
42
+ @serviceContent = nil
43
+ end
44
+
45
+ # Return the ServiceInstance
46
+ #
47
+ # The ServiceInstance is the root of the vSphere inventory.
48
+ def serviceInstance
49
+ @serviceInstance ||= VIM::PbmServiceInstance self, 'ServiceInstance'
50
+ end
51
+
52
+ # Alias to serviceInstance.PbmRetrieveServiceContent
53
+ def serviceContent
54
+ @serviceContent ||= serviceInstance.PbmRetrieveServiceContent
55
+ end
56
+
57
+ # @private
58
+ def pretty_print pp
59
+ pp.text "PBM(#{@opts[:host]})"
60
+ end
61
+
62
+ add_extension_dir File.join(File.dirname(__FILE__), "pbm")
63
+ load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.db"))
64
+ end
65
+
66
+ end
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2013 VMware, Inc. All Rights Reserved.
2
+ require 'rbvmomi'
3
+ module RbVmomi
4
+
5
+ # A connection to one vSphere SMS endpoint.
6
+ # @see #serviceInstance
7
+ class SMS < Connection
8
+ # Connect to a vSphere SMS endpoint
9
+ #
10
+ # @param [VIM] Connection to main vSphere API endpoint
11
+ # @param [Hash] opts The options hash.
12
+ # @option opts [String] :host Host to connect to.
13
+ # @option opts [Numeric] :port (443) Port to connect to.
14
+ # @option opts [Boolean] :ssl (true) Whether to use SSL.
15
+ # @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors.
16
+ # @option opts [String] :path (/sms/sdk) SDK endpoint path.
17
+ # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
18
+ def self.connect vim, opts = {}
19
+ fail unless opts.is_a? Hash
20
+ opts[:host] = vim.host
21
+ opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
22
+ opts[:insecure] ||= true
23
+ opts[:port] ||= (opts[:ssl] ? 443 : 80)
24
+ opts[:path] ||= '/sms/sdk'
25
+ opts[:ns] ||= 'urn:sms'
26
+ rev_given = opts[:rev] != nil
27
+ opts[:rev] = '4.0' unless rev_given
28
+ opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
29
+
30
+ new(opts).tap do |sms|
31
+ sms.vcSessionCookie = vim.cookie.split('"')[1]
32
+ end
33
+ end
34
+
35
+ def vcSessionCookie= cookie
36
+ @vcSessionCookie = cookie
37
+ end
38
+
39
+ def rev= x
40
+ super
41
+ @serviceContent = nil
42
+ end
43
+
44
+ # Return the ServiceInstance
45
+ #
46
+ # The ServiceInstance is the root of the vSphere inventory.
47
+ def serviceInstance
48
+ @serviceInstance ||= VIM::SmsServiceInstance self, 'ServiceInstance'
49
+ end
50
+
51
+ # @private
52
+ def pretty_print pp
53
+ pp.text "SMS(#{@opts[:host]})"
54
+ end
55
+
56
+ add_extension_dir File.join(File.dirname(__FILE__), "sms")
57
+ load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.db"))
58
+ end
59
+
60
+ end
61
+
@@ -0,0 +1,7 @@
1
+ class RbVmomi::SMS::SmsStorageManager
2
+
3
+ def RegisterProvider_Task2 providerSpec
4
+ self.RegisterProvider_Task providerSpec
5
+ end
6
+
7
+ end
@@ -14,7 +14,7 @@ class RbVmomi::TrivialSoap
14
14
  @opts = opts
15
15
  return unless @opts[:host] # for testcases
16
16
  @debug = @opts[:debug]
17
- @cookie = nil
17
+ @cookie = @opts[:cookie]
18
18
  @lock = Mutex.new
19
19
  @http = nil
20
20
  restart_http
@@ -62,6 +62,11 @@ class RbVmomi::TrivialSoap
62
62
  xsi = 'http://www.w3.org/2001/XMLSchema-instance'
63
63
  xml = Builder::XmlMarkup.new :indent => 0
64
64
  xml.tag!('env:Envelope', 'xmlns:xsd' => xsd, 'xmlns:env' => env, 'xmlns:xsi' => xsi) do
65
+ if @vcSessionCookie
66
+ xml.tag!('env:Header') do
67
+ xml.tag!('vcSessionCookie', @vcSessionCookie)
68
+ end
69
+ end
65
70
  xml.tag!('env:Body') do
66
71
  yield xml if block_given?
67
72
  end