Class: Chef::Knife::Cloud::VcenterVmList
- Inherits:
-
ServerListCommand
- Object
- ServerListCommand
- Chef::Knife::Cloud::VcenterVmList
- Includes:
- VcenterServiceOptions
- Defined in:
- lib/chef/knife/vcenter_vm_list.rb
Overview
Extends the ServerListCommand for specific vCenter
Instance Method Summary collapse
-
#before_exec_command ⇒ Object
Sets up the columns for listing out and sorts by name.
-
#format_memory_value(value) ⇒ Object
Formats the memory value.
-
#format_power_status(status) ⇒ Object
Sets the color for the different status of the machines.
Methods included from VcenterServiceOptions
Instance Method Details
#before_exec_command ⇒ Object
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
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 |