instance_finder 0.1.0
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 +7 -0
- data/.env.example +2 -0
- data/.gitignore +10 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/exe/instance_finder +45 -0
- data/instance_finder.gemspec +31 -0
- data/lib/instance_finder.rb +63 -0
- data/lib/instance_finder/version.rb +5 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd5d91e67f42c7c960085a25202475a656ddda67
|
4
|
+
data.tar.gz: 7dd8de44ef0d5d0d25c2e0f91544382a613d10d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5f955215f3b9f92d58e3a8c07ff4dc9451b71bb61e52cf242155095e5a92efe7323face2e47744d8a47241a906e2ef35b87389313a3ca5196afe7cb7ecf3d441
|
7
|
+
data.tar.gz: 5dc483f49d9506f6132c8688cda25d6a7f70bed088efc028783ff9d5ff177ffcb57ebb98a93e86b429e8e141f458927a6055d3b2fdcf1b79d3800290d6ad639e
|
data/.env.example
ADDED
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
instance-finder (0.1.0)
|
5
|
+
awesome_print (~> 1.8)
|
6
|
+
aws-sdk-ec2 (~> 1)
|
7
|
+
slop (~> 4.6)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
awesome_print (1.8.0)
|
13
|
+
aws-partitions (1.52.0)
|
14
|
+
aws-sdk-core (3.13.0)
|
15
|
+
aws-partitions (~> 1.0)
|
16
|
+
aws-sigv4 (~> 1.0)
|
17
|
+
jmespath (~> 1.0)
|
18
|
+
aws-sdk-ec2 (1.24.0)
|
19
|
+
aws-sdk-core (~> 3)
|
20
|
+
aws-sigv4 (~> 1.0)
|
21
|
+
aws-sigv4 (1.0.2)
|
22
|
+
coderay (1.1.2)
|
23
|
+
dotenv (2.2.1)
|
24
|
+
jmespath (1.3.1)
|
25
|
+
method_source (0.9.0)
|
26
|
+
pry (0.11.3)
|
27
|
+
coderay (~> 1.1.0)
|
28
|
+
method_source (~> 0.9.0)
|
29
|
+
rake (10.5.0)
|
30
|
+
slop (4.6.1)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.16)
|
37
|
+
dotenv (~> 2.2)
|
38
|
+
instance-finder!
|
39
|
+
pry (~> 0.11)
|
40
|
+
rake (~> 10.0)
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Robert Coleman
|
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,39 @@
|
|
1
|
+
# Instance::Finder
|
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/instance/finder`. 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 'instance-finder'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install instance-finder
|
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. 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]/instance-finder.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'dotenv/load'
|
5
|
+
require 'instance_finder'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
data/exe/instance_finder
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'instance_finder'
|
4
|
+
require 'slop'
|
5
|
+
require 'awesome_print'
|
6
|
+
require 'csv'
|
7
|
+
|
8
|
+
opts = Slop.parse do |o|
|
9
|
+
o.string '-t', '--tag-key', 'tag-key', required: true
|
10
|
+
o.string '-v', '--tag-value', 'tag-value', required: true
|
11
|
+
o.array '--states', 'a list of states', delimiter: ',', default: 'running'
|
12
|
+
o.string '-o', '--output-format', 'output format', default: 'csv'
|
13
|
+
o.array '--output-attributes', 'a list of attributes to output', delimiter: ',', default: 'private_ip_address'
|
14
|
+
o.separator ''
|
15
|
+
o.separator 'other options:'
|
16
|
+
o.on '--version' do
|
17
|
+
puts Instance::Finder::VERSION
|
18
|
+
end
|
19
|
+
o.on '--help' do
|
20
|
+
puts o
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
results = Instance::Finder.instances({ opts[:tag_key] => opts[:tag_value] }, opts[:states])
|
26
|
+
filtered_results = results.map do |hash|
|
27
|
+
hash.select do |key, value|
|
28
|
+
opts[:output_attributes].include? key.to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
case opts[:output_format].downcase
|
33
|
+
when 'csv'
|
34
|
+
csv_string = CSV.generate do |csv|
|
35
|
+
filtered_results.each do |hash|
|
36
|
+
csv << hash.values
|
37
|
+
end
|
38
|
+
end
|
39
|
+
puts csv_string
|
40
|
+
when 'json'
|
41
|
+
puts JSON.pretty_generate filtered_results
|
42
|
+
else
|
43
|
+
# output type not specified; PRs are welcome.
|
44
|
+
puts "Output format '#{opts[:output_format]}' doesn't exist. Valid options are CSV, JSON"
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'instance_finder/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'instance_finder'
|
7
|
+
spec.version = Instance::Finder::VERSION
|
8
|
+
spec.authors = ['Robert Coleman']
|
9
|
+
spec.email = ['github@robert.net.nz']
|
10
|
+
|
11
|
+
spec.summary = %q{Find your EC2 instances based on tags}
|
12
|
+
spec.description = %q{Find your EC2 instances based on tags - for CLI usage, Capistrano or as a library}
|
13
|
+
spec.homepage = 'https://github.com/rjocoleman/instance-finder'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'pry', '~> 0.11'
|
26
|
+
spec.add_development_dependency 'dotenv', '~> 2.2'
|
27
|
+
|
28
|
+
spec.add_dependency 'aws-sdk-ec2', '~> 1'
|
29
|
+
spec.add_dependency 'slop', '~> 4.6'
|
30
|
+
spec.add_dependency 'awesome_print', '~> 1.8'
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'instance_finder/version'
|
2
|
+
require 'aws-sdk-ec2'
|
3
|
+
|
4
|
+
module Instance
|
5
|
+
class Finder
|
6
|
+
class << self
|
7
|
+
def instances(tags, states=['running'])
|
8
|
+
finder = Instance::Finder.new
|
9
|
+
finder.instances(tags, states)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@ec2 = Aws::EC2::Client.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def instances(tags, states=['running'])
|
18
|
+
output = []
|
19
|
+
results = @ec2.describe_instances filters: make_filters(tags, states)
|
20
|
+
results.reservations.each do |reservation|
|
21
|
+
reservation.instances.each do |instance|
|
22
|
+
output << {
|
23
|
+
instance_id: instance.instance_id,
|
24
|
+
private_ip_address: instance.private_ip_address,
|
25
|
+
private_dns_name: instance.private_dns_name,
|
26
|
+
public_ip_address: instance.public_ip_address,
|
27
|
+
public_dns_name: instance.public_dns_name,
|
28
|
+
subnet_id: instance.subnet_id,
|
29
|
+
vpc_id: instance.vpc_id,
|
30
|
+
availability_zone: instance.placement.availability_zone,
|
31
|
+
tags: coerce_tags(instance.tags),
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
output
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def make_filters(tags, states)
|
41
|
+
filters = [
|
42
|
+
{
|
43
|
+
name: 'instance-state-name',
|
44
|
+
values: Array(states),
|
45
|
+
},
|
46
|
+
]
|
47
|
+
tags.each do |key, value|
|
48
|
+
filters << {
|
49
|
+
name: "tag:#{key}",
|
50
|
+
values: Array(value),
|
51
|
+
}
|
52
|
+
end
|
53
|
+
filters
|
54
|
+
end
|
55
|
+
|
56
|
+
def coerce_tags(tags)
|
57
|
+
tags.map do |tag|
|
58
|
+
{ tag.key => tag.value }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: instance_finder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Coleman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aws-sdk-ec2
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: slop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.6'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: awesome_print
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.8'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.8'
|
111
|
+
description: Find your EC2 instances based on tags - for CLI usage, Capistrano or
|
112
|
+
as a library
|
113
|
+
email:
|
114
|
+
- github@robert.net.nz
|
115
|
+
executables:
|
116
|
+
- instance_finder
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".env.example"
|
121
|
+
- ".gitignore"
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- exe/instance_finder
|
130
|
+
- instance_finder.gemspec
|
131
|
+
- lib/instance_finder.rb
|
132
|
+
- lib/instance_finder/version.rb
|
133
|
+
homepage: https://github.com/rjocoleman/instance-finder
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.6.13
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Find your EC2 instances based on tags
|
157
|
+
test_files: []
|