rbvmomi 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,66 +0,0 @@
1
- # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
- # SPDX-License-Identifier: MIT
3
-
4
- # @todo Retrieve ESX log bundles when run against VC.
5
- require 'optimist'
6
- require 'rbvmomi'
7
- require 'rbvmomi/optimist'
8
-
9
- VIM = RbVmomi::VIM
10
- DEFAULT_SERVER_PLACEHOLDER = '0.0.0.0'
11
-
12
- opts = Optimist.options do
13
- banner <<-EOS
14
- Generate and retrieve a log bundle.
15
-
16
- Usage:
17
- logbundle.rb [options] dest
18
-
19
- dest must be a directory.
20
-
21
- VIM connection options:
22
- EOS
23
-
24
- rbvmomi_connection_opts
25
-
26
- text <<-EOS
27
-
28
- Other options:
29
- EOS
30
- end
31
-
32
- Optimist.die("must specify host") unless opts[:host]
33
- dest = ARGV[0] or abort("must specify destination directory")
34
-
35
- abort "destination is not a directory" unless File.directory? dest
36
-
37
- vim = VIM.connect opts
38
- is_vc = vim.serviceContent.about.apiType == 'VirtualCenter'
39
- diagMgr = vim.serviceContent.diagnosticManager
40
-
41
- bundles =
42
- begin
43
- diagMgr.GenerateLogBundles_Task(includeDefault: true).wait_for_completion
44
- rescue VIM::TaskInProgress
45
- $!.task.wait_for_completion
46
- end
47
-
48
- bundles.each do |b|
49
- uri = URI.parse(b.url.sub('*', DEFAULT_SERVER_PLACEHOLDER))
50
- dest_path = File.join(dest, File.basename(uri.path))
51
- puts "downloading bundle #{b.url} to #{dest_path}"
52
- if uri.host == DEFAULT_SERVER_PLACEHOLDER
53
- vim.http.request_get(uri.path) do |res|
54
- File.open dest_path, 'w' do |io|
55
- res.read_body do |data|
56
- io.write data
57
- $stdout.write '.'
58
- $stdout.flush
59
- end
60
- end
61
- puts
62
- end
63
- else
64
- puts 'not supported yet'
65
- end
66
- end
@@ -1,63 +0,0 @@
1
- # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
- # SPDX-License-Identifier: MIT
3
-
4
- # Translation of example 2-2 from the vSphere SDK for Perl Programming Guide
5
- require 'optimist'
6
- require 'rbvmomi'
7
- require 'rbvmomi/optimist'
8
-
9
- VIM = RbVmomi::VIM
10
-
11
- opts = Optimist.options do
12
- banner <<-EOS
13
- Follow a log file.
14
-
15
- Usage:
16
- logtail.rb [options] [logKey]
17
-
18
- If logKey is not provided the list of available log keys will be printed and
19
- the program will exit.
20
-
21
- VIM connection options:
22
- EOS
23
-
24
- rbvmomi_connection_opts
25
-
26
- text <<-EOS
27
-
28
- Other options:
29
- EOS
30
- end
31
-
32
- Optimist.die("must specify host") unless opts[:host]
33
- logKey = ARGV[0]
34
-
35
- vim = VIM.connect opts
36
- diagMgr = vim.serviceContent.diagnosticManager
37
-
38
- if not logKey
39
- puts "Available logs:"
40
- diagMgr.QueryDescriptions.each do |desc|
41
- puts "#{desc.key}: #{desc.info.label}"
42
- end
43
- exit 0
44
- end
45
-
46
- # Obtain the last line of the logfile by setting an arbitrarily large
47
- # line number as the starting point
48
- log = diagMgr.BrowseDiagnosticLog(key: logKey, start: 999999999)
49
- lineEnd = log.lineEnd
50
-
51
- # Get the last 5 lines of the log first, and then check every 2 seconds
52
- # to see if the log size has increased.
53
- start = lineEnd - 5
54
- while true
55
- log = diagMgr.BrowseDiagnosticLog(key: logKey, start: start)
56
- if log.lineStart != 0
57
- log.lineText.each do |l|
58
- puts l
59
- end
60
- end
61
- start = log.lineEnd + 1
62
- sleep 2
63
- end
@@ -1,99 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
4
- # SPDX-License-Identifier: MIT
5
-
6
- require 'optimist'
7
- require 'rbvmomi'
8
- require 'rbvmomi/optimist'
9
-
10
- VIM = RbVmomi::VIM
11
- CMDS = %w(mount unmount)
12
-
13
- opts = Optimist.options do
14
- banner <<-EOS
15
- Mount/Unmount an NFS datastore from a cluster or single host system.
16
-
17
- Usage:
18
- nfs_datastore.rb [options] resource mount nfs-hostname:/remote/path [name]
19
- nfs_datastore.rb [options] resource unmount nfs-hostname:/remote/path [name]
20
-
21
- Commands: #{CMDS * ' '}
22
-
23
- VIM connection options:
24
- EOS
25
-
26
- rbvmomi_connection_opts
27
-
28
- text <<-EOS
29
-
30
- VM location options:
31
- EOS
32
-
33
- rbvmomi_datacenter_opt
34
-
35
- text <<-EOS
36
-
37
- Other options:
38
- EOS
39
-
40
- stop_on CMDS
41
- end
42
-
43
- Optimist.die("must specify host") unless opts[:host]
44
-
45
- cr_path = ARGV[0] or Optimist.die("no system name given")
46
- cmd = ARGV[1] or Optimist.die("no command given")
47
- abort "invalid command" unless CMDS.member? cmd
48
- nfs_spec = ARGV[2] or Optimist.die("no nfs path given")
49
- remoteHost, remotePath = nfs_spec.split(":")
50
- localPath = ARGV[3] || remoteHost
51
- mode = "readOnly" #hardcoded.
52
-
53
- vim = VIM.connect opts
54
- dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
55
- cr = dc.find_compute_resource(cr_path) || dc.hostFolder.children.find(cr_path).first
56
- abort "compute resource not found" unless cr
57
-
58
- case cr
59
- when VIM::ClusterComputeResource
60
- hosts = cr.host
61
- when VIM::ComputeResource
62
- hosts = [cr]
63
- else
64
- abort "invalid resource"
65
- end
66
-
67
- hosts.each do |host|
68
- hds = host.configManager.datastoreSystem
69
-
70
- ds = hds.datastore.select {|ds|
71
- ds.info.respond_to?(:nas) and
72
- ds.info.name == localPath and
73
- ds.info.nas.remoteHost == remoteHost and
74
- ds.info.nas.remotePath == remotePath
75
- }.first
76
-
77
- case cmd
78
- when 'mount'
79
- if ds
80
- puts "already mounted on #{host.name} as #{ds.name}"
81
- else
82
- ds =
83
- hds.CreateNasDatastore(:spec => VIM.HostNasVolumeSpec(:remoteHost => remoteHost,
84
- :remotePath => remotePath,
85
- :localPath => localPath,
86
- :accessMode => mode))
87
- puts "mounted on #{host.name} as #{ds.name}"
88
- end
89
- when 'unmount'
90
- if ds
91
- hds.RemoveDatastore(:datastore => ds)
92
- puts "unmounted from #{host.name}"
93
- else
94
- puts "not mounted on #{host.name}"
95
- end
96
- else
97
- abort "invalid command"
98
- end
99
- end
@@ -1,62 +0,0 @@
1
- # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
- # SPDX-License-Identifier: MIT
3
-
4
- require 'optimist'
5
- require 'rbvmomi'
6
- require 'rbvmomi/optimist'
7
-
8
- VIM = RbVmomi::VIM
9
- CMDS = %w(on off reset suspend destroy)
10
-
11
- opts = Optimist.options do
12
- banner <<-EOS
13
- Perform VM power operations.
14
-
15
- Usage:
16
- power.rb [options] cmd VM
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
- cmd = ARGV[0] or Optimist.die("no command given")
41
- vm_name = ARGV[1] or Optimist.die("no VM name given")
42
- Optimist.die("must specify host") unless opts[:host]
43
-
44
- vim = VIM.connect opts
45
-
46
- dc = vim.serviceInstance.content.rootFolder.traverse(opts[:datacenter], VIM::Datacenter) or abort "datacenter not found"
47
- vm = dc.vmFolder.traverse(vm_name, VIM::VirtualMachine) or abort "VM not found"
48
-
49
- case cmd
50
- when 'on'
51
- vm.PowerOnVM_Task.wait_for_completion
52
- when 'off'
53
- vm.PowerOffVM_Task.wait_for_completion
54
- when 'reset'
55
- vm.ResetVM_Task.wait_for_completion
56
- when 'suspend'
57
- vm.SuspendVM_Task.wait_for_completion
58
- when 'destroy'
59
- vm.Destroy_Task.wait_for_completion
60
- else
61
- abort "invalid command"
62
- end
@@ -1,38 +0,0 @@
1
- # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
- # SPDX-License-Identifier: MIT
3
-
4
- require 'rbvmomi'
5
- require 'rbvmomi/optimist'
6
-
7
- opts = Optimist.options do
8
- banner <<-EOS
9
- Example 1 from the README: Power on a VM.
10
-
11
- Usage:
12
- readme-1.rb [options] VM name
13
-
14
- VIM connection options:
15
- EOS
16
-
17
- rbvmomi_connection_opts
18
-
19
- text <<-EOS
20
-
21
- VM location options:
22
- EOS
23
-
24
- rbvmomi_datacenter_opt
25
-
26
- text <<-EOS
27
-
28
- Other options:
29
- EOS
30
- end
31
-
32
- Optimist.die("must specify host") unless opts[:host]
33
- vm_name = ARGV[0] or abort "must specify VM name"
34
-
35
- vim = RbVmomi::VIM.connect opts
36
- dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or fail "datacenter not found"
37
- vm = dc.find_vm(vm_name) or fail "VM not found"
38
- vm.PowerOnVM_Task.wait_for_completion
@@ -1,54 +0,0 @@
1
- # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
- # SPDX-License-Identifier: MIT
3
-
4
- require 'rbvmomi'
5
- require 'rbvmomi/optimist'
6
-
7
- opts = Optimist.options do
8
- banner <<-EOS
9
- Example 2 from the README: Power on a VM the hard way.
10
-
11
- Usage:
12
- readme-2.rb [options] VM name
13
-
14
- VIM connection options:
15
- EOS
16
-
17
- rbvmomi_connection_opts
18
-
19
- text <<-EOS
20
-
21
- VM location options:
22
- EOS
23
-
24
- rbvmomi_datacenter_opt
25
-
26
- text <<-EOS
27
-
28
- Other options:
29
- EOS
30
- end
31
-
32
- Optimist.die("must specify host") unless opts[:host]
33
- vm_name = ARGV[0] or abort "must specify VM name"
34
-
35
- vim = RbVmomi::VIM.connect opts
36
- rootFolder = vim.serviceInstance.content.rootFolder
37
- dc = rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).find { |x| x.name == opts[:datacenter] } or fail "datacenter not found"
38
- vm = dc.vmFolder.childEntity.grep(RbVmomi::VIM::VirtualMachine).find { |x| x.name == vm_name } or fail "VM not found"
39
- task = vm.PowerOnVM_Task
40
- filter = vim.propertyCollector.CreateFilter(
41
- :spec => {
42
- :propSet => [{ :type => 'Task', :all => false, :pathSet => ['info.state']}],
43
- :objectSet => [{ :obj => task }]
44
- },
45
- :partialUpdates => false
46
- )
47
- ver = ''
48
- while true
49
- result = vim.propertyCollector.WaitForUpdates(:version => ver)
50
- ver = result.version
51
- break if ['success', 'error'].member? task.info.state
52
- end
53
- filter.DestroyPropertyFilter
54
- raise task.info.error if task.info.state == 'error'
@@ -1,41 +0,0 @@
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 Querying datastore utilization
39
- $RUBY $EXAMPLES/vdf.rb
40
- echo Destroying VM
41
- $RUBY $EXAMPLES/power.rb destroy foo
@@ -1,51 +0,0 @@
1
- # Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
2
- # SPDX-License-Identifier: MIT
3
-
4
- # Based on takeVMScreenshot.pl by William Lam
5
- require 'optimist'
6
- require 'rbvmomi'
7
- require 'rbvmomi/optimist'
8
-
9
- VIM = RbVmomi::VIM
10
-
11
- opts = Optimist.options do
12
- banner <<-EOS
13
- Take a screenshot.
14
-
15
- Usage:
16
- screenshot.rb [options] vm filename
17
-
18
- A PNG image will be saved to the given filename.
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
- end
37
-
38
- Optimist.die("must specify host") unless opts[:host]
39
- vm_name = ARGV[0] or abort("must specify VM name")
40
- output_path = ARGV[1] or abort("must specify output filename")
41
-
42
- vim = VIM.connect opts
43
- dc = vim.serviceInstance.find_datacenter(opts[:datacenter])
44
- vm = dc.find_vm vm_name
45
- abort "VM must be running" unless vm.runtime.powerState == 'poweredOn'
46
- remote_path = vm.CreateScreenshot_Task.wait_for_completion
47
- remote_path =~ /^(\/vmfs\/volumes\/[^\/]+)\// or fail
48
- datastore_prefix = $1
49
- datastore_path = $'
50
- datastore = vm.datastore.find { |ds| ds.info.url == datastore_prefix }
51
- datastore.download datastore_path, output_path