rbvmomi2 3.0.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.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +114 -0
- data/exe/rbvmomish +138 -0
- data/lib/rbvmomi/basic_types.rb +383 -0
- data/lib/rbvmomi/connection.rb +272 -0
- data/lib/rbvmomi/deserialization.rb +249 -0
- data/lib/rbvmomi/fault.rb +19 -0
- data/lib/rbvmomi/optimist.rb +72 -0
- data/lib/rbvmomi/pbm.rb +68 -0
- data/lib/rbvmomi/sms/SmsStorageManager.rb +10 -0
- data/lib/rbvmomi/sms.rb +63 -0
- data/lib/rbvmomi/sso.rb +313 -0
- data/lib/rbvmomi/trivial_soap.rb +122 -0
- data/lib/rbvmomi/type_loader.rb +138 -0
- data/lib/rbvmomi/utils/admission_control.rb +401 -0
- data/lib/rbvmomi/utils/deploy.rb +318 -0
- data/lib/rbvmomi/utils/leases.rb +145 -0
- data/lib/rbvmomi/utils/perfdump.rb +631 -0
- data/lib/rbvmomi/version.rb +6 -0
- data/lib/rbvmomi/vim/ComputeResource.rb +54 -0
- data/lib/rbvmomi/vim/Datacenter.rb +25 -0
- data/lib/rbvmomi/vim/Datastore.rb +72 -0
- data/lib/rbvmomi/vim/DynamicTypeMgrAllTypeInfo.rb +78 -0
- data/lib/rbvmomi/vim/DynamicTypeMgrDataTypeInfo.rb +23 -0
- data/lib/rbvmomi/vim/DynamicTypeMgrManagedTypeInfo.rb +54 -0
- data/lib/rbvmomi/vim/Folder.rb +214 -0
- data/lib/rbvmomi/vim/HostSystem.rb +177 -0
- data/lib/rbvmomi/vim/ManagedEntity.rb +60 -0
- data/lib/rbvmomi/vim/ManagedObject.rb +63 -0
- data/lib/rbvmomi/vim/ObjectContent.rb +26 -0
- data/lib/rbvmomi/vim/ObjectUpdate.rb +26 -0
- data/lib/rbvmomi/vim/OvfManager.rb +204 -0
- data/lib/rbvmomi/vim/PerfCounterInfo.rb +28 -0
- data/lib/rbvmomi/vim/PerformanceManager.rb +113 -0
- data/lib/rbvmomi/vim/PropertyCollector.rb +28 -0
- data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +33 -0
- data/lib/rbvmomi/vim/ResourcePool.rb +58 -0
- data/lib/rbvmomi/vim/ServiceInstance.rb +58 -0
- data/lib/rbvmomi/vim/Task.rb +68 -0
- data/lib/rbvmomi/vim/VirtualMachine.rb +75 -0
- data/lib/rbvmomi/vim.rb +157 -0
- data/lib/rbvmomi.rb +16 -0
- data/lib/rbvmomi2.rb +3 -0
- data/vmodl.db +0 -0
- metadata +214 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a9290a6ccd179ef5e0dddb1d0956a1ba976a368ceb1534b44b13024fbe7a2fb5
|
4
|
+
data.tar.gz: 2cb20596b8f3cef9db32468e2f110f3abdcef70235a466efe81726259a650ea7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8238c2c399f04f57930ac7bb2437de3eb2abc16723700366a6c57c97076f9043e342393bca69cc511ebe1fe91d9df354149144cff04f859c8178471fe5644381
|
7
|
+
data.tar.gz: ed586f8b93ded01b4ade32d1c4e95b1e349c94584084db14e83a6433b011e0c70f85a6df7674ac4228e1bc4d7d94814ba91bb0d2cb55f84bcfd828dc6fc802bf
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010-2017 VMware, Inc. All Rights Reserved.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# RbVmomi
|
2
|
+
|
3
|
+
[<img src="https://badge.fury.io/rb/rbvmomi.svg" alt="gem-version">](https://rubygems.org/gems/rbvmomi)
|
4
|
+
[<img src="https://travis-ci.org/vmware/rbvmomi.svg?branch=master" alt="travis-ci">](http://travis-ci.org/vmware/rbvmomi)
|
5
|
+
[<img src="https://badges.gitter.im/vmware/rbvmomi.svg">](https://gitter.im/vmware/rbvmomi)
|
6
|
+
|
7
|
+
This is a community-supported, open source project at VMware. It is built and
|
8
|
+
maintained by programmers like you!
|
9
|
+
|
10
|
+
## Introduction
|
11
|
+
|
12
|
+
RbVmomi is a Ruby interface to the vSphere API. Like the Perl and Java SDKs,
|
13
|
+
you can use it to manage ESX and vCenter servers. The current release
|
14
|
+
supports the vSphere 6.5 API. RbVmomi specific documentation is
|
15
|
+
[online](http://rdoc.info/github/vmware/rbvmomi/master/frames) and is meant to
|
16
|
+
be used alongside the official [documentation](http://pubs.vmware.com/vsphere-65/index.jsp#com.vmware.wssdk.apiref.doc/right-pane.html).
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
gem install rbvmomi
|
21
|
+
|
22
|
+
### Support for older Ruby versions
|
23
|
+
|
24
|
+
RbVmomi supports Ruby 1.8.7 and higher, but certain dependencies may need
|
25
|
+
pinning to older versions to get a compatible set of gems.
|
26
|
+
|
27
|
+
On Ruby 1.8.7:
|
28
|
+
|
29
|
+
* use `nokogiri` 1.5.x (Gemfile: `gem 'nokogiri', '< 1.6'`)
|
30
|
+
|
31
|
+
|
32
|
+
On both Ruby 1.9 and 1.8.7:
|
33
|
+
|
34
|
+
* use `json` 1.x (Gemfile: `gem 'json', '< 2'`)
|
35
|
+
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
A simple example of turning on a VM:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'rbvmomi'
|
43
|
+
|
44
|
+
vim = RbVmomi::VIM.connect(host: 'foo', user: 'bar', password: 'baz')
|
45
|
+
dc = vim.serviceInstance.find_datacenter('my_datacenter') || fail('datacenter not found')
|
46
|
+
vm = dc.find_vm('my_vm') || fail('VM not found')
|
47
|
+
vm.PowerOnVM_Task.wait_for_completion
|
48
|
+
```
|
49
|
+
|
50
|
+
This code uses several RbVmomi extensions to the vSphere API for concision.
|
51
|
+
The expanded snippet below uses only standard API calls and should be familiar
|
52
|
+
to users of the Java SDK:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'rbvmomi'
|
56
|
+
|
57
|
+
vim = RbVmomi::VIM.connect(host: 'foo', user: 'bar', password: 'baz')
|
58
|
+
root_folder = vim.serviceInstance.content.rootFolder
|
59
|
+
dc = root_folder.childEntity.grep(RbVmomi::VIM::Datacenter).find { |x| x.name == 'mydatacenter' } || fail('datacenter not found')
|
60
|
+
vm = dc.vmFolder.childEntity.grep(RbVmomi::VIM::VirtualMachine).find { |x| x.name == 'my_vm' } || fail('VM not found')
|
61
|
+
task = vm.PowerOnVM_Task
|
62
|
+
filter = vim.propertyCollector.CreateFilter(
|
63
|
+
spec: {
|
64
|
+
propSet: [{ type: 'Task', all: false, pathSet: ['info.state']}],
|
65
|
+
objectSet: [{ obj: task }]
|
66
|
+
},
|
67
|
+
partialUpdates: false
|
68
|
+
)
|
69
|
+
ver = ''
|
70
|
+
loop do
|
71
|
+
result = vim.propertyCollector.WaitForUpdates(version: ver)
|
72
|
+
ver = result.version
|
73
|
+
break if ['success', 'error'].member?(task.info.state)
|
74
|
+
end
|
75
|
+
filter.DestroyPropertyFilter
|
76
|
+
raise(task.info.error) if task.info.state == 'error'
|
77
|
+
```
|
78
|
+
|
79
|
+
As you can see, the extensions RbVmomi adds can dramatically decrease the code
|
80
|
+
needed to perform simple tasks while still letting you use the full power of
|
81
|
+
the API when necessary. RbVmomi extensions are often more efficient than a
|
82
|
+
naive implementation; for example, the find_vm method on VIM::Datacenter used
|
83
|
+
in the first example uses the SearchIndex for fast lookups.
|
84
|
+
|
85
|
+
A few important points:
|
86
|
+
|
87
|
+
* All class, method, parameter, and property names match the official [documentation](http://pubs.vmware.com/vsphere-65/index.jsp#com.vmware.wssdk.apiref.doc/right-pane.html).
|
88
|
+
* Properties are exposed as accessor methods.
|
89
|
+
* Data object types can usually be inferred from context, so you may use a hash instead.
|
90
|
+
* Enumeration values are simply strings.
|
91
|
+
* Example code is included in the examples/ directory.
|
92
|
+
* A set of helper methods for Optimist is included to speed up development of
|
93
|
+
command line apps. See the included examples for usage.
|
94
|
+
* If you don't have trusted SSL certificates installed on the host you're
|
95
|
+
connecting to, you'll get an `OpenSSL::SSL::SSLError` "certificate verify
|
96
|
+
failed". You can work around this by using the `:insecure` option to
|
97
|
+
`RbVmomi::VIM.connect`.
|
98
|
+
* This is a side project of a VMware employee and is entirely unsupported by
|
99
|
+
VMware.
|
100
|
+
|
101
|
+
|
102
|
+
Built-in extensions are under `lib/rbvmomi/vim/`. You are encouraged to reopen
|
103
|
+
VIM classes in your applications and add extensions of your own. If you write
|
104
|
+
something generally useful please open a [pull request](https://github.com/vmware/rbvmomi/pulls) so it can be merged back in
|
105
|
+
|
106
|
+
## Development
|
107
|
+
|
108
|
+
Open an issue on the [issues page](https://github.com/vmware/rbvmomi/issues)
|
109
|
+
or fork the project on [GitHub](https://github.com/vmware/rbvmomi) and send a
|
110
|
+
[pull request](https://github.com/vmware/rbvmomi/pulls).
|
111
|
+
|
112
|
+
## Support
|
113
|
+
|
114
|
+
You can chat on [Gitter](https://gitter.im/vmware/rbvmomi) or join the [VMware {code} Slack team](https://vmwarecode.slack.com/) and join the [#rbvmomi channel](https://vmwarecode.slack.com/messages/rbvmomi).
|
data/exe/rbvmomish
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# TODO keepalive
|
3
|
+
# TODO rc file
|
4
|
+
# TODO proxy support?
|
5
|
+
require 'optimist'
|
6
|
+
require 'readline'
|
7
|
+
require 'rbvmomi'
|
8
|
+
require 'rbvmomi/optimist'
|
9
|
+
|
10
|
+
VIM = RbVmomi::VIM
|
11
|
+
|
12
|
+
opts = Optimist.options do
|
13
|
+
banner <<-EOS
|
14
|
+
vSphere API console.
|
15
|
+
|
16
|
+
Usage:
|
17
|
+
rbvmomish [options]
|
18
|
+
|
19
|
+
Predefined methods:
|
20
|
+
conn: Returns the VIM connection
|
21
|
+
si: Returns the ServiceInstance
|
22
|
+
help: Displays this text.
|
23
|
+
|
24
|
+
Special syntax:
|
25
|
+
Adding a '#' suffix to an expression displays information about the type of the
|
26
|
+
result, including its properties and methods, instead of the value.
|
27
|
+
|
28
|
+
VIM connection options:
|
29
|
+
EOS
|
30
|
+
|
31
|
+
rbvmomi_connection_opts
|
32
|
+
|
33
|
+
text <<-EOS
|
34
|
+
|
35
|
+
Other options:
|
36
|
+
EOS
|
37
|
+
|
38
|
+
$optimist = self
|
39
|
+
end
|
40
|
+
|
41
|
+
begin
|
42
|
+
$vim = VIM.connect opts
|
43
|
+
rescue Errno::EHOSTUNREACH
|
44
|
+
abort $!.message
|
45
|
+
end
|
46
|
+
|
47
|
+
typenames = VIM.loader.typenames
|
48
|
+
Readline.completion_append_character = " "
|
49
|
+
Readline.completion_proc = lambda do |word|
|
50
|
+
return unless word
|
51
|
+
prefix_regex = /^#{Regexp.escape(word)}/
|
52
|
+
candidates = typenames.sort
|
53
|
+
candidates.find_all { |e| e.match(prefix_regex) }
|
54
|
+
end
|
55
|
+
|
56
|
+
history_fn = "#{ENV['HOME']}/.rbvmomish-history"
|
57
|
+
IO.foreach(history_fn) { |l| Readline::HISTORY << l.chomp } rescue nil
|
58
|
+
history = File.open(history_fn, 'a')
|
59
|
+
|
60
|
+
def type name
|
61
|
+
klass = VIM.type(name) rescue err("invalid type #{name.inspect}")
|
62
|
+
q = lambda { |x| x =~ /^xsd:/ ? $' : x }
|
63
|
+
if klass < VIM::DataObject
|
64
|
+
puts "Data Object #{klass}"
|
65
|
+
klass.full_props_desc.each do |desc|
|
66
|
+
puts " #{desc['name']}: #{q[desc['wsdl_type']]}#{desc['is-array'] ? '[]' : ''}"
|
67
|
+
end
|
68
|
+
elsif klass < VIM::ManagedObject
|
69
|
+
puts "Managed Object #{klass}"
|
70
|
+
puts
|
71
|
+
puts "Properties:"
|
72
|
+
klass.full_props_desc.each do |desc|
|
73
|
+
puts " #{desc['name']}: #{q[desc['wsdl_type']]}#{desc['is-array'] ? '[]' : ''}"
|
74
|
+
end
|
75
|
+
puts
|
76
|
+
puts "Methods:"
|
77
|
+
klass.full_methods_desc.sort_by(&:first).each do |name,desc|
|
78
|
+
params = desc['params']
|
79
|
+
puts " #{name}(#{params.map { |x| "#{x['name']} : #{q[x['wsdl_type'] || 'void']}#{x['is-array'] ? '[]' : ''}" } * ', '}) : #{q[desc['result']['wsdl_type'] || 'void']}"
|
80
|
+
end
|
81
|
+
else
|
82
|
+
err("cannot introspect type #{klass}")
|
83
|
+
end
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
87
|
+
class UserError < RuntimeError; end
|
88
|
+
def err msg
|
89
|
+
raise UserError.new(msg)
|
90
|
+
end
|
91
|
+
|
92
|
+
def cookie str
|
93
|
+
$vim.cookie = str
|
94
|
+
end
|
95
|
+
|
96
|
+
def conn
|
97
|
+
$vim
|
98
|
+
end
|
99
|
+
|
100
|
+
def si
|
101
|
+
$vim.serviceInstance
|
102
|
+
end
|
103
|
+
|
104
|
+
def help
|
105
|
+
$optimist.educate
|
106
|
+
:no_result
|
107
|
+
end
|
108
|
+
|
109
|
+
$binding = $vim.instance_eval { binding }
|
110
|
+
|
111
|
+
loop do
|
112
|
+
begin
|
113
|
+
input = Readline.readline("#{opts[:host]}> ", false) or break
|
114
|
+
input = input.strip
|
115
|
+
next if input.empty?
|
116
|
+
|
117
|
+
(history.puts input; Readline::HISTORY << input) unless input == Readline::HISTORY.to_a[-1]
|
118
|
+
|
119
|
+
result = eval(input, $binding)
|
120
|
+
if input =~ /\#$/
|
121
|
+
type result.class.wsdl_name
|
122
|
+
else
|
123
|
+
pp result unless result == :no_result
|
124
|
+
end
|
125
|
+
rescue SystemExit, IOError
|
126
|
+
raise
|
127
|
+
rescue RuntimeError, RbVmomi::Fault
|
128
|
+
puts "#{$!.class}: #{$!.message}"
|
129
|
+
puts $!.backtrace * "\n"
|
130
|
+
rescue UserError
|
131
|
+
puts $!.message
|
132
|
+
rescue Interrupt
|
133
|
+
puts
|
134
|
+
rescue Exception
|
135
|
+
puts "#{$!.class}: #{$!.message}"
|
136
|
+
puts $!.backtrace * "\n"
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,383 @@
|
|
1
|
+
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
|
2
|
+
# SPDX-License-Identifier: MIT
|
3
|
+
|
4
|
+
require 'pp'
|
5
|
+
require 'set'
|
6
|
+
|
7
|
+
module RbVmomi
|
8
|
+
module BasicTypes
|
9
|
+
|
10
|
+
BUILTIN = Set.new %w(ManagedObject DataObject TypeName PropertyPath ManagedObjectReference MethodName MethodFault LocalizedMethodFault KeyValue)
|
11
|
+
|
12
|
+
class Base
|
13
|
+
class << self
|
14
|
+
attr_accessor :wsdl_name
|
15
|
+
|
16
|
+
def init wsdl_name=self.name
|
17
|
+
@wsdl_name = wsdl_name
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
@wsdl_name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
init
|
26
|
+
end
|
27
|
+
|
28
|
+
class ObjectWithProperties < Base
|
29
|
+
class << self
|
30
|
+
attr_accessor :props_desc
|
31
|
+
|
32
|
+
def init name=self.name, props=[]
|
33
|
+
super name
|
34
|
+
@props_desc = props
|
35
|
+
@props_desc.each do |d|
|
36
|
+
sym = d['name'].to_sym
|
37
|
+
define_method(sym) { _get_property sym }
|
38
|
+
define_method(:"#{sym}=") { |x| _set_property sym, x }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def full_props_set
|
43
|
+
@full_props_set ||= Set.new(full_props_desc.map { |x| x['name'] })
|
44
|
+
end
|
45
|
+
|
46
|
+
def full_props_desc
|
47
|
+
@full_props_desc ||= (self == ObjectWithProperties ? [] : superclass.full_props_desc) + props_desc
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_prop_desc name
|
51
|
+
full_props_desc.find { |x| x['name'] == name.to_s }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def _get_property sym
|
56
|
+
fail 'unimplemented'
|
57
|
+
end
|
58
|
+
|
59
|
+
def _set_property sym, val
|
60
|
+
fail 'unimplemented'
|
61
|
+
end
|
62
|
+
|
63
|
+
init
|
64
|
+
end
|
65
|
+
|
66
|
+
class ObjectWithMethods < ObjectWithProperties
|
67
|
+
class << self
|
68
|
+
attr_accessor :methods_desc
|
69
|
+
|
70
|
+
def init name=self.name, props=[], methods={}
|
71
|
+
super name, props
|
72
|
+
@methods_desc = methods
|
73
|
+
|
74
|
+
@methods_desc.each do |k,d|
|
75
|
+
sym = k.to_sym
|
76
|
+
define_method(sym) { |*args| _call sym, *args }
|
77
|
+
define_method(:"#{sym}!") { |*args| _call sym, *args }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# XXX cache
|
82
|
+
def full_methods_desc
|
83
|
+
(self == ObjectWithMethods ? {} : superclass.full_methods_desc).merge methods_desc
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
init
|
88
|
+
end
|
89
|
+
|
90
|
+
class DataObject < ObjectWithProperties
|
91
|
+
attr_reader :props
|
92
|
+
|
93
|
+
def self.kind; :data end
|
94
|
+
|
95
|
+
def initialize props={}
|
96
|
+
# Deserialization fast path
|
97
|
+
if props == nil
|
98
|
+
@props = {}
|
99
|
+
return
|
100
|
+
end
|
101
|
+
|
102
|
+
@props = Hash[props.map { |k,v| [k.to_sym, v] }]
|
103
|
+
#self.class.full_props_desc.each do |desc|
|
104
|
+
#fail "missing required property #{desc['name'].inspect} of #{self.class.wsdl_name}" if @props[desc['name'].to_sym].nil? and not desc['is-optional']
|
105
|
+
#end
|
106
|
+
@props.each do |k,v|
|
107
|
+
fail "unexpected property name #{k}" unless self.class.find_prop_desc(k)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def initialize_copy(source)
|
112
|
+
super
|
113
|
+
@props = @props.dup
|
114
|
+
end
|
115
|
+
|
116
|
+
def _get_property sym
|
117
|
+
@props[sym]
|
118
|
+
end
|
119
|
+
|
120
|
+
def [] sym
|
121
|
+
_get_property sym
|
122
|
+
end
|
123
|
+
|
124
|
+
def _set_property sym, val
|
125
|
+
@props[sym] = val
|
126
|
+
end
|
127
|
+
|
128
|
+
def []= sym, val
|
129
|
+
_set_property sym, val
|
130
|
+
end
|
131
|
+
|
132
|
+
def == o
|
133
|
+
return false unless o.class == self.class
|
134
|
+
keys = (props.keys + o.props.keys).uniq
|
135
|
+
keys.all? { |k| props[k] == o.props[k] }
|
136
|
+
end
|
137
|
+
|
138
|
+
alias eql? ==
|
139
|
+
|
140
|
+
def hash
|
141
|
+
props.hash
|
142
|
+
end
|
143
|
+
|
144
|
+
def pretty_print q
|
145
|
+
q.text self.class.wsdl_name
|
146
|
+
q.group 2 do
|
147
|
+
q.text '('
|
148
|
+
q.breakable
|
149
|
+
props = @props.sort_by { |k,v| k.to_s }
|
150
|
+
q.seplist props, nil, :each do |e|
|
151
|
+
k, v = e
|
152
|
+
q.group do
|
153
|
+
q.text k.to_s
|
154
|
+
q.text ': '
|
155
|
+
q.pp v
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
q.breakable
|
160
|
+
q.text ')'
|
161
|
+
end
|
162
|
+
|
163
|
+
def to_json(*args)
|
164
|
+
h = self.props
|
165
|
+
m = h.merge({ JSON.create_id => self.class.name })
|
166
|
+
m.to_json(*args)
|
167
|
+
end
|
168
|
+
|
169
|
+
init
|
170
|
+
end
|
171
|
+
|
172
|
+
class ManagedObject < ObjectWithMethods
|
173
|
+
def self.kind; :managed end
|
174
|
+
|
175
|
+
def initialize connection, ref
|
176
|
+
super()
|
177
|
+
@connection = connection
|
178
|
+
@soap = @connection # XXX deprecated
|
179
|
+
@ref = ref
|
180
|
+
end
|
181
|
+
|
182
|
+
def _connection
|
183
|
+
@connection
|
184
|
+
end
|
185
|
+
|
186
|
+
def _ref
|
187
|
+
@ref
|
188
|
+
end
|
189
|
+
|
190
|
+
def _get_property sym
|
191
|
+
ret = @connection.propertyCollector.RetrieveProperties(:specSet => [{
|
192
|
+
:propSet => [{ :type => self.class.wsdl_name, :pathSet => [sym.to_s] }],
|
193
|
+
:objectSet => [{ :obj => self }],
|
194
|
+
}])[0]
|
195
|
+
|
196
|
+
if !ret
|
197
|
+
return nil
|
198
|
+
elsif ret.propSet.empty?
|
199
|
+
return nil if ret.missingSet.empty?
|
200
|
+
raise ret.missingSet[0].fault
|
201
|
+
else
|
202
|
+
ret.propSet[0].val
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def _set_property sym, val
|
207
|
+
fail 'unimplemented'
|
208
|
+
end
|
209
|
+
|
210
|
+
def _call method, o={}
|
211
|
+
fail "parameters must be passed as a hash" unless o.is_a? Hash
|
212
|
+
desc = self.class.full_methods_desc[method.to_s] or fail "unknown method"
|
213
|
+
@connection.call method, desc, self, o
|
214
|
+
end
|
215
|
+
|
216
|
+
def to_s
|
217
|
+
"#{self.class.wsdl_name}(#{@ref.inspect})"
|
218
|
+
end
|
219
|
+
|
220
|
+
def pretty_print pp
|
221
|
+
pp.text to_s
|
222
|
+
end
|
223
|
+
|
224
|
+
def [] k
|
225
|
+
_get_property k
|
226
|
+
end
|
227
|
+
|
228
|
+
def == x
|
229
|
+
out = (x.class == self.class && x._ref == @ref)
|
230
|
+
out = (x._connection.instanceUuid == self._connection.instanceUuid) if out && x._connection.host
|
231
|
+
out
|
232
|
+
end
|
233
|
+
|
234
|
+
alias eql? ==
|
235
|
+
|
236
|
+
def hash
|
237
|
+
[self.class, @ref].hash
|
238
|
+
end
|
239
|
+
|
240
|
+
init 'ManagedObject'
|
241
|
+
end
|
242
|
+
|
243
|
+
class Enum < Base
|
244
|
+
class << self
|
245
|
+
attr_accessor :values
|
246
|
+
|
247
|
+
def init name=self.name, values=[]
|
248
|
+
super name
|
249
|
+
@values = values
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def self.kind; :enum end
|
254
|
+
|
255
|
+
attr_reader :value
|
256
|
+
|
257
|
+
def initialize value
|
258
|
+
@value = value
|
259
|
+
end
|
260
|
+
|
261
|
+
init
|
262
|
+
end
|
263
|
+
|
264
|
+
class MethodFault < DataObject
|
265
|
+
init 'MethodFault', [
|
266
|
+
{
|
267
|
+
'name' => 'faultCause',
|
268
|
+
'wsdl_type' => 'LocalizedMethodFault',
|
269
|
+
'is-array' => false,
|
270
|
+
'is-optional' => true,
|
271
|
+
}, {
|
272
|
+
'name' => 'faultMessage',
|
273
|
+
'wsdl_type' => 'LocalizableMessage',
|
274
|
+
'is-array' => true,
|
275
|
+
'is-optional' => true,
|
276
|
+
},
|
277
|
+
]
|
278
|
+
|
279
|
+
def self.=== exn
|
280
|
+
exn.class == RbVmomi::Fault and self <= exn.fault.class
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
class LocalizedMethodFault < DataObject
|
285
|
+
init 'LocalizedMethodFault', [
|
286
|
+
{
|
287
|
+
'name' => 'fault',
|
288
|
+
'wsdl_type' => 'MethodFault',
|
289
|
+
'is-array' => false,
|
290
|
+
'is-optional' => false,
|
291
|
+
}, {
|
292
|
+
'name' => 'localizedMessage',
|
293
|
+
'wsdl_type' => 'xsd:string',
|
294
|
+
'is-array' => false,
|
295
|
+
'is-optional' => true,
|
296
|
+
},
|
297
|
+
]
|
298
|
+
|
299
|
+
def exception
|
300
|
+
RbVmomi::Fault.new(self.localizedMessage, self.fault)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
class RuntimeFault < MethodFault
|
305
|
+
init
|
306
|
+
end
|
307
|
+
|
308
|
+
class MethodName < String
|
309
|
+
def self.wsdl_name; 'MethodName' end
|
310
|
+
end
|
311
|
+
|
312
|
+
class PropertyPath < String
|
313
|
+
def self.wsdl_name; 'PropertyPath' end
|
314
|
+
end
|
315
|
+
|
316
|
+
class TypeName < String
|
317
|
+
def self.wsdl_name; 'TypeName' end
|
318
|
+
end
|
319
|
+
|
320
|
+
class ManagedObjectReference
|
321
|
+
def self.wsdl_name; 'ManagedObjectReference' end
|
322
|
+
end
|
323
|
+
|
324
|
+
class Boolean
|
325
|
+
def self.wsdl_name; 'xsd:boolean' end
|
326
|
+
end
|
327
|
+
|
328
|
+
class AnyType
|
329
|
+
def self.wsdl_name; 'xsd:anyType' end
|
330
|
+
end
|
331
|
+
|
332
|
+
class Binary
|
333
|
+
def self.wsdl_name; 'xsd:base64Binary' end
|
334
|
+
end
|
335
|
+
|
336
|
+
class ::Class
|
337
|
+
def wsdl_name; self.class.name end
|
338
|
+
end
|
339
|
+
|
340
|
+
class ::String
|
341
|
+
def self.wsdl_name; 'xsd:string' end
|
342
|
+
end
|
343
|
+
|
344
|
+
class ::Integer
|
345
|
+
def self.wsdl_name; 'xsd:int' end
|
346
|
+
end
|
347
|
+
|
348
|
+
class ::Float
|
349
|
+
def self.wsdl_name; 'xsd:float' end
|
350
|
+
end
|
351
|
+
|
352
|
+
class Int
|
353
|
+
def self.wsdl_name; 'xsd:int' end
|
354
|
+
|
355
|
+
def initialize x
|
356
|
+
@val = x
|
357
|
+
end
|
358
|
+
|
359
|
+
def to_s
|
360
|
+
@val.to_s
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
class KeyValue
|
365
|
+
def self.wsdl_name; 'KeyValue' end
|
366
|
+
attr_accessor :key, :value
|
367
|
+
|
368
|
+
def initialize k, v
|
369
|
+
@key = k
|
370
|
+
@value = v
|
371
|
+
end
|
372
|
+
|
373
|
+
def [] i
|
374
|
+
if i == 0 then @key
|
375
|
+
elsif i == 1 then @value
|
376
|
+
else fail "invalid index #{i.inspect}"
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
|
382
|
+
end
|
383
|
+
end
|