contexto 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70a1d561afdac4ad1e724a0f4e5174b2e302b5c6
4
- data.tar.gz: 899491e29583693bcde3f42d5f02b17dfb943765
3
+ metadata.gz: de77f650841b467399bee6dbf2d29a5696109e56
4
+ data.tar.gz: 828dd1907ca53b14b6a157993f60e7c4ca2582f2
5
5
  SHA512:
6
- metadata.gz: ed11c289dd07940251a6a75eb67f6d8d1f158a0b36b98380871103f503203ae84a728cebd400c117eb6c2819de7259eea377c3055211caa0cf5a1b3f074e7b79
7
- data.tar.gz: e0c9492d095b2af5b3284295c9a47e1e4839a84579d49b0006053e00e0532439c289f71eb7091e39fe5f57b2b0366bd071cc6ebb2710823f2ec5cc945cf1a8fa
6
+ metadata.gz: 89c7a8bd03f7354bdebe06e4160801f19984ed5ff55da37366287733ce8f74f2241a7d6e0410c0c8709c3484ad02525427d48d173fc7914e4391dce37156bacf
7
+ data.tar.gz: 041afed7733f84b832d593498cacce3bc7ae833f93d8c8e5e7c70ba4a44c4759328109f425fb5419801b6b5f55520d6a062e50b0cdd96cd682a0e406d5825ed5
@@ -4,7 +4,7 @@ require 'aws-sdk'
4
4
  module Contexto
5
5
  # ECS class
6
6
  class Contextualize
7
- attr_reader :display, :cluster, :service
7
+ attr_reader :display, :cluster, :service, :container, :console, :rake
8
8
 
9
9
  def initialize(params = {})
10
10
  @cluster = params.fetch(:cluster) if params[:cluster]
@@ -16,37 +16,41 @@ module Contexto
16
16
  end
17
17
 
18
18
  def run
19
- if (@console || @rake)
19
+ if ssh?
20
20
  task = describe_tasks
21
21
  ec2_instance_id = describe_container_instance(task[:container_instance_arn])
22
- @ssh = Contexto::SSH.new(describe_instances(ec2_instance_id), @cluster, @service, @container)
23
- if @console
22
+ @ssh = Contexto::SSH.new(describe_instances(ec2_instance_id), cluster, service, container)
23
+ if console
24
24
  @ssh.console
25
- elsif @rake
26
- @ssh.rake(@rake)
25
+ elsif rake
26
+ @ssh.rake(rake)
27
27
  end
28
28
  return
29
29
  end
30
- if !@cluster
31
- clusters
30
+ if !cluster
31
+ show_clusters
32
32
  return
33
33
  end
34
- cluster
34
+ show_cluster
35
35
  puts "\n"
36
- if !@service
37
- services
36
+ if !service
37
+ show_services
38
38
  end
39
- if @service
39
+ if service
40
40
  puts "\n"
41
- service
41
+ show_service
42
42
  puts "\n"
43
- tasks
43
+ show_tasks
44
44
  end
45
45
  end
46
46
 
47
47
  private
48
48
 
49
- def clusters
49
+ def ssh?
50
+ (console || rake)
51
+ end
52
+
53
+ def show_clusters
50
54
  title = "Clusters"
51
55
  headings = %w(Name)
52
56
  clusters = list_clusters
@@ -57,8 +61,8 @@ module Contexto
57
61
  @display.create_display(title, headings, rows)
58
62
  end
59
63
 
60
- def cluster
61
- title = "Cluster #{@cluster}"
64
+ def show_cluster
65
+ title = "Cluster #{cluster}"
62
66
  headings = %w(Name Status Instances Services RunningTasks PendingTasks)
63
67
  cluster = describe_clusters
64
68
  rows = []
@@ -66,7 +70,7 @@ module Contexto
66
70
  @display.create_display(title, headings, rows)
67
71
  end
68
72
 
69
- def services
73
+ def show_services
70
74
  title = "Services"
71
75
  headings = %w(Name)
72
76
  services = list_services
@@ -77,8 +81,8 @@ module Contexto
77
81
  @display.create_display(title, headings, rows)
78
82
  end
79
83
 
80
- def service
81
- title = "Service #{@service}"
84
+ def show_service
85
+ title = "Service #{service}"
82
86
  headings = %w(Name Status Desired Running Pending)
83
87
  service = describe_services
84
88
  rows = []
@@ -88,7 +92,7 @@ module Contexto
88
92
  puts 'Service not found'
89
93
  end
90
94
 
91
- def tasks
95
+ def show_tasks
92
96
  task = describe_tasks
93
97
  containers = task[:containers]
94
98
  ec2_instance_id = describe_container_instance(task[:container_instance_arn])
@@ -109,7 +113,7 @@ module Contexto
109
113
  def describe_clusters
110
114
  resp = ecs_client.describe_clusters(
111
115
  clusters: [
112
- @cluster
116
+ cluster
113
117
  ]
114
118
  )
115
119
  resp.clusters[0].to_h
@@ -117,16 +121,16 @@ module Contexto
117
121
 
118
122
  def list_services
119
123
  resp = ecs_client.list_services(
120
- cluster: @cluster
124
+ cluster: cluster
121
125
  )
122
126
  resp.service_arns
123
127
  end
124
128
 
125
129
  def describe_services
126
130
  resp = ecs_client.describe_services(
127
- cluster: @cluster,
131
+ cluster: cluster,
128
132
  services: [
129
- @service
133
+ service
130
134
  ]
131
135
  )
132
136
  resp.services[0].to_h
@@ -134,7 +138,7 @@ module Contexto
134
138
 
135
139
  def describe_tasks
136
140
  resp = ecs_client.describe_tasks(
137
- cluster: @cluster,
141
+ cluster: cluster,
138
142
  tasks: [task_arn]
139
143
  )
140
144
  resp.tasks[0].to_h
@@ -142,15 +146,15 @@ module Contexto
142
146
 
143
147
  def task_arn
144
148
  resp = ecs_client.list_tasks(
145
- cluster: @cluster,
146
- service_name: @service
149
+ cluster: cluster,
150
+ service_name: service
147
151
  )
148
152
  resp.task_arns[0]
149
153
  end
150
154
 
151
155
  def describe_container_instance(container_instance_arn)
152
156
  resp = ecs_client.describe_container_instances(
153
- cluster: @cluster,
157
+ cluster: cluster,
154
158
  container_instances: [
155
159
  container_instance_arn
156
160
  ]
@@ -1,4 +1,4 @@
1
1
  # Contexto version
2
2
  module Contexto
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contexto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Turnbull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-28 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk