rbvmomi 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.5
1
+ 1.1.6
data/devel/analyze-xml.rb CHANGED
@@ -36,7 +36,7 @@ def print_tree tree, indent=0
36
36
  puts "#{' '*indent}#{k}#{numsym}: #{attrs.sort.map { |a| "[#{a * ' '}]"} * ', '} {#{min},#{max}}"
37
37
  print_tree v, (indent+1)
38
38
  end
39
- end
39
+ end
40
40
 
41
41
  tree = {}
42
42
  ARGV.each do |fn|
@@ -0,0 +1,48 @@
1
+ # Based on takeVMScreenshot.pl by William Lam
2
+ require 'trollop'
3
+ require 'rbvmomi'
4
+ require 'rbvmomi/trollop'
5
+
6
+ VIM = RbVmomi::VIM
7
+
8
+ opts = Trollop.options do
9
+ banner <<-EOS
10
+ Take a screenshot.
11
+
12
+ Usage:
13
+ screenshot.rb [options] vm filename
14
+
15
+ A PNG image will be saved to the given filename.
16
+
17
+ VIM connection options:
18
+ EOS
19
+
20
+ rbvmomi_connection_opts
21
+
22
+ text <<-EOS
23
+
24
+ VM location options:
25
+ EOS
26
+
27
+ rbvmomi_datacenter_opt
28
+
29
+ text <<-EOS
30
+
31
+ Other options:
32
+ EOS
33
+ end
34
+
35
+ Trollop.die("must specify host") unless opts[:host]
36
+ vm_name = ARGV[0] or abort("must specify VM name")
37
+ output_path = ARGV[1] or abort("must specify output filename")
38
+
39
+ vim = VIM.connect opts
40
+ dc = vim.serviceInstance.find_datacenter(opts[:datacenter])
41
+ vm = dc.find_vm vm_name
42
+ abort "VM must be running" unless vm.runtime.powerState == 'poweredOn'
43
+ remote_path = vm.CreateScreenshot_Task.wait_for_completion
44
+ remote_path =~ /^(\/vmfs\/volumes\/[^\/]+)\// or fail
45
+ datastore_prefix = $1
46
+ datastore_path = $'
47
+ datastore = vm.datastore.find { |ds| ds.info.url == datastore_prefix }
48
+ datastore.download datastore_path, output_path
@@ -5,17 +5,6 @@ require 'nokogiri'
5
5
  require 'net/http'
6
6
  require 'pp'
7
7
 
8
- module Net
9
- class HTTPGenericRequest
10
- alias old_exec exec
11
-
12
- def exec sock, ver, path
13
- old_exec sock, ver, path
14
- sock.io.flush
15
- end
16
- end
17
- end
18
-
19
8
  class RbVmomi::TrivialSoap
20
9
  attr_accessor :debug, :cookie
21
10
  attr_reader :http
@@ -48,6 +37,9 @@ class RbVmomi::TrivialSoap
48
37
  @http.set_debug_output(STDERR) if $DEBUG
49
38
  @http.read_timeout = 1000000000
50
39
  @http.open_timeout = 5
40
+ def @http.on_connect
41
+ @socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
42
+ end
51
43
  @http.start
52
44
  end
53
45
 
@@ -68,7 +60,7 @@ class RbVmomi::TrivialSoap
68
60
  headers = { 'content-type' => 'text/xml; charset=utf-8', 'SOAPAction' => action }
69
61
  headers['cookie'] = @cookie if @cookie
70
62
  body = soap_envelope(&b).target!
71
-
63
+
72
64
  if @debug
73
65
  $stderr.puts "Request:"
74
66
  $stderr.puts body
@@ -27,7 +27,7 @@ class Parser
27
27
  def rbvmomi_connection_opts
28
28
  opt :host, "host", :type => :string, :short => 'o', :default => ENV['RBVMOMI_HOST']
29
29
  opt :port, "port", :type => :int, :short => :none, :default => (ENV.member?('RBVMOMI_PORT') ? ENV['RBVMOMI_PORT'].to_i : 443)
30
- opt :"no-ssl", "don't use ssl", :short => :none, :default => (ENV['RBVMOMI_SSL'] == '0')
30
+ opt :"no-ssl", "don't use ssl", :short => :none, :default => (ENV['RBVMOMI_SSL'] == '0')
31
31
  opt :insecure, "don't verify ssl certificate", :short => 'k', :default => (ENV['RBVMOMI_INSECURE'] == '1')
32
32
  opt :user, "username", :short => 'u', :default => (ENV['RBVMOMI_USER'] || 'root')
33
33
  opt :password, "password", :short => 'p', :default => (ENV['RBVMOMI_PASSWORD'] || '')
@@ -41,8 +41,10 @@ class TypeLoader
41
41
  private
42
42
 
43
43
  def load_extension name
44
- path = @target.extension_path name
45
- load path if File.exists? path
44
+ dirs = @target.extension_dirs
45
+ dirs.map { |x| File.join(x, "#{name}.rb") }.
46
+ select { |x| File.exists? x }.
47
+ each { |x| load x }
46
48
  end
47
49
 
48
50
  def make_type name
data/lib/rbvmomi/vim.rb CHANGED
@@ -22,7 +22,7 @@ class VIM < Connection
22
22
  fail "host option required" unless opts[:host]
23
23
  opts[:user] ||= 'root'
24
24
  opts[:password] ||= ''
25
- opts[:ssl] = true unless opts.member? :ssl
25
+ opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
26
26
  opts[:insecure] ||= false
27
27
  opts[:port] ||= (opts[:ssl] ? 443 : 80)
28
28
  opts[:path] ||= '/sdk'
@@ -67,9 +67,11 @@ class VIM < Connection
67
67
  serviceContent.searchIndex
68
68
  end
69
69
 
70
- # @private
71
- def self.extension_path name
72
- File.join(File.dirname(__FILE__), "vim", "#{name}.rb")
70
+ @extension_dirs = [File.join(File.dirname(__FILE__), "vim")]
71
+
72
+ # Directories to search for extensions
73
+ def self.extension_dirs
74
+ @extension_dirs
73
75
  end
74
76
 
75
77
  load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.cdb"))
@@ -15,13 +15,19 @@ class RbVmomi::VIM::Folder
15
15
  end
16
16
 
17
17
  # Retrieve a descendant of this Folder.
18
- # @param path [String] Path delimited by '/'.
18
+ # @param path [String] Path delimited by '/', or an array of path elements.
19
19
  # @param type (see Folder#find)
20
20
  # @param create [Boolean] If set, create folders that don't exist.
21
21
  # @return (see Folder#find)
22
22
  # @todo Move +create+ functionality into another method.
23
23
  def traverse path, type=Object, create=false
24
- es = path.split('/').reject(&:empty?)
24
+ if path.is_a? String
25
+ es = path.split('/').reject(&:empty?)
26
+ elsif path.is_a? Enumerable
27
+ es = path
28
+ else
29
+ fail "unexpected path class"
30
+ end
25
31
  return self if es.empty?
26
32
  final = es.pop
27
33
 
@@ -87,7 +87,7 @@ class RbVmomi::VIM::OvfManager
87
87
  vm
88
88
  end
89
89
  rescue Exception
90
- nfcLease.HttpNfcLeaseAbort
90
+ nfcLease.HttpNfcLeaseAbort if nfcLease
91
91
  raise
92
92
  end
93
93
  end
@@ -91,7 +91,9 @@ def test_array2
91
91
  :vlanIds => [
92
92
  VIM::NumericRange(:dynamicProperty => [], :start => 5, :end => 7),
93
93
  VIM::NumericRange(:dynamicProperty => [], :start => 10, :end => 20),
94
- ]
94
+ ],
95
+ :vmDirectPathGen2InactiveReasonNetwork => [],
96
+ :vmDirectPathGen2InactiveReasonOther => []
95
97
  )
96
98
 
97
99
  check <<-EOS, obj, 'DVPortStatus'
@@ -115,7 +117,9 @@ def test_empty_array
115
117
  :dynamicProperty => [],
116
118
  :linkUp => true,
117
119
  :blocked => false,
118
- :vlanIds => []
120
+ :vlanIds => [],
121
+ vmDirectPathGen2InactiveReasonNetwork: [],
122
+ vmDirectPathGen2InactiveReasonOther: []
119
123
  )
120
124
 
121
125
  check <<-EOS, obj, 'DVPortStatus'
@@ -257,7 +261,8 @@ end
257
261
  :powerState => "poweredOn",
258
262
  :recordReplayState => "inactive",
259
263
  :suspendInterval => 0,
260
- :toolsInstallerMounted => false
264
+ :toolsInstallerMounted => false,
265
+ :device => []
261
266
  )
262
267
 
263
268
  check <<-EOS, obj, 'VirtualMachineRuntimeInfo'
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbvmomi
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 1
8
- - 5
9
- version: 1.1.5
4
+ prerelease:
5
+ version: 1.1.6
10
6
  platform: ruby
11
7
  authors:
12
8
  - Rich Lane
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-02-22 00:00:00 -08:00
13
+ date: 2011-02-28 00:00:00 -08:00
18
14
  default_executable: rbvmomish
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,10 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 4
31
- - 1
32
24
  version: 1.4.1
