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
data/lib/rbvmomi/pbm.rb CHANGED
@@ -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
 
@@ -7,62 +8,63 @@ module RbVmomi
7
8
 
8
9
  # A connection to one vSphere ProfileBasedManagement endpoint.
9
10
  # @see #serviceInstance
10
- class PBM < Connection
11
- # Connect to a vSphere ProfileBasedManagement endpoint
12
- #
13
- # @param [VIM] Connection to main vSphere API endpoint
14
- # @param [Hash] opts The options hash.
15
- # @option opts [String] :host Host to connect to.
16
- # @option opts [Numeric] :port (443) Port to connect to.
17
- # @option opts [Boolean] :ssl (true) Whether to use SSL.
18
- # @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors.
19
- # @option opts [String] :path (/pbm/sdk) SDK endpoint path.
20
- # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
21
- def self.connect vim, opts = {}
22
- fail unless opts.is_a? Hash
23
- opts[:host] = vim.host
24
- opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
25
- opts[:insecure] ||= false
26
- opts[:port] ||= (opts[:ssl] ? 443 : 80)
27
- opts[:path] ||= '/pbm/sdk'
28
- opts[:ns] ||= 'urn:pbm'
29
- rev_given = opts[:rev] != nil
30
- opts[:rev] = '1.0' unless rev_given
31
- opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
11
+ class PBM < Connection
12
+ # Connect to a vSphere ProfileBasedManagement endpoint
13
+ #
14
+ # @param [VIM] Connection to main vSphere API endpoint
15
+ # @param [Hash] opts The options hash.
16
+ # @option opts [String] :host Host to connect to.
17
+ # @option opts [Numeric] :port (443) Port to connect to.
18
+ # @option opts [Boolean] :ssl (true) Whether to use SSL.
19
+ # @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors.
20
+ # @option opts [String] :path (/pbm/sdk) SDK endpoint path.
21
+ # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
22
+ def self.connect vim, opts = {}
23
+ raise unless opts.is_a? Hash
32
24
 
33
- new(opts).tap do |pbm|
34
- pbm.vcSessionCookie = vim.cookie.split('"')[1]
25
+ opts[:host] = vim.host
26
+ opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
27
+ opts[:insecure] ||= false
28
+ opts[:port] ||= (opts[:ssl] ? 443 : 80)
29
+ opts[:path] ||= '/pbm/sdk'
30
+ opts[:ns] ||= 'urn:pbm'
31
+ rev_given = opts[:rev] != nil
32
+ opts[:rev] = '1.0' unless rev_given
33
+ opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
34
+
35
+ new(opts).tap do |pbm|
36
+ pbm.vcSessionCookie = vim.cookie.split('"')[1]
37
+ end
35
38
  end
36
- end
37
-
38
- def vcSessionCookie= cookie
39
- @vcSessionCookie = cookie
40
- end
41
39
 
42
- def rev= x
43
- super
44
- @serviceContent = nil
45
- end
40
+ def vcSessionCookie= cookie
41
+ @vcSessionCookie = cookie
42
+ end
46
43
 
47
- # Return the ServiceInstance
48
- #
49
- # The ServiceInstance is the root of the vSphere inventory.
50
- def serviceInstance
51
- @serviceInstance ||= VIM::PbmServiceInstance self, 'ServiceInstance'
52
- end
44
+ def rev= x
45
+ super
46
+ @serviceContent = nil
47
+ end
53
48
 
54
- # Alias to serviceInstance.PbmRetrieveServiceContent
55
- def serviceContent
56
- @serviceContent ||= serviceInstance.PbmRetrieveServiceContent
57
- end
49
+ # Return the ServiceInstance
50
+ #
51
+ # The ServiceInstance is the root of the vSphere inventory.
52
+ def serviceInstance
53
+ @serviceInstance ||= VIM::PbmServiceInstance self, 'ServiceInstance'
54
+ end
58
55
 
