Module: VimSdk::VmomiSupport

Defined in:
lib/ruby_vim_sdk/core_types.rb,
lib/ruby_vim_sdk/missing_types.rb,
lib/ruby_vim_sdk/vmomi_support.rb,
lib/ruby_vim_sdk/server_objects.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject (readonly)

Returns the value of attribute logger.



91
92
93
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 91

def logger
  @logger
end

Class Method Details

.add_type(type) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 132

def add_type(type)
  @type_info[type.name] = type
  namespace = wsdl_namespace(type.version)
  @wsdl_type_namespaces << namespace

  if @wsdl_type_info.has_key?([namespace, type.wsdl_name])
    raise "Duplicate wsdl type #{type.wsdl_name} (already in typemap)" if @wsdl_type_info[namespace, type.wsdl_name] != type
  else
    @wsdl_type_info[[namespace, type.wsdl_name]] = type
  end
end

.add_version(version, ns, version_id, is_legacy, service_ns) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 93

def add_version(version, ns, version_id, is_legacy, service_ns)
  unless @version_parents.has_key?(version)
    @version_namespaces[version] = ns
    @versions["#{ns}/#{version_id}"] = version unless version_id.empty?
    @versions[ns] = version if is_legacy || ns.empty?
    @version_ids[version] = version_id
    service_ns = ns if service_ns.nil?
    @service_version_namespaces[version] = service_ns
    @version_parents[version] = {}
  end
end

.add_version_parent(version, parent) ⇒ Object



105
106
107
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 105

def add_version_parent(version, parent)
  @version_parents[version][parent] = true
end

.compatible_type(type, version) ⇒ Object



152
153
154
155
156
157
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 152

def compatible_type(type, version)
  if type.respond_to?(:version)
    type = type.superclass until is_child_version(version, type.version)
  end
  type
end

.create_data_type(*args) ⇒ Object



109
110
111
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 109

def create_data_type(*args)
  add_type(DataType.new(*args))
end

.create_enum_type(*args) ⇒ Object



113
114
115
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 113

def create_enum_type(*args)
  add_type(EnumType.new(*args))
end

.create_managed_type(*args) ⇒ Object



117
118
119
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 117

def create_managed_type(*args)
  add_type(ManagedType.new(*args))
end

.guess_wsdl_type(name) ⇒ Object



159
160
161
162
163
164
165
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 159

def guess_wsdl_type(name)
  @wsdl_type_namespaces.each do |namespace|
    type = @wsdl_types[[namespace, name]]
    return type if type
  end
  raise "Couldn't guess type for #{name}"
end

.is_child_version(a, b) ⇒ Object



148
149
150
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 148

def is_child_version(a, b)
  a == b || (@version_parents[a] && @version_parents[a][b])
end

.load_type(type) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 186

def load_type(type)
  if type.respond_to?(:parent)
    parent = type.parent
  else
    parent = nil
  end

  unless parent.nil? || @types.has_key?(type.parent)
    load_type(@type_info[type.parent])
  end

  names = type.name.split(".")

  current_name = ""
  current_module = VimSdk

  names[0..-2].each do |name|
    if current_name.empty?
      current_name = name
    else
      current_name = "#{current_name}.#{name}"
    end

    module_name = name.to_sym
    unless current_module.const_defined?(module_name)
      if @type_info.has_key?(current_name)
        load_type(@type_info[current_name])
      else
        current_module.const_set(module_name, Module.new)
      end
    end
    current_module = current_module.const_get(module_name)
  end

  if type.kind_of?(EnumType)
    super_class = SoapEnum
  else
    super_class = @types[type.parent]
  end

  clazz = Class.new(super_class) do
    @type_info = type
  end
  current_module.const_set(names.last, clazz)

  array_clazz = Class.new(TypedArray) do
    @item = clazz
  end
  clazz.const_set(:TypedArray, array_clazz)

  @types[type.name] = clazz
  @types["#{type.name}[]"] = array_clazz
  @wsdl_types[[wsdl_namespace(type.version), type.wsdl_name]] = clazz
  @wsdl_types[[wsdl_namespace(type.version), "ArrayOf#{type.wsdl_name}"]] = array_clazz
end

.load_typesObject



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 167

def load_types
  @type_info.each_value do |type|
    load_type(type) unless @types.has_key?(type.name)
  end

  @types.each_value do |clazz|
    type_info = clazz.instance_eval { @type_info }
    if type_info
      if type_info.kind_of?(DataType)
        clazz.finalize
      elsif type_info.class == EnumType
        type_info.values.each do |value|
          clazz.const_set(VmodlHelper.underscore(value).upcase, value)
        end
      end
    end
  end
end

.loaded_type(type_name) ⇒ Object



242
243
244
245
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 242

def loaded_type(type_name)
  raise "Can't find #{type_name}" unless @types[type_name]
  @types[type_name]
end

.loaded_wsdl_type(namespace, name) ⇒ Object



247
248
249
250
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 247

def loaded_wsdl_type(namespace, name)
  raise "Can't find #{namespace}/#{name}" unless @wsdl_types[[namespace, name]]
  @wsdl_types[[namespace, name]]
end

.qualified_wsdl_name(type) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 252

def qualified_wsdl_name(type)
  result = @wsdl_names[type]
  if result
    result
  else
    if type.ancestors.include?(Array)
      type_info = type.class.type_info
      [type_info.version, "ArrayOf#{type_info.wsdl_name}"]
    else
      namespace = wsdl_namespace(type.version)
      [namespace, type.type_info.wsdl_name]
    end
  end
end

.version_namespace(version) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 121

def version_namespace(version)
  namespace = @version_namespaces[version]
  version_id = @version_ids[version]

  if version_id
    "#{namespace}/#{version_id}"
  else
    namespace
  end
end

.wsdl_name(type) ⇒ Object



267
268
269
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 267

def wsdl_name(type)
  qualified_wsdl_name(type).last
end

.wsdl_namespace(version) ⇒ Object



144
145
146
# File 'lib/ruby_vim_sdk/vmomi_support.rb', line 144

def wsdl_namespace(version)
  "urn:#{@service_version_namespaces[version]}"
end