rbvmomi 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.yardopts CHANGED
@@ -3,3 +3,4 @@
3
3
  --readme README.rdoc
4
4
  lib/rbvmomi/vim.rb
5
5
  lib/rbvmomi/vim/*.rb
6
+ lib/rbvmomi/trollop.rb
data/README.rdoc CHANGED
@@ -8,6 +8,10 @@ supports the vSphere 4.1 API. RbVmomi specific documentation is
8
8
  online[http://rdoc.info/github/rlane/rbvmomi/master/frames] and is meant to
9
9
  be used alongside the official documentation[http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/index.html].
10
10
 
11
+ == Installation
12
+
13
+ gem install rbvmomi
14
+
11
15
  == Usage
12
16
 
13
17
  A simple example of turning on a VM:
@@ -52,9 +56,8 @@ in the first example uses the SearchIndex for fast lookups.
52
56
 
53
57
  A few important points:
54
58
 
55
- * Ruby 1.9 is required.
56
- * Properties are exposed as accessor methods.
57
59
  * All class, method, parameter, and property names match the official documentation[http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/index.html].
60
+ * Properties are exposed as accessor methods.
58
61
  * Data object types can usually be inferred from context, so you may use a hash instead.
59
62
  * Enumeration values are simply strings.
60
63
  * Example code is included in the examples/ directory.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ begin
6
6
  require 'jeweler'
7
7
  Jeweler::Tasks.new do |gem|
8
8
  gem.name = "rbvmomi"
9
- gem.summary = "Ruby interface to the VI API"
9
+ gem.summary = "Ruby interface to the VMware vSphere API"
10
10
  #gem.description = ""
11
11
  gem.email = "rlane@vmware.com"
12
12
  gem.homepage = "https://github.com/rlane/rbvmomi"
@@ -17,6 +17,7 @@ begin
17
17
  gem.add_dependency 'cdb-full'
18
18
  gem.required_ruby_version = '>= 1.9.1'
19
19
  gem.files.include 'vmodl.cdb'
20
+ gem.files.include '.yardopts'
20
21
  end
21
22
  rescue LoadError
22
23
  puts "Jeweler not available. Install it with: gem install jeweler"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -2,7 +2,7 @@
2
2
  require 'nokogiri'
3
3
  require 'cdb'
4
4
 
5
- # usage: analyze-vim-declarations.rb vim-declarations.xml foo-declarations.xml vmodl.db
5
+ # :usage => analyze-vim-declarations.rb vim-declarations.xml foo-declarations.xml vmodl.db
6
6
 
7
7
  XML_FNS = ARGV[0...-1]
8
8
  abort "must specify path to vim-declarations.xml" if XML_FNS.empty?
@@ -4,11 +4,10 @@ require 'rbvmomi'
4
4
  require 'rbvmomi/trollop'
5
5
 
6
6
  VIM = RbVmomi::VIM
7
- N = 2
8
7
 
9
8
  opts = Trollop.options do
10
9
  banner <<-EOS
11
- Create and destroy a couple of VMs.
10
+ Create a VM.
12
11
 
13
12
  Usage:
14
13
  create_vm.rb [options]
@@ -41,52 +40,52 @@ hosts = dc.hostFolder.children
41
40
  rp = hosts.first.resourcePool
42
41
 
43
42
  vm_cfg = {
44
- name: vm_name,
45
- guestId: 'otherGuest',
46
- files: { vmPathName: '[datastore1]' },
47
- numCPUs: 1,
48
- memoryMB: 128,
49
- deviceChange: [
43
+ :name => vm_name,
44
+ :guestId => 'otherGuest',
45
+ :files => { :vmPathName => '[datastore1]' },
46
+ :numCPUs => 1,
47
+ :memoryMB => 128,
48
+ :deviceChange => [
50
49
  {
51
- operation: :add,
52
- device: VIM.VirtualLsiLogicController(
53
- key: 1000,
54
- busNumber: 0,
55
- sharedBus: :noSharing,
50
+ :operation => :add,
51
+ :device => VIM.VirtualLsiLogicController(
52
+ :key => 1000,
53
+ :busNumber => 0,
54
+ :sharedBus => :noSharing
56
55
  )
57
56
  }, {
58
- operation: :add,
59
- fileOperation: :create,
60
- device: VIM.VirtualDisk(
61
- key: 0,
62
- backing: VIM.VirtualDiskFlatVer2BackingInfo(
63
- fileName: '[datastore1]',
64
- diskMode: :persistent,
65
- thinProvisioned: true,
57
+ :operation => :add,
58
+ :fileOperation => :create,
59
+ :device => VIM.VirtualDisk(
60
+ :key => 0,
61
+ :backing => VIM.VirtualDiskFlatVer2BackingInfo(
62
+ :fileName => '[datastore1]',
63
+ :diskMode => :persistent,
64
+ :thinProvisioned => true
66
65
  ),
67
- controllerKey: 1000,
68
- unitNumber: 0,
69
- capacityInKB: 4000000,
66
+ :controllerKey => 1000,
67
+ :unitNumber => 0,
68
+ :capacityInKB => 4000000
70
69
  )
71
70
  }, {
72
- operation: :add,
73
- device: VIM.VirtualE1000(
74
- key: 0,
75
- deviceInfo: {
76
- label: 'Network Adapter 1',
77
- summary: 'VM Network',
71
+ :operation => :add,
72
+ :device => VIM.VirtualE1000(
73
+ :key => 0,
74
+ :deviceInfo => {
75
+ :label => 'Network Adapter 1',
76
+ :summary => 'VM Network'
78
77
  },
79
- backing: VIM.VirtualEthernetCardNetworkBackingInfo(
80
- deviceName: 'VM Network',
78
+ :backing => VIM.VirtualEthernetCardNetworkBackingInfo(
79
+ :deviceName => 'VM Network'
81
80
  ),
82
- addressType: 'generated'
81
+ :addressType => 'generated'
83
82
  )
84
83
  }
85
84
  ],
86
- extraConfig: [
85
+ :extraConfig => [
87
86
  {
88
- key: 'bios.bootOrder',
89
- value: 'ethernet0'
87
+ :key => 'bios.bootOrder',
88
+ :value => 'ethernet0'
90
89
  }
91
90
  ]
92
91
  }
@@ -49,6 +49,6 @@ case cmd
49
49
  when 'list'
50
50
  vm.config.extraConfig.each { |x| puts "#{x.key}: #{x.value}" }
51
51
  when 'set'
52
- extraConfig = ARGV.map { |x| x.split("=", 2) }.map { |k,v| { key: k, value: v } }
53
- vm.ReconfigVM_Task(spec: VIM.VirtualMachineConfigSpec(extraConfig: extraConfig)).wait_for_completion
52
+ extraConfig = ARGV.map { |x| x.split("=", 2) }.map { |k,v| { :key => k, :value => v } }
53
+ vm.ReconfigVM_Task(:spec => VIM.VirtualMachineConfigSpec(:extraConfig => extraConfig)).wait_for_completion
54
54
  end
data/examples/power.rb CHANGED
@@ -3,7 +3,7 @@ require 'rbvmomi'
3
3
  require 'rbvmomi/trollop'
4
4
 
5
5
  VIM = RbVmomi::VIM
6
- CMDS = %w(on off reset suspend)
6
+ CMDS = %w(on off reset suspend destroy)
7
7
 
8
8
  opts = Trollop.options do
9
9
  banner <<-EOS
@@ -52,6 +52,8 @@ when 'reset'
52
52
  vm.ResetVM_Task.wait_for_completion
53
53
  when 'suspend'
54
54
  vm.SuspendVM_Task.wait_for_completion
55
+ when 'destroy'
56
+ vm.Destroy_Task.wait_for_completion
55
57
  else
56
58
  abort "invalid command"
57
59
  end
data/examples/readme-2.rb CHANGED
@@ -35,15 +35,15 @@ dc = rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).find { |x| x.name ==
35
35
  vm = dc.vmFolder.childEntity.grep(RbVmomi::VIM::VirtualMachine).find { |x| x.name == vm_name } or fail "VM not found"
36
36
  task = vm.PowerOnVM_Task
37
37
  filter = vim.propertyCollector.CreateFilter(
38
- spec: {
39
- propSet: [{ type: 'Task', all: false, pathSet: ['info.state']}],
40
- objectSet: [{ obj: task }]
38
+ :spec => {
39
+ :propSet => [{ :type => 'Task', :all => false, :pathSet => ['info.state']}],
40
+ :objectSet => [{ :obj => task }]
41
41
  },
42
- partialUpdates: false
42
+ :partialUpdates => false
43
43
  )
44
44
  ver = ''
45
45
  while true
46
- result = vim.propertyCollector.WaitForUpdates(version: ver)
46
+ result = vim.propertyCollector.WaitForUpdates(:version => ver)
47
47
  ver = result.version
48
48
  break if ['success', 'error'].member? task.info.state
49
49
  end
data/examples/run.sh ADDED
@@ -0,0 +1,39 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ if [ -z "$RBVMOMI_HOST" ]
5
+ then
6
+ echo "export at least RBVMOMI_HOST"
7
+ exit 1
8
+ fi
9
+
10
+ EXAMPLES="$(dirname $(which $0))"
11
+ export RUBYOPT="-I$EXAMPLES/../lib -rubygems"
12
+
13
+ source "$HOME/.rvm/scripts/rvm"
14
+ rvm use 1.8.7
15
+ ruby -v
16
+ RUBY=ruby
17
+
18
+ echo Creating VM
19
+ $RUBY $EXAMPLES/create_vm.rb foo
20
+ echo Powering on VM
21
+ $RUBY $EXAMPLES/power.rb on foo
22
+ echo Resetting VM
23
+ $RUBY $EXAMPLES/power.rb reset foo
24
+ echo Powering off VM
25
+ $RUBY $EXAMPLES/power.rb off foo
26
+ echo "Powering on VM (1)"
27
+ $RUBY $EXAMPLES/readme-1.rb foo
28
+ echo Powering off VM
29
+ $RUBY $EXAMPLES/power.rb off foo
30
+ echo "Powering on VM (2)"
31
+ $RUBY $EXAMPLES/readme-2.rb foo
32
+ echo "Setting extraConfig"
33
+ $RUBY $EXAMPLES/extraConfig.rb foo set guestinfo.bar=baz
34
+ echo "Listing extraConfig"
35
+ $RUBY $EXAMPLES/extraConfig.rb foo list | grep guestinfo.bar
36
+ echo Powering off VM
37
+ $RUBY $EXAMPLES/power.rb off foo
38
+ echo Destroying VM
39
+ $RUBY $EXAMPLES/power.rb destroy foo
@@ -1,33 +1,34 @@
1
1
  # Copyright (c) 2011 VMware, Inc. All Rights Reserved.
2
2
  require 'trollop'
3
3
 
4
+ # @todo Document
4
5
  module Trollop
5
6
  class Parser
6
7
  def rbvmomi_connection_opts
7
- opt :host, "host", type: :string, short: 'o', default: ENV['RBVMOMI_HOST']
8
- opt :port, "port", type: :int, short: :none, default: (ENV.member?('RBVMOMI_PORT') ? ENV['RBVMOMI_PORT'].to_i : 443)
9
- opt :"no-ssl", "don't use ssl", short: :none, default: (ENV['RBVMOMI_SSL'] == '0')
10
- opt :insecure, "don't verify ssl certificate", short: 'k', default: (ENV['RBVMOMI_INSECURE'] == '1')
11
- opt :user, "username", short: 'u', default: (ENV['RBVMOMI_USER'] || 'root')
12
- opt :password, "password", short: 'p', default: (ENV['RBVMOMI_PASSWORD'] || '')
13
- opt :path, "SOAP endpoint path", short: :none, default: (ENV['RBVMOMI_PATH'] || '/sdk')
14
- opt :debug, "Log SOAP messages", short: 'd'
8
+ opt :host, "host", :type => :string, :short => 'o', :default => ENV['RBVMOMI_HOST']
9
+ opt :port, "port", :type => :int, :short => :none, :default => (ENV.member?('RBVMOMI_PORT') ? ENV['RBVMOMI_PORT'].to_i : 443)
10
+ opt :"no-ssl", "don't use ssl", :short => :none, :default => (ENV['RBVMOMI_SSL'] == '0')
11
+ opt :insecure, "don't verify ssl certificate", :short => 'k', :default => (ENV['RBVMOMI_INSECURE'] == '1')
12
+ opt :user, "username", :short => 'u', :default => (ENV['RBVMOMI_USER'] || 'root')
13
+ opt :password, "password", :short => 'p', :default => (ENV['RBVMOMI_PASSWORD'] || '')
14
+ opt :path, "SOAP endpoint path", :short => :none, :default => (ENV['RBVMOMI_PATH'] || '/sdk')
15
+ opt :debug, "Log SOAP messages", :short => 'd'
15
16
  end
16
17
 
17
18
  def rbvmomi_datacenter_opt
18
- opt :datacenter, "datacenter", type: :string, short: "D", default: (ENV['RBVMOMI_DATACENTER'] || 'ha-datacenter')
19
+ opt :datacenter, "datacenter", :type => :string, :short => "D", :default => (ENV['RBVMOMI_DATACENTER'] || 'ha-datacenter')
19
20
  end
20
21
 
21
22
  def rbvmomi_folder_opt
22
- opt :folder, "VM folder", type: :string, short: "F", default: (ENV['RBVMOMI_FOLDER'] || '')
23
+ opt :folder, "VM folder", :type => :string, :short => "F", :default => (ENV['RBVMOMI_FOLDER'] || '')
23
24
  end
24
25
 
25
26
  def rbvmomi_computer_opt
26
- opt :computer, "Compute resource", type: :string, short: "R", default: ENV['RBVMOMI_COMPUTER']
27
+ opt :computer, "Compute resource", :type => :string, :short => "R", :default => ENV['RBVMOMI_COMPUTER']
27
28
  end
28
29
 
29
30
  def rbvmomi_datastore_opt
30
- opt :datastore, "Datastore", short: 's', default: (ENV['RBVMOMI_DATASTORE'] || 'datastore1')
31
+ opt :datastore, "Datastore", :short => 's', :default => (ENV['RBVMOMI_DATASTORE'] || 'datastore1')
31
32
  end
32
33
  end
33
34
  end
@@ -4,38 +4,38 @@ class RbVmomi::VIM::ComputeResource
4
4
  # @note Values are returned in a hash.
5
5
  #
6
6
  # @return [Mhz] totalCPU: Sum of the frequencies of each CPU in the cluster.
7
- # @return [Mhz] usedCPU: CPU cycles used across the cluster.
8
- # @return [MB] totalMem: Total RAM.
9
- # @return [MB] usedMem: Used RAM.
7
+ # @return [Mhz] usedCPU: CPU cycles used across the cluster.
8
+ # @return [MB] totalMem: Total RAM.
9
+ # @return [MB] usedMem: Used RAM.
10
10
  def stats
11
11
  filterSpec = RbVmomi::VIM.PropertyFilterSpec(
12
- objectSet: [{
13
- obj: self,
14
- selectSet: [
12
+ :objectSet => [{
13
+ :obj => self,
14
+ :selectSet => [
15
15
  RbVmomi::VIM.TraversalSpec(
16
- name: 'tsHosts',
17
- type: 'ComputeResource',
18
- path: 'host',
19
- skip: false,
16
+ :name => 'tsHosts',
17
+ :type => 'ComputeResource',
18
+ :path => 'host',
19
+ :skip => false
20
20
  )
21
21
  ]
22
22
  }],
23
- propSet: [{
24
- pathSet: %w(name overallStatus summary.hardware.cpuMhz
23
+ :propSet => [{
24
+ :pathSet => %w(name overallStatus summary.hardware.cpuMhz
25
25
  summary.hardware.numCpuCores summary.hardware.memorySize
26
26
  summary.quickStats.overallCpuUsage
27
27
  summary.quickStats.overallMemoryUsage),
28
- type: 'HostSystem'
28
+ :type => 'HostSystem'
29
29
  }]
30
30
  )
31
31
 
32
- result = @soap.propertyCollector.RetrieveProperties(specSet: [filterSpec])
32
+ result = @soap.propertyCollector.RetrieveProperties(:specSet => [filterSpec])
33
33
 
34
34
  stats = {
35
- totalCPU: 0,
36
- totalMem: 0,
37
- usedCPU: 0,
38
- usedMem: 0,
35
+ :totalCPU => 0,
36
+ :totalMem => 0,
37
+ :usedCPU => 0,
38
+ :usedMem => 0,
39
39
  }
40
40
 
41
41
  result.each do |x|
@@ -30,7 +30,7 @@ class RbVmomi::VIM::Datastore
30
30
  "-o", local_path,
31
31
  "-b", @soap.cookie,
32
32
  url,
33
- out: '/dev/null'
33
+ :out => '/dev/null'
34
34
  Process.waitpid(pid, 0)
35
35
  fail "download failed" unless $?.success?
36
36
  end
@@ -45,7 +45,7 @@ class RbVmomi::VIM::Datastore
45
45
  "-T", local_path,
46
46
  "-b", @soap.cookie,
47
47
  url,
48
- out: '/dev/null'
48
+ :out => '/dev/null'
49
49
  Process.waitpid(pid, 0)
50
50
  fail "upload failed" unless $?.success?
51
51
  end
@@ -4,7 +4,7 @@ class RbVmomi::VIM::Folder
4
4
  # @param type [Class] Return nil unless the found entity <tt>is_a? type</tt>.
5
5
  # @return [VIM::ManagedEntity]
6
6
  def find name, type=Object
7
- x = @soap.searchIndex.FindChild(entity: self, name: name)
7
+ x = @soap.searchIndex.FindChild(:entity => self, :name => name)
8
8
  x if x.is_a? type
9
9
  end
10
10
 
@@ -26,13 +26,13 @@ class RbVmomi::VIM::Folder
26
26
  final = es.pop
27
27
 
28
28
  p = es.inject(self) do |f,e|
29
- f.find(e, Folder) || (create && f.CreateFolder(name: e)) || return
29
+ f.find(e, Folder) || (create && f.CreateFolder(:name => e)) || return
30
30
  end
31
31
 
32
32
  if x = p.find(final, type)
33
33
  x
34
34
  elsif create and type == Folder
35
- p.CreateFolder(name: final)
35
+ p.CreateFolder(:name => final)
36
36
  else
37
37
  nil
38
38
  end
@@ -57,7 +57,7 @@ class RbVmomi::VIM::Folder
57
57
  #
58
58
  # @todo Return ObjectContent instead of the leaf hash.
59
59
  def inventory propSpecs={}
60
- propSet = [{ type: 'Folder', pathSet: ['name', 'parent'] }]
60
+ propSet = [{ :type => 'Folder', :pathSet => ['name', 'parent'] }]
61
61
  propSpecs.each do |k,v|
62
62
  case k
63
63
  when RbVmomi::VIM::ManagedEntity
@@ -68,7 +68,7 @@ class RbVmomi::VIM::Folder
68
68
  fail "key must be a ManagedEntity"
69
69
  end
70
70
 
71
- h = { type: k }
71
+ h = { :type => k }
72
72
  if v == :all
73
73
  h[:all] = true
74
74
  elsif v.is_a? Array
@@ -80,24 +80,24 @@ class RbVmomi::VIM::Folder
80
80
  end
81
81
 
82
82
  filterSpec = RbVmomi::VIM.PropertyFilterSpec(
83
- objectSet: [
84
- obj: self,
85
- selectSet: [
83
+ :objectSet => [
84
+ :obj => self,
85
+ :selectSet => [
86
86
  RbVmomi::VIM.TraversalSpec(
87
- name: 'tsFolder',
88
- type: 'Folder',
89
- path: 'childEntity',
90
- skip: false,
91
- selectSet: [
92
- RbVmomi::VIM.SelectionSpec(name: 'tsFolder')
87
+ :name => 'tsFolder',
88
+ :type => 'Folder',
89
+ :path => 'childEntity',
90
+ :skip => false,
91
+ :selectSet => [
92
+ RbVmomi::VIM.SelectionSpec(:name => 'tsFolder')
93
93
  ]
94
94
  )
95
95
  ]
96
96
  ],
97
- propSet: propSet
97
+ :propSet => propSet
98
98
  )
99
99
 
100
- result = @soap.propertyCollector.RetrieveProperties(specSet: [filterSpec])
100
+ result = @soap.propertyCollector.RetrieveProperties(:specSet => [filterSpec])
101
101
 
102
102
  tree = { self => {} }
103
103
  result.each do |x|
@@ -3,27 +3,27 @@ class RbVmomi::VIM::ManagedEntity
3
3
  # @return [Array] Ancestors of this entity, starting with the root.
4
4
  def path
5
5
  filterSpec = RbVmomi::VIM.PropertyFilterSpec(
6
- objectSet: [{
7
- obj: self,
8
- selectSet: [
6
+ :objectSet => [{
7
+ :obj => self,
8
+ :selectSet => [
9
9
  RbVmomi::VIM.TraversalSpec(
10
- name: 'tsME',
11
- type: 'ManagedEntity',
12
- path: 'parent',
13
- skip: false,
14
- selectSet: [
15
- RbVmomi::VIM.SelectionSpec(name: 'tsME')
10
+ :name => 'tsME',
11
+ :type => 'ManagedEntity',
12
+ :path => 'parent',
13
+ :skip => false,
14
+ :selectSet => [
15
+ RbVmomi::VIM.SelectionSpec(:name => 'tsME')
16
16
  ]
17
17
  )
18
18
  ]
19
19
  }],
20
- propSet: [{
21
- pathSet: %w(name parent),
22
- type: 'ManagedEntity'
20
+ :propSet => [{
21
+ :pathSet => %w(name parent),
22
+ :type => 'ManagedEntity'
23
23
  }]
24
24
  )
25
25
 
26
- result = @soap.propertyCollector.RetrieveProperties(specSet: [filterSpec])
26
+ result = @soap.propertyCollector.RetrieveProperties(:specSet => [filterSpec])
27
27
 
28
28
  tree = {}
29
29
  result.each { |x| tree[x.obj] = [x['parent'], x['name']] }
@@ -14,7 +14,7 @@ class RbVmomi::VIM::ManagedObject
14
14
  }, :partialUpdates => false
15
15
  ver = ''
16
16
  loop do
17
- result = @soap.propertyCollector.WaitForUpdates(version: ver)
17
+ result = @soap.propertyCollector.WaitForUpdates(:version => ver)
18
18
  ver = result.version
19
19
  if x = b.call
20
20
  return x
@@ -29,13 +29,13 @@ class RbVmomi::VIM::ManagedObject
29
29
  # @return [Hash] Hash from property paths to values.
30
30
  def collect! *pathSet
31
31
  spec = {
32
- objectSet: [{ obj: self }],
33
- propSet: [{
34
- pathSet: pathSet,
35
- type: self.class.wsdl_name
32
+ :objectSet => [{ :obj => self }],
33
+ :propSet => [{
34
+ :pathSet => pathSet,
35
+ :type => self.class.wsdl_name
36
36
  }]
37
37
  }
38
- @soap.propertyCollector.RetrieveProperties(specSet: [spec])[0].to_hash
38
+ @soap.propertyCollector.RetrieveProperties(:specSet => [spec])[0].to_hash
39
39
  end
40
40
 
41
41
  # Efficiently retrieve multiple properties from an object.
@@ -17,29 +17,29 @@ class RbVmomi::VIM::OvfManager
17
17
  # @option opts [Hash] :networkMappings Network mappings.
18
18
  # @option opts [Hash] :propertyMappings Property mappings.
19
19
  def deployOVF opts
20
- opts = { networkMappings: {},
21
- propertyMappings: {},
22
- diskProvisioning: :thin }.merge opts
20
+ opts = { :networkMappings => {},
21
+ :propertyMappings => {},
22
+ :diskProvisioning => :thin }.merge opts
23
23
 
24
24
  %w(uri vmName vmFolder host resourcePool datastore).each do |k|
25
25
  fail "parameter #{k} required" unless opts[k.to_sym]
26
26
  end
27
27
 
28
28
  ovfImportSpec = RbVmomi::VIM::OvfCreateImportSpecParams(
29
- hostSystem: opts[:host],
30
- locale: "US",
31
- entityName: opts[:vmName],
32
- deploymentOption: "",
33
- networkMapping: opts[:networkMappings].map{|from, to| RbVmomi::VIM::OvfNetworkMapping(name: from, network: to)},
34
- propertyMapping: opts[:propertyMappings].map{|key, value| RbVmomi::VIM::KeyValue(key: key, value: value)},
35
- diskProvisioning: opts[:diskProvisioning]
29
+ :hostSystem => opts[:host],
30
+ :locale => "US",
31
+ :entityName => opts[:vmName],
32
+ :deploymentOption => "",
33
+ :networkMapping => opts[:networkMappings].map{|from, to| RbVmomi::VIM::OvfNetworkMapping(:name => from, :network => to)},
34
+ :propertyMapping => opts[:propertyMappings].map{|key, value| RbVmomi::VIM::KeyValue(:key => key, :value => value)},
35
+ :diskProvisioning => opts[:diskProvisioning]
36
36
  )
37
37
 
38
38
  result = CreateImportSpec(
39
- ovfDescriptor: open(opts[:uri]).read,
40
- resourcePool: opts[:resourcePool],
41
- datastore: opts[:datastore],
42
- cisp: ovfImportSpec
39
+ :ovfDescriptor => open(opts[:uri]).read,
40
+ :resourcePool => opts[:resourcePool],
41
+ :datastore => opts[:datastore],
42
+ :cisp => ovfImportSpec
43
43
  )
44
44
 
45
45
  raise result.error[0].localizedMessage if result.error && !result.error.empty?
@@ -48,15 +48,15 @@ class RbVmomi::VIM::OvfManager
48
48
  result.warning.each{|x| puts "OVF Warning: #{x.localizedMessage.chomp}" }
49
49
  end
50
50
 
51
- nfcLease = opts[:resourcePool].ImportVApp(spec: result.importSpec,
52
- folder: opts[:vmFolder],
53
- host: opts[:host])
51
+ nfcLease = opts[:resourcePool].ImportVApp(:spec => result.importSpec,
52
+ :folder => opts[:vmFolder],
53
+ :host => opts[:host])
54
54
 
55
55
  nfcLease.wait_until(:state) { nfcLease.state != "initializing" }
56
56
  raise nfcLease.error if nfcLease.state == "error"
57
57
 
58
58
  begin
59
- nfcLease.HttpNfcLeaseProgress(percent: 5)
59
+ nfcLease.HttpNfcLeaseProgress(:percent => 5)
60
60
  progress = 0.0
61
61
  result.fileItem.each do |fileItem|
62
62
  deviceUrl = nfcLease.info.deviceUrl.find{|x| x.importKey == fileItem.deviceId}
@@ -78,10 +78,10 @@ class RbVmomi::VIM::OvfManager
78
78
  uploadCmd = "#{CURLBIN} -X #{method} --insecure -T - -H 'Content-Type: application/x-vnd.vmware-streamVmdk' -H 'Content-Length: #{fileItem.size}' '#{href}'"
79
79
  system("#{downloadCmd} | #{uploadCmd}")
80
80
  progress += (95.0 / result.fileItem.length)
81
- nfcLease.HttpNfcLeaseProgress(percent: progress.to_i)
81
+ nfcLease.HttpNfcLeaseProgress(:percent => progress.to_i)
82
82
  end
83
83
 
84
- nfcLease.HttpNfcLeaseProgress(percent: 100)
84
+ nfcLease.HttpNfcLeaseProgress(:percent => 100)
85
85
  vm = nfcLease.info.entity
86
86
  nfcLease.HttpNfcLeaseComplete
87
87
  vm
@@ -3,7 +3,7 @@ class RbVmomi::VIM::ResourcePool
3
3
  # @param name [String] Name of the child.
4
4
  # @return [VIM::ResourcePool]
5
5
  def find name
6
- @soap.searchIndex.FindChild(entity: self, name: name)
6
+ @soap.searchIndex.FindChild(:entity => self, :name => name)
7
7
  end
8
8
 
9
9
  # Retrieve a descendant of this ResourcePool.
@@ -30,7 +30,7 @@ class RbVmomi::VIM::ServiceInstance
30
30
 
31
31
  begin
32
32
  until task_props.size == tasks.size and task_props.all? { |k,h| %w(success error).member? h['info.state'] }
33
- result = @soap.propertyCollector.WaitForUpdates(version: version)
33
+ result = @soap.propertyCollector.WaitForUpdates(:version => version)
34
34
  version = result.version
35
35
  os = result.filterSet[0].objectSet
36
36
 
@@ -1,10 +1,10 @@
1
1
  require 'test/unit'
2
2
  require 'rbvmomi'
3
- VIM ||= RbVmomi::VIM
3
+ VIM = RbVmomi::VIM unless Object.const_defined? :VIM
4
4
 
5
5
  class DeserializationTest < Test::Unit::TestCase
6
6
  def setup
7
- @soap = VIM.new(ns: 'urn:vim25', rev: '4.0')
7
+ @soap = VIM.new(:ns => 'urn:vim25', :rev => '4.0')
8
8
  end
9
9
 
10
10
  def check str, expected, type
@@ -24,15 +24,15 @@ class DeserializationTest < Test::Unit::TestCase
24
24
 
25
25
  def test_dataobject
26
26
  obj = VIM.DatastoreSummary(
27
- capacity: 1000,
28
- accessible: true,
29
- datastore: VIM.Datastore(nil, "foo"),
30
- freeSpace: 31,
31
- multipleHostAccess: false,
32
- name: "baz",
33
- type: "VMFS",
34
- url: "http://foo/",
35
- dynamicProperty: []
27
+ :capacity => 1000,
28
+ :accessible => true,
29
+ :datastore => VIM.Datastore(nil, "foo"),
30
+ :freeSpace => 31,
31
+ :multipleHostAccess => false,
32
+ :name => "baz",
33
+ :type => "VMFS",
34
+ :url => "http://foo/",
35
+ :dynamicProperty => []
36
36
  )
37
37
 
38
38
  check <<-EOS, obj, 'DatastoreSummary'
@@ -57,13 +57,13 @@ class DeserializationTest < Test::Unit::TestCase
57
57
 
58
58
  def test_array
59
59
  obj = VIM.ObjectContent(
60
- obj: VIM.Folder(nil, 'ha-folder-root'),
61
- dynamicProperty: [],
62
- missingSet: [],
63
- propSet: [
60
+ :obj => VIM.Folder(nil, 'ha-folder-root'),
61
+ :dynamicProperty => [],
62
+ :missingSet => [],
63
+ :propSet => [
64
64
  VIM.DynamicProperty(
65
- name: 'childEntity',
66
- val: [
65
+ :name => 'childEntity',
66
+ :val => [
67
67
  VIM.Datacenter(nil, 'ha-datacenter')
68
68
  ]
69
69
  )
@@ -85,12 +85,12 @@ class DeserializationTest < Test::Unit::TestCase
85
85
 
86
86
  def test_array2
87
87
  obj = VIM.DVPortStatus(
88
- dynamicProperty: [],
89
- linkUp: true,
90
- blocked: false,
91
- vlanIds: [
92
- VIM::NumericRange(dynamicProperty: [], start: 5, end: 7),
93
- VIM::NumericRange(dynamicProperty: [], start: 10, end: 20),
88
+ :dynamicProperty => [],
89
+ :linkUp => true,
90
+ :blocked => false,
91
+ :vlanIds => [
92
+ VIM::NumericRange(:dynamicProperty => [], :start => 5, :end => 7),
93
+ VIM::NumericRange(:dynamicProperty => [], :start => 10, :end => 20),
94
94
  ]
95
95
  )
96
96
 
@@ -112,10 +112,10 @@ end
112
112
 
113
113
  def test_empty_array
114
114
  obj = VIM.DVPortStatus(
115
- dynamicProperty: [],
116
- linkUp: true,
117
- blocked: false,
118
- vlanIds: []
115
+ :dynamicProperty => [],
116
+ :linkUp => true,
117
+ :blocked => false,
118
+ :vlanIds => []
119
119
  )
120
120
 
121
121
  check <<-EOS, obj, 'DVPortStatus'
@@ -128,11 +128,11 @@ end
128
128
 
129
129
  def test_fault
130
130
  obj = VIM.LocalizedMethodFault(
131
- localizedMessage: "The attempted operation cannot be performed in the current state (Powered off).",
132
- fault: VIM.InvalidPowerState(
133
- requestedState: 'poweredOn',
134
- existingState: 'poweredOff',
135
- faultMessage: []
131
+ :localizedMessage => "The attempted operation cannot be performed in the current state (Powered off).",
132
+ :fault => VIM.InvalidPowerState(
133
+ :requestedState => 'poweredOn',
134
+ :existingState => 'poweredOff',
135
+ :faultMessage => []
136
136
  )
137
137
  )
138
138
 
@@ -149,25 +149,25 @@ end
149
149
 
150
150
  def test_wait_for_updates
151
151
  obj = VIM.UpdateSet(
152
- version: '7',
153
- dynamicProperty: [],
154
- filterSet: [
152
+ :version => '7',
153
+ :dynamicProperty => [],
154
+ :filterSet => [
155
155
  VIM.PropertyFilterUpdate(
156
- dynamicProperty: [],
157
- filter: VIM.PropertyFilter(nil, "session[528BA5EB-335B-4AF6-B49C-6160CF5E8D5B]71E3AC7E-7927-4D9E-8BC3-522769F22DAF"),
158
- missingSet: [],
159
- objectSet: [
156
+ :dynamicProperty => [],
157
+ :filter => VIM.PropertyFilter(nil, "session[528BA5EB-335B-4AF6-B49C-6160CF5E8D5B]71E3AC7E-7927-4D9E-8BC3-522769F22DAF"),
158
+ :missingSet => [],
159
+ :objectSet => [
160
160
  VIM.ObjectUpdate(
161
- dynamicProperty: [],
162
- kind: 'enter',
163
- obj: VIM.VirtualMachine(nil, 'vm-1106'),
164
- missingSet: [],
165
- changeSet: [
161
+ :dynamicProperty => [],
162
+ :kind => 'enter',
163
+ :obj => VIM.VirtualMachine(nil, 'vm-1106'),
164
+ :missingSet => [],
165
+ :changeSet => [
166
166
  VIM.PropertyChange(
167
- dynamicProperty: [],
168
- name: 'runtime.powerState',
169
- op: 'assign',
170
- val: 'poweredOn'
167
+ :dynamicProperty => [],
168
+ :name => 'runtime.powerState',
169
+ :op => 'assign',
170
+ :val => 'poweredOn'
171
171
  )
172
172
  ]
173
173
  )
@@ -204,14 +204,14 @@ end
204
204
 
205
205
  def test_hba
206
206
  obj = VIM::HostBlockHba(
207
- dynamicProperty: [],
208
- key: 'key-vim.host.BlockHba-vmhba0',
209
- device: 'vmhba0',
210
- bus: 0,
211
- status: 'unknown',
212
- model: 'Virtual Machine Chipset',
213
- driver: 'ata_piix',
214
- pci: '00:07.1')
207
+ :dynamicProperty => [],
208
+ :key => 'key-vim.host.BlockHba-vmhba0',
209
+ :device => 'vmhba0',
210
+ :bus => 0,
211
+ :status => 'unknown',
212
+ :model => 'Virtual Machine Chipset',
213
+ :driver => 'ata_piix',
214
+ :pci => '00:07.1')
215
215
 
216
216
  check <<-EOS, obj, "HostBlockHba"
217
217
  <hostBusAdapter xsi:type="HostBlockHba">
@@ -229,10 +229,10 @@ end
229
229
  =begin
230
230
  def test_runtime_state
231
231
  obj = VIM::VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState(
232
- dynamicProperty: [],
233
- vmDirectPathGen2Active: false,
234
- vmDirectPathGen2InactiveReasonOther: ["vmNptIncompatibleHost"],
235
- vmDirectPathGen2InactiveReasonVm: []
232
+ :dynamicProperty => [],
233
+ vmDirectPathGen2:Active => false,
234
+ vmDirectPathGen2:InactiveReasonOther => ["vmNptIncompatibleHost"],
235
+ vmDirectPathGen2:InactiveReasonVm => []
236
236
  )
237
237
  check <<-EOS, obj, 'VirtualMachineDeviceRuntimeInfoDeviceRuntimeState'
238
238
  <runtimeState xsi:type="VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState" xmlns:xsi="#{VIM::NS_XSI}">
@@ -245,19 +245,19 @@ end
245
245
 
246
246
  def test_runtime_info
247
247
  obj = VIM::VirtualMachineRuntimeInfo(
248
- bootTime: Time.parse('2010-08-20 05:44:35 UTC'),
249
- connectionState: "connected",
250
- dynamicProperty: [],
251
- faultToleranceState: "notConfigured",
252
- host: VIM::HostSystem(nil, "host-32"),
253
- maxCpuUsage: 5612,
254
- maxMemoryUsage: 3072,
255
- memoryOverhead: 128671744,
256
- numMksConnections: 1,
257
- powerState: "poweredOn",
258
- recordReplayState: "inactive",
259
- suspendInterval: 0,
260
- toolsInstallerMounted: false
248
+ :bootTime => Time.parse('2010-08-20 05:44:35 UTC'),
249
+ :connectionState => "connected",
250
+ :dynamicProperty => [],
251
+ :faultToleranceState => "notConfigured",
252
+ :host => VIM::HostSystem(nil, "host-32"),
253
+ :maxCpuUsage => 5612,
254
+ :maxMemoryUsage => 3072,
255
+ :memoryOverhead => 128671744,
256
+ :numMksConnections => 1,
257
+ :powerState => "poweredOn",
258
+ :recordReplayState => "inactive",
259
+ :suspendInterval => 0,
260
+ :toolsInstallerMounted => false
261
261
  )
262
262
 
263
263
  check <<-EOS, obj, 'VirtualMachineRuntimeInfo'
@@ -1,12 +1,12 @@
1
1
  require 'test/unit'
2
2
  require 'rbvmomi'
3
- VIM ||= RbVmomi::VIM
3
+ VIM = RbVmomi::VIM unless Object.const_defined? :VIM
4
4
 
5
5
  class EmitRequestTest < Test::Unit::TestCase
6
6
  MO = VIM::VirtualMachine(nil, "foo")
7
7
 
8
8
  def check desc, str, this, params
9
- soap = VIM.new(ns: 'urn:vim25', rev: '4.0')
9
+ soap = VIM.new(:ns => 'urn:vim25', :rev => '4.0')
10
10
  xml = Builder::XmlMarkup.new :indent => 2
11
11
  soap.emit_request xml, 'root', desc, this, params
12
12
 
@@ -33,7 +33,7 @@ class EmitRequestTest < Test::Unit::TestCase
33
33
  }
34
34
  ]
35
35
 
36
- check desc, <<-EOS, MO, blah: ['a', 'b', 'c']
36
+ check desc, <<-EOS, MO, :blah => ['a', 'b', 'c']
37
37
  <root xmlns="urn:vim25">
38
38
  <_this type="VirtualMachine">foo</_this>
39
39
  <blah>a</blah>
@@ -53,7 +53,7 @@ class EmitRequestTest < Test::Unit::TestCase
53
53
  }
54
54
  ]
55
55
 
56
- check desc, <<-EOS, MO, blah: 'a'
56
+ check desc, <<-EOS, MO, :blah => 'a'
57
57
  <root xmlns="urn:vim25">
58
58
  <_this type="VirtualMachine">foo</_this>
59
59
  <blah>a</blah>
@@ -1,11 +1,11 @@
1
1
  require 'test/unit'
2
2
  require 'rbvmomi'
3
- VIM ||= RbVmomi::VIM
3
+ VIM = RbVmomi::VIM unless Object.const_defined? :VIM
4
4
 
5
5
  class ExceptionTest < Test::Unit::TestCase
6
6
  def test_fault
7
7
  begin
8
- fault = VIM::InvalidArgument.new invalidProperty: 'foo'
8
+ fault = VIM::InvalidArgument.new :invalidProperty => 'foo'
9
9
  assert_raises RbVmomi::Fault do
10
10
  raise RbVmomi::Fault.new('A specified parameter was not correct.', fault)
11
11
  end
@@ -1,10 +1,10 @@
1
1
  require 'test/unit'
2
2
  require 'rbvmomi'
3
- VIM ||= RbVmomi::VIM
3
+ VIM = RbVmomi::VIM unless Object.const_defined? :VIM
4
4
 
5
5
  class ParseResponseTest < Test::Unit::TestCase
6
6
  def check desc, str, expected
7
- soap = VIM.new(ns: 'urn:vim25', rev: '4.0')
7
+ soap = VIM.new(:ns => 'urn:vim25', :rev => '4.0')
8
8
  got = soap.parse_response Nokogiri(str).root, desc
9
9
  assert_equal expected, got
10
10
  end
@@ -1,10 +1,10 @@
1
1
  require 'test/unit'
2
2
  require 'rbvmomi'
3
- VIM ||= RbVmomi::VIM
3
+ VIM = RbVmomi::VIM unless Object.const_defined? :VIM
4
4
 
5
5
  class SerializationTest < Test::Unit::TestCase
6
6
  def check str, obj, type, array=false
7
- @soap = VIM.new(ns: 'urn:vim25', rev: '4.0')
7
+ @soap = VIM.new(:ns => 'urn:vim25', :rev => '4.0')
8
8
  xml = Builder::XmlMarkup.new :indent => 2
9
9
  @soap.obj2xml(xml, 'root', type, array, obj)
10
10
 
@@ -29,52 +29,52 @@ class SerializationTest < Test::Unit::TestCase
29
29
 
30
30
  def test_config
31
31
  cfg = VIM.VirtualMachineConfigSpec(
32
- name: 'vm',
33
- files: { vmPathName: '[datastore1]' },
34
- guestId: 'otherGuest64',
35
- numCPUs: 2,
36
- memoryMB: 3072,
37
- deviceChange: [
32
+ :name => 'vm',
33
+ :files => { :vmPathName => '[datastore1]' },
34
+ :guestId => 'otherGuest64',
35
+ :numCPUs => 2,
36
+ :memoryMB => 3072,
37
+ :deviceChange => [
38
38
  {
39
- operation: :add,
40
- device: VIM.VirtualLsiLogicController(
41
- key: 1000,
42
- busNumber: 0,
43
- sharedBus: :noSharing,
39
+ :operation => :add,
40
+ :device => VIM.VirtualLsiLogicController(
41
+ :key => 1000,
42
+ :busNumber => 0,
43
+ :sharedBus => :noSharing
44
44
  )
45
45
  }, VIM.VirtualDeviceConfigSpec(
46
- operation: VIM.VirtualDeviceConfigSpecOperation(:add),
47
- fileOperation: VIM.VirtualDeviceConfigSpecFileOperation(:create),
48
- device: VIM.VirtualDisk(
49
- key: 0,
50
- backing: VIM.VirtualDiskFlatVer2BackingInfo(
51
- fileName: '[datastore1]',
52
- diskMode: :persistent,
53
- thinProvisioned: true,
46
+ :operation => VIM.VirtualDeviceConfigSpecOperation(:add),
47
+ :fileOperation => VIM.VirtualDeviceConfigSpecFileOperation(:create),
48
+ :device => VIM.VirtualDisk(
49
+ :key => 0,
50
+ :backing => VIM.VirtualDiskFlatVer2BackingInfo(
51
+ :fileName => '[datastore1]',
52
+ :diskMode => :persistent,
53
+ :thinProvisioned => true
54
54
  ),
55
- controllerKey: 1000,
56
- unitNumber: 0,
57
- capacityInKB: 4000000,
55
+ :controllerKey => 1000,
56
+ :unitNumber => 0,
57
+ :capacityInKB => 4000000
58
58
  )
59
59
  ), {
60
- operation: :add,
61
- device: VIM.VirtualE1000(
62
- key: 0,
63
- deviceInfo: {
64
- label: 'Network Adapter 1',
65
- summary: 'VM Network',
60
+ :operation => :add,
61
+ :device => VIM.VirtualE1000(
62
+ :key => 0,
63
+ :deviceInfo => {
64
+ :label => 'Network Adapter 1',
65
+ :summary => 'VM Network'
66
66
  },
67
- backing: VIM.VirtualEthernetCardNetworkBackingInfo(
68
- deviceName: 'VM Network',
67
+ :backing => VIM.VirtualEthernetCardNetworkBackingInfo(
68
+ :deviceName => 'VM Network'
69
69
  ),
70
- addressType: 'generated'
70
+ :addressType => 'generated'
71
71
  )
72
72
  }
73
73
  ],
74
- extraConfig: [
74
+ :extraConfig => [
75
75
  {
76
- key: 'bios.bootOrder',
77
- value: 'ethernet0'
76
+ :key => 'bios.bootOrder',
77
+ :value => 'ethernet0'
78
78
  }
79
79
  ]
80
80
  )
@@ -133,7 +133,7 @@ class SerializationTest < Test::Unit::TestCase
133
133
  end
134
134
 
135
135
  def test_nil_field
136
- obj = VIM.OptionValue(key: 'foo', value: nil)
136
+ obj = VIM.OptionValue(:key => 'foo', :value => nil)
137
137
  check <<-EOS, obj, "OptionValue"
138
138
  <root xsi:type="OptionValue">
139
139
  <key>foo</key>
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbvmomi
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 17
5
+ prerelease:
5
6
  segments:
6
7
  - 1
7
8
  - 1
8
- - 0
9
- version: 1.1.0
9
+ - 1
10
+ version: 1.1.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Rich Lane
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-02-20 00:00:00 -08:00
18
+ date: 2011-02-21 00:00:00 -08:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 5
28
30
  segments:
29
31
  - 1
30
32
  - 4
@@ -40,6 +42,7 @@ dependencies:
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
45
+ hash: 3
43
46
  segments:
44
47
  - 0
45
48
  version: "0"
@@ -53,6 +56,7 @@ dependencies:
53
56
  requirements:
54
57
  - - ">="
55
58
  - !ruby/object:Gem::Version
59
+ hash: 3
56
60
  segments:
57
61
  - 0
58
62
  version: "0"
@@ -66,6 +70,7 @@ dependencies:
66
70
  requirements:
67
71
  - - ">="
68
72
  - !ruby/object:Gem::Version
73
+ hash: 3
69
74
  segments:
70
75
  - 0
71
76
  version: "0"
@@ -93,6 +98,7 @@ files:
93
98
  - examples/power.rb
94
99
  - examples/readme-1.rb
95
100
  - examples/readme-2.rb
101
+ - examples/run.sh
96
102
  - lib/rbvmomi.rb
97
103
  - lib/rbvmomi/basic_types.rb
98
104
  - lib/rbvmomi/connection.rb
@@ -134,6 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
140
  requirements:
135
141
  - - ">="
136
142
  - !ruby/object:Gem::Version
143
+ hash: 49
137
144
  segments:
138
145
  - 1
139
146
  - 9
@@ -144,16 +151,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
151
  requirements:
145
152
  - - ">="
146
153
  - !ruby/object:Gem::Version
154
+ hash: 3
147
155
  segments:
148
156
  - 0
149
157
  version: "0"
150
158
  requirements: []
151
159
 
152
160
  rubyforge_project:
153
- rubygems_version: 1.3.7
161
+ rubygems_version: 1.4.2
154
162
  signing_key:
155
163
  specification_version: 3
156
- summary: Ruby interface to the VI API
164
+ summary: Ruby interface to the VMware vSphere API
157
165
  test_files:
158
166
  - examples/create_vm.rb
159
167
  - examples/extraConfig.rb