rbvmomi 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -29,3 +29,17 @@ Rake::TestTask.new do |t|
29
29
  end
30
30
 
31
31
  YARD::Rake::YardocTask.new
32
+
33
+ begin
34
+ require 'rcov/rcovtask'
35
+ desc 'Measures test coverage using rcov'
36
+ Rcov::RcovTask.new do |rcov|
37
+ rcov.pattern = 'test/test_*.rb'
38
+ rcov.output_dir = 'coverage'
39
+ rcov.verbose = true
40
+ rcov.libs << "test"
41
+ rcov.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+ rescue LoadError
44
+ puts "Rcov not available. Install it with: gem install rcov"
45
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.2
1
+ 1.2.3
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'nokogiri'
3
- require 'cdb'
4
3
 
5
4
  # :usage => analyze-vim-declarations.rb vim-declarations.xml foo-declarations.xml vmodl.db
6
5
 
@@ -175,16 +174,16 @@ TYPES.each do |k,t|
175
174
  end
176
175
  end
177
176
 
178
- db = CDBMake.new(OUT_FN)
177
+ db = {}
179
178
 
180
179
  TYPES.each do |k,t|
181
- db[k] = Marshal.dump t
180
+ db[k] = t
182
181
  end
183
182
 
184
- db['_typenames'] = Marshal.dump TYPES.keys
185
- db['_versions'] = Marshal.dump VERSIONS
183
+ db['_typenames'] = TYPES.keys
184
+ db['_versions'] = VERSIONS
186
185
 
187
- db.finish
186
+ File.open(OUT_FN, 'w') { |io| Marshal.dump db, io }
188
187
 
189
188
  if filename = ENV['VERSION_GRAPH']
190
189
  File.open(filename, 'w') do |io|
