class Chef::Knife::Cloud::VcenterVmList
Extends the ServerListCommand 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_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)
click to toggle source
Formats the memory value
@param [Object] value takes the number and formats it how you need it to
# 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)
click to toggle source
Sets the color for the different status of the machines
# 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