aws-ec2-list 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/aws-ec2-list.gemspec +31 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/aws-ec2-list +6 -0
- data/lib/aws_ec2_list.rb +12 -0
- data/lib/aws_ec2_list/instance.rb +29 -0
- data/lib/aws_ec2_list/runner.rb +78 -0
- data/lib/aws_ec2_list/version.rb +3 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 630994a36ff29213ba5c8b3f6bf69e2352812141
|
4
|
+
data.tar.gz: 0f524ec0191d1c62597e490fff85418831e9fdb9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 984ffe07f156a1e036a92e6982bb66b65adee3afad2ad26bd01f0d6baf21db186bc7c1e892efb8005b04598e87dc9105cc741f176750225dd8f734f254855e78
|
7
|
+
data.tar.gz: f333ea7d86565c2f2606341fd3f9147f4806a1c4f65d5752fd344b39a255dce158e378c5f47adff77e9e3d767ed585636a510396533ec26fb6a7ce1b09644f7a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 pauloancheta
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Aws::Ec2::List
|
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
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'aws-ec2-list'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install aws-ec2-list
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aws-ec2-list.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'aws_ec2_list/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "aws-ec2-list"
|
8
|
+
spec.version = AwsEc2List::VERSION
|
9
|
+
spec.authors = ["pauloancheta"]
|
10
|
+
spec.email = ["paulo.ancheta@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{list all your ec2 instances}
|
13
|
+
spec.description = %q{list all ec2 instances}
|
14
|
+
spec.homepage = "https://github.com/pauloancheta/aws-ec2-list"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "aws-sdk", "~> 2"
|
25
|
+
spec.add_dependency "virtus", "~> 1.0"
|
26
|
+
spec.add_dependency "tabularize", '~> 0.2.9'
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "aws_ec2_list"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/aws-ec2-list
ADDED
data/lib/aws_ec2_list.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class AwsEc2List::Instance
|
2
|
+
|
3
|
+
include Virtus.model
|
4
|
+
|
5
|
+
attribute :instance_id, String
|
6
|
+
attribute :state, String
|
7
|
+
attribute :private_dns_name, String
|
8
|
+
attribute :public_dns_name, String
|
9
|
+
attribute :instance_type, String
|
10
|
+
attribute :launch_time, String
|
11
|
+
attribute :tags, Array
|
12
|
+
|
13
|
+
|
14
|
+
def name
|
15
|
+
tags.find{ |t| t.key == "Name" }.value rescue nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def stack_name
|
19
|
+
tags.find{ |t| t.key == "aws:cloudformation:stack-name" }.value rescue nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def project
|
23
|
+
tags.find{ |t| t.key == "project" }.value rescue nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def app_version
|
27
|
+
tags.find{ |t| t.key == "app_version" }.value rescue nil
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative 'instance'
|
2
|
+
|
3
|
+
class AwsEc2List::Runner
|
4
|
+
attr_reader :ec2, :credentials_path, :stdout, :env
|
5
|
+
|
6
|
+
def initialize(ec2: Aws::EC2::Client.new,
|
7
|
+
credentials_path: "#{Dir.home}/.aws/credentials",
|
8
|
+
stdout: $stdout,
|
9
|
+
env: ENV)
|
10
|
+
@ec2 = ec2
|
11
|
+
@credentials_path = credentials_path
|
12
|
+
@stdout = stdout
|
13
|
+
@env = env
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
data_header = ["PROJECT", "STACK NAME", "PUBLIC DNS NAME", "LAUNCH TIME", "APP VERSION", "STATE"]
|
18
|
+
data = instances.map do |d|
|
19
|
+
[d.project, d.stack_name, d.public_dns_name, d.launch_time, d.app_version, d.state]
|
20
|
+
end
|
21
|
+
data = data.insert(0, data_header)
|
22
|
+
puts Tabularize.it(data, :align => :left).map { |row| row.join ' | ' }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def instances
|
28
|
+
|
29
|
+
# Aws::EC2::Types::Instance
|
30
|
+
# instance_id="i-0e5846a2b3988300d",
|
31
|
+
# state=#<struct Aws::EC2::Types::InstanceState code=16, name="running">,
|
32
|
+
# private_dns_name="ip-172-16-92-73.ec2.internal",
|
33
|
+
# public_dns_name="ec2-54-157-47-22.compute-1.amazonaws.com",
|
34
|
+
# instance_type="m4.xlarge",
|
35
|
+
# launch_time=2017-01-12 19:46:29 UTC,
|
36
|
+
# subnet_id="subnet-844ef9df",
|
37
|
+
# vpc_id="vpc-2d583b48",
|
38
|
+
# private_ip_address="172.16.92.73",
|
39
|
+
# public_ip_address="54.157.47.22",
|
40
|
+
# architecture="x86_64",
|
41
|
+
# client_token="40459b52-177d-4e54-a3ed-e07e9d434ecc_subnet-844ef9df_5",
|
42
|
+
# tags=[
|
43
|
+
# #<struct Aws::EC2::Types::Tag key="Name", value="lp-webapp-product-0e5846a2b3988300d">,
|
44
|
+
# #<struct Aws::EC2::Types::Tag key="aws:cloudformation:logical-id", value="WebASG">,
|
45
|
+
# #<struct Aws::EC2::Types::Tag key="owner", value="a-team">,
|
46
|
+
# #<struct Aws::EC2::Types::Tag key="environment", value="production">,
|
47
|
+
# #<struct Aws::EC2::Types::Tag key="aws:autoscaling:groupName", value="lp-webapp-production-31-WebASG-RYQPV710NC8B">,
|
48
|
+
# #<struct Aws::EC2::Types::Tag key="aws:cloudformation:stack-name", value="lp-webapp-production-31">,
|
49
|
+
# #<struct Aws::EC2::Types::Tag key="app_version", value="9da8527">,
|
50
|
+
# #<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">,
|
51
|
+
# #<struct Aws::EC2::Types::Tag key="datadog", value="true">,
|
52
|
+
# #<struct Aws::EC2::Types::Tag key="project", value="lp-webapp">
|
53
|
+
# ],
|
54
|
+
# security_groups=[
|
55
|
+
# #<struct Aws::EC2::Types::GroupIdentifier group_name="vpc-us-east-classic-link-ClassicLinkSecurityGroup-1H5UKPIA5IANJ", group_id="sg-87c20ce3">,
|
56
|
+
# #<struct Aws::EC2::Types::GroupIdentifier group_name="shared-security-groups-mainvpc-SshSecurityGroup-15DV69GVO6M5F", group_id="sg-c5ba0db8">
|
57
|
+
# ]
|
58
|
+
reservations.map(&:instances).flatten.map do |instance|
|
59
|
+
AwsEc2List::Instance.new(
|
60
|
+
instance_id: instance.instance_id,
|
61
|
+
state: instance.state.name,
|
62
|
+
private_dns_name: instance.private_dns_name,
|
63
|
+
public_dns_name: instance.public_dns_name,
|
64
|
+
instance_type: instance.instance_type,
|
65
|
+
launch_time: instance.launch_time,
|
66
|
+
tags: instance.tags
|
67
|
+
)
|
68
|
+
end.sort{ |x, y| y.launch_time <=> x.launch_time }
|
69
|
+
end
|
70
|
+
|
71
|
+
def reservations
|
72
|
+
describe_instances.reservations
|
73
|
+
end
|
74
|
+
|
75
|
+
def describe_instances
|
76
|
+
ec2.describe_instances
|
77
|
+
end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws-ec2-list
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pauloancheta
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: virtus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tabularize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.9
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.9
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: list all ec2 instances
|
98
|
+
email:
|
99
|
+
- paulo.ancheta@gmail.com
|
100
|
+
executables:
|
101
|
+
- aws-ec2-list
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- aws-ec2-list.gemspec
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- exe/aws-ec2-list
|
116
|
+
- lib/aws_ec2_list.rb
|
117
|
+
- lib/aws_ec2_list/instance.rb
|
118
|
+
- lib/aws_ec2_list/runner.rb
|
119
|
+
- lib/aws_ec2_list/version.rb
|
120
|
+
homepage: https://github.com/pauloancheta/aws-ec2-list
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.4.5.1
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: list all your ec2 instances
|
144
|
+
test_files: []
|