rbvmomi 1.1.6 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.html +76 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/rbvmomi/trivial_soap.rb +1 -1
- data/lib/rbvmomi/vim/Folder.rb +45 -0
- metadata +33 -4
data/README.html
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
<h1>RbVmomi</h1>
|
2
|
+
|
3
|
+
<h2>Introduction</h2>
|
4
|
+
|
5
|
+
<p>RbVmomi is a Ruby interface to the vSphere API. Like the Perl and Java SDKs,
|
6
|
+
you can use it to manage ESX and VirtualCenter servers. The current release
|
7
|
+
supports the vSphere 4.1 API.</p>
|
8
|
+
|
9
|
+
<h2>Usage</h2>
|
10
|
+
|
11
|
+
<p>A simple example of turning on a VM:</p>
|
12
|
+
|
13
|
+
<pre><code>require 'rbvmomi'
|
14
|
+
conn = RbVmomi.connect host: 'foo', user: 'bar', password: 'baz'
|
15
|
+
dc = conn.serviceInstance.find_datacenter("mydatacenter") or fail "datacenter not found"
|
16
|
+
vm = dc.find_vm("myvm") or fail "VM not found"
|
17
|
+
vm.PowerOn_Task.wait_for_completion
|
18
|
+
</code></pre>
|
19
|
+
|
20
|
+
<p>This code uses several RbVmomi extensions to the VI API for concision. The
|
21
|
+
expanded snippet below uses only standard API calls and should be familiar to
|
22
|
+
users of the Java SDK:</p>
|
23
|
+
|
24
|
+
<pre><code>require 'rbvmomi'
|
25
|
+
conn = RbVmomi.connect host: 'foo', user: 'bar', password: 'baz'
|
26
|
+
rootFolder = conn.serviceInstance.content.rootFolder
|
27
|
+
dc = rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).find { |x| x.name == "mydatacenter" } or fail "datacenter not found"
|
28
|
+
vm = dc.vmFolder.childEntity.grep(RbVmomi::VIM::VirtualMachine).find { |x| x.name == "myvm" } or fail "VM not found"
|
29
|
+
task = vm.PowerOn_Task
|
30
|
+
filter = conn.propertyCollector.CreateFilter(
|
31
|
+
spec: {
|
32
|
+
propSet: [{ type => 'Task', all: false, pathSet: ['info.state']}],
|
33
|
+
objectSet: [{ obj: task }]
|
34
|
+
},
|
35
|
+
partialUpdates: false
|
36
|
+
)
|
37
|
+
ver = ''
|
38
|
+
while true
|
39
|
+
result = conn.propertyCollector.WaitForUpdates(version: ver)
|
40
|
+
ver = result.version
|
41
|
+
break if ['success', ['error'].member? task.info.state
|
42
|
+
end
|
43
|
+
filter.DestroyPropertyFilter
|
44
|
+
raise task.info.error if task.info.state == 'error'
|
45
|
+
</code></pre>
|
46
|
+
|
47
|
+
<p>As you can see, the extensions RbVmomi adds can dramatically decrease the code
|
48
|
+
needed to perform simple tasks while still letting you use the full power of
|
49
|
+
the API when necessary. RbVmomi extensions are often more efficient than a
|
50
|
+
naive implementation; for example, the find_vm method on VIM::Datacenter used
|
51
|
+
in the first example uses the SearchIndex for fast lookups.</p>
|
52
|
+
|
53
|
+
<p>A few important points:</p>
|
54
|
+
|
55
|
+
<ul>
|
56
|
+
<li>Ruby 1.9 is required.</li>
|
57
|
+
<li>Properties are exposed as methods: vm.summary</li>
|
58
|
+
<li>All class, method, parameter, and property names match the <a href="http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/index.html">official documentation</a>.</li>
|
59
|
+
<li>Data object types can usually be inferred from context, so you may simply use a hash instead.</li>
|
60
|
+
<li>Enumeration values are simply strings.</li>
|
61
|
+
<li>Example code is included in the examples/ directory.</li>
|
62
|
+
<li>A set of helper methods for Trollop is included to speed up development of
|
63
|
+
command line apps. See the included examples for usage.</li>
|
64
|
+
<li>This is a side project of a VMware developer and is entirely unsupported by VMware.</li>
|
65
|
+
</ul>
|
66
|
+
|
67
|
+
<p>Built-in extensions are in lib/rbvmomi/extensions.rb. You are encouraged to
|
68
|
+
reopen VIM classes in your applications and add extensions of your own. If you
|
69
|
+
write something generally useful please send it to me and I'll add it in. One
|
70
|
+
important point about extensions is that since VIM classes are lazily loaded,
|
71
|
+
you need to trigger this loading before you can reopen the class. Putting the
|
72
|
+
class name on a line by itself before reopening is enough.</p>
|
73
|
+
|
74
|
+
<h2>Development</h2>
|
75
|
+
|
76
|
+
<p>Send patches to rlane@vmware.com.</p>
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.8
|
data/lib/rbvmomi/trivial_soap.rb
CHANGED
@@ -35,7 +35,7 @@ class RbVmomi::TrivialSoap
|
|
35
35
|
@http.key = OpenSSL::PKey::RSA.new(@opts[:key]) if @opts[:key]
|
36
36
|
end
|
37
37
|
@http.set_debug_output(STDERR) if $DEBUG
|
38
|
-
@http.read_timeout =
|
38
|
+
@http.read_timeout = 1000000
|
39
39
|
@http.open_timeout = 5
|
40
40
|
def @http.on_connect
|
41
41
|
@socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
data/lib/rbvmomi/vim/Folder.rb
CHANGED
@@ -8,6 +8,51 @@ class RbVmomi::VIM::Folder
|
|
8
8
|
x if x.is_a? type
|
9
9
|
end
|
10
10
|
|
11
|
+
# Retrieve a virtual machine or host by DNS name
|
12
|
+
# @param name [String] The fully qualified domain name to find.
|
13
|
+
# @param type [Class] Return nil unless the found entity <tt>is_a? type</tt>.
|
14
|
+
# @param dc [RbVmomi::VIM::Datacenter] Restricts the query to entities in the given Datacenter.
|
15
|
+
# @return [VIM::ManagedEntity]
|
16
|
+
def findByDnsName name, type=RbVmomi::VIM::VirtualMachine, dc=nil
|
17
|
+
propSpecs = {
|
18
|
+
:entity => self, :dnsName => name,
|
19
|
+
:vmSearch => type == RbVmomi::VIM::VirtualMachine
|
20
|
+
}
|
21
|
+
propSpecs[:datacenter] = dc if dc
|
22
|
+
x = @soap.searchIndex.FindByDnsName(propSpecs)
|
23
|
+
x if x.is_a? type
|
24
|
+
end
|
25
|
+
|
26
|
+
# Retrieve a virtual machine or host by IP address
|
27
|
+
# @param ip [String] The IP address is in dot-decimal notation.
|
28
|
+
# @param type [Class] Return nil unless the found entity <tt>is_a? type</tt>.
|
29
|
+
# @param dc [RbVmomi::VIM::Datacenter] Restricts the query to entities in the given Datacenter.
|
30
|
+
# @return [VIM::ManagedEntity]
|
31
|
+
def findByIp ip, type=RbVmomi::VIM::VirtualMachine, dc=nil
|
32
|
+
propSpecs = {
|
33
|
+
:entity => self, :ip => ip,
|
34
|
+
:vmSearch => type == RbVmomi::VIM::VirtualMachine
|
35
|
+
}
|
36
|
+
propSpecs[:datacenter] = dc if dc
|
37
|
+
x = @soap.searchIndex.FindByIp(propSpecs)
|
38
|
+
x if x.is_a? type
|
39
|
+
end
|
40
|
+
|
41
|
+
# Retrieve a virtual machine or host by BIOS UUID.
|
42
|
+
# @param uuid [String] The UUID to find.
|
43
|
+
# @param type [Class] Return nil unless the found entity <tt>is_a? type</tt>.
|
44
|
+
# @param dc [RbVmomi::VIM::Datacenter] Restricts the query to entities in the given Datacenter.
|
45
|
+
# @return [VIM::ManagedEntity]
|
46
|
+
def findByUuid uuid, type=RbVmomi::VIM::VirtualMachine, dc=nil
|
47
|
+
propSpecs = {
|
48
|
+
:entity => self, :uuid => uuid, :instanceUuid => false,
|
49
|
+
:vmSearch => type == RbVmomi::VIM::VirtualMachine
|
50
|
+
}
|
51
|
+
propSpecs[:datacenter] = dc if dc
|
52
|
+
x = @soap.searchIndex.FindByUuid(propSpecs)
|
53
|
+
x if x.is_a? type
|
54
|
+
end
|
55
|
+
|
11
56
|
# Alias to <tt>traverse path, type, true</tt>
|
12
57
|
# @see #traverse
|
13
58
|
def traverse! path, type=Object
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbvmomi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 8
|
10
|
+
version: 1.1.8
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Rich Lane
|
@@ -10,7 +15,7 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-03-15 00:00:00 -07:00
|
14
19
|
default_executable: rbvmomish
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
@@ -21,6 +26,11 @@ dependencies:
|
|
21
26
|
requirements:
|
22
27
|
- - ">="
|
23
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 4
|
33
|
+
- 1
|
24
34
|
version: 1.4.1
|
25
35
|
type: :runtime
|
26
36
|
version_requirements: *id001
|
@@ -32,6 +42,9 @@ dependencies:
|
|
32
42
|
requirements:
|
33
43
|
- - ">="
|
34
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
35
48
|
version: "0"
|
36
49
|
type: :runtime
|
37
50
|
version_requirements: *id002
|
@@ -43,6 +56,9 @@ dependencies:
|
|
43
56
|
requirements:
|
44
57
|
- - ">="
|
45
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
46
62
|
version: "0"
|
47
63
|
type: :runtime
|
48
64
|
version_requirements: *id003
|
@@ -54,6 +70,9 @@ dependencies:
|
|
54
70
|
requirements:
|
55
71
|
- - ">="
|
56
72
|
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
57
76
|
version: "0"
|
58
77
|
type: :runtime
|
59
78
|
version_requirements: *id004
|
@@ -65,6 +84,7 @@ extensions: []
|
|
65
84
|
|
66
85
|
extra_rdoc_files:
|
67
86
|
- LICENSE
|
87
|
+
- README.html
|
68
88
|
- README.rdoc
|
69
89
|
files:
|
70
90
|
- .yardopts
|
@@ -114,6 +134,7 @@ files:
|
|
114
134
|
- test/test_parse_response.rb
|
115
135
|
- test/test_serialization.rb
|
116
136
|
- vmodl.cdb
|
137
|
+
- README.html
|
117
138
|
has_rdoc: true
|
118
139
|
homepage: https://github.com/rlane/rbvmomi
|
119
140
|
licenses: []
|
@@ -128,17 +149,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
149
|
requirements:
|
129
150
|
- - ">="
|
130
151
|
- !ruby/object:Gem::Version
|
131
|
-
|
152
|
+
hash: 57
|
153
|
+
segments:
|
154
|
+
- 1
|
155
|
+
- 8
|
156
|
+
- 7
|
157
|
+
version: 1.8.7
|
132
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
159
|
none: false
|
134
160
|
requirements:
|
135
161
|
- - ">="
|
136
162
|
- !ruby/object:Gem::Version
|
163
|
+
hash: 3
|
164
|
+
segments:
|
165
|
+
- 0
|
137
166
|
version: "0"
|
138
167
|
requirements: []
|
139
168
|
|
140
169
|
rubyforge_project:
|
141
|
-
rubygems_version: 1.
|
170
|
+
rubygems_version: 1.4.1
|
142
171
|
signing_key:
|
143
172
|
specification_version: 3
|
144
173
|
summary: Ruby interface to the VMware vSphere API
|