Class: Chef::Knife::ClcTemplateList
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::ClcTemplateList
- Includes:
- ClcBase
- Defined in:
- lib/chef/knife/clc_template_list.rb
Instance Method Summary collapse
- #cloud_templates ⇒ Object
- #execute ⇒ Object
- #fields ⇒ Object
- #filters ⇒ Object
- #headers ⇒ Object
- #parse_and_validate_parameters ⇒ Object
- #render ⇒ Object
- #width_limits ⇒ Object
Methods included from ClcBase
Instance Method Details
#cloud_templates ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/chef/knife/clc_template_list.rb', line 28 def cloud_templates if config[:clc_datacenter] connection.list_templates(config[:clc_datacenter]) elsif config[:clc_all] datacenters = connection.list_datacenters datacenters.map do |dc| connection.list_templates(dc['id']) end.flatten end end |
#execute ⇒ Object
23 24 25 26 |
# File 'lib/chef/knife/clc_template_list.rb', line 23 def execute context[:templates] = cloud_templates render end |
#fields ⇒ Object
63 64 65 66 67 |
# File 'lib/chef/knife/clc_template_list.rb', line 63 def fields # TODO AS: Displaying shortened list of fields for now # %w(name osType description storageSizeGB capabilities apiOnly) %w(name storageSizeGB capabilities) end |
#filters ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/chef/knife/clc_template_list.rb', line 46 def filters { 'storageSizeGB' => ->(size) { (size.zero? ? '-' : "#{size} GB").rjust(7) }, 'apiOnly' => ->(api_flag) { (api_flag ? '+' : '-').center(9) }, 'capabilities' => ->(capabilities) { capabilities.empty? ? '-' : capabilities.join(', ') } } end |
#headers ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chef/knife/clc_template_list.rb', line 69 def headers { 'name' => 'Name', 'osType' => 'OS Type', 'description' => 'Description', 'storageSizeGB' => 'Storage', 'capabilities' => 'Capabilities', 'apiOnly' => 'API Only' } end |
#parse_and_validate_parameters ⇒ Object
40 41 42 43 44 |
# File 'lib/chef/knife/clc_template_list.rb', line 40 def parse_and_validate_parameters if config[:clc_datacenter].nil? && !config[:clc_all] errors << 'Datacenter ID is required' end end |
#render ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/chef/knife/clc_template_list.rb', line 80 def render ui.info Hirb::Helpers::AutoTable.render(context[:templates], :headers => headers, :fields => fields, :filters => filters, :max_fields => width_limits, :resize => false, :description => false) end |
#width_limits ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/chef/knife/clc_template_list.rb', line 54 def width_limits { 'description' => 0.2, 'storageSizeGB' => 7, 'capabilities' => 15, 'apiOnly' => 9 } end |