rbvmomi 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
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 =&gt; '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/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.2.2
@@ -138,18 +138,23 @@ class DataObject < ObjectWithProperties
138
138
  end
139
139
 
140
140
  class ManagedObject < ObjectWithMethods
141
- def initialize soap, ref
141
+ def initialize connection, ref
142
142
  super()
143
- @soap = soap
143
+ @connection = connection
144
+ @soap = @connection # XXX deprecated
144
145
  @ref = ref
145
146
  end
146
147
 
148
+ def _connection
149
+ @connection
150
+ end
151
+
147
152
  def _ref
148
153
  @ref
149
154
  end
150
155
 
151
156
  def _get_property sym
152
- ret = @soap.propertyCollector.RetrieveProperties(:specSet => [{
157
+ ret = @connection.propertyCollector.RetrieveProperties(:specSet => [{
153
158
  :propSet => [{ :type => self.class.wsdl_name, :pathSet => [sym.to_s] }],
154
159
  :objectSet => [{ :obj => self }],
155
160
  }])[0]
@@ -169,7 +174,7 @@ class ManagedObject < ObjectWithMethods
169
174
  def _call method, o={}
170
175
  fail "parameters must be passed as a hash" unless o.is_a? Hash
171
176
  desc = self.class.full_methods_desc[method.to_s] or fail "unknown method"
172
- @soap.call method, desc, self, o
177
+ @connection.call method, desc, self, o
173
178
  end
174
179
 
175
180
  def to_s
@@ -71,7 +71,7 @@ class RbVmomi::VIM::Folder
71
71
  elsif path.is_a? Enumerable
72
72
  es = path
73
73
  else
74
- fail "unexpected path class"
74
+ fail "unexpected path class #{path.class}"
75
75
  end
76
76
  return self if es.empty?
77
77
  final = es.pop
@@ -74,8 +74,8 @@ class RbVmomi::VIM::OvfManager
74
74
  method = fileItem.create ? "PUT" : "POST"
75
75
 
76
76
  href = deviceUrl.url.gsub("*", opts[:host].config.network.vnic[0].spec.ip.ipAddress)
77
- downloadCmd = "#{CURLBIN} -L '#{filename}'"
78
- uploadCmd = "#{CURLBIN} -X #{method} --insecure -T - -H 'Content-Type: application/x-vnd.vmware-streamVmdk' -H 'Content-Length: #{fileItem.size}' '#{href}'"
77
+ downloadCmd = "#{CURLBIN} -L '#{URI::escape(filename)}'"
78
+ uploadCmd = "#{CURLBIN} -X #{method} --insecure -T - -H 'Content-Type: application/x-vnd.vmware-streamVmdk' -H 'Content-Length: #{fileItem.size}' '#{URI::escape(href)}'"
79
79
  system("#{downloadCmd} | #{uploadCmd}")
80
80
  progress += (95.0 / result.fileItem.length)
81
81
  nfcLease.HttpNfcLeaseProgress(:percent => progress.to_i)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rbvmomi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.1
5
+ version: 1.2.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rich Lane
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-17 00:00:00 -07:00
13
+ date: 2011-03-18 00:00:00 -07:00
14
14
  default_executable: rbvmomish
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -54,6 +54,7 @@ extensions: []
54
54
 
55
55
  extra_rdoc_files:
56
56
  - LICENSE
57
+ - README.html
57
58
  - README.rdoc
58
59
  files:
59
60
  - .yardopts
@@ -103,6 +104,7 @@ files:
103
104
  - test/test_parse_response.rb
104
105
  - test/test_serialization.rb
105
106
  - vmodl.db
107
+ - README.html
106
108
  has_rdoc: true
107
109
  homepage: https://github.com/rlane/rbvmomi
108
110
  licenses: []
@@ -127,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
129
  requirements: []
128
130
 
129
131
  rubyforge_project:
130
- rubygems_version: 1.5.3
132
+ rubygems_version: 1.6.2
131
133
  signing_key:
132
134
  specification_version: 3
133
135
  summary: Ruby interface to the VMware vSphere API