59
- # @private
60
- def pretty_print pp
61
- pp.text "PBM(#{@opts[:host]})"
62
- end
56
+ # Alias to serviceInstance.PbmRetrieveServiceContent
57
+ def serviceContent
58
+ @serviceContent ||= serviceInstance.PbmRetrieveServiceContent
59
+ end
63
60
 
64
- add_extension_dir File.join(File.dirname(__FILE__), "pbm")
65
- load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.db"))
66
- end
61
+ # @private
62
+ def pretty_print pp
63
+ pp.text "PBM(#{@opts[:host]})"
64
+ end
65
+
66
+ add_extension_dir File.join(File.dirname(__FILE__), 'pbm')
67
+ load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), '../../vmodl.db'))
68
+ end
67
69
 
68
70
  end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2013-2017 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
4
5
  class RbVmomi::SMS::SmsStorageManager
5
6
 
6
7
  def RegisterProvider_Task2 providerSpec
7
- self.RegisterProvider_Task providerSpec
8
+ self.RegisterProvider_Task providerSpec
8
9
  end
9
10
 
10
11
  end
data/lib/rbvmomi/sms.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Copyright (c) 2013-2017 VMware, Inc. All Rights Reserved.
2
3
  # SPDX-License-Identifier: MIT
3
4
 
@@ -6,58 +7,59 @@ module RbVmomi
6
7
 
7
8
  # A connection to one vSphere SMS endpoint.
8
9
  # @see #serviceInstance
9
- class SMS < Connection
10
- # Connect to a vSphere SMS endpoint
11
- #
12
- # @param [VIM] Connection to main vSphere API endpoint
13
- # @param [Hash] opts The options hash.
14
- # @option opts [String] :host Host to connect to.
15
- # @option opts [Numeric] :port (443) Port to connect to.
16
- # @option opts [Boolean] :ssl (true) Whether to use SSL.
17
- # @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors.
18
- # @option opts [String] :path (/sms/sdk) SDK endpoint path.
19
- # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
20
- def self.connect vim, opts = {}
21
- fail unless opts.is_a? Hash
22
- opts[:host] = vim.host
23
- opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
24
- opts[:insecure] ||= true
25
- opts[:port] ||= (opts[:ssl] ? 443 : 80)
26
- opts[:path] ||= '/sms/sdk'
27
- opts[:ns] ||= 'urn:sms'
28
- rev_given = opts[:rev] != nil
29
- opts[:rev] = '4.0' unless rev_given
30
- opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
31
-
32
- new(opts).tap do |sms|
33
- sms.vcSessionCookie = vim.cookie.split('"')[1]
10
+ class SMS < Connection
11
+ # Connect to a vSphere SMS endpoint
12
+ #
13
+ # @param [VIM] Connection to main vSphere API endpoint
14
+ # @param [Hash] opts The options hash.
15
+ # @option opts [String] :host Host to connect to.
16
+ # @option opts [Numeric] :port (443) Port to connect to.
17
+ # @option opts [Boolean] :ssl (true) Whether to use SSL.
18
+ # @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors.
19
+ # @option opts [String] :path (/sms/sdk) SDK endpoint path.
20
+ # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
21
+ def self.connect vim, opts = {}
22
+ raise unless opts.is_a? Hash
23
+
24
+ opts[:host] = vim.host
25
+ opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
26
+ opts[:insecure] ||= true
27
+ opts[:port] ||= (opts[:ssl] ? 443 : 80)
28
+ opts[:path] ||= '/sms/sdk'
29
+ opts[:ns] ||= 'urn:sms'
30
+ rev_given = opts[:rev] != nil
31
+ opts[:rev] = '4.0' unless rev_given
32
+ opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
33
+
34
+ new(opts).tap do |sms|
35
+ sms.vcSessionCookie = vim.cookie.split('"')[1]
36
+ end
34
37
  end
35
- end
36
38
 
37
- def vcSessionCookie= cookie
38
- @vcSessionCookie = cookie
39
- end
39
+ def vcSessionCookie= cookie
40
+ @vcSessionCookie = cookie
41
+ end
40
42
 
