rvc 1.0.0
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.
- data/LICENSE +19 -0
- data/README.rdoc +120 -0
- data/Rakefile +39 -0
- data/TODO +4 -0
- data/VERSION +1 -0
- data/bin/rvc +104 -0
- data/lib/rvc.rb +31 -0
- data/lib/rvc/completion.rb +110 -0
- data/lib/rvc/extensions/ClusterComputeResource.rb +42 -0
- data/lib/rvc/extensions/ComputeResource.rb +47 -0
- data/lib/rvc/extensions/Datacenter.rb +36 -0
- data/lib/rvc/extensions/Datastore.rb +188 -0
- data/lib/rvc/extensions/DistributedVirtualPortgroup.rb +38 -0
- data/lib/rvc/extensions/DistributedVirtualSwitch.rb +40 -0
- data/lib/rvc/extensions/Folder.rb +33 -0
- data/lib/rvc/extensions/HostSystem.rb +48 -0
- data/lib/rvc/extensions/ManagedEntity.rb +28 -0
- data/lib/rvc/extensions/Network.rb +28 -0
- data/lib/rvc/extensions/ResourcePool.rb +52 -0
- data/lib/rvc/extensions/VirtualMachine.rb +72 -0
- data/lib/rvc/fs.rb +123 -0
- data/lib/rvc/inventory.rb +125 -0
- data/lib/rvc/modules.rb +74 -0
- data/lib/rvc/modules/basic.rb +276 -0
- data/lib/rvc/modules/datastore.rb +63 -0
- data/lib/rvc/modules/host.rb +29 -0
- data/lib/rvc/modules/resource_pool.rb +95 -0
- data/lib/rvc/modules/vim.rb +128 -0
- data/lib/rvc/modules/vm.rb +607 -0
- data/lib/rvc/modules/vmrc.rb +72 -0
- data/lib/rvc/modules/vnc.rb +111 -0
- data/lib/rvc/option_parser.rb +114 -0
- data/lib/rvc/path.rb +37 -0
- data/lib/rvc/readline-ffi.rb +41 -0
- data/lib/rvc/shell.rb +220 -0
- data/lib/rvc/ttl_cache.rb +44 -0
- data/lib/rvc/util.rb +168 -0
- data/test/_test_completion.rb +27 -0
- data/test/_test_option_parser.rb +6 -0
- data/test/inventory_fixtures.rb +15 -0
- data/test/test_fs.rb +113 -0
- data/test/test_parse_path.rb +41 -0
- metadata +146 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
class RbVmomi::VIM::ComputeResource
|
22
|
+
# TODO expand, optimize
|
23
|
+
def display_info
|
24
|
+
puts "name: #{name}"
|
25
|
+
puts "hosts:"
|
26
|
+
host.each do |h|
|
27
|
+
puts " #{h.name}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.ls_properties
|
32
|
+
%w(name summary.effectiveCpu summary.effectiveMemory)
|
33
|
+
end
|
34
|
+
|
35
|
+
def ls_text r
|
36
|
+
" (standalone): cpu #{r['summary.effectiveCpu']/1000} GHz, memory #{r['summary.effectiveMemory']/1000} GB"
|
37
|
+
end
|
38
|
+
|
39
|
+
# TODO add datastore, network
|
40
|
+
def children
|
41
|
+
hosts, resourcePool = collect *%w(host resourcePool)
|
42
|
+
{
|
43
|
+
'host' => hosts[0],
|
44
|
+
'resourcePool' => resourcePool,
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
class RbVmomi::VIM::Datacenter
|
22
|
+
def ls_text r
|
23
|
+
" (datacenter)"
|
24
|
+
end
|
25
|
+
|
26
|
+
def children
|
27
|
+
vmFolder, datastoreFolder, networkFolder, hostFolder =
|
28
|
+
collect *%w(vmFolder datastoreFolder networkFolder hostFolder)
|
29
|
+
{
|
30
|
+
'vm' => vmFolder,
|
31
|
+
'datastore' => datastoreFolder,
|
32
|
+
'network' => networkFolder,
|
33
|
+
'host' => hostFolder,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
class RbVmomi::VIM::Datastore
|
22
|
+
def display_info
|
23
|
+
s, info, = collect :summary, :info
|
24
|
+
puts "type: #{s.type}"
|
25
|
+
puts "url: #{s.accessible ? s.url : '<inaccessible>'}"
|
26
|
+
puts "uuid: #{info.vmfs.uuid}"
|
27
|
+
puts "multipleHostAccess: #{s.multipleHostAccess}"
|
28
|
+
puts "capacity: %0.2fGB" % (s.capacity.to_f/10**9)
|
29
|
+
puts "free space: %0.2fGB" % (s.freeSpace.to_f/10**9)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.ls_properties
|
33
|
+
%w(name summary.capacity summary.freeSpace)
|
34
|
+
end
|
35
|
+
|
36
|
+
def ls_text r
|
37
|
+
pct_used = 100*(1-(r['summary.freeSpace'].to_f/r['summary.capacity']))
|
38
|
+
pct_used_text = "%0.1f%%" % pct_used
|
39
|
+
capacity_text = "%0.2fGB" % (r['summary.capacity'].to_f/10**9)
|
40
|
+
": #{capacity_text} #{pct_used_text}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def children
|
44
|
+
{
|
45
|
+
'files' => FakeDatastoreFolder.new(self, ""),
|
46
|
+
'vms' => RVC::FakeFolder.new(self, :children_vms),
|
47
|
+
'hosts' => RVC::FakeFolder.new(self, :children_hosts),
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def children_vms
|
52
|
+
RVC::Util.collect_children self, :vm
|
53
|
+
end
|
54
|
+
|
55
|
+
def children_hosts
|
56
|
+
# XXX optimize
|
57
|
+
Hash[host.map(&:key).map { |x| [x.name, x] }]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class RbVmomi::VIM::Datastore::FakeDatastoreFolder
|
62
|
+
include RVC::InventoryObject
|
63
|
+
|
64
|
+
attr_reader :path, :datastore
|
65
|
+
|
66
|
+
def initialize datastore, path
|
67
|
+
@datastore = datastore
|
68
|
+
@path = path
|
69
|
+
end
|
70
|
+
|
71
|
+
def datastore_path
|
72
|
+
@ds_name ||= @datastore.name
|
73
|
+
"[#{@ds_name}] #{@path}"
|
74
|
+
end
|
75
|
+
|
76
|
+
def search_result_to_object x
|
77
|
+
case x
|
78
|
+
when RbVmomi::VIM::FolderFileInfo
|
79
|
+
RbVmomi::VIM::Datastore::FakeDatastoreFolder.new(@datastore, "#{@path}/#{x.path}")
|
80
|
+
when RbVmomi::VIM::FileInfo
|
81
|
+
RbVmomi::VIM::Datastore::FakeDatastoreFile.new(@datastore, "#{@path}/#{x.path}", x)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def children
|
86
|
+
results = @datastore.browser.SearchDatastore_Task(
|
87
|
+
:datastorePath => datastore_path,
|
88
|
+
:searchSpec => {
|
89
|
+
:details => {
|
90
|
+
:fileType => true,
|
91
|
+
:fileSize => true,
|
92
|
+
:fileOwner => false,
|
93
|
+
:modification => false
|
94
|
+
}
|
95
|
+
}
|
96
|
+
).wait_for_completion
|
97
|
+
|
98
|
+
Hash[results.file.map { |x| [x.path, search_result_to_object(x)] }]
|
99
|
+
end
|
100
|
+
|
101
|
+
def traverse_one arc
|
102
|
+
browser, ds_name = @datastore.collect :browser, :name
|
103
|
+
results = browser.SearchDatastore_Task(
|
104
|
+
:datastorePath => "[#{ds_name}] #{@path}",
|
105
|
+
:searchSpec => {
|
106
|
+
:details => {
|
107
|
+
:fileType => true,
|
108
|
+
:fileSize => true,
|
109
|
+
:fileOwner => false,
|
110
|
+
:modification => false
|
111
|
+
},
|
112
|
+
:matchPattern => [arc]
|
113
|
+
}
|
114
|
+
).wait_for_completion
|
115
|
+
return unless results.file.size == 1
|
116
|
+
search_result_to_object results.file[0]
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.folder?
|
120
|
+
true
|
121
|
+
end
|
122
|
+
|
123
|
+
def parent
|
124
|
+
els = path.split '/'
|
125
|
+
if els.empty?
|
126
|
+
@datastore
|
127
|
+
else
|
128
|
+
parent_path = els[0...-1].join '/'
|
129
|
+
RbVmomi::VIM::Datastore::FakeDatastoreFolder.new(@datastore, parent_path)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def display_info
|
134
|
+
puts "Datastore Folder"
|
135
|
+
puts "datastore: #{@datastore.name}"
|
136
|
+
puts "path: #{@path}"
|
137
|
+
end
|
138
|
+
|
139
|
+
def eql? x
|
140
|
+
@datastore == x.instance_variable_get(:@datastore) &&
|
141
|
+
@path == x.instance_variable_get(:@path)
|
142
|
+
end
|
143
|
+
|
144
|
+
def hash
|
145
|
+
@datastore.hash ^ @path.hash
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
class RbVmomi::VIM::Datastore::FakeDatastoreFile
|
150
|
+
include RVC::InventoryObject
|
151
|
+
|
152
|
+
attr_reader :path, :datastore
|
153
|
+
|
154
|
+
def initialize datastore, path, info
|
155
|
+
@datastore = datastore
|
156
|
+
@path = path
|
157
|
+
@info = info
|
158
|
+
end
|
159
|
+
|
160
|
+
def datastore_path
|
161
|
+
@ds_name ||= @datastore.name
|
162
|
+
"[#{@ds_name}] #{@path}"
|
163
|
+
end
|
164
|
+
|
165
|
+
def parent
|
166
|
+
els = path.split '/'
|
167
|
+
parent_path = els[0...-1].join '/'
|
168
|
+
RbVmomi::VIM::Datastore::FakeDatastoreFolder.new(@datastore, parent_path)
|
169
|
+
end
|
170
|
+
|
171
|
+
def display_info
|
172
|
+
puts "Datastore File"
|
173
|
+
puts "datastore: #{@datastore.name}"
|
174
|
+
puts "path: #{@path}"
|
175
|
+
puts "size: #{@info.fileSize} bytes"
|
176
|
+
case @info
|
177
|
+
when RbVmomi::VIM::VmConfigFileInfo
|
178
|
+
puts "config version: #{@info.configVersion}"
|
179
|
+
when RbVmomi::VIM::VmDiskFileInfo
|
180
|
+
puts "capacity: #{@info.capacityKb} KB"
|
181
|
+
puts "hardware version: #{@info.hardwareVersion}"
|
182
|
+
puts "controller type: #{@info.controllerType}"
|
183
|
+
puts "thin provisioned: #{@info.thin}"
|
184
|
+
puts "type: #{@info.diskType}"
|
185
|
+
puts "extents:\n#{@info.diskExtents.map { |x| " #{x}" } * "\n"}"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
class RbVmomi::VIM::DistributedVirtualPortgroup
|
22
|
+
def display_info
|
23
|
+
config, = collect(:config)
|
24
|
+
puts "name: #{config.name}"
|
25
|
+
puts "ports: #{config.numPorts}"
|
26
|
+
puts "description: #{config.description}"
|
27
|
+
puts "switch: #{config.distributedVirtualSwitch.name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.ls_properties
|
31
|
+
%w(name config.distributedVirtualSwitch)
|
32
|
+
end
|
33
|
+
|
34
|
+
def ls_text r
|
35
|
+
# XXX optimize
|
36
|
+
" (dvpg): <#{r['config.distributedVirtualSwitch'].name}"
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
class RbVmomi::VIM::DistributedVirtualSwitch
|
22
|
+
def display_info
|
23
|
+
config, = collect(:config)
|
24
|
+
puts "name: #{config.name}"
|
25
|
+
puts "description: #{config.description}"
|
26
|
+
puts "product: #{config.productInfo.vendor} #{config.productInfo.name} #{config.productInfo.version}"
|
27
|
+
puts "ports: #{config.numPorts}"
|
28
|
+
puts "standalone ports: #{config.numStandalonePorts}"
|
29
|
+
puts "maximum ports: #{config.maxPorts}"
|
30
|
+
puts "netIORM: #{config.networkResourceManagementEnabled}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.ls_properties
|
34
|
+
%w(name summary.description)
|
35
|
+
end
|
36
|
+
|
37
|
+
def ls_text r
|
38
|
+
" (dvs)"
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
class RbVmomi::VIM::Folder
|
22
|
+
def traverse_one arc
|
23
|
+
@soap.searchIndex.FindChild :entity => self, :name => arc
|
24
|
+
end
|
25
|
+
|
26
|
+
def children
|
27
|
+
RVC::Util.collect_children self, :childEntity
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.folder?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
class RbVmomi::VIM::HostSystem
|
22
|
+
def self.ls_properties
|
23
|
+
%w(name summary.hardware.memorySize summary.hardware.cpuModel
|
24
|
+
summary.hardware.cpuMhz summary.hardware.numCpuPkgs
|
25
|
+
summary.hardware.numCpuCores summary.hardware.numCpuThreads)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ls_text r
|
29
|
+
memorySize, cpuModel, cpuMhz, numCpuPkgs, numCpuCores =
|
30
|
+
%w(memorySize cpuModel cpuMhz numCpuPkgs numCpuCores).map { |x| r["summary.hardware.#{x}"] }
|
31
|
+
" (host): cpu #{numCpuPkgs}*#{numCpuCores}*#{"%.2f" % (cpuMhz.to_f/1000)} GHz, memory #{"%.2f" % (memorySize/10**9)} GB"
|
32
|
+
end
|
33
|
+
|
34
|
+
def children
|
35
|
+
{
|
36
|
+
'vms' => RVC::FakeFolder.new(self, :ls_vms),
|
37
|
+
'datastores' => RVC::FakeFolder.new(self, :ls_datastores),
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def ls_vms
|
42
|
+
RVC::Util.collect_children self, :vm
|
43
|
+
end
|
44
|
+
|
45
|
+
def ls_datastores
|
46
|
+
RVC::Util.collect_children self, :datastore
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
class RbVmomi::VIM::ManagedEntity
|
22
|
+
include RVC::InventoryObject
|
23
|
+
|
24
|
+
def display_info
|
25
|
+
puts "name: #{name}"
|
26
|
+
puts "type: #{self.class.name}"
|
27
|
+
end
|
28
|
+
end
|