class Chef::Knife::ClcGroupList
Public Instance Methods
execute()
click to toggle source
# File lib/chef/knife/clc_group_list.rb, line 32 def execute context[:groups] = connection.list_groups(config[:clc_datacenter]).map do |group| parent_link = group['links'].find { |link| link['rel'] == 'parentGroup' } group['parentId'] = parent_link['id'] if parent_link group end render end
fields()
click to toggle source
# File lib/chef/knife/clc_group_list.rb, line 56 def fields # TODO AS: Displaying shortened list of fields for now # %w(name id parentId description serversCount type status) %w(name id serversCount type) end
filters()
click to toggle source
# File lib/chef/knife/clc_group_list.rb, line 42 def filters { 'serversCount' => ->(count) { count.zero? ? '-' : count }, 'parentId' => ->(id) { id ? id : '-' }, 'description' => ->(description) { description.to_s.empty? ? '-' : description } } end
headers()
click to toggle source
# File lib/chef/knife/clc_group_list.rb, line 62 def headers { 'name' => 'Name', 'id' => 'ID', 'parentId' => 'Parent', 'description' => 'Description', 'serversCount' => 'Servers', 'type' => 'Type', 'status' => 'Status' } end
parse_and_validate_parameters()
click to toggle source
# File lib/chef/knife/clc_group_list.rb, line 22 def parse_and_validate_parameters unless config[:clc_datacenter] errors << 'Datacenter ID is required' end unless %w(tree table).include?(config[:clc_view]) errors << 'View parameter should be either table or a tree' end end
render()
click to toggle source
# File lib/chef/knife/clc_group_list.rb, line 74 def render case config[:clc_view] when 'tree' then render_tree when 'table' then render_table end end
render_table()
click to toggle source
# File lib/chef/knife/clc_group_list.rb, line 98 def render_table ui.info Hirb::Helpers::AutoTable.render(context[:groups], :fields => fields, :headers => headers, :filters => filters, :max_fields => width_limits, :resize => false, :description => false) end
render_tree()
click to toggle source
# File lib/chef/knife/clc_group_list.rb, line 81 def render_tree display_value = ->(group) { "#{group['name']} (#{group['id']})" } group_children = ->(parent_group) do context[:groups].select { |group| group['parentId'] == parent_group['id'] } end root = context[:groups].find { |group| group['parentId'].nil? } return unless root ui.info Hirb::Helpers::ParentChildTree.render(root, :type => :directory, :value_method => display_value, :children_method => group_children) end
width_limits()
click to toggle source
# File lib/chef/knife/clc_group_list.rb, line 50 def width_limits { 'description' => 0.2 } end