vaws 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: 78ff8fcecab4808f0c06e867988b7cd12ff5d8a06a8fcc7f28a1bb7a55d1a4cf
4
- data.tar.gz: 41a06df0e45c882addefcaff157e06bbbc16bdfe5c8a1d4d3717e4776e547b0d
3
+ metadata.gz: 9f8eb77fa88e21844c910909a863e1a5033a644a91bdc62d9952bc4b67715fbf
4
+ data.tar.gz: ee1f2d299e2674417f1c2980b2196dfa8af51ecce84b6af5add02fedffeb27b5
5
5
  SHA512:
6
- metadata.gz: 4c805803c4d0dcf080ee355d9ab12adcfdd86eac63e8df3913299f4ee744cdd988aba8be4ccf81c0dd129dc8613a43e4d3fbdc43bff76c9922732ecc1930f3a2
7
- data.tar.gz: 5688032c6d6ac00a3da63c2eae324cf4c126ff62429ee019db421dc70987f7214c5105b84ab4376d66f87c25dc885b197c1558f0979a147f133f2c24e6304a92
6
+ metadata.gz: d0f9cba8ae0517eba72c33c0da06f9bab7c4a6a9b4afd200cc2bbe3dfffed18925d449f98e0d32ad7923a199be53560c04f5201804b35b92b764bbe8b2c2aea8
7
+ data.tar.gz: b5040b1374c7212fedd5f12e0a56c6698ca4f32f09d3ce120c518829c6d5d7c48401ce6c6fc40bef077b5f7126c539db0e35d3bb5a0448a9e1e51490d70132b3
data/Gemfile.lock CHANGED
@@ -1,8 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vaws (0.1.0)
4
+ vaws (0.2.0)
5
5
  aws-sdk-ec2
6
+ aws-sdk-ecs
7
+ aws-sdk-elasticloadbalancingv2
6
8
  terminal-table (~> 1.8.0)
7
9
  thor (~> 0.20.3)
8
10
 
@@ -19,6 +21,12 @@ GEM
19
21
  aws-sdk-ec2 (1.88.0)
20
22
  aws-sdk-core (~> 3, >= 3.53.0)
21
23
  aws-sigv4 (~> 1.1)
24
+ aws-sdk-ecs (1.40.0)
25
+ aws-sdk-core (~> 3, >= 3.53.0)
26
+ aws-sigv4 (~> 1.1)
27
+ aws-sdk-elasticloadbalancingv2 (1.29.0)
28
+ aws-sdk-core (~> 3, >= 3.53.0)
29
+ aws-sigv4 (~> 1.1)
22
30
  aws-sigv4 (1.1.0)
23
31
  aws-eventstream (~> 1.0, >= 1.0.2)
24
32
  diff-lcs (1.3)
data/README.md CHANGED
@@ -12,9 +12,11 @@ $ gem install vaws
12
12
 
13
13
  ```bash
14
14
  $ vaws help
15
- Commands:
16
- vaws ec2 # View ec2 instances
17
- vaws help [COMMAND] # Describe available commands or one specific command
15
+ Commands:
16
+ vaws alb # View Application Loadbalarancers
17
+ vaws ec2 # View EC2 instances
18
+ vaws help [COMMAND] # Describe available commands or one specific command
19
+ vaws subnet # View Subnet
18
20
  ```
19
21
 
20
22
  ### View EC2 Instances
@@ -30,6 +32,42 @@ $ vaws ec2
30
32
  $
