rbvmomi 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/examples/logbundle.rb +63 -0
- data/examples/logtail.rb +60 -0
- data/examples/run.sh +2 -0
- data/examples/vdf.rb +81 -0
- data/lib/rbvmomi/connection.rb +1 -1
- data/test/test_parse_response.rb +13 -1
- metadata +9 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.3
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# @todo Retrieve ESX log bundles when run against VC.
|
2
|
+
require 'trollop'
|
3
|
+
require 'rbvmomi'
|
4
|
+
require 'rbvmomi/trollop'
|
5
|
+
|
6
|
+
VIM = RbVmomi::VIM
|
7
|
+
DEFAULT_SERVER_PLACEHOLDER = '0.0.0.0'
|
8
|
+
|
9
|
+
opts = Trollop.options do
|
10
|
+
banner <<-EOS
|
11
|
+
Generate and retrieve a log bundle.
|
12
|
+
|
13
|
+
Usage:
|
14
|
+
logbundle.rb [options] dest
|
15
|
+
|
16
|
+
dest must be a directory.
|
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
|
+
dest = ARGV[0] or abort("must specify destination directory")
|
31
|
+
|
32
|
+
abort "destination is not a directory" unless File.directory? dest
|
33
|
+
|
34
|
+
vim = VIM.connect opts
|
35
|
+
is_vc = vim.serviceContent.about.apiType == 'VirtualCenter'
|
36
|
+
diagMgr = vim.serviceContent.diagnosticManager
|
37
|
+
|
38
|
+
bundles =
|
39
|
+
begin
|
40
|
+
diagMgr.GenerateLogBundles_Task(includeDefault: true).wait_for_completion
|
41
|
+
rescue VIM::TaskInProgress
|
42
|
+
$!.task.wait_for_completion
|
43
|
+
end
|
44
|
+
|
45
|
+
bundles.each do |b|
|
46
|
+
uri = URI.parse(b.url.sub('*', DEFAULT_SERVER_PLACEHOLDER))
|
47
|
+
dest_path = File.join(dest, File.basename(uri.path))
|
48
|
+
puts "downloading bundle #{b.url} to #{dest_path}"
|
49
|
+
if uri.host == DEFAULT_SERVER_PLACEHOLDER
|
50
|
+
vim.http.request_get(uri.path) do |res|
|
51
|
+
File.open dest_path, 'w' do |io|
|
52
|
+
res.read_body do |data|
|
53
|
+
io.write data
|
54
|
+
$stdout.write '.'
|
55
|
+
$stdout.flush
|
56
|
+
end
|
57
|
+
end
|
58
|
+
puts
|
59
|
+
end
|
60
|
+
else
|
61
|
+
puts 'not supported yet'
|
62
|
+
end
|
63
|
+
end
|
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
|
data/examples/run.sh
CHANGED
@@ -35,5 +35,7 @@ echo "Listing extraConfig"
|
|
35
35
|
$RUBY $EXAMPLES/extraConfig.rb foo list | grep guestinfo.bar
|
36
36
|
echo Powering off VM
|
37
37
|
$RUBY $EXAMPLES/power.rb off foo
|
38
|
+
echo Querying datastore utilization
|
39
|
+
$RUBY $EXAMPLES/vdf.rb
|
38
40
|
echo Destroying VM
|
39
41
|
$RUBY $EXAMPLES/power.rb destroy foo
|
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#{' '*43}Size Used Avail Use% Mounted on"
|
55
|
+
fmt = "%-52s %-7s %-7s %-7s %-7s %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
|
data/lib/rbvmomi/connection.rb
CHANGED
@@ -49,7 +49,7 @@ class Connection < TrivialSoap
|
|
49
49
|
if desc
|
50
50
|
type = desc['is-task'] ? 'Task' : desc['wsdl_type']
|
51
51
|
returnvals = resp.children.select(&:element?).map { |c| xml2obj c, type }
|
52
|
-
desc['is-array'] ? returnvals : returnvals.first
|
52
|
+
(desc['is-array'] && !desc['is-task']) ? returnvals : returnvals.first
|
53
53
|
else
|
54
54
|
nil
|
55
55
|
end
|
data/test/test_parse_response.rb
CHANGED
@@ -50,10 +50,22 @@ class ParseResponseTest < Test::Unit::TestCase
|
|
50
50
|
</detail>
|
51
51
|
</soapenv:Fault>
|
52
52
|
EOS
|
53
|
-
rescue
|
53
|
+
rescue VIM::InvalidArgument
|
54
54
|
raise
|
55
|
+
rescue
|
56
|
+
raise "wrong fault"
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
60
|
+
|
61
|
+
def test_task_array_result
|
62
|
+
desc = { 'wsdl_type' => 'xsd:string', 'is-array' => true, 'is-task' => true }
|
63
|
+
|
64
|
+
check desc, <<-EOS, VIM.Task(nil, 'haTask-ha-host-vim.DiagnosticManager.generateLogBundles-865')
|
65
|
+
<root xmlns="urn:vim25">
|
66
|
+
<returnval type="Task">haTask-ha-host-vim.DiagnosticManager.generateLogBundles-865</returnval>
|
67
|
+
</root>
|
68
|
+
EOS
|
69
|
+
end
|
58
70
|
end
|
59
71
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
8
|
+
- 3
|
9
|
+
version: 1.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Rich Lane
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-22 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -91,10 +91,13 @@ files:
|
|
91
91
|
- examples/create_vm-1.9.rb
|
92
92
|
- examples/create_vm.rb
|
93
93
|
- examples/extraConfig.rb
|
94
|
+
- examples/logbundle.rb
|
95
|
+
- examples/logtail.rb
|
94
96
|
- examples/power.rb
|
95
97
|
- examples/readme-1.rb
|
96
98
|
- examples/readme-2.rb
|
97
99
|
- examples/run.sh
|
100
|
+
- examples/vdf.rb
|
98
101
|
- lib/rbvmomi.rb
|
99
102
|
- lib/rbvmomi/basic_types.rb
|
100
103
|
- lib/rbvmomi/connection.rb
|
@@ -160,9 +163,12 @@ test_files:
|
|
160
163
|
- examples/create_vm-1.9.rb
|
161
164
|
- examples/create_vm.rb
|
162
165
|
- examples/extraConfig.rb
|
166
|
+
- examples/logbundle.rb
|
167
|
+
- examples/logtail.rb
|
163
168
|
- examples/power.rb
|
164
169
|
- examples/readme-1.rb
|
165
170
|
- examples/readme-2.rb
|
171
|
+
- examples/vdf.rb
|
166
172
|
- test/test_deserialization.rb
|
167
173
|
- test/test_emit_request.rb
|
168
174
|
- test/test_exceptions.rb
|