41
- def rev= x
42
- super
43
- @serviceContent = nil
44
- end
43
+ def rev= x
44
+ super
45
+ @serviceContent = nil
46
+ end
45
47
 
46
- # Return the ServiceInstance
47
- #
48
- # The ServiceInstance is the root of the vSphere inventory.
49
- def serviceInstance
50
- @serviceInstance ||= VIM::SmsServiceInstance self, 'ServiceInstance'
51
- end
48
+ # Return the ServiceInstance
49
+ #
50
+ # The ServiceInstance is the root of the vSphere inventory.
51
+ def serviceInstance
52
+ @serviceInstance ||= VIM::SmsServiceInstance self, 'ServiceInstance'
53
+ end
52
54
 
53
- # @private
54
- def pretty_print pp
55
- pp.text "SMS(#{@opts[:host]})"
56
- end
55
+ # @private
56
+ def pretty_print pp
57
+ pp.text "SMS(#{@opts[:host]})"
58
+ end
57
59
 
58
- add_extension_dir File.join(File.dirname(__FILE__), "sms")
59
- load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.db"))
60
- end
60
+ add_extension_dir File.join(File.dirname(__FILE__), 'sms')
61
+ load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), '../../vmodl.db'))
62
+ end
61
63
 
62
64
  end
63
65
 
data/lib/rbvmomi/sso.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'base64'
2
3
  require 'net/https'
3
4
  require 'nokogiri'
@@ -18,12 +19,12 @@ module RbVmomi
18
19
  TOKEN_TYPE = 'urn:oasis:names:tc:SAML:2.0:assertion'.freeze
19
20
  TOKEN_PROFILE = 'http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0'.freeze
20
21
  NAMESPACES = {
21
- :ds => 'http://www.w3.org/2000/09/xmldsig#',
22
- :soap => 'http://schemas.xmlsoap.org/soap/envelope/',
23
- :wsse => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
24
- :wsse11 => 'http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd',
25
- :wst => 'http://docs.oasis-open.org/ws-sx/ws-trust/200512',
26
- :wsu => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
22
+ ds: 'http://www.w3.org/2000/09/xmldsig#',
23
+ soap: 'http://schemas.xmlsoap.org/soap/envelope/',
24
+ wsse: 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
25
+ wsse11: 'http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd',
26
+ wst: 'http://docs.oasis-open.org/ws-sx/ws-trust/200512',
27
+ wsu: 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
27
28
  }.freeze
28
29
 
29
30
  attr_reader :assertion,
@@ -110,14 +111,14 @@ module RbVmomi
110
111
  end
111
112
 
112
113
  signed = sign(request)
113
- signed.gsub!('SAML_ASSERTION_PLACEHOLDER', @assertion.to_xml(:indent => 0, :save_with => Nokogiri::XML::Node::SaveOptions::AS_XML).strip)
114
+ signed.gsub!('SAML_ASSERTION_PLACEHOLDER', @assertion.to_xml(indent: 0, save_with: Nokogiri::XML::Node::SaveOptions::AS_XML).strip)
114
115
 
115
116
  signed
116
117
  end
117
118
 
118
119
  # We default to Issue, since that's all we currently need.
119
120
  def sso_call(body)
120
- sso_url = URI::HTTPS.build(:host => @host, :port => @port, :path => @path)
121
+ sso_url = URI::HTTPS.build(host: @host, port: @port, path: @path)
121
122
  http = Net::HTTP.new(sso_url.host, sso_url.port)
122
123
  http.use_ssl = true
123
124
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @insecure
@@ -209,23 +210,17 @@ module RbVmomi
209
210
  signature_value_tag = doc.at_xpath('/soap:Envelope/soap:Header/wsse:Security/ds:Signature/ds:SignatureValue', doc.collect_namespaces)
210
211
  signature_value_tag.add_child(Nokogiri::XML::Text.new(signature, doc))
211
212
 
212
- doc.to_xml(:indent => 0, :save_with => Nokogiri::XML::Node::SaveOptions::AS_XML).strip
213
+ doc.to_xml(indent: 0, save_with: Nokogiri::XML::Node::SaveOptions::AS_XML).strip
213
214
  end