@@ -0,0 +1,54 @@
1
+ require 'trollop'
2
+ require 'rbvmomi'
3
+ require 'rbvmomi/trollop'
4
+
5
+ VIM = RbVmomi::VIM
6
+ CMDS = %w(get set)
7
+
8
+ opts = Trollop.options do
9
+ banner <<-EOS
10
+ Annotate a VM.
11
+
12
+ Usage:
13
+ annotate.rb [options] VM get
14
+ annotate.rb [options] VM set annotation
15
+
16
+ Commands: #{CMDS * ' '}
17
+
18
+ VIM connection options:
19
+ EOS
20
+
21
+ rbvmomi_connection_opts
22
+
23
+ text <<-EOS
24
+
25
+ VM location options:
26
+ EOS
27
+
28
+ rbvmomi_datacenter_opt
29
+
30
+ text <<-EOS
31
+
32
+ Other options:
33
+ EOS
34
+
35
+ stop_on CMDS
36
+ end
37
+
38
+ vm_name = ARGV[0] or Trollop.die("no VM name given")
39
+ cmd = ARGV[1] or Trollop.die("no command given")
40
+ abort "invalid command" unless CMDS.member? cmd
41
+ Trollop.die("must specify host") unless opts[:host]
42
+
43
+ vim = VIM.connect opts
44
+
45
+ dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
46
+ vm = dc.find_vm(vm_name) or abort "VM not found"
47
+
48
+ case cmd
49
+ when 'get'
50
+ puts vm.config.annotation
51
+ when 'set'
52
+ value = ARGV[2] or Trollop.die("no annotation given")
53
+ vm.ReconfigVM_Task(:spec => VIM.VirtualMachineConfigSpec(:annotation => value)).wait_for_completion
54
+ end
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
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
+ Clone a VM.
11
+
12
+ Usage:
13
+ clone_vm.rb [options] source_vm dest_vm
14
+
15
+ VIM connection options:
16
+ EOS
17
+
18
+ rbvmomi_connection_opts
19
+
20
+ text <<-EOS
21
+
22
+ VM location options:
23
+ EOS
24
+
25
+ rbvmomi_datacenter_opt
26
+
27
+ text <<-EOS
28
+
29
+ Other options:
30
+ EOS
31
+
32
+ opt :linked_clone, "Use a linked clone instead of a full clone"
33
+ end
34
+
35
+ Trollop.die("must specify host") unless opts[:host]
36
+ ARGV.size == 2 or abort "must specify VM source name and VM target name"
37
+ vm_source = ARGV[0]
38
+ vm_target = ARGV[1]
39
+
40
+ vim = VIM.connect opts
41
+ dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
42
+ vm = dc.find_vm(vm_source) or abort "VM not found"
43
+
44
+ if opts[:linked_clone]
45
+ # The API for linked clones is quite strange. We can't create a linked
46
+ # straight from any VM. The disks of the VM for which we can create a
47
+ # linked clone need to be read-only and thus VC demands that the VM we
48
+ # are cloning from uses delta-disks. Only then it will allow us to
49
+ # share the base disk.
50
+ #
51
+ # Thus, this code first create a delta disk on top of the base disk for
52
+ # the to-be-cloned VM, if delta disks aren't used already.
53
+ disks = vm.config.hardware.device.grep(VIM::VirtualDisk)
54
+ disks.select { |x| x.backing.parent == nil }.each do |disk|
55
+ spec = {
56
+ :deviceChange => [
57
+ {
58
+ :operation => :remove,
59
+ :device => disk
60
+ },
61
+ {
62
+ :operation => :add,
63
+ :fileOperation => :create,
64
+ :device => disk.dup.tap { |x|
65
+ x.backing = x.backing.dup
66
+ x.backing.fileName = "[#{disk.backing.datastore.name}]"
67
+ x.backing.parent = disk.backing
68
+ },
69
+ }
70
+ ]
71
+ }
72
+ vm.ReconfigVM_Task(:spec => spec).wait_for_completion
73
+ end
74
+
75
+ relocateSpec = VIM.VirtualMachineRelocateSpec(:diskMoveType => :moveChildMostDiskBacking)
76
+ else
77
+ relocateSpec = VIM.VirtualMachineRelocateSpec
78
+ end
79
+
80
+ spec = VIM.VirtualMachineCloneSpec(:location => relocateSpec,
81
+ :powerOn => false,
82
+ :template => false)
83
+
84
+ vm.CloneVM_Task(:folder => vm.parent, :name => vm_target, :spec => spec).wait_for_completion
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ require 'trollop'
3
+ require 'rbvmomi'
4
+ require 'rbvmomi/trollop'
5
+
6
+ VIM = RbVmomi::VIM
7
+ CMDS = %w(get set)
8
+ BEHAVIOR = %w(fullyAutomated manual partiallyAutomated default)
9
+
10
+ opts = Trollop.options do
11
+ banner <<-EOS
12
+ Configure VM DRS behavior.
13
+
14
+ Usage:
15
+ vm_drs_behavior.rb [options] VM get
16
+ vm_drs_behavior.rb [options] VM set #{BEHAVIOR.join('|')}
17
+
18
+ Commands: #{CMDS * ' '}
19
+
20
+ VIM connection options:
21
+ EOS
22
+
23
+ rbvmomi_connection_opts
24
+
25
+ text <<-EOS
26
+
27
+ VM location options:
28
+ EOS
29
+
30
+ rbvmomi_datacenter_opt
31
+
32
+ text <<-EOS
33
+
34
+ Other options:
35
+ EOS
36
+
37
+ stop_on CMDS
38
+ end
39
+
40
+ Trollop.die("must specify host") unless opts[:host]
41
+
42
+ vm_name = ARGV[0] or Trollop.die("no VM name given")
43
+ cmd = ARGV[1] or Trollop.die("no command given")
44
+ abort "invalid command" unless CMDS.member? cmd
45
+
46
+ vim = VIM.connect opts
47
+ dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
48
+ vm = dc.find_vm(vm_name) or abort "VM not found"
49
+
50
+ cluster = vm.runtime.host.parent
51
+ config = cluster.configurationEx.drsVmConfig.select {|c| c.key.name == vm.name }.first
52
+ default = cluster.configurationEx.drsConfig.defaultVmBehavior
53
+
54
+ case cmd
55
+ when 'get'
56
+ if config
57
+ behavior = config.behavior
58
+ else
59
+ behavior = "#{default} (default)"
60
+ end
61
+ puts "#{vm.name} is #{behavior}"
62
+ when 'set'
63
+ behavior = ARGV[2] or Trollop.die("no behavior given")
64
+ abort "invalid behavior" unless BEHAVIOR.member? behavior
65
+
66
+ if behavior == "default"
67
+ behavior = default
68
+ end
69
+ vm_spec =
70
+ VIM.ClusterDrsVmConfigSpec(:operation => VIM.ArrayUpdateOperation(config ? "edit" : "add"),
71
+ :info => VIM.ClusterDrsVmConfigInfo(:key => vm,
72
+ :behavior => VIM.DrsBehavior(behavior)))
73
+ spec = VIM.ClusterConfigSpecEx(:drsVmConfigSpec => [vm_spec])
74
+ cluster.ReconfigureComputeResource_Task(:spec => spec, :modify => true).wait_for_completion
75
+ end
76
+
@@ -94,6 +94,11 @@ class DataObject < ObjectWithProperties
94
94
  end
