Class: Chef::Knife::VsphereHostsList
- Inherits:
-
BaseVsphereCommand
- Object
- Chef::Knife
- BaseVsphereCommand
- Chef::Knife::VsphereHostsList
- Defined in:
- lib/chef/knife/vsphere_hosts_list.rb
Overview
list hosts belonging to pool
Instance Method Summary collapse
Methods inherited from BaseVsphereCommand
#choose_datastore, common_options, #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, #get_config, #get_path_to_object, #get_vm, #get_vms, #linux?, #password, #tcp_test_port, #tcp_test_port_vm, #traverse_folders_for_computeresources, #traverse_folders_for_dc, #traverse_folders_for_vm, #traverse_folders_for_vms, #vim_connection, #windows?
Methods inherited from Chef::Knife
Instance Method Details
#find_pools(folder, poolname = nil) ⇒ Object
16 17 18 19 |
# File 'lib/chef/knife/vsphere_hosts_list.rb', line 16 def find_pools(folder, poolname = nil) pools = folder.children.find_all.select { |p| p.is_a?(RbVmomi::VIM::ComputeResource) || p.is_a?(RbVmomi::VIM::ResourcePool) } poolname.nil? ? pools : pools.select { |p| p.name == poolname } end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chef/knife/vsphere_hosts_list.rb', line 21 def run vim_connection dc = datacenter folder = dc.hostFolder target_pool = config[:pool] pools = find_pools(folder, target_pool) if target_pool && pools.empty? puts "Pool #{target_pool} not found" return end pools.each do |pool| puts "#{ui.color('Pool', :cyan)}: #{pool.name}" hosts = pool.host || [] hosts.each do |hostc| puts " #{ui.color('Host', :cyan)}: #{hostc.name}" end end end |