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

Inherits:
ResourceListCommand
  • Object
show all
Includes:
VcenterServiceHelpers, 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

Methods included from VcenterServiceHelpers

#check_for_missing_config_values!, #create_service_instance, #validate!, #verify_ssl?

Instance Method Details

#before_exec_commandObject

Sets up the columns for listing out and sorts by name



40
41
42
43
44
45
46
47
48
49
# File 'lib/chef/knife/vcenter_host_list.rb', line 40

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



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/chef/knife/vcenter_host_list.rb', line 60

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



53
54
55
# File 'lib/chef/knife/vcenter_host_list.rb', line 53

def query_resource
  service.list_hosts
end