aws-ec2-list 0.1.1 → 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
  SHA1:
3
- metadata.gz: 288213b6d0677699be342357a0505356c85a34e3
4
- data.tar.gz: fe59d92cdb81cc58ea5af7fd6799b018b7bf0d24
3
+ metadata.gz: 1de08a9a8b1f4c504df3445f2ea454ce959f5bc7
4
+ data.tar.gz: 11ba2503a070f5be5240932378adb594c9265595
5
5
  SHA512:
6
- metadata.gz: f62b85e549bb732d470343c3831e03252eae6252b911a26ead3e2514b8ec9c4b44e3f00920d0d602bf696a35a9ded16b30f9b6d693016e9ffc70d202f871671e
7
- data.tar.gz: 30e39213e3f654a80cc96b86ad6bdabf561eb51a2f56bc674df874afd76f1e5ba7e5b7c3bfc95f0a1a53240f5a4d3b6c31d9ddc542b365b215d791fb29f30212
6
+ metadata.gz: 01deb763c76ed17201811386ea2805b8f85d6a9c64f6f5ee2903ef90b546d43f5133170a8faae00d20a76ec72608061a91e3b7761588c3628cf568c665080f71
7
+ data.tar.gz: 2f584fb1235d150df3d2f5380d2a41bc6cfd7f34ecaa9a6c5a05b216016f5e284cf7f9f312bca60ce4e558ce54364672c7757b35beedbf178e6fcf46fb0e772a
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Aws::Ec2::List
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aws/ec2/list`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Get the information from your ec2 instances
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,13 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ AwsEc2List defaults to us-east-1
24
+
25
+ ```bash
26
+ $> aws-ec2-list
27
+
28
+ $> aws-ec2-list --region=us-west-1
29
+ ```
26
30
 
27
31
  ## Development
28
32
 
data/exe/aws-ec2-list CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "aws_ec2_list"
4
4
 
5
- AwsEc2List.call
5
+ AwsEc2List.call(ARGV)
data/lib/aws_ec2_list.rb CHANGED
@@ -5,8 +5,44 @@ require 'tabularize'
5
5
 
6
6
  module AwsEc2List
7
7
  def self.call(*args)
8
- Runner.new(*args).call
8
+ defaults = parse_args(args)
9
+ if defaults
10
+ DescribeInstances.new(defaults).call
11
+ else
12
+ DescribeInstances.new.call
13
+ end
14
+ end
15
+
16
+ private
17
+ def self.parse_args(args)
18
+ return nil if args.empty?
19
+ return args.first if args.first.is_a?(Hash)
20
+ option_string, default_args = args
21
+
22
+ option_string = option_string.first
23
+
24
+ if option_string && default_args
25
+ option_hash = option_string_to_hash(option_string)
26
+ option_hash.merge(default_args)
27
+
28
+ elsif option_string
29
+ option_string_to_hash(option_string)
30
+
31
+ end
32
+ end
33
+
34
+ def self.option_string_to_hash(option_string)
35
+ option_array = option_string.split("--").reject { |o| o.empty? }
36
+ option_array = option_array.map{ |opt| opt.split("=") }.flatten
37
+
38
+ option_hash = Hash[*option_array]
39
+
40
+ option_hash.keys.each do |key|
41
+ option_hash[key.to_sym] = option_hash.delete(key)
42
+ end
43
+
44
+ option_hash
9
45
  end
10
46
  end
11
47
 
12
- require_relative "aws_ec2_list/runner"
48
+ require_relative "aws_ec2_list/describe_instances"
@@ -0,0 +1,43 @@
1
+ require_relative 'instance'
2
+
3
+ class AwsEc2List::DescribeInstances
4
+ attr_reader :ec2, :stdout
5
+
6
+ def initialize(ec2: Aws::EC2::Client, region: 'us-east-1', stdout: $stdout)
7
+ @ec2 = ec2.new(region: region)
8
+ @stdout = stdout
9
+ end
10
+
11
+ def call
12
+ data_header = ["PROJECT", "STACK NAME", "PUBLIC DNS NAME", "LAUNCH TIME", "APP VERSION", "STATE"]
13
+ data = instances.map do |d|
14
+ [d.project, d.stack_name, d.public_dns_name, d.launch_time, d.app_version, d.state]
15
+ end
16
+ data = data.insert(0, data_header)
17
+ stdout.puts Tabularize.it(data, :align => :left).map { |row| row.join ' | ' }
18
+ end
19
+
20
+ private
21
+
22
+ def instances
23
+ reservations.map(&:instances).flatten.map do |instance|
24
+ AwsEc2List::Instance.new(
25
+ instance_id: instance.instance_id,
26
+ state: instance.state.name,
27
+ private_dns_name: instance.private_dns_name,
28
+ public_dns_name: instance.public_dns_name,
29
+ instance_type: instance.instance_type,
30
+ launch_time: instance.launch_time,
31
+ tags: instance.tags
32
+ )
33
+ end.sort{ |x, y| y.launch_time <=> x.launch_time }
34
+ end
35
+
36
+ def reservations
37
+ describe_instances.reservations
38
+ end
39
+
40
+ def describe_instances
41
+ ec2.describe_instances
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module AwsEc2List
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-ec2-list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pauloancheta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -114,8 +114,8 @@ files:
114
114
  - bin/setup
115
115
  - exe/aws-ec2-list
116
116
  - lib/aws_ec2_list.rb
117
+ - lib/aws_ec2_list/describe_instances.rb
117
118
  - lib/aws_ec2_list/instance.rb
118
- - lib/aws_ec2_list/runner.rb
119
119
  - lib/aws_ec2_list/version.rb
120
120
  homepage: https://github.com/pauloancheta/aws-ec2-list
121
121
  licenses:
@@ -1,73 +0,0 @@
1
- require_relative 'instance'
2
-
3
- class AwsEc2List::Runner
4
- attr_reader :ec2, :stdout
5
-
6
- def initialize(ec2: Aws::EC2::Client, region: 'us-east-1', stdout: $stdout)
7
- @ec2 = ec2.new(region: region)
8
- @stdout = stdout
9
- end
10
-
11
- def call
12
- data_header = ["PROJECT", "STACK NAME", "PUBLIC DNS NAME", "LAUNCH TIME", "APP VERSION", "STATE"]
13
- data = instances.map do |d|
14
- [d.project, d.stack_name, d.public_dns_name, d.launch_time, d.app_version, d.state]
15
- end
16
- data = data.insert(0, data_header)
17
- stdout.puts Tabularize.it(data, :align => :left).map { |row| row.join ' | ' }
18
- end
19
-
20
- private
21
-
22
- def instances
23
-
24
- # Aws::EC2::Types::Instance
25
- # instance_id="i-0e5846a2b3988300d",
26
- # state=#<struct Aws::EC2::Types::InstanceState code=16, name="running">,
27
- # private_dns_name="ip-172-16-92-73.ec2.internal",
28
- # public_dns_name="ec2-54-157-47-22.compute-1.amazonaws.com",
29
- # instance_type="m4.xlarge",
30
- # launch_time=2017-01-12 19:46:29 UTC,
31
- # subnet_id="subnet-844ef9df",
32
- # vpc_id="vpc-2d583b48",
33
- # private_ip_address="172.16.92.73",
34
- # public_ip_address="54.157.47.22",
35
- # architecture="x86_64",
36
- # client_token="40459b52-177d-4e54-a3ed-e07e9d434ecc_subnet-844ef9df_5",
37
- # tags=[
38
- # #<struct Aws::EC2::Types::Tag key="Name", value="lp-webapp-product-0e5846a2b3988300d">,
39
- # #<struct Aws::EC2::Types::Tag key="aws:cloudformation:logical-id", value="WebASG">,
40
- # #<struct Aws::EC2::Types::Tag key="owner", value="a-team">,
41
- # #<struct Aws::EC2::Types::Tag key="environment", value="production">,
42
- # #<struct Aws::EC2::Types::Tag key="aws:autoscaling:groupName", value="lp-webapp-production-31-WebASG-RYQPV710NC8B">,
43
- # #<struct Aws::EC2::Types::Tag key="aws:cloudformation:stack-name", value="lp-webapp-production-31">,
44
- # #<struct Aws::EC2::Types::Tag key="app_version", value="9da8527">,
45
- # #<struct Aws::EC2::Types::Tag key="aws:cloudformation:stack-id", value="arn:aws:cloudformation:us-east-1:002682819933:stack/lp-webapp-production-31/09547990-d8ff-11e6-aedf-50fae9882035">,
46
- # #<struct Aws::EC2::Types::Tag key="datadog", value="true">,
47
- # #<struct Aws::EC2::Types::Tag key="project", value="lp-webapp">
48
- # ],
49
- # security_groups=[
50
- # #<struct Aws::EC2::Types::GroupIdentifier group_name="vpc-us-east-classic-link-ClassicLinkSecurityGroup-1H5UKPIA5IANJ", group_id="sg-87c20ce3">,
51
- # #<struct Aws::EC2::Types::GroupIdentifier group_name="shared-security-groups-mainvpc-SshSecurityGroup-15DV69GVO6M5F", group_id="sg-c5ba0db8">
52
- # ]
53
- reservations.map(&:instances).flatten.map do |instance|
54
- AwsEc2List::Instance.new(
55
- instance_id: instance.instance_id,
56
- state: instance.state.name,
57
- private_dns_name: instance.private_dns_name,
58
- public_dns_name: instance.public_dns_name,
59
- instance_type: instance.instance_type,
60
- launch_time: instance.launch_time,
61
- tags: instance.tags
62
- )
63
- end.sort{ |x, y| y.launch_time <=> x.launch_time }
64
- end
65
-
66
- def reservations
67
- describe_instances.reservations
68
- end
69
-
70
- def describe_instances
71
- ec2.describe_instances
72
- end
73
- end