95
95
  end
96
96
 
97
+ def initialize_copy(source)
98
+ super
99
+ @props = @props.dup
100
+ end
101
+
97
102
  def _get_property sym
98
103
  @props[sym]
99
104
  end
@@ -174,7 +174,7 @@ class Connection < TrivialSoap
174
174
  when Symbol, String
175
175
  if expected == BasicTypes::Binary
176
176
  attrs['xsi:type'] = 'xsd:base64Binary' if expected == BasicTypes::AnyType
177
- xml.tag! name, [o].pack('m').chomp, attrs
177
+ xml.tag! name, [o].pack('m').chomp.gsub("\n", ""), attrs
178
178
  else
179
179
  attrs['xsi:type'] = 'xsd:string' if expected == BasicTypes::AnyType
180
180
  xml.tag! name, o.to_s, attrs
data/lib/rbvmomi/vim.rb CHANGED
@@ -27,13 +27,16 @@ class VIM < Connection
27
27
  opts[:port] ||= (opts[:ssl] ? 443 : 80)
28
28
  opts[:path] ||= '/sdk'
29
29
  opts[:ns] ||= 'urn:vim25'
30
- opts[:rev] = '4.0'
30
+ rev_given = opts[:rev] != nil
31
+ opts[:rev] = '4.0' unless rev_given
31
32
  opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
32
33
 
33
34
  new(opts).tap do |vim|
34
35
  vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password]
35
- rev = vim.serviceContent.about.apiVersion
36
- vim.rev = [rev, '4.1'].min
36
+ unless rev_given
37
+ rev = vim.serviceContent.about.apiVersion
38
+ vim.rev = [rev, '4.1'].min
39
+ end
37
40
  end
38
41
  end
39
42
 
@@ -67,6 +70,11 @@ class VIM < Connection
67
70
  serviceContent.searchIndex
68
71
  end
69
72
 
73
+ # @private
74
+ def pretty_print pp
75
+ pp.text "VIM(#{@opts[:host]})"
76
+ end
77
+
70
78
  @extension_dirs = [File.join(File.dirname(__FILE__), "vim")]
71
79
 
72
80
  # Directories to search for extensions
data/vmodl.db CHANGED
Binary file
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rbvmomi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.2
5
+ version: 1.2.3
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-18 00:00:00 -07:00
13
+ date: 2011-04-05 00:00:00 -07:00
14
14
  default_executable: rbvmomish
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -65,6 +65,8 @@ files:
65
65
  - bin/rbvmomish
66
66
  - devel/analyze-vim-declarations.rb
67
67
  - devel/analyze-xml.rb
68
+ - examples/annotate.rb
69
+ - examples/clone_vm.rb
68
70
  - examples/create_vm-1.9.rb
69
71
  - examples/create_vm.rb
70
72
  - examples/extraConfig.rb
@@ -76,6 +78,7 @@ files:
76
78
  - examples/run.sh
77
79
  - examples/screenshot.rb
78
80
  - examples/vdf.rb
81
+ - examples/vm_drs_behavior.rb
79
82
  - lib/rbvmomi.rb
80
83
  - lib/rbvmomi/basic_types.rb
81
84
  - lib/rbvmomi/connection.rb
@@ -134,6 +137,8 @@ signing_key:
134
137
  specification_version: 3
135
138
  summary: Ruby interface to the VMware vSphere API
136
139
  test_files:
140
+ - examples/annotate.rb
141
+ - examples/clone_vm.rb
137
142
  - examples/create_vm-1.9.rb
138
143
  - examples/create_vm.rb
139
144
  - examples/extraConfig.rb
@@ -144,6 +149,7 @@ test_files:
144
149
  - examples/readme-2.rb
145
150
  - examples/screenshot.rb
146
151
  - examples/vdf.rb
152
+ - examples/vm_drs_behavior.rb
147
153
  - test/test_deserialization.rb
148
154
  - test/test_emit_request.rb
149
155
  - test/test_exceptions.rb