214
215
 
215
216
  def load_x509(private_key, certificate)
216
217
  @private_key = private_key ? private_key : OpenSSL::PKey::RSA.new(2048)
217
- if @private_key.is_a? String
218
- @private_key = OpenSSL::PKey::RSA.new(@private_key)
219
- end
218
+ @private_key = OpenSSL::PKey::RSA.new(@private_key) if @private_key.is_a? String
220
219
 
221
220
  @certificate = certificate
222
- if @certificate && !private_key
223
- raise(ArgumentError, "Can't generate private key from a certificate")
224
- end
221
+ raise(ArgumentError, "Can't generate private key from a certificate") if @certificate && !private_key
225
222
 
226
- if @certificate.is_a? String
227
- @certificate = OpenSSL::X509::Certificate.new(@certificate)
228
- end
223
+ @certificate = OpenSSL::X509::Certificate.new(@certificate) if @certificate.is_a? String
229
224
  # If only a private key is specified, we will generate a certificate.
230
225
  unless @certificate
231
226
  timestamp = Time.now.utc
@@ -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,9 +13,11 @@ class RbVmomi::TrivialSoap
12
13
  attr_reader :http
13
14
 
14
15
  def initialize opts
15
- fail unless opts.is_a? Hash
16
+ raise unless opts.is_a? Hash
17
+
16
18
  @opts = opts
17
19
  return unless @opts[:host] # for testcases
20
+
18
21
  @debug = @opts[:debug]
19
22
  @cookie = @opts[:cookie]
20
23
  @sso = @opts[:sso]
@@ -33,7 +36,7 @@ class RbVmomi::TrivialSoap
33
36
  end
34
37
 
35
38
  def restart_http
36
- begin
39
+ begin
37
40
  @http.finish if @http
38
41
  rescue Exception => ex
39
42
  puts "WARNING: Ignoring exception: #{ex.message}"
@@ -61,7 +64,7 @@ class RbVmomi::TrivialSoap
61
64
  xsd = 'http://www.w3.org/2001/XMLSchema'
62
65
  env = 'http://schemas.xmlsoap.org/soap/envelope/'
63
66
  xsi = 'http://www.w3.org/2001/XMLSchema-instance'
64
- xml = Builder::XmlMarkup.new :indent => 0
67
+ xml = Builder::XmlMarkup.new indent: 0
65
68
  xml.tag!('env:Envelope', 'xmlns:xsd' => xsd, 'xmlns:env' => env, 'xmlns:xsi' => xsi) do
66
69
  if @vcSessionCookie || @operation_id
67
70
  xml.tag!('env:Header') do
@@ -82,7 +85,7 @@ class RbVmomi::TrivialSoap
82
85
  headers['cookie'] = @cookie if @cookie
83
86
 
84
87
  if @debug
85
- $stderr.puts "Request:"
88
+ $stderr.puts 'Request:'
86
89
  $stderr.puts body
87
90
  $stderr.puts
88
91
  end
@@ -102,10 +105,8 @@ class RbVmomi::TrivialSoap
102
105
  end
103
106
  end
104
107
  end_time = Time.now
105
-
106
- if response.is_a? Net::HTTPServiceUnavailable
107
- raise "Got HTTP 503: Service unavailable"
108
- end
108
+
109
+ raise 'Got HTTP 503: Service unavailable' if response.is_a? Net::HTTPServiceUnavailable
109
110
 
110
111
  self.cookie = response['set-cookie'] if response.key? 'set-cookie'
111
112
 
@@ -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,133 +7,131 @@ require 'monitor'
6
7
 
7
8
  module RbVmomi
8
9
 
