rbvmomi2 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -25
- data/exe/rbvmomish +50 -48
- data/lib/rbvmomi/basic_types.rb +318 -294
- data/lib/rbvmomi/connection.rb +221 -216
- data/lib/rbvmomi/deserialization.rb +201 -205
- data/lib/rbvmomi/fault.rb +10 -9
- data/lib/rbvmomi/optimist.rb +51 -50
- data/lib/rbvmomi/pbm.rb +52 -50
- data/lib/rbvmomi/sms/SmsStorageManager.rb +2 -1
- data/lib/rbvmomi/sms.rb +48 -46
- data/lib/rbvmomi/sso.rb +13 -18
- data/lib/rbvmomi/trivial_soap.rb +9 -8
- data/lib/rbvmomi/type_loader.rb +100 -101
- data/lib/rbvmomi/utils/admission_control.rb +90 -106
- data/lib/rbvmomi/utils/deploy.rb +77 -85
- data/lib/rbvmomi/utils/leases.rb +31 -33
- data/lib/rbvmomi/utils/perfdump.rb +177 -207
- data/lib/rbvmomi/version.rb +2 -1
- data/lib/rbvmomi/vim/ComputeResource.rb +17 -15
- data/lib/rbvmomi/vim/Datacenter.rb +1 -0
- data/lib/rbvmomi/vim/Datastore.rb +18 -15
- data/lib/rbvmomi/vim/DynamicTypeMgrAllTypeInfo.rb +7 -6
- data/lib/rbvmomi/vim/DynamicTypeMgrDataTypeInfo.rb +3 -2
- data/lib/rbvmomi/vim/DynamicTypeMgrManagedTypeInfo.rb +7 -6
- data/lib/rbvmomi/vim/Folder.rb +37 -33
- data/lib/rbvmomi/vim/HostSystem.rb +139 -136
- data/lib/rbvmomi/vim/ManagedEntity.rb +15 -14
- data/lib/rbvmomi/vim/ManagedObject.rb +11 -10
- data/lib/rbvmomi/vim/ObjectContent.rb +3 -1
- data/lib/rbvmomi/vim/ObjectUpdate.rb +3 -1
- data/lib/rbvmomi/vim/OvfManager.rb +50 -57
- data/lib/rbvmomi/vim/PerfCounterInfo.rb +4 -3
- data/lib/rbvmomi/vim/PerformanceManager.rb +28 -31
- data/lib/rbvmomi/vim/PropertyCollector.rb +8 -7
- data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +22 -21
- data/lib/rbvmomi/vim/ResourcePool.rb +19 -18
- data/lib/rbvmomi/vim/ServiceInstance.rb +8 -7
- data/lib/rbvmomi/vim/Task.rb +6 -5
- data/lib/rbvmomi/vim/VirtualMachine.rb +8 -7
- data/lib/rbvmomi/vim.rb +112 -129
- data/lib/rbvmomi.rb +1 -0
- metadata +54 -10
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (c) 2012-2017 VMware, Inc. All Rights Reserved.
|
2
3
|
# SPDX-License-Identifier: MIT
|
3
4
|
|
@@ -20,18 +21,18 @@ class RbVmomi::VIM::PerformanceManager
|
|
20
21
|
def perfcounter_cached
|
21
22
|
@perfcounter ||= perfCounter
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
def perfcounter_hash
|
25
|
-
@perfcounter_hash ||= Hash[perfcounter_cached.map{|x| [x.name, x]}]
|
26
|
+
@perfcounter_hash ||= Hash[perfcounter_cached.map{ |x| [x.name, x] }]
|
26
27
|
end
|
27
|
-
|
28
|
-
def perfcounter_idhash
|
29
|
-
@perfcounter_idhash ||= Hash[perfcounter_cached.map{|x| [x.key, x]}]
|
28
|
+
|
29
|
+
def perfcounter_idhash
|
30
|
+
@perfcounter_idhash ||= Hash[perfcounter_cached.map{ |x| [x.key, x] }]
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
def provider_summary obj
|
33
34
|
@provider_summary ||= {}
|
34
|
-
@provider_summary[obj.class] ||= QueryPerfProviderSummary(:
|
35
|
+
@provider_summary[obj.class] ||= QueryPerfProviderSummary(entity: obj)
|
35
36
|
end
|
36
37
|
|
37
38
|
def retrieve_stats objects, metrics, opts = {}
|
@@ -44,45 +45,41 @@ class RbVmomi::VIM::PerformanceManager
|
|
44
45
|
realtime = true
|
45
46
|
else
|
46
47
|
provider = provider_summary objects.first
|
47
|
-
if opts[:interval] == provider.refreshRate
|
48
|
-
realtime = true
|
49
|
-
end
|
48
|
+
realtime = true if opts[:interval] == provider.refreshRate
|
50
49
|
end
|
51
|
-
|
50
|
+
|
52
51
|
instances = opts[:instance] || '*'
|
53
|
-
if !instances.is_a?(Array)
|
54
|
-
instances = [instances]
|
55
|
-
end
|
52
|
+
instances = [instances] if !instances.is_a?(Array)
|
56
53
|
metric_ids = []
|
57
|
-
metrics.each do |x|
|
54
|
+
metrics.each do |x|
|
58
55
|
counter = perfcounter_hash[x]
|
59
56
|
if !counter
|
60
57
|
pp perfcounter_hash.keys
|
61
|
-
|
58
|
+
raise "Counter for #{x} couldn't be found"
|
62
59
|
end
|
63
60
|
instances.each do |instance|
|
64
|
-
metric_ids << RbVmomi::VIM::PerfMetricId(:
|
65
|
-
:
|
61
|
+
metric_ids << RbVmomi::VIM::PerfMetricId(counterId: counter.key,
|
62
|
+
instance: instance)
|
66
63
|
end
|
67
64
|
end
|
68
65
|
query_specs = objects.map do |obj|
|
69
66
|
RbVmomi::VIM::PerfQuerySpec({
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:
|
67
|
+
maxSample: max_samples,
|
68
|
+
entity: obj,
|
69
|
+
metricId: metric_ids,
|
70
|
+
intervalId: opts[:interval],
|
71
|
+
startTime: (realtime == false ? opts[:start_time].to_datetime : nil),
|
75
72
|
})
|
76
73
|
end
|
77
|
-
stats = QueryPerf(:
|
78
|
-
|
74
|
+
stats = QueryPerf(querySpec: query_specs)
|
75
|
+
|
79
76
|
if !opts[:multi_instance]
|
80
77
|
Hash[stats.map do |res|
|
81
78
|
[
|
82
|
-
res.entity,
|
79
|
+
res.entity,
|
83
80
|
{
|
84
|
-
:
|
85
|
-
:
|
81
|
+
sampleInfo: res.sampleInfo,
|
82
|
+
metrics: Hash[res.value.map do |metric|
|
86
83
|
metric_name = perfcounter_idhash[metric.id.counterId].name
|
87
84
|
[metric_name, metric.value]
|
88
85
|
end]
|
@@ -92,10 +89,10 @@ class RbVmomi::VIM::PerformanceManager
|
|
92
89
|
else
|
93
90
|
Hash[stats.map do |res|
|
94
91
|
[
|
95
|
-
res.entity,
|
92
|
+
res.entity,
|
96
93
|
{
|
97
|
-
:
|
98
|
-
:
|
94
|
+
sampleInfo: res.sampleInfo,
|
95
|
+
metrics: Hash[res.value.map do |metric|
|
99
96
|
metric_name = perfcounter_idhash[metric.id.counterId].name
|
100
97
|
[[metric_name, metric.id.instance], metric.value]
|
101
98
|
end]
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
|
2
3
|
# SPDX-License-Identifier: MIT
|
3
4
|
|
@@ -5,22 +6,22 @@ class RbVmomi::VIM::PropertyCollector
|
|
5
6
|
def collectMultiple objs, *pathSet
|
6
7
|
return {} if objs.empty?
|
7
8
|
|
8
|
-
klasses = objs.map{|x| x.class}.uniq
|
9
|
+
klasses = objs.map{ |x| x.class }.uniq
|
9
10
|
klass = if klasses.length > 1
|
10
11
|
# common superclass
|
11
|
-
|
12
|
+
klasses.map(&:ancestors).inject(&:&)[0]
|
12
13
|
else
|
13
14
|
klasses.first
|
14
15
|
end
|
15
16
|
|
16
17
|
spec = {
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
18
|
+
objectSet: objs.map{ |x| { obj: x } },
|
19
|
+
propSet: [{
|
20
|
+
pathSet: pathSet,
|
21
|
+
type: klass.wsdl_name
|
21
22
|
}]
|
22
23
|
}
|
23
|
-
res = RetrieveProperties(:
|
24
|
+
res = RetrieveProperties(specSet: [spec])
|
24
25
|
Hash[res.map do |x|
|
25
26
|
[x.obj, x.to_hash]
|
26
27
|
end]
|
@@ -1,33 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
|
2
3
|
# SPDX-License-Identifier: MIT
|
3
4
|
|
4
5
|
module RbVmomi
|
5
6
|
|
6
|
-
class VIM::ReflectManagedMethodExecuter
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class VIM::ReflectManagedMethodExecuter
|
8
|
+
def fetch moid, prop
|
9
|
+
result = FetchSoap(moid: moid, version: 'urn:vim25/6.5', prop: prop)
|
10
|
+
xml = Nokogiri(result.response)
|
11
|
+
_connection.deserializer.deserialize xml.root, nil
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def execute moid, method, args
|
15
|
+
soap_args = args.map do |k, v|
|
16
|
+
VIM::ReflectManagedMethodExecuterSoapArgument.new.tap do |soap_arg|
|
17
|
+
soap_arg.name = k
|
18
|
+
xml = Builder::XmlMarkup.new indent: 0
|
19
|
+
_connection.obj2xml xml, k, :anyType, false, v
|
20
|
+
soap_arg.val = xml.target!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
result = ExecuteSoap(moid: moid, version: 'urn:vim25/6.5',
|
24
|
+
method: method, argument: soap_args)
|
25
|
+
if result
|
26
|
+
_connection.deserializer.deserialize Nokogiri(result.response).root, nil
|
27
|
+
else
|
28
|
+
nil
|
20
29
|
end
|
21
|
-
end
|
22
|
-
result = ExecuteSoap(:moid => moid, :version => 'urn:vim25/6.5',
|
23
|
-
:method => method, :argument => soap_args)
|
24
|
-
if result
|
25
|
-
_connection.deserializer.deserialize Nokogiri(result.response).root, nil
|
26
|
-
else
|
27
|
-
nil
|
28
30
|
end
|
29
31
|
end
|
30
|
-
end
|
31
32
|
|
32
33
|
end
|
33
34
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
|
2
3
|
# SPDX-License-Identifier: MIT
|
3
4
|
|
@@ -6,7 +7,7 @@ class RbVmomi::VIM::ResourcePool
|
|
6
7
|
# @param name [String] Name of the child.
|
7
8
|
# @return [VIM::ResourcePool]
|
8
9
|
def find name
|
9
|
-
_connection.searchIndex.FindChild(:
|
10
|
+
_connection.searchIndex.FindChild(entity: self, name: name)
|
10
11
|
end
|
11
12
|
|
12
13
|
# Retrieve a descendant of this ResourcePool.
|
@@ -14,7 +15,7 @@ class RbVmomi::VIM::ResourcePool
|
|
14
15
|
# @return [VIM::ResourcePool]
|
15
16
|
def traverse path
|
16
17
|
es = path.split('/').reject(&:empty?)
|
17
|
-
es.inject(self) do |f,e|
|
18
|
+
es.inject(self) do |f, e|
|
18
19
|
f.find(e) || return
|
19
20
|
end
|
20
21
|
end
|
@@ -22,35 +23,35 @@ class RbVmomi::VIM::ResourcePool
|
|
22
23
|
def resourcePoolSubTree fields = []
|
23
24
|
self.class.resourcePoolSubTree [self], fields
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
def self.resourcePoolSubTree objs, fields = []
|
27
28
|
fields = (fields + ['name', 'resourcePool']).uniq
|
28
29
|
filterSpec = RbVmomi::VIM.PropertyFilterSpec(
|
29
|
-
:
|
30
|
+
objectSet: objs.map do |obj|
|
30
31
|
RbVmomi::VIM.ObjectSpec(
|
31
|
-
:
|
32
|
-
:
|
32
|
+
obj: obj,
|
33
|
+
selectSet: [
|
33
34
|
RbVmomi::VIM.TraversalSpec(
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
RbVmomi::VIM.SelectionSpec(:
|
35
|
+
name: 'tsRP',
|
36
|
+
type: 'ResourcePool',
|
37
|
+
path: 'resourcePool',
|
38
|
+
skip: false,
|
39
|
+
selectSet: [
|
40
|
+
RbVmomi::VIM.SelectionSpec(name: 'tsRP')
|
40
41
|
]
|
41
42
|
)
|
42
43
|
]
|
43
44
|
)
|
44
45
|
end,
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
46
|
+
propSet: [{
|
47
|
+
pathSet: fields,
|
48
|
+
type: 'ResourcePool'
|
48
49
|
}]
|
49
50
|
)
|
50
|
-
|
51
|
+
|
51
52
|
propCollector = objs.first._connection.propertyCollector
|
52
|
-
result = propCollector.RetrieveProperties(:
|
53
|
-
|
53
|
+
result = propCollector.RetrieveProperties(specSet: [filterSpec])
|
54
|
+
|
54
55
|
Hash[result.map do |x|
|
55
56
|
[x.obj, x.to_hash]
|
56
57
|
end]
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
|
2
3
|
# SPDX-License-Identifier: MIT
|
3
4
|
|
@@ -24,16 +25,16 @@ class RbVmomi::VIM::ServiceInstance
|
|
24
25
|
def wait_for_multiple_tasks interested, tasks
|
25
26
|
version = ''
|
26
27
|
interested = (interested + ['info.state']).uniq
|
27
|
-
task_props = Hash.new { |h,k| h[k] = {} }
|
28
|
+
task_props = Hash.new { |h, k| h[k] = {} }
|
28
29
|
|
29
|
-
filter = _connection.propertyCollector.CreateFilter :
|
30
|
-
:
|
31
|
-
:
|
32
|
-
}, :
|
30
|
+
filter = _connection.propertyCollector.CreateFilter spec: {
|
31
|
+
propSet: [{ type: 'Task', all: false, pathSet: interested }],
|
32
|
+
objectSet: tasks.map { |x| { obj: x } },
|
33
|
+
}, partialUpdates: false
|
33
34
|
|
34
35
|
begin
|
35
|
-
until task_props.size == tasks.size and task_props.all? { |k,h| %w(success error).member? h['info.state'] }
|
36
|
-
result = _connection.propertyCollector.WaitForUpdates(:
|
36
|
+
until task_props.size == tasks.size and task_props.all? { |k, h| %w(success error).member? h['info.state'] }
|
37
|
+
result = _connection.propertyCollector.WaitForUpdates(version: version)
|
37
38
|
version = result.version
|
38
39
|
os = result.filterSet[0].objectSet
|
39
40
|
|
data/lib/rbvmomi/vim/Task.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
|
2
3
|
# SPDX-License-Identifier: MIT
|
3
4
|
|
@@ -14,7 +15,7 @@ class RbVmomi::VIM::Task
|
|
14
15
|
raise info.error
|
15
16
|
end
|
16
17
|
end
|
17
|
-
|
18
|
+
|
18
19
|
# Wait for all child tasks to finish. If any one child task failed,
|
19
20
|
# the exception of the first failing task is thrown.
|
20
21
|
# @return [Hash] Map of tasks to their +info.result+ on success.
|
@@ -51,17 +52,17 @@ class RbVmomi::VIM::Task
|
|
51
52
|
raise info.error
|
52
53
|
end
|
53
54
|
end
|
54
|
-
|
55
|
+
|
55
56
|
# Get child tasks of this task.
|
56
57
|
# @return [Array] List of VIM::Task objects
|
57
58
|
def child_tasks
|
58
59
|
tm = _connection.serviceContent.taskManager
|
59
|
-
col = tm.CreateCollectorForTasks(:
|
60
|
-
:
|
60
|
+
col = tm.CreateCollectorForTasks(filter: {
|
61
|
+
rootTaskKey: [self.info.key],
|
61
62
|
})
|
62
63
|
# XXX: Likely this is not enough and we need to collect pages other
|
63
64
|
# than the latest.
|
64
|
-
tasks = col.latestPage.map{|x| x.task}
|
65
|
+
tasks = col.latestPage.map{ |x| x.task }
|
65
66
|
col.DestroyCollector()
|
66
67
|
tasks
|
67
68
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
|
2
3
|
# SPDX-License-Identifier: MIT
|
3
4
|
|
@@ -18,7 +19,7 @@ class RbVmomi::VIM::VirtualMachine
|
|
18
19
|
# @return [String] Current IP reported (as per VMware Tools) or nil
|
19
20
|
def guest_ip
|
20
21
|
g = self.guest
|
21
|
-
if g.ipAddress && (g.toolsStatus ==
|
22
|
+
if g.ipAddress && (g.toolsStatus == 'toolsOk' || g.toolsStatus == 'toolsOld')
|
22
23
|
g.ipAddress
|
23
24
|
else
|
24
25
|
nil
|
@@ -36,7 +37,7 @@ class RbVmomi::VIM::VirtualMachine
|
|
36
37
|
# share the base disk.
|
37
38
|
def add_delta_disk_layer_on_all_disks
|
38
39
|
spec = update_spec_add_delta_disk_layer_on_all_disks
|
39
|
-
self.ReconfigVM_Task(:
|
40
|
+
self.ReconfigVM_Task(spec: spec).wait_for_completion
|
40
41
|
end
|
41
42
|
|
42
43
|
# Updates a passed in spec to perform the task of adding a delta disk layer
|
@@ -50,13 +51,13 @@ class RbVmomi::VIM::VirtualMachine
|
|
50
51
|
device_change = []
|
51
52
|
disks.each do |disk|
|
52
53
|
device_change << {
|
53
|
-
:
|
54
|
-
:
|
54
|
+
operation: :remove,
|
55
|
+
device: disk
|
55
56
|
}
|
56
57
|
device_change << {
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
58
|
+
operation: :add,
|
59
|
+
fileOperation: :create,
|
60
|
+
device: disk.dup.tap { |x|
|
60
61
|
x.backing = x.backing.dup
|
61
62
|
x.backing.fileName = "[#{disk.backing.datastore.name}]"
|
62
63
|
x.backing.parent = disk.backing
|
data/lib/rbvmomi/vim.rb
CHANGED
@@ -1,157 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
|
2
3
|
# SPDX-License-Identifier: MIT
|
3
4
|
|
4
|
-
# Win32::SSPI is part of core on Windows
|
5
|
-
begin
|
6
|
-
require 'win32/sspi'
|
7
|
-
rescue LoadError
|
8
|
-
end
|
9
|
-
WIN32 = (defined? Win32::SSPI)
|
10
|
-
|
11
5
|
module RbVmomi
|
12
6
|
|
13
7
|
# A connection to one vSphere SDK endpoint.
|
14
8
|
# @see #serviceInstance
|
15
|
-
class VIM < Connection
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if !fault.fault.is_a?(RbVmomi::VIM::SSPIChallenge)
|
54
|
-
raise
|
55
|
-
else
|
56
|
-
vim.serviceContent.sessionManager.LoginBySSPI :base64Token => negotiation.complete_authentication(fault.base64Token)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
elsif opts[:sso]
|
60
|
-
vim.serviceContent.sessionManager.LoginByToken
|
61
|
-
else
|
62
|
-
vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password]
|
9
|
+
class VIM < Connection
|
10
|
+
# Connect to a vSphere SDK endpoint
|
11
|
+
#
|
12
|
+
# @param [Hash] opts The options hash.
|
13
|
+
# @option opts [String] :host Host to connect to.
|
14
|
+
# @option opts [Numeric] :port (443) Port to connect to.
|
15
|
+
# @option opts [Boolean] :ssl (true) Whether to use SSL.
|
16
|
+
# @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors.
|
17
|
+
# @option opts [String] :cookie If set, use cookie to connect instead of user/password
|
18
|
+
# @option opts [String] :user (root) Username.
|
19
|
+
# @option opts [String] :password Password.
|
20
|
+
# @option opts [String] :path (/sdk) SDK endpoint path.
|
21
|
+
# @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
|
22
|
+
# @option opts [String] :operation_id If set, use for operationID
|
23
|
+
# @option opts [Boolean] :close_on_exit (true) If true, will close connection with at_exit
|
24
|
+
# @option opts [RbVmomi::SSO] :sso (nil) Use SSO token to login if set
|
25
|
+
def self.connect opts
|
26
|
+
raise unless opts.is_a? Hash
|
27
|
+
raise 'host option required' unless opts[:host]
|
28
|
+
|
29
|
+
opts[:cookie] ||= nil
|
30
|
+
opts[:user] ||= 'root'
|
31
|
+
opts[:password] ||= ''
|
32
|
+
opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
|
33
|
+
opts[:insecure] ||= false
|
34
|
+
opts[:port] ||= (opts[:ssl] ? 443 : 80)
|
35
|
+
opts[:path] ||= '/sdk'
|
36
|
+
opts[:ns] ||= 'urn:vim25'
|
37
|
+
opts[:rev] = '6.7' if opts[:rev].nil?
|
38
|
+
opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
|
39
|
+
|
40
|
+
conn = new(opts).tap do |vim|
|
41
|
+
unless opts[:cookie]
|
42
|
+
if opts[:sso]
|
43
|
+
vim.serviceContent.sessionManager.LoginByToken
|
44
|
+
else
|
45
|
+
vim.serviceContent.sessionManager.Login userName: opts[:user], password: opts[:password]
|
46
|
+
end
|
63
47
|
end
|
48
|
+
rev = vim.serviceContent.about.apiVersion
|
49
|
+
vim.rev = [rev, opts[:rev]].min { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }
|
64
50
|
end
|
65
|
-
rev = vim.serviceContent.about.apiVersion
|
66
|
-
vim.rev = [rev, opts[:rev]].min { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }
|
67
|
-
end
|
68
51
|
|
69
|
-
|
70
|
-
|
71
|
-
|
52
|
+
at_exit { conn.close } if opts.fetch(:close_on_exit, true)
|
53
|
+
conn
|
54
|
+
end
|
72
55
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
56
|
+
def close
|
57
|
+
serviceContent.sessionManager.Logout
|
58
|
+
rescue RbVmomi::Fault => e
|
59
|
+
$stderr.puts(e.message) if debug
|
60
|
+
ensure
|
61
|
+
self.cookie = nil
|
62
|
+
super
|
63
|
+
end
|
81
64
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
65
|
+
def rev= x
|
66
|
+
super
|
67
|
+
@serviceContent = nil
|
68
|
+
end
|
86
69
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
70
|
+
# Return the ServiceInstance
|
71
|
+
#
|
72
|
+
# The ServiceInstance is the root of the vSphere inventory.
|
73
|
+
# @see http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.ServiceInstance.html
|
74
|
+
def serviceInstance
|
75
|
+
VIM::ServiceInstance self, 'ServiceInstance'
|
76
|
+
end
|
94
77
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
78
|
+
# Alias to serviceInstance.RetrieveServiceContent
|
79
|
+
def serviceContent
|
80
|
+
@serviceContent ||= serviceInstance.RetrieveServiceContent
|
81
|
+
end
|
99
82
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
83
|
+
# Alias to serviceContent.rootFolder
|
84
|
+
def rootFolder
|
85
|
+
serviceContent.rootFolder
|
86
|
+
end
|
104
87
|
|
105
|
-
|
88
|
+
alias root rootFolder
|
106
89
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
# Alias to serviceContent.searchIndex
|
113
|
-
def searchIndex
|
114
|
-
serviceContent.searchIndex
|
115
|
-
end
|
90
|
+
# Alias to serviceContent.propertyCollector
|
91
|
+
def propertyCollector
|
92
|
+
serviceContent.propertyCollector
|
93
|
+
end
|
116
94
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
95
|
+
# Alias to serviceContent.searchIndex
|
96
|
+
def searchIndex
|
97
|
+
serviceContent.searchIndex
|
98
|
+
end
|
121
99
|
|
122
|
-
|
123
|
-
|
124
|
-
|
100
|
+
# @private
|
101
|
+
def pretty_print pp
|
102
|
+
pp.text "VIM(#{@opts[:host]})"
|
103
|
+
end
|
125
104
|
|
126
|
-
|
127
|
-
|
128
|
-
if !start
|
129
|
-
log = diagMgr.BrowseDiagnosticLog(:host => host, :key => logKey, :start => 999999999)
|
130
|
-
lineEnd = log.lineEnd
|
131
|
-
start = lineEnd - lines
|
105
|
+
def instanceUuid
|
106
|
+
serviceContent.about.instanceUuid
|
132
107
|
end
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
108
|
+
|
109
|
+
def get_log_lines logKey, lines=5, start=nil, host=nil
|
110
|
+
diagMgr = self.serviceContent.diagnosticManager
|
111
|
+
if !start
|
112
|
+
log = diagMgr.BrowseDiagnosticLog(host: host, key: logKey, start: 999999999)
|
113
|
+
lineEnd = log.lineEnd
|
114
|
+
start = lineEnd - lines
|
115
|
+
end
|
116
|
+
start = start < 0 ? 0 : start
|
117
|
+
log = diagMgr.BrowseDiagnosticLog(host: host, key: logKey, start: start)
|
118
|
+
if log.lineText.size > 0
|
119
|
+
[log.lineText.slice(-lines, log.lineText.size), log.lineEnd]
|
120
|
+
else
|
121
|
+
[log.lineText, log.lineEnd]
|
122
|
+
end
|
139
123
|
end
|
140
|
-
end
|
141
124
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
125
|
+
def get_log_keys host=nil
|
126
|
+
diagMgr = self.serviceContent.diagnosticManager
|
127
|
+
keys = []
|
128
|
+
diagMgr.QueryDescriptions(host: host).each do |desc|
|
129
|
+
keys << "#{desc.key}"
|
130
|
+
end
|
131
|
+
keys
|
147
132
|
end
|
148
|
-
keys
|
149
|
-
end
|
150
133
|
|
151
|
-
|
152
|
-
|
134
|
+
add_extension_dir File.join(File.dirname(__FILE__), 'vim')
|
135
|
+
(ENV['RBVMOMI_VIM_EXTENSION_PATH']||'').split(':').each { |dir| add_extension_dir dir }
|
153
136
|
|
154
|
-
|
155
|
-
end
|
137
|
+
load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), '../../vmodl.db'))
|
138
|
+
end
|
156
139
|
|
157
140
|
end
|
data/lib/rbvmomi.rb
CHANGED