lib/contexto/contextualize.rb in contexto-0.1.0 vs lib/contexto/contextualize.rb in contexto-0.1.1
- old
+ new
@@ -8,14 +8,21 @@
def initialize(params = {})
@cluster = params.fetch(:cluster)
@service = params.fetch(:service) if params[:service]
@container = params.fetch(:container) if params[:container]
+ @ssh = params.fetch(:ssh)
@display = Contexto::Display.new
end
- def show
+ def run
+ if @ssh
+ task = describe_tasks
+ ec2_instance_id = describe_container_instance(task[:container_instance_arn])
+ @connect = Contexto::SSH.new(describe_instances(ec2_instance_id), @cluster, @service, @container)
+ return
+ end
cluster
puts "\n"
return unless @service
service
puts "\n"
@@ -54,23 +61,27 @@
rescue Aws::ECS::Errors::ServiceNotFoundException
puts 'Service not found'
end
def tasks
- resp = ecs_client.describe_tasks(
- cluster: @cluster,
- tasks: [task_arn]
- )
- task = resp.tasks[0].to_h
+ task = describe_tasks
containers = task[:containers]
ec2_instance_id = describe_container_instance(task[:container_instance_arn])
title = 'Containers'
headings = %w(Container Status IP)
rows = []
containers.each do |container|
rows << [container[:name], container[:last_status], describe_instances(ec2_instance_id)]
end
@display.create_display(title, headings, rows)
+ end
+
+ def describe_tasks
+ resp = ecs_client.describe_tasks(
+ cluster: @cluster,
+ tasks: [task_arn]
+ )
+ resp.tasks[0].to_h
end
def task_arn
resp = ecs_client.list_tasks(
cluster: @cluster,