vaws 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ef88a26bd7a8546b4446da23d67d7bda2a1fc24fb4cf6e6b94b3289f3efd89e
4
- data.tar.gz: 44eae4395d523b11ea01f5e13f254960177ac02957d41ff59084e5accdb9e880
3
+ metadata.gz: ca435519c8294b066a053a4bc36de39e8bd346bd9525c816078179d07b57739a
4
+ data.tar.gz: f6288d2518b0bdec627bf92a95ffc88b59546f08ef80c7fbbe94488d8177f1a6
5
5
  SHA512:
6
- metadata.gz: 20c89a795c4df9904d7ae9f7351a962e6368b2c3a5f5d5b7724a69ee782ee89ca5d639086de2c63a58bea9978fc5b9893c77b801b22b7b51f888bb3e92875615
7
- data.tar.gz: b43a6f6737b2b01ff117d77b1d7038a2ad13e167a3166f377ff7cdeaf9741b01759a7d214cc6d621f9a90dcdabe323f02f21585d38d8c2b7fba8f15557f96275
6
+ metadata.gz: e05a075e2a9cbd643125f48f3af753d75237e75e43af04fb17bab6a020cb02b9347c15994870e351b69ce5dec53a6464d873f14ad43da6e08a2b063df0c1f999
7
+ data.tar.gz: e7480c918eb5fbeb6bceaa2311f7d9cc75947f63c0db22b4d27a0781f4ee35bb51d5b7eb4984f91cd0efffaeb38ebe15e2cb38cd3effba480cd7fd62b72c41e7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vaws (0.8.1)
4
+ vaws (0.8.2)
5
5
  aws-sdk-acm
6
6
  aws-sdk-ec2
7
7
  aws-sdk-ecs
@@ -60,7 +60,7 @@ GEM
60
60
  terminal-table (1.8.0)
61
61
  unicode-display_width (~> 1.1, >= 1.1.1)
62
62
  thor (0.20.3)
63
- unicode-display_width (1.6.1)
63
+ unicode-display_width (1.7.0)
64
64
 
65
65
  PLATFORMS
66
66
  ruby
@@ -2,8 +2,14 @@ module Vaws
2
2
  module Aws
3
3
  class Describer
4
4
  #TODO Add def to confirm AWS credential
5
- def set_basic_info
6
- raise NotImplementedError
5
+
6
+ # 単一のオプションしか許可されていないコマンドのオプション数を確認
7
+ def single_option_validation(*options)
8
+ options_count = options.length - options.count(nil)
9
+ if options_count > 1
10
+ puts "Can't specify more than one option"
11
+ exit 1
12
+ end
7
13
  end
8
14
  end
9
15
  end
@@ -4,36 +4,90 @@ require 'vaws/aws/describer'
4
4
  module Vaws
5
5
  module Aws
6
6
  class EcsDescriber < Describer
7
- attr_reader :term_table
8
-
9
7
  def initialize
10
- @ecs_client = ::Aws::ECS::Client.new
11
- @term_table = ''
12
- @cluster_arns = []
13
- @cluster_info = {}
8
+ @ecs_client = ::Aws::ECS::Client.new
14
9
  end
15
10
 
16
- def set_basic_info
17
- rows = []
11
+ def terminal_table(opt_tasks:, opt_networks:, opt_services:)
12
+ single_option_validation(opt_tasks, opt_networks, opt_services)
13
+ table = tasks if opt_tasks
14
+ table = networks if opt_networks
15
+ table = services if opt_services
16
+ table = clusters if opt_tasks.nil? && opt_networks.nil? && opt_services.nil?
17
+ table
18
+ end
18
19
 
20
+ private
21
+
22
+ def clusters
23
+ rows = []
19
24
  cluster_arns.each do |cluster_arn|
20
- cluster_name = cluster_arn.gsub(/arn:aws:ecs:#{ENV['AWS_DEFAULT_REGION']}:[0-9]*:cluster\//, "")
21
- @cluster_info.store("#{cluster_name}", {})
22
- cluster_name = "#{cluster_name}"
23
- cluster_services = service_names(cluster_arn)
25
+ cluster_name = cluster_arn.gsub(/arn:aws:ecs:#{ENV['AWS_DEFAULT_REGION']}:[0-9]*:cluster\//, "")
26
+ cluster_services = service_arns(cluster_arn).join("\n").gsub(/.*:[0-9]*:service\//, "")
24
27
 
25
28
  ecs_cluster = @ecs_client.describe_clusters({ clusters: ["#{cluster_arn}"] }).clusters
26
29
  running_tasks_count = ecs_cluster[0].running_tasks_count
27
30
  pending_tasks_count = ecs_cluster[0].pending_tasks_count
28
31
  active_services_count = ecs_cluster[0].active_services_count
29
32
 
30
- rows << [cluster_name, cluster_services, active_services_count, running_tasks_count, pending_tasks_count]
33
+ rows << [cluster_name, active_services_count, running_tasks_count, pending_tasks_count, cluster_services]
31
34
  end
32
35
 
33
- @term_table = Terminal::Table.new :headings => ['ClusterName', 'Services', 'ActService', 'RunTask', 'PenTask'], :rows => rows.sort
36
+ Terminal::Table.new :headings => ['ClusterName', 'ActService', 'RunTask', 'PenTask', 'Services'], :rows => rows.sort
34
37
  end
35
38
 
36
- private
39
+ def tasks
40
+ rows = []
41
+ lb_target_group = nil
42
+ task, d_count, p_count, r_count, updated_at, sg, c_provider = nil
43
+ cluster_arn = selected_cluster_arn
44
+ cluster_name = cluster_arn.gsub(/.*:cluster\//, '')
45
+ service_names = service_names(cluster_arn)
46
+
47
+ service_names.each_slice(1).to_a.each do |s|
48
+ describe_services(cluster: cluster_name, service_names: s).services.each do |ds|
49
+ ds.load_balancers.each do |lb|
50
+ lb_target_group = lb.target_group_arn.gsub(/.*:targetgroup\//, '')
51
+ end
52
+
53
+ ds.deployments.each do |d|
54
+ task = d.task_definition.gsub(/.*:task-definition\//, '')
55
+ d_count = d.desired_count
56
+ p_count = d.pending_count
57
+ r_count = d.running_count
58
+ updated_at = d.updated_at
59
+ sg = d.network_configuration.awsvpc_configuration.security_groups.join(',') if d.network_configuration
60
+ if d.capacity_provider_strategy
61
+ d.capacity_provider_strategy.each do |c|
62
+ c_provider = c.capacity_provider
63
+ end
64
+ else
65
+ c_provider = "EC2"
66
+ end
67
+ end
68
+
69
+ rows << [task, d_count, r_count, p_count, lb_target_group, sg, updated_at, c_provider]
70
+ task, d_count, r_count, p_count, lb_target_group, sg, updated_at, c_provider = nil
71
+ end
72
+ end
73
+
74
+ Terminal::Table.new :headings => ['TaskDefinition', 'Desired', 'Running', 'Pending', 'LbTargetGroup', 'SecurityGroup', 'UpdatedAt', 'CapacityProvider'], :rows => rows.sort
75
+ end
76
+
77
+ def networks
78
+ # TODO
79
+ end
80
+
81
+ def services
82
+ # TODO
83
+ end
84
+
85
+ def describe_services(cluster:, service_names:)
86
+ @ecs_client.describe_services({
87
+ cluster: cluster,
88
+ services: service_names,
89
+ })
90
+ end
37
91
 
38
92
  def cluster_arns
39
93
  param_args = {
@@ -42,17 +96,36 @@ module Vaws
42
96
  @ecs_client.list_clusters(param_args)[:cluster_arns]
43
97
  end
44
98
 
99
+ def selected_cluster_arn
100
+ puts "# CLUSTER LIST"
101
+ arns = cluster_arns
102
+ arns.each_with_index do |arn, cnt|
103
+ puts "#{cnt}: #{arn}"
104
+ end
105
+ print "cluster numbner:"
106
+ input = STDIN.gets
107
+ begin
108
+ raise unless /[0-9].*/ =~ input
109
+ input_cluster_number = input.to_i
110
+ arns[input_cluster_number]
111
+ rescue
112
+ puts "Not found cluster"
113
+ exit
114
+ end
115
+ end
116
+
45
117
  def service_arns(cluster_arn)
46
- param_args = {
47
- cluster: cluster_arn,
48
- max_results: 1
49
- }
50
- @ecs_client.list_services(param_args)[:service_arns]
118
+ service_ary = []
119
+ service_ary << @ecs_client.list_services({ cluster: "#{cluster_arn}", max_results: 100 })[:service_arns].sort
51
120
  end
52
121
 
53
122
  def service_names(cluster_arn)
54
- service_ary = @ecs_client.list_services({ cluster: "#{cluster_arn}", max_results: 100 })[:service_arns].sort
55
- service_ary.join("\n").gsub(/arn:aws:ecs:#{ENV['AWS_DEFAULT_REGION']}:[0-9]*:service\//, "")
123
+ service_ary = []
124
+ names = []
125
+ service_ary << @ecs_client.list_services({ cluster: "#{cluster_arn}", max_results: 100 })[:service_arns].sort.each do |arn|
126
+ names << arn.gsub(/.*:[0-9]*:service\//, "")
127
+ end
128
+ names
56
129
  end
57
130
  end
58
131
  end
@@ -46,11 +46,13 @@ module Vaws
46
46
  end
47
47
 
48
48
  desc 'ecs', 'View ECS'
49
+ option :tasks, aliases: 't', :type => :boolean
50
+ option :networks, aliases: 'n', :type => :boolean
51
+ option :services, aliases: 's', :type => :boolean
49
52
 
50
53
  def ecs
51
- ecs_desc = Vaws::Aws::EcsDescriber.new
52
- ecs_desc.set_basic_info
53
- puts ecs_desc.term_table
54
+ describer = Vaws::Aws::EcsDescriber.new
55
+ puts describer.terminal_table(opt_tasks: options["tasks"], opt_networks: options["networks"], opt_services: options["services"])
54
56
  end
55
57
 
56
58
  desc 'route53', 'View Route53'
@@ -1,3 +1,3 @@
1
1
  module Vaws
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vaws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shota Ito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-10 00:00:00.000000000 Z
11
+ date: 2020-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler