vagrant-rbvmomi 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +6 -0
- data/LICENSE +19 -0
- data/README.rdoc +78 -0
- data/Rakefile +31 -0
- data/VERSION +1 -0
- data/bin/rbvmomish +138 -0
- data/devel/analyze-vim-declarations.rb +213 -0
- data/devel/analyze-xml.rb +46 -0
- data/devel/benchmark.rb +117 -0
- data/devel/collisions.rb +18 -0
- data/devel/merge-internal-vmodl.rb +59 -0
- data/devel/merge-manual-vmodl.rb +32 -0
- data/examples/annotate.rb +54 -0
- data/examples/cached_ovf_deploy.rb +120 -0
- data/examples/clone_vm.rb +84 -0
- data/examples/create_vm-1.9.rb +93 -0
- data/examples/create_vm.rb +93 -0
- data/examples/extraConfig.rb +54 -0
- data/examples/lease_tool.rb +102 -0
- data/examples/logbundle.rb +63 -0
- data/examples/logtail.rb +60 -0
- data/examples/nfs_datastore.rb +95 -0
- data/examples/power.rb +59 -0
- data/examples/readme-1.rb +35 -0
- data/examples/readme-2.rb +51 -0
- data/examples/run.sh +41 -0
- data/examples/screenshot.rb +48 -0
- data/examples/vdf.rb +81 -0
- data/examples/vm_drs_behavior.rb +76 -0
- data/lib/rbvmomi.rb +12 -0
- data/lib/rbvmomi/basic_types.rb +375 -0
- data/lib/rbvmomi/connection.rb +270 -0
- data/lib/rbvmomi/deserialization.rb +248 -0
- data/lib/rbvmomi/fault.rb +17 -0
- data/lib/rbvmomi/pbm.rb +66 -0
- data/lib/rbvmomi/sms.rb +61 -0
- data/lib/rbvmomi/sms/SmsStorageManager.rb +7 -0
- data/lib/rbvmomi/trivial_soap.rb +114 -0
- data/lib/rbvmomi/trollop.rb +70 -0
- data/lib/rbvmomi/type_loader.rb +136 -0
- data/lib/rbvmomi/utils/admission_control.rb +398 -0
- data/lib/rbvmomi/utils/deploy.rb +336 -0
- data/lib/rbvmomi/utils/leases.rb +142 -0
- data/lib/rbvmomi/utils/perfdump.rb +628 -0
- data/lib/rbvmomi/vim.rb +128 -0
- data/lib/rbvmomi/vim/ComputeResource.rb +51 -0
- data/lib/rbvmomi/vim/Datacenter.rb +17 -0
- data/lib/rbvmomi/vim/Datastore.rb +68 -0
- data/lib/rbvmomi/vim/DynamicTypeMgrAllTypeInfo.rb +75 -0
- data/lib/rbvmomi/vim/DynamicTypeMgrDataTypeInfo.rb +20 -0
- data/lib/rbvmomi/vim/DynamicTypeMgrManagedTypeInfo.rb +46 -0
- data/lib/rbvmomi/vim/Folder.rb +207 -0
- data/lib/rbvmomi/vim/HostSystem.rb +174 -0
- data/lib/rbvmomi/vim/ManagedEntity.rb +57 -0
- data/lib/rbvmomi/vim/ManagedObject.rb +60 -0
- data/lib/rbvmomi/vim/ObjectContent.rb +23 -0
- data/lib/rbvmomi/vim/ObjectUpdate.rb +23 -0
- data/lib/rbvmomi/vim/OvfManager.rb +200 -0
- data/lib/rbvmomi/vim/PerfCounterInfo.rb +26 -0
- data/lib/rbvmomi/vim/PerformanceManager.rb +110 -0
- data/lib/rbvmomi/vim/PropertyCollector.rb +25 -0
- data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +30 -0
- data/lib/rbvmomi/vim/ResourcePool.rb +55 -0
- data/lib/rbvmomi/vim/ServiceInstance.rb +55 -0
- data/lib/rbvmomi/vim/Task.rb +65 -0
- data/lib/rbvmomi/vim/VirtualMachine.rb +74 -0
- data/test/test_deserialization.rb +383 -0
- data/test/test_emit_request.rb +128 -0
- data/test/test_exceptions.rb +14 -0
- data/test/test_helper.rb +14 -0
- data/test/test_misc.rb +24 -0
- data/test/test_parse_response.rb +69 -0
- data/test/test_serialization.rb +311 -0
- data/vmodl.db +0 -0
- metadata +163 -0
data/examples/logtail.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Translation of example 2-2 from the vSphere SDK for Perl Programming Guide
|
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
|
+
Follow a log file.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
logtail.rb [options] [logKey]
|
14
|
+
|
15
|
+
If logKey is not provided the list of available log keys will be printed and
|
16
|
+
the program will exit.
|
17
|
+
|
18
|
+
VIM connection options:
|
19
|
+
EOS
|
20
|
+
|
21
|
+
rbvmomi_connection_opts
|
22
|
+
|
23
|
+
text <<-EOS
|
24
|
+
|
25
|
+
Other options:
|
26
|
+
EOS
|
27
|
+
end
|
28
|
+
|
29
|
+
Trollop.die("must specify host") unless opts[:host]
|
30
|
+
logKey = ARGV[0]
|
31
|
+
|
32
|
+
vim = VIM.connect opts
|
33
|
+
diagMgr = vim.serviceContent.diagnosticManager
|
34
|
+
|
35
|
+
if not logKey
|
36
|
+
puts "Available logs:"
|
37
|
+
diagMgr.QueryDescriptions.each do |desc|
|
38
|
+
puts "#{desc.key}: #{desc.info.label}"
|
39
|
+
end
|
40
|
+
exit 0
|
41
|
+
end
|
42
|
+
|
43
|
+
# Obtain the last line of the logfile by setting an arbitrarily large
|
44
|
+
# line number as the starting point
|
45
|
+
log = diagMgr.BrowseDiagnosticLog(key: logKey, start: 999999999)
|
46
|
+
lineEnd = log.lineEnd
|
47
|
+
|
48
|
+
# Get the last 5 lines of the log first, and then check every 2 seconds
|
49
|
+
# to see if the log size has increased.
|
50
|
+
start = lineEnd - 5
|
51
|
+
while true
|
52
|
+
log = diagMgr.BrowseDiagnosticLog(key: logKey, start: start)
|
53
|
+
if log.lineStart != 0
|
54
|
+
log.lineText.each do |l|
|
55
|
+
puts l
|
56
|
+
end
|
57
|
+
end
|
58
|
+
start = log.lineEnd + 1
|
59
|
+
sleep 2
|
60
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'trollop'
|
3
|
+
require 'rbvmomi'
|
4
|
+
require 'rbvmomi/trollop'
|
5
|
+
|
6
|
+
VIM = RbVmomi::VIM
|
7
|
+
CMDS = %w(mount unmount)
|
8
|
+
|
9
|
+
opts = Trollop.options do
|
10
|
+
banner <<-EOS
|
11
|
+
Mount/Unmount an NFS datastore from a cluster or single host system.
|
12
|
+
|
13
|
+
Usage:
|
14
|
+
nfs_datastore.rb [options] resource mount nfs-hostname:/remote/path [name]
|
15
|
+
nfs_datastore.rb [options] resource unmount nfs-hostname:/remote/path [name]
|
16
|
+
|
17
|
+
Commands: #{CMDS * ' '}
|
18
|
+
|
19
|
+
VIM connection options:
|
20
|
+
EOS
|
21
|
+
|
22
|
+
rbvmomi_connection_opts
|
23
|
+
|
24
|
+
text <<-EOS
|
25
|
+
|
26
|
+
VM location options:
|
27
|
+
EOS
|
28
|
+
|
29
|
+
rbvmomi_datacenter_opt
|
30
|
+
|
31
|
+
text <<-EOS
|
32
|
+
|
33
|
+
Other options:
|
34
|
+
EOS
|
35
|
+
|
36
|
+
stop_on CMDS
|
37
|
+
end
|
38
|
+
|
39
|
+
Trollop.die("must specify host") unless opts[:host]
|
40
|
+
|
41
|
+
cr_path = ARGV[0] or Trollop.die("no system name given")
|
42
|
+
cmd = ARGV[1] or Trollop.die("no command given")
|
43
|
+
abort "invalid command" unless CMDS.member? cmd
|
44
|
+
nfs_spec = ARGV[2] or Trollop.die("no nfs path given")
|
45
|
+
remoteHost, remotePath = nfs_spec.split(":")
|
46
|
+
localPath = ARGV[3] || remoteHost
|
47
|
+
mode = "readOnly" #hardcoded.
|
48
|
+
|
49
|
+
vim = VIM.connect opts
|
50
|
+
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
|
51
|
+
cr = dc.find_compute_resource(cr_path) || dc.hostFolder.children.find(cr_path).first
|
52
|
+
abort "compute resource not found" unless cr
|
53
|
+
|
54
|
+
case cr
|
55
|
+
when VIM::ClusterComputeResource
|
56
|
+
hosts = cr.host
|
57
|
+
when VIM::ComputeResource
|
58
|
+
hosts = [cr]
|
59
|
+
else
|
60
|
+
abort "invalid resource"
|
61
|
+
end
|
62
|
+
|
63
|
+
hosts.each do |host|
|
64
|
+
hds = host.configManager.datastoreSystem
|
65
|
+
|
66
|
+
ds = hds.datastore.select {|ds|
|
67
|
+
ds.info.respond_to?(:nas) and
|
68
|
+
ds.info.name == localPath and
|
69
|
+
ds.info.nas.remoteHost == remoteHost and
|
70
|
+
ds.info.nas.remotePath == remotePath
|
71
|
+
}.first
|
72
|
+
|
73
|
+
case cmd
|
74
|
+
when 'mount'
|
75
|
+
if ds
|
76
|
+
puts "already mounted on #{host.name} as #{ds.name}"
|
77
|
+
else
|
78
|
+
ds =
|
79
|
+
hds.CreateNasDatastore(:spec => VIM.HostNasVolumeSpec(:remoteHost => remoteHost,
|
80
|
+
:remotePath => remotePath,
|
81
|
+
:localPath => localPath,
|
82
|
+
:accessMode => mode))
|
83
|
+
puts "mounted on #{host.name} as #{ds.name}"
|
84
|
+
end
|
85
|
+
when 'unmount'
|
86
|
+
if ds
|
87
|
+
hds.RemoveDatastore(:datastore => ds)
|
88
|
+
puts "unmounted from #{host.name}"
|
89
|
+
else
|
90
|
+
puts "not mounted on #{host.name}"
|
91
|
+
end
|
92
|
+
else
|
93
|
+
abort "invalid command"
|
94
|
+
end
|
95
|
+
end
|
data/examples/power.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
require 'rbvmomi'
|
3
|
+
require 'rbvmomi/trollop'
|
4
|
+
|
5
|
+
VIM = RbVmomi::VIM
|
6
|
+
CMDS = %w(on off reset suspend destroy)
|
7
|
+
|
8
|
+
opts = Trollop.options do
|
9
|
+
banner <<-EOS
|
10
|
+
Perform VM power operations.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
power.rb [options] cmd VM
|
14
|
+
|
15
|
+
Commands: #{CMDS * ' '}
|
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
|
+
|
34
|
+
stop_on CMDS
|
35
|
+
end
|
36
|
+
|
37
|
+
cmd = ARGV[0] or Trollop.die("no command given")
|
38
|
+
vm_name = ARGV[1] or Trollop.die("no VM name given")
|
39
|
+
Trollop.die("must specify host") unless opts[:host]
|
40
|
+
|
41
|
+
vim = VIM.connect opts
|
42
|
+
|
43
|
+
dc = vim.serviceInstance.content.rootFolder.traverse(opts[:datacenter], VIM::Datacenter) or abort "datacenter not found"
|
44
|
+
vm = dc.vmFolder.traverse(vm_name, VIM::VirtualMachine) or abort "VM not found"
|
45
|
+
|
46
|
+
case cmd
|
47
|
+
when 'on'
|
48
|
+
vm.PowerOnVM_Task.wait_for_completion
|
49
|
+
when 'off'
|
50
|
+
vm.PowerOffVM_Task.wait_for_completion
|
51
|
+
when 'reset'
|
52
|
+
vm.ResetVM_Task.wait_for_completion
|
53
|
+
when 'suspend'
|
54
|
+
vm.SuspendVM_Task.wait_for_completion
|
55
|
+
when 'destroy'
|
56
|
+
vm.Destroy_Task.wait_for_completion
|
57
|
+
else
|
58
|
+
abort "invalid command"
|
59
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rbvmomi'
|
2
|
+
require 'rbvmomi/trollop'
|
3
|
+
|
4
|
+
opts = Trollop.options do
|
5
|
+
banner <<-EOS
|
6
|
+
Example 1 from the README: Power on a VM.
|
7
|
+
|
8
|
+
Usage:
|
9
|
+
readme-1.rb [options] VM name
|
10
|
+
|
11
|
+
VIM connection options:
|
12
|
+
EOS
|
13
|
+
|
14
|
+
rbvmomi_connection_opts
|
15
|
+
|
16
|
+
text <<-EOS
|
17
|
+
|
18
|
+
VM location options:
|
19
|
+
EOS
|
20
|
+
|
21
|
+
rbvmomi_datacenter_opt
|
22
|
+
|
23
|
+
text <<-EOS
|
24
|
+
|
25
|
+
Other options:
|
26
|
+
EOS
|
27
|
+
end
|
28
|
+
|
29
|
+
Trollop.die("must specify host") unless opts[:host]
|
30
|
+
vm_name = ARGV[0] or abort "must specify VM name"
|
31
|
+
|
32
|
+
vim = RbVmomi::VIM.connect opts
|
33
|
+
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or fail "datacenter not found"
|
34
|
+
vm = dc.find_vm(vm_name) or fail "VM not found"
|
35
|
+
vm.PowerOnVM_Task.wait_for_completion
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rbvmomi'
|
2
|
+
require 'rbvmomi/trollop'
|
3
|
+
|
4
|
+
opts = Trollop.options do
|
5
|
+
banner <<-EOS
|
6
|
+
Example 2 from the README: Power on a VM the hard way.
|
7
|
+
|
8
|
+
Usage:
|
9
|
+
readme-2.rb [options] VM name
|
10
|
+
|
11
|
+
VIM connection options:
|
12
|
+
EOS
|
13
|
+
|
14
|
+
rbvmomi_connection_opts
|
15
|
+
|
16
|
+
text <<-EOS
|
17
|
+
|
18
|
+
VM location options:
|
19
|
+
EOS
|
20
|
+
|
21
|
+
rbvmomi_datacenter_opt
|
22
|
+
|
23
|
+
text <<-EOS
|
24
|
+
|
25
|
+
Other options:
|
26
|
+
EOS
|
27
|
+
end
|
28
|
+
|
29
|
+
Trollop.die("must specify host") unless opts[:host]
|
30
|
+
vm_name = ARGV[0] or abort "must specify VM name"
|
31
|
+
|
32
|
+
vim = RbVmomi::VIM.connect opts
|
33
|
+
rootFolder = vim.serviceInstance.content.rootFolder
|
34
|
+
dc = rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter).find { |x| x.name == opts[:datacenter] } or fail "datacenter not found"
|
35
|
+
vm = dc.vmFolder.childEntity.grep(RbVmomi::VIM::VirtualMachine).find { |x| x.name == vm_name } or fail "VM not found"
|
36
|
+
task = vm.PowerOnVM_Task
|
37
|
+
filter = vim.propertyCollector.CreateFilter(
|
38
|
+
:spec => {
|
39
|
+
:propSet => [{ :type => 'Task', :all => false, :pathSet => ['info.state']}],
|
40
|
+
:objectSet => [{ :obj => task }]
|
41
|
+
},
|
42
|
+
:partialUpdates => false
|
43
|
+
)
|
44
|
+
ver = ''
|
45
|
+
while true
|
46
|
+
result = vim.propertyCollector.WaitForUpdates(:version => ver)
|
47
|
+
ver = result.version
|
48
|
+
break if ['success', 'error'].member? task.info.state
|
49
|
+
end
|
50
|
+
filter.DestroyPropertyFilter
|
51
|
+
raise task.info.error if task.info.state == 'error'
|
data/examples/run.sh
ADDED
@@ -0,0 +1,41 @@
|
|
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
|
@@ -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
|
data/examples/vdf.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Translation of vGhetto vdf, originally 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
|
+
Display utilization of each datastore in the datacenter.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
vdf.rb [options]
|
14
|
+
|
15
|
+
VIM connection options:
|
16
|
+
EOS
|
17
|
+
|
18
|
+
rbvmomi_connection_opts
|
19
|
+
|
20
|
+
text <<-EOS
|
21
|
+
|
22
|
+
Datacenter selection:
|
23
|
+
EOS
|
24
|
+
|
25
|
+
rbvmomi_datacenter_opt
|
26
|
+
|
27
|
+
text <<-EOS
|
28
|
+
|
29
|
+
Other options:
|
30
|
+
EOS
|
31
|
+
end
|
32
|
+
|
33
|
+
Trollop.die("must specify host") unless opts[:host]
|
34
|
+
|
35
|
+
vim = VIM.connect opts
|
36
|
+
|
37
|
+
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
|
38
|
+
|
39
|
+
def si n
|
40
|
+
['', 'K', 'M', 'G', 'T', 'P'].each_with_index do |x,i|
|
41
|
+
v = n.to_f/(1000**i)
|
42
|
+
return v,x if v < 1000 or x == 'P'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def unit n, u, p
|
47
|
+
"%.*g%s%s" % [p, si(n), u].flatten
|
48
|
+
end
|
49
|
+
|
50
|
+
def b n
|
51
|
+
unit(n,'B',3)
|
52
|
+
end
|
53
|
+
|
54
|
+
puts "Filesystem#{' '*53}Size Used Avail Use% Mounted on"
|
55
|
+
fmt = "%-62s %-8s %-8s %-8s %-8s %s"
|
56
|
+
|
57
|
+
if false
|
58
|
+
# simple version
|
59
|
+
dc.datastore.sort_by { |ds| ds.info.url }.each do |ds|
|
60
|
+
s = ds.summary
|
61
|
+
next unless s.accessible
|
62
|
+
size = s.capacity
|
63
|
+
free = s.freeSpace
|
64
|
+
used = size - free
|
65
|
+
pct_used = used*100.0/size
|
66
|
+
puts(fmt % [ds.info.url, b(size), b(used), b(free), unit(pct_used,'%',3), ds.name])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
# fast version
|
70
|
+
paths = %w(name info.url summary.accessible summary.capacity summary.freeSpace)
|
71
|
+
propSet = [{ :type => 'Datastore', :pathSet => paths }]
|
72
|
+
filterSpec = { :objectSet => dc.datastore.map { |ds| { :obj => ds } }, :propSet => propSet }
|
73
|
+
data = vim.propertyCollector.RetrieveProperties(:specSet => [filterSpec])
|
74
|
+
data.select { |d| d['summary.accessible'] }.sort_by { |d| d['info.url'] }.each do |d|
|
75
|
+
size = d['summary.capacity']
|
76
|
+
free = d['summary.freeSpace']
|
77
|
+
used = size - free
|
78
|
+
pct_used = used*100.0/size
|
79
|
+
puts(fmt % [d['info.url'], b(size), b(used), b(free), unit(pct_used,'%',3), d['name']])
|
80
|
+
end
|
81
|
+
end
|