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

Inherits:
ServerListCommand
  • Object
show all
Includes:
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

Instance Method Details

#before_exec_commandObject

Sets up the columns for listing out and sorts by name



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/knife/vcenter_vm_list.rb', line 44

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



74
75
76
# File 'lib/chef/knife/vcenter_vm_list.rb', line 74

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



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

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