class Kontena::Cli::Services::ListCommand
Public Instance Methods
execute()
click to toggle source
# File lib/kontena/cli/services/list_command.rb, line 50 def execute print_table(services) do |row| row['name'] = quiet? ? service_name(row) : health_status_icon(health_status(row)) + " " + service_name(row) next if quiet? row['stateful'] = row['stateful'] ? pastel.green('yes') : 'no' row['ports'] = row['ports'].map(&method(:service_port)).join(',') row['state'] = pastel.send(state_color(row['state']), row['state']) instances = [row['instance_counts']['running'], row['instances']] if instances.first < instances.last instances[0] = pastel.cyan(instances[0].to_s) end row['instances'] = instances.join(' / ') end end
fields()
click to toggle source
# File lib/kontena/cli/services/list_command.rb, line 19 def fields quiet? ? ['name'] : {name: 'name', instances: 'instances', stateful: 'stateful', state: 'state', "exposed ports" => 'ports' } end
service_name(service)
click to toggle source
# File lib/kontena/cli/services/list_command.rb, line 35 def service_name(service) stack_id = stack_id(service) return service['name'] if stack_id == 'null' [ stack_id(service), service['name'] ].compact.join('/') end
service_port(port)
click to toggle source
# File lib/kontena/cli/services/list_command.rb, line 23 def service_port(port) "#{port['ip']}:#{port['node_port']}->#{port['container_port']}/#{port['protocol']}" end
services()
click to toggle source
# File lib/kontena/cli/services/list_command.rb, line 15 def services client.get("grids/#{current_grid}/services#{"?stack=#{stack}" if stack}")['services'].sort_by{|s| s['updated_at'] }.reverse end
stack_id(service)
click to toggle source
# File lib/kontena/cli/services/list_command.rb, line 27 def stack_id(service) if quiet? service.fetch('stack', {}).fetch('id', 'null') else service.fetch('stack', {}).fetch('name', nil) end end
state_color(state)
click to toggle source
# File lib/kontena/cli/services/list_command.rb, line 41 def state_color(state) case state when 'running' then :green when 'initialized' then :cyan when 'stopped' then :red else :blue end end