Class: Chef::Knife::VspherePoolShow
Instance Method Summary
collapse
#choose_datastore, common_options, #conn_opts, #datacenter, #fatal_exit, #find_all_in_folder, #find_datastore, #find_datastorecluster, #find_datastores_regex, #find_device, #find_folder, #find_in_folder, #find_network, #find_pool, #find_pool_folder, #find_pools_and_clusters, #get_config, #get_password_from_stdin, #get_path_to_object, #linux?, #number_to_human_size, #password, #tcp_test_port, #tcp_test_port_vm, #traverse_folders_for_computeresources, #traverse_folders_for_dc, #traverse_folders_for_pools, #vim_connection, #windows?
Instance Method Details
#run ⇒ Object
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
54
55
56
57
58
59
|
# File 'lib/chef/knife/vsphere_pool_show.rb', line 26
def run
$stdout.sync = true
poolname = @name_args[0]
if poolname.nil?
show_usage
fatal_exit("You must specify a resource poor or cluster name (see knife vsphere pool list)")
end
query_string = @name_args[1]
if query_string.nil?
show_usage
fatal_exit("You must specify a QUERY value (e.g. summary.overallStatus )")
end
vim_connection
dc = datacenter
folder = dc.hostFolder
pool = traverse_folders_for_pool(folder, poolname) || abort("Pool #{poolname} not found")
query = query_string.split "."
result = pool
query.each do |part|
message, index = part.split(/[\[\]]/)
unless result.respond_to? message.to_sym
fatal_exit("\"#{query_string}\" not recognized.")
end
result = index ? result.send(message)[index.to_i] : result.send(message)
end
puts result
end
|
#traverse_folders_for_pool(folder, poolname) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/chef/knife/vsphere_pool_show.rb', line 13
def traverse_folders_for_pool(folder, poolname)
children = folder.children.find_all
children.each do |child|
if child.class == RbVmomi::VIM::ClusterComputeResource || child.class == RbVmomi::VIM::ComputeResource || child.class == RbVmomi::VIM::ResourcePool
return child if child.name == poolname
elsif child.class == RbVmomi::VIM::Folder
pool = traverse_folders_for_pool(child, poolname)
return pool if pool
end
end
false
end
|