Class: Chef::Knife::Cloud::VcenterVmList

Inherits:
ServerListCommand
  • Object
show all
Includes:
VcenterServiceHelpers, VcenterServiceOptions
Defined in:
lib/chef/knife/vcenter_vm_list.rb

Overview

Extends the ServerListCommand 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



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

def before_exec_command
  @columns_with_info = [
    { label: "ID",    key: "vm" },
    { label: "Name",  key: "name" },
    { label: "Power State", key: "power_state", value_callback: method(:format_power_status) },
    { label: "CPU Count", key: "cpu_count" },
    { label: "RAM Size (MB)", key: "memory_size_MiB", value_callback: method(:format_memory_value) }
  ]

  @sort_by_field = "name"
end

#format_memory_value(value) ⇒ Object

Formats the memory value

Parameters:

  • value (Object)

    takes the number and formats it how you need it to



72
73
74
# File 'lib/chef/knife/vcenter_vm_list.rb', line 72

def format_memory_value(value)
  value.to_s.reverse.gsub(/...(?=.)/, '\&,').reverse
end

#format_power_status(status) ⇒ Object

Sets the color for the different status of the machines



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/chef/knife/vcenter_vm_list.rb', line 55

def format_power_status(status)
  status_check = status.value
  status_color = case status_check
                 when "POWERED_OFF"
                   :red
                 when "POWERED_ON"
                   :green
                 when "SUSPENDED"
                   :yellow
                  end

  ui.color(status.value, status_color)
end