31
33
  ```
32
34
 
35
+ ### View ALB
36
+
37
+ ```bash
38
+ $ vaws alb
39
+ +---------------------------------+-------------+-----------------+-----------------------+--------------------------------------------------+-----------------------------------------------------------------------------------+
40
+ | Name | Type | Scheme | Vpc | Short_Arn | Dns |
41
+ +---------------------------------+-------------+-----------------+-----------------------+--------------------------------------------------+-----------------------------------------------------------------------------------+
42
+ | hogehoge-nlb-internal | network | internal | vpc-xxxxxxxx | hogehoge-nlb-internal/xxxxxxxxxxxxxxx | hogehoge-nlb-internal-xxxxxxxxxxxxxxxx.elb.ap-northeast-1.amazonaws.com |
43
+ | fugafuga-alb-internal | application | internet-facing | vpc-xxxxxxxx | fugafuga-alb-internal/xxxxxxxxxxxxxxx | fugafuga-alb-internal-xxxxxxxxxxxxxxxx.ap-northeast-1.elb.amazonaws.com |
44
+ +---------------------------------+-------------+-----------------+-----------------------+--------------------------------------------------+-----------------------------------------------------------------------------------+
45
+ $
46
+ ```
47
+
48
+ ### View Subnet
49
+
50
+ ```bash
51
+ $ vaws subnet
52
+ +------------------+--------------------------+-----------------+-----------------------+
53
+ | Cidr | SubnetId | Az | VpcId |
54
+ +------------------+--------------------------+-----------------+-----------------------+
55
+ | 172.16.10.0/24 | subnet-xxxxxxxx | ap-northeast-1a | vpc-xxxxxxxx |
56
+ +------------------+--------------------------+-----------------+-----------------------+
57
+ $
58
+ ```
59
+
60
+ ### View VPC
61
+
62
+ ```bash
63
+ $ vaws vpc
64
+ +-----------------------+------------------+-------------------------+
65
+ | VpcId | Cidr | Tags |
66
+ +-----------------------+------------------+-------------------------+
67
+ | vpc-xxxxxxxx | 172.16.0.0/16 | default-vpc |
68
+ +-----------------------+------------------+-------------------------+
69
+ ```
70
+
33
71
  ## License
34
72
 
35
73
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,33 @@
1
+ require 'aws-sdk-elasticloadbalancingv2'
2
+ require 'vaws/aws/describer'
3
+
4
+ module Vaws
5
+ module Aws
6
+ class AlbDescriber < Describer
7
+ attr_reader :term_table
8
+
9
+ def initialize
10
+ @alb_client = ::Aws::ElasticLoadBalancingV2::Client.new
11
+ @term_table = ''
12
+ end
13
+
14
+ def set_basic_info
15
+ rows = []
16
+ albs = @alb_client.describe_load_balancers
17
+
18
+ # https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/ElasticLoadBalancingV2/Client.html#describe_load_balancers-instance_method
19
+ albs.load_balancers.each do |alb|
20
+ arn = alb.load_balancer_arn.sub!(/arn:aws:elasticloadbalancing:ap-northeast-1:163714994724:loadbalancer\/...\//, '')
21
+ dns = alb.dns_name
22
+ name = alb.load_balancer_name
23
+ scheme = alb.scheme
24
+ vpc = alb.vpc_id
25
+ type = alb.type
26
+
27
+ rows << [name, type, scheme, vpc, arn, dns]
28
+ end
29
+ @term_table = Terminal::Table.new :headings => ['Name', 'Type', 'Scheme', 'Vpc', 'Short_Arn', 'Dns'], :rows => rows
30
+ end
31
+ end
32
+ end
33
+ end
@@ -8,6 +8,7 @@ module Vaws
8
8
 
9
9
  def initialize
10
10
  @ec2_client = ::Aws::EC2::Client.new
11
+ @tag = 'No Name'
11
12
  @term_table = ''
12
13
  end
13
14
 
@@ -16,13 +17,15 @@ module Vaws
16
17
  ec2_reservations = @ec2_client.describe_instances.reservations
17
18
  ec2_reservations.each do |ec2_rsvn|
18
19
  ec2_rsvn.instances.each do |ec2_instance|
19
- tag = ec2_instance.tags[0].value
20
+ ec2_instance.tags.each do |tag|
21
+ @tag = tag.value if tag.key == 'Name'
22
+ end
20
23
  instance_id = ec2_instance.instance_id
21
24
  instance_type = ec2_instance.instance_type
22
25
  public_ip = ec2_instance.public_ip_address
23
26
  private_ip = ec2_instance.private_ip_address
24
27
  state_name = ec2_instance.state.name
25
- rows << [tag, instance_id, instance_type, public_ip, private_ip, state_name]
28
+ rows << [@tag, instance_id, instance_type, public_ip, private_ip, state_name]
26
29
  end
27
30
  end
28
31
  @term_table = Terminal::Table.new :headings => ['Name', 'Id', 'Type', 'GlobalIp', 'PrivateIp', 'Status'], :rows => rows
@@ -0,0 +1,53 @@
1
+ require 'aws-sdk-ecs'
2
+ require 'vaws/aws/describer'
3
+
4
+ module Vaws
5
+ module Aws
6
+ class EcsDescriber < Describer
7
+ attr_reader :term_table
8
+
9
+ def initialize
10
+ @ecs_client = ::Aws::ECS::Client.new
11
+ @term_table = ''
12
+ @cluster_arns = []
13
+ @cluster_info = {}
14
+ end
15
+
16
+ def set_basic_info
17
+ get_cluster_arns
18
+
19
+ rows = []
20
+ @cluster_arns.each do |cluster_arn|
21
+ cluster_name = cluster_arn.gsub(/arn:aws:ecs:#{ENV['AWS_DEFAULT_REGION']}:[0-9]*:cluster\//, "")
22
+ @cluster_info.store("#{cluster_name}", {})
23
+ cluster_name = "#{cluster_name}"
24
+ cluster_services = get_service_names(cluster_arn)
25
+
26
+ ecs_cluster = @ecs_client.describe_clusters({ clusters: ["#{cluster_arn}"] }).clusters
27
+ running_tasks_count = ecs_cluster[0].running_tasks_count
28
+ pending_tasks_count = ecs_cluster[0].pending_tasks_count
29
+ active_services_count = ecs_cluster[0].active_services_count
30
+
31
+ rows << [cluster_name, cluster_services, active_services_count, running_tasks_count, pending_tasks_count]
32
+ end
33
+
34
+ @term_table = Terminal::Table.new :headings => ['ClusterName', 'Services', 'ActService', 'RunTask', 'PenTask'], :rows => rows
35
+ end
36
+
37
+ private
38
+
39
+ def get_cluster_arns
40
+ @cluster_arns = @ecs_client.list_clusters[:cluster_arns]
41
+ end
42
+
43
+ def get_service_arns(cluster_arn)
44
+ return @ecs_client.list_services({ cluster: "#{cluster_arn}" })[:service_arns]
45
+ end
46
+
47
+ def get_service_names(cluster_arn)
48
+ service_ary = @ecs_client.list_services({ cluster: "#{cluster_arn}", max_results: 100 })[:service_arns]
49
+ return service_ary.join(",").gsub(/arn:aws:ecs:#{ENV['AWS_DEFAULT_REGION']}:[0-9]*:service\//, "")
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,29 @@
1
+ require 'aws-sdk-ec2'
2
+ require 'vaws/aws/describer'
3
+
4
+ module Vaws
5
+ module Aws
6
+ class SubnetDescriber < Describer
7
+ attr_reader :term_table
8
+
9
+ def initialize
10
+ @subnet_client = ::Aws::EC2::Client.new
11
+ @term_table = ''
12
+ end
13
+
14
+ def set_basic_info
15
+ rows = []
16
+ subnets = @subnet_client.describe_subnets
17
+ subnets.subnets.each do |subnet|
18
+ az = subnet.availability_zone
19
+ cidr = subnet.cidr_block
20
+ subnet_id = subnet.subnet_id
21
+ vpc_id = subnet.vpc_id
22
+
23
+ rows << [cidr, subnet_id, az, vpc_id]
24
+ end
25
+ @term_table = Terminal::Table.new :headings => ['Cidr', 'SubnetId', 'Az', 'VpcId'], :rows => rows
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ require 'aws-sdk-ec2'
2
+ require 'vaws/aws/describer'
3
+
4
+ module Vaws
5
+ module Aws
6
+ class VpcDescriber < Describer
7
+ attr_reader :term_table
8
+
9
+ def initialize
10
+ @vpc_client = ::Aws::EC2::Client.new
11
+ @term_table = ''
12
+ end
13
+
14
+ def set_basic_info
15
+ rows = []
16
+ vpcs = @vpc_client.describe_vpcs
17
+
18
+ vpcs.vpcs.each do |vpc|
19
+ cidr = vpc.cidr_block
20
+ vpc_id = vpc.vpc_id
21
+
22
+ tags = ''
23
+ vpc.tags.each_with_index do |tag, index|
24
+ tags << "#{tag.value}, "
25
+ tags = tags.gsub(/, $/, '') if index == vpc.tags.size - 1
26
+ end
27
+
28
+ rows << [vpc_id, cidr, tags]
29
+ end
30
+ @term_table = Terminal::Table.new :headings => ['VpcId', 'Cidr', 'Tags'], :rows => rows
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,17 +1,54 @@
1
1
  require 'thor'
2
2
  require 'terminal-table'
3
3
  require 'vaws/aws/ec2_describer'
4
+ require 'vaws/aws/alb_describer'
5
+ require 'vaws/aws/subnet_describer'
6
+ require 'vaws/aws/vpc_describer'
7
+ require 'vaws/aws/ecs_describer'
4
8
 
5
9
  module Vaws
6
10
  module Handlers
7
11
  class Describer < Thor
8
- desc 'ec2', 'View ec2 instances'
12
+ desc 'ec2', 'View EC2 instances'
9
13
 
10
14
  def ec2
11
15
  ec2_desc = Vaws::Aws::Ec2Describer.new
12
16
  ec2_desc.set_basic_info
13
17
  puts ec2_desc.term_table
14
18
  end
19
+
20
+ desc 'alb', 'View Application Loadbalarancers'
21
+
22
+ def alb
23
+ alb_desc = Vaws::Aws::AlbDescriber.new
24
+ alb_desc.set_basic_info
25
+ puts alb_desc.term_table
26
+ end
27
+
28
+ desc 'subnet', 'View Subnet'
29
+
30
+ def subnet
31
+ subnet_desc = Vaws::Aws::SubnetDescriber.new
32
+ subnet_desc.set_basic_info
33
+ puts subnet_desc.term_table
34
+ end
35
+
36
+ desc 'vpc', 'View Vpc'
37
+
38
+ def vpc
39
+ vpc_desc = Vaws::Aws::VpcDescriber.new
40
+ vpc_desc.set_basic_info
41
+ puts vpc_desc.term_table
42
+ end
43
+
44
+ desc 'ecs', 'View ECS'
45
+
46
+ def ecs
47
+ ecs_desc = Vaws::Aws::EcsDescriber.new
48
+ ecs_desc.set_basic_info
49
+ puts ecs_desc.term_table
50
+ end
51
+
15
52
  end
16
53
  end
17
54
  end
data/lib/vaws/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vaws
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/vaws.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/st1t/vaws"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
17
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
18
  end
19
19
  spec.files += Dir.glob("bin/**/*")
@@ -30,5 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
31
  spec.add_runtime_dependency "thor", "~> 0.20.3"
32
32
  spec.add_runtime_dependency "aws-sdk-ec2"
33
+ spec.add_runtime_dependency "aws-sdk-elasticloadbalancingv2"
34
+ spec.add_runtime_dependency "aws-sdk-ecs"
33
35
  spec.add_runtime_dependency "terminal-table", "~> 1.8.0"
34
36
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shota Ito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-31 00:00:00.000000000 Z
11
+ date: 2019-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: aws-sdk-elasticloadbalancingv2
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: aws-sdk-ecs
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: terminal-table
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -116,8 +144,12 @@ files:
116
144
  - bin/setup
117
145
  - exe/vaws
118
146
  - lib/vaws.rb
147
+ - lib/vaws/aws/alb_describer.rb
119
148
  - lib/vaws/aws/describer.rb
120
149
  - lib/vaws/aws/ec2_describer.rb
150
+ - lib/vaws/aws/ecs_describer.rb
151
+ - lib/vaws/aws/subnet_describer.rb
152
+ - lib/vaws/aws/vpc_describer.rb
121
153
  - lib/vaws/handlers/describer.rb
122
154
  - lib/vaws/version.rb
123
155
  - spec/spec_helper.rb