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.
- checksums.yaml +4 -4
- data/README.md +11 -25
- data/exe/rbvmomish +50 -48
- data/lib/rbvmomi/basic_types.rb +318 -294
- data/lib/rbvmomi/connection.rb +221 -216
- data/lib/rbvmomi/deserialization.rb +201 -205
- data/lib/rbvmomi/fault.rb +10 -9
- data/lib/rbvmomi/optimist.rb +51 -50
- data/lib/rbvmomi/pbm.rb +52 -50
- data/lib/rbvmomi/sms/SmsStorageManager.rb +2 -1
- data/lib/rbvmomi/sms.rb +48 -46
- data/lib/rbvmomi/sso.rb +13 -18
- data/lib/rbvmomi/trivial_soap.rb +9 -8
- data/lib/rbvmomi/type_loader.rb +100 -101
- data/lib/rbvmomi/utils/admission_control.rb +90 -106
- data/lib/rbvmomi/utils/deploy.rb +77 -85
- data/lib/rbvmomi/utils/leases.rb +31 -33
- data/lib/rbvmomi/utils/perfdump.rb +177 -207
- data/lib/rbvmomi/version.rb +2 -1
- data/lib/rbvmomi/vim/ComputeResource.rb +17 -15
- data/lib/rbvmomi/vim/Datacenter.rb +1 -0
- data/lib/rbvmomi/vim/Datastore.rb +18 -15
- data/lib/rbvmomi/vim/DynamicTypeMgrAllTypeInfo.rb +7 -6
- data/lib/rbvmomi/vim/DynamicTypeMgrDataTypeInfo.rb +3 -2
- data/lib/rbvmomi/vim/DynamicTypeMgrManagedTypeInfo.rb +7 -6
- data/lib/rbvmomi/vim/Folder.rb +37 -33
- data/lib/rbvmomi/vim/HostSystem.rb +139 -136
- data/lib/rbvmomi/vim/ManagedEntity.rb +15 -14
- data/lib/rbvmomi/vim/ManagedObject.rb +11 -10
- data/lib/rbvmomi/vim/ObjectContent.rb +3 -1
- data/lib/rbvmomi/vim/ObjectUpdate.rb +3 -1
- data/lib/rbvmomi/vim/OvfManager.rb +50 -57
- data/lib/rbvmomi/vim/PerfCounterInfo.rb +4 -3
- data/lib/rbvmomi/vim/PerformanceManager.rb +28 -31
- data/lib/rbvmomi/vim/PropertyCollector.rb +8 -7
- data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +22 -21
- data/lib/rbvmomi/vim/ResourcePool.rb +19 -18
- data/lib/rbvmomi/vim/ServiceInstance.rb +8 -7
- data/lib/rbvmomi/vim/Task.rb +6 -5
- data/lib/rbvmomi/vim/VirtualMachine.rb +8 -7
- data/lib/rbvmomi/vim.rb +112 -129
- data/lib/rbvmomi.rb +1 -0
- 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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
34
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
40
|
+
def vcSessionCookie= cookie
|
41
|
+
@vcSessionCookie = cookie
|
42
|
+
end
|
46
43
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@serviceInstance ||= VIM::PbmServiceInstance self, 'ServiceInstance'
|
52
|
-
end
|
44
|
+
def rev= x
|
45
|
+
super
|
46
|
+
@serviceContent = nil
|
47
|
+
end
|
53
48
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
56
|
+
# Alias to serviceInstance.PbmRetrieveServiceContent
|
57
|
+
def serviceContent
|
58
|
+
@serviceContent ||= serviceInstance.PbmRetrieveServiceContent
|
59
|
+
end
|
63
60
|
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
39
|
+
def vcSessionCookie= cookie
|
40
|
+
@vcSessionCookie = cookie
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def rev= x
|
44
|
+
super
|
45
|
+
@serviceContent = nil
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
# @private
|
56
|
+
def pretty_print pp
|
57
|
+
pp.text "SMS(#{@opts[:host]})"
|
58
|
+
end
|
57
59
|
|
58
|
-
|
59
|
-
|
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
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
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(:
|
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(:
|
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(:
|
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
|
data/lib/rbvmomi/trivial_soap.rb
CHANGED
@@ -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
|
-
|
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 :
|
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
|
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
|
|
data/lib/rbvmomi/type_loader.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
46
|
+
file_path = File.join(dir, file)
|
47
|
+
load file_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
55
51
|
|
56
|
-
|
57
|
-
|
52
|
+
def has? name
|
53
|
+
raise unless name.is_a? String
|
58
54
|
|
59
|
-
|
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
|
-
|
65
|
-
|
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
|
-
|
68
|
-
@
|
69
|
-
|
70
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
88
|
+
def typenames
|
89
|
+
@db.keys
|
90
|
+
end
|
93
91
|
|
94
|
-
|
92
|
+
private
|
95
93
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|