33
25
  type: :runtime
34
26
  version_requirements: *id001
@@ -40,8 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ">="
42
34
  - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
35
  version: "0"
46
36
  type: :runtime
47
37
  version_requirements: *id002
@@ -53,8 +43,6 @@ dependencies:
53
43
  requirements:
54
44
  - - ">="
55
45
  - !ruby/object:Gem::Version
56
- segments:
57
- - 0
58
46
  version: "0"
59
47
  type: :runtime
60
48
  version_requirements: *id003
@@ -66,8 +54,6 @@ dependencies:
66
54
  requirements:
67
55
  - - ">="
68
56
  - !ruby/object:Gem::Version
69
- segments:
70
- - 0
71
57
  version: "0"
72
58
  type: :runtime
73
59
  version_requirements: *id004
@@ -79,7 +65,6 @@ extensions: []
79
65
 
80
66
  extra_rdoc_files:
81
67
  - LICENSE
82
- - README.html
83
68
  - README.rdoc
84
69
  files:
85
70
  - .yardopts
@@ -99,6 +84,7 @@ files:
99
84
  - examples/readme-1.rb
100
85
  - examples/readme-2.rb
101
86
  - examples/run.sh
87
+ - examples/screenshot.rb
102
88
  - examples/vdf.rb
103
89
  - lib/rbvmomi.rb
104
90
  - lib/rbvmomi/basic_types.rb
@@ -128,7 +114,6 @@ files:
128
114
  - test/test_parse_response.rb
129
115
  - test/test_serialization.rb
130
116
  - vmodl.cdb
131
- - README.html
132
117
  has_rdoc: true
133
118
  homepage: https://github.com/rlane/rbvmomi
134
119
  licenses: []
@@ -143,23 +128,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
128
  requirements:
144
129
  - - ">="
145
130
  - !ruby/object:Gem::Version
146
- segments:
147
- - 1
148
- - 9
149
- - 1
150
131
  version: 1.9.1
151
132
  required_rubygems_version: !ruby/object:Gem::Requirement
152
133
  none: false
153
134
  requirements:
154
135
  - - ">="
155
136
  - !ruby/object:Gem::Version
156
- segments:
157
- - 0
158
137
  version: "0"
159
138
  requirements: []
160
139
 
161
140
  rubyforge_project:
162
- rubygems_version: 1.3.7
141
+ rubygems_version: 1.5.3
163
142
  signing_key:
164
143
  specification_version: 3
165
144
  summary: Ruby interface to the VMware vSphere API
@@ -172,6 +151,7 @@ test_files:
172
151
  - examples/power.rb
173
152
  - examples/readme-1.rb
174
153
  - examples/readme-2.rb
154
+ - examples/screenshot.rb
175
155
  - examples/vdf.rb
176
156
  - test/test_deserialization.rb
177
157
  - test/test_emit_request.rb
data/README.html DELETED
@@ -1,76 +0,0 @@
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>