9
- class TypeLoader
10
- def initialize fn, extension_dirs, namespace
11
- @extension_dirs = extension_dirs
12
- @namespace = namespace
13
- @lock = Monitor.new
14
- @db = {}
15
- @id2wsdl = {}
16
- @loaded = {}
17
- add_types Hash[BasicTypes::BUILTIN.map { |k| [k,nil] }]
18
- vmodl_database = File.open(fn, 'r') { |io| Marshal.load io }
19
- vmodl_database.reject! { |k,v| k =~ /^_/ }
20
- add_types vmodl_database
21
- preload
22
- end
23
-
24
- def preload
25
- names = (@namespace.constants + Object.constants).map(&:to_s).uniq.
26
- select { |x| has? x }
27
- names.each { |x| get(x) }
28
- end
10
+ class TypeLoader
11
+ def initialize fn, extension_dirs, namespace
12
+ @extension_dirs = extension_dirs
13
+ @namespace = namespace
14
+ @lock = Monitor.new
15
+ @db = {}
16
+ @id2wsdl = {}
17
+ @loaded = {}
18
+ add_types Hash[BasicTypes::BUILTIN.map { |k| [k, nil] }]
19
+ vmodl_database = File.open(fn, 'r') { |io| Marshal.load io }
20
+ vmodl_database.reject! { |k, v| k =~ /^_/ }
21
+ add_types vmodl_database
22
+ preload
23
+ end
29
24
 
30
- # Reload all extensions for loaded VMODL types
31
- def reload_extensions
32
- @extension_dirs.each do |path|
33
- reload_extensions_dir path
25
+ def preload
26
+ names = (@namespace.constants + Object.constants).map(&:to_s).uniq.
27
+ select { |x| has? x }
28
+ names.each { |x| get(x) }
34
29
  end
35
- end
36
30
 
37
- # Reload all extensions for loaded VMODL types from the given directory
38
- def reload_extensions_dir path
39
- loaded = Set.new(typenames.select { |x| @namespace.const_defined? x })
40
- Dir.open(path) do |dir|
41
- dir.each do |file|
42
- next unless file =~ /\.rb$/
43
- next unless loaded.member? $`
44
- file_path = File.join(dir, file)
45
- load file_path
31
+ # Reload all extensions for loaded VMODL types
32
+ def reload_extensions
33
+ @extension_dirs.each do |path|
34
+ reload_extensions_dir path
46
35
  end
47
36
  end
48
- end
49
37
 
50
- def has? name
51
- fail unless name.is_a? String
38
+ # Reload all extensions for loaded VMODL types from the given directory
39
+ def reload_extensions_dir path
40
+ loaded = Set.new(typenames.select { |x| @namespace.const_defined? x })
41
+ Dir.open(path) do |dir|
42
+ dir.each do |file|
43
+ next unless file =~ /\.rb$/
44
+ next unless loaded.member? $`
52
45
 
53
- @db.member?(name) or BasicTypes::BUILTIN.member?(name)
54
- end
46
+ file_path = File.join(dir, file)
47
+ load file_path
48
+ end
49
+ end
50
+ end
55
51
 
56
- def get name
57
- fail "name '#{name}' is #{name.class} expecting String" unless name.is_a? String
52
+ def has? name
53
+ raise unless name.is_a? String
58
54
 
59
- first_char = name[0].chr
60
- if first_char.downcase == first_char
61
- name = "%s%s" % [first_char.upcase, name[1..-1]]
55
+ @db.member?(name) or BasicTypes::BUILTIN.member?(name)
62
56
  end
63
57
 
64
- return @loaded[name] if @loaded.member? name
65
- @lock.synchronize do
58
+ def get name
59
+ raise "name '#{name}' is #{name.class} expecting String" unless name.is_a? String
60
+
61
+ first_char = name[0].chr
62
+ name = '%s%s' % [first_char.upcase, name[1..-1]] if first_char.downcase == first_char
63
+
66
64
  return @loaded[name] if @loaded.member? name
67
- klass = make_type(name)
68
- @namespace.const_set name, klass
69
- load_extension name
70
- @loaded[name] = klass
65
+
66
+ @lock.synchronize do
67
+ return @loaded[name] if @loaded.member? name
68
+
69
+ klass = make_type(name)
70
+ @namespace.const_set name, klass
71
+ load_extension name
72
+ @loaded[name] = klass
73
+ end
71
74
  end
72
- end
73
75
 
74
- def add_types types
75
- @lock.synchronize do
76
- @db.merge! types
77
- @db = Hash[@db.map do |name, value|
78
- if value
79
- value['wsdl_name'] ||= name
80
- end
81
- first_char = name[0].chr
82
- if first_char.downcase == first_char
83
- name = "%s%s" % [first_char.upcase, name[1..-1]]
84
- end
85
- [name, value]
86
- end]
76
+ def add_types types
77
+ @lock.synchronize do
78
+ @db.merge! types
79
+ @db = Hash[@db.map do |name, value|
80
+ value['wsdl_name'] ||= name if value
81
+ first_char = name[0].chr
82
+ name = '%s%s' % [first_char.upcase, name[1..-1]] if first_char.downcase == first_char
83
+ [name, value]
84
+ end]
85
+ end
87
86
  end
88
- end
89
87
 
90
- def typenames
91
- @db.keys
92
- end
88
+ def typenames
89
+ @db.keys
90
+ end
93
91
 
94
- private
92
+ private
95
93
 
96
- def load_extension name
97
- @extension_dirs.map { |x| File.join(x, "#{name}.rb") }.
98
- select { |x| File.exist? x }.
99
- each { |x| load x }
100
- end
94
+ def load_extension name
95
+ @extension_dirs.map { |x| File.join(x, "#{name}.rb") }.
96
+ select { |x| File.exist? x }.
97
+ each { |x| load x }
98
+ end
99
+
100
+ def make_type name
101
+ name = name.to_s
102
+ return BasicTypes.const_get(name) if BasicTypes::BUILTIN.member? name
101
103
 
102
- def make_type name
103
- name = name.to_s
104
- return BasicTypes.const_get(name) if BasicTypes::BUILTIN.member? name
105
- desc = @db[name] or fail "unknown VMODL type #{name}"
106
- case desc['kind']
107
- when 'data' then make_data_type name, desc
108
- when 'managed' then make_managed_type name, desc
109
- when 'enum' then make_enum_type name, desc
110
- else fail desc.inspect
104
+ desc = @db[name] or raise "unknown VMODL type #{name}"
105
+ case desc['kind']
106
+ when 'data' then make_data_type name, desc
107
+ when 'managed' then make_managed_type name, desc
108
+ when 'enum' then make_enum_type name, desc
109
+ else raise desc.inspect
110
+ end
111
111
  end
112
- end
113
112
 
114
- def make_data_type name, desc
115
- superclass = get desc['wsdl_base']
116
- Class.new(superclass).tap do |klass|
117
- klass.init name, desc['props']
118
- klass.wsdl_name = desc['wsdl_name']
113
+ def make_data_type name, desc
114
+ superclass = get desc['wsdl_base']
115
+ Class.new(superclass).tap do |klass|
116
+ klass.init name, desc['props']
117
+ klass.wsdl_name = desc['wsdl_name']
118
+ end
119
119
  end
120
- end
121
120
 
122
- def make_managed_type name, desc
123
- superclass = get desc['wsdl_base']
124
- Class.new(superclass).tap do |klass|
125
- klass.init name, desc['props'], desc['methods']
126
- klass.wsdl_name = desc['wsdl_name']
121
+ def make_managed_type name, desc
122
+ superclass = get desc['wsdl_base']
123
+ Class.new(superclass).tap do |klass|
124
+ klass.init name, desc['props'], desc['methods']
125
+ klass.wsdl_name = desc['wsdl_name']
126
+ end
127
127
  end
128
- end
129
128
 
130
- def make_enum_type name, desc
131
- Class.new(BasicTypes::Enum).tap do |klass|
132
- klass.init name, desc['values']
133
- klass.wsdl_name = desc['wsdl_name']
129
+ def make_enum_type name, desc
130
+ Class.new(BasicTypes::Enum).tap do |klass|
131
+ klass.init name, desc['values']
132
+ klass.wsdl_name = desc['wsdl_name']
133
+ end
134
134
  end
135
135
  end
136
- end
137
136
 
138
137
  end