Class: Chef::Knife::Cloud::VcenterHostList

Inherits:
ResourceListCommand
  • Object
show all
Includes:
VcenterServiceOptions
Defined in:
lib/chef/knife/vcenter_host_list.rb

Overview

Extends the ResourceListcommand for specific vCenter

Instance Method Summary collapse

Methods included from VcenterServiceOptions

included

Instance Method Details

#before_exec_commandObject

Sets up the columns for listing out and sorts by name



43
44
45
46
47
48
49
50
51
52
# 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) ⇒ Object

Formats the power status

Parameters:

  • status (Object)

    takes the number and formats it how you need it to



63
64
65
66
67
68
69
70
71
72
73
74
# 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_resourceObject

Call service to get the list of hosts from vCenter



56
57
58
# File 'lib/chef/knife/vcenter_host_list.rb', line 56

def query_resource
  service.list_hosts
end