class Chef::Knife::VsphereHostsList

list hosts belonging to pool VsphereHostslist extends the BaseVspherecommand

Public Instance Methods

run() click to toggle source

The main run method for hosts_list

# File lib/chef/knife/vsphere_hosts_list.rb, line 23
def run
  vim_connection
  dc = datacenter
  folder = dc.hostFolder

  target_pool = config[:pool]

  pools = find_pools_and_clusters(folder, target_pool)
  if target_pool && pools.empty?
    fatal_exit("Pool #{target_pool} not found")
  end

  pool_list = pools.map do |pool|
    host_list = list_hosts(pool)
    { "Pool" => pool.name, "Hosts" => host_list }
  end
  ui.output(pool_list)
end

Private Instance Methods

list_hosts(pool) click to toggle source
# File lib/chef/knife/vsphere_hosts_list.rb, line 44
def list_hosts(pool)
  hosts = pool.host || []
  hosts.map do |hostc|
    { "Host" => hostc.name }
  end
end