class Chef::Knife::Cloud::VcenterHostList

Extends the ResourceListcommand for specific vCenter

Public Instance Methods

before_exec_command() click to toggle source

Sets up the columns for listing out and sorts by name

# File lib/chef/knife/vcenter_host_list.rb, line 43
def before_exec_command
  @columns_with_info = [
    { label: "ID",    key: "host" },
    { label: "Name",  key: "name" },
    { label: "Power State", key: "power_state", value_callback: method(:format_power_status) },
    { label: "Connection State", key: "connection_state" },
  ]

  @sort_by_field = "name"
end
format_power_status(status) click to toggle source

Formats the power status

@param [Object] status takes the number and formats it how you need it to

# File lib/chef/knife/vcenter_host_list.rb, line 63
def format_power_status(status)
  status_color = case status
                 when "POWERED_OFF"
                   :red
                 when "POWERED_ON"
                   :green
                 when "SUSPENDED"
                   :yellow
                 end

  ui.color(status, status_color)
end
query_resource() click to toggle source

Call service to get the list of hosts from vCenter

# File lib/chef/knife/vcenter_host_list.rb, line 56
def query_resource
  service.list_hosts
end