asg-detailer 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/.gitignore +11 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/asg-detailer.gemspec +25 -0
- data/bin/asg-detailer +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/asg-detailer.rb +1 -0
- data/lib/asg-detailer/detailer.rb +83 -0
- data/lib/asg-detailer/infra.rb +37 -0
- data/lib/asg-detailer/version.rb +3 -0
- metadata +120 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ddc26adc18b1a24bfbe6b12339db2b106901fc08
|
|
4
|
+
data.tar.gz: 3c6816410843a9d0a7749f850c72fb9d3355d405
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: cecef64235e59b3f126ee70b26e3dab89dcbb51d9ac26b8080ff1490212eb8369887544b211bc6f3693d52e5e81d869621c99f35a9747aa793b44cc1c525741f
|
|
7
|
+
data.tar.gz: cef20d4acdad2a673718ce29b3c5639e54d40eac5de46505de49fc2e6485752bd60e2dbbd6180822840ac361b9c81fea3866e8ff2f715ae0b6b7d596d3e7cb15
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# AsgDetailer
|
|
2
|
+
|
|
3
|
+
I found myself wanting to be able to quickly see what a typical AWS ASG and ELB setup looked like without poking away at the interface or needing to use multiple command-line tools. This is a small gem to detail some of the basics of that style setup.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'asg-detailer'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install asg-detailer
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
The gem relies on the aws-sdk, which uses env vars to set AWS auth.
|
|
24
|
+
|
|
25
|
+
`
|
|
26
|
+
export AWS_ACCESS_KEY_ID=<YOUR AWS ID>
|
|
27
|
+
export AWS_SECRET_ACCESS_KEY=<YOUR AWS KEY>
|
|
28
|
+
export AWS_REGION=us-west-2
|
|
29
|
+
`
|
|
30
|
+
|
|
31
|
+
It requires an ASG name as an arg.
|
|
32
|
+
|
|
33
|
+
`asg-detailer <asg name>`
|
|
34
|
+
|
|
35
|
+
## Development
|
|
36
|
+
|
|
37
|
+
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.
|
|
38
|
+
|
|
39
|
+
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).
|
|
40
|
+
|
|
41
|
+
## Contributing
|
|
42
|
+
|
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hortoncd/asg-detailer
|
data/Rakefile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'asg-detailer/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "asg-detailer"
|
|
8
|
+
spec.version = AsgDetailer::VERSION
|
|
9
|
+
spec.authors = ["Chris Horton"]
|
|
10
|
+
spec.email = ["hortoncd@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Deatil an existing infrastructure.}
|
|
13
|
+
spec.description = %q{Produce details of an existing infrastructure built with typical ASG & ELB setup.}
|
|
14
|
+
spec.homepage = "https://github.com/hortoncd/asg-detailer"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
17
|
+
spec.bindir = "bin"
|
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/asg-detailer}) { |f| File.basename(f) }
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
24
|
+
spec.add_dependency 'aws-sdk', '~> 2.6', '>= 2.6.0'
|
|
25
|
+
end
|
data/bin/asg-detailer
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "asg-detailer"
|
|
5
|
+
include AsgDetailer
|
|
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
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require "irb"
|
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/asg-detailer.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require_relative "asg-detailer/detailer.rb"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require_relative "infra.rb"
|
|
2
|
+
|
|
3
|
+
include AsgDetailer
|
|
4
|
+
|
|
5
|
+
module AsgDetailer
|
|
6
|
+
class Detailer
|
|
7
|
+
attr_reader :name
|
|
8
|
+
|
|
9
|
+
def initialize(name, options = {})
|
|
10
|
+
@name = name
|
|
11
|
+
@infra = Infra.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def run
|
|
15
|
+
detail_asg
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def detail_asg
|
|
21
|
+
resp = @infra.query_asg(@name)
|
|
22
|
+
|
|
23
|
+
# should be only one, but returns array...
|
|
24
|
+
resp[:auto_scaling_groups].each do |a|
|
|
25
|
+
puts "Autoscaling Group: #{a[:auto_scaling_group_name]}"
|
|
26
|
+
puts "min size: #{a[:min_size]}"
|
|
27
|
+
puts "max size: #{a[:max_size]}"
|
|
28
|
+
puts "desired capacity: #{a[:desired_capacity]}"
|
|
29
|
+
puts "subnets: #{a[:vpc_zone_identifier]}"
|
|
30
|
+
|
|
31
|
+
detail_lc(a[:launch_configuration_name])
|
|
32
|
+
detail_lbs(a)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def detail_lc(lc)
|
|
37
|
+
puts
|
|
38
|
+
puts "Launch Configuration: #{lc}"
|
|
39
|
+
|
|
40
|
+
resp = @infra.query_lc(lc)
|
|
41
|
+
|
|
42
|
+
# should be only one, but returns array...
|
|
43
|
+
resp[:launch_configurations].each do |l|
|
|
44
|
+
puts "instance type: #{l[:instance_type]}"
|
|
45
|
+
puts "AMI: #{l[:image_id]}"
|
|
46
|
+
puts "security groups: #{l[:security_groups]}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# returns the instance health for any of the instances in the LB
|
|
51
|
+
def detail_lbs(a)
|
|
52
|
+
instance_health = Hash.new
|
|
53
|
+
a[:load_balancer_names].each do |n|
|
|
54
|
+
puts
|
|
55
|
+
puts "Load Balancer: #{n}"
|
|
56
|
+
|
|
57
|
+
resp = @infra.query_instance_health(n)
|
|
58
|
+
resp.instance_states.each do |i|
|
|
59
|
+
instance_health[i[:instance_id]] = i[:state]
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
detail_instances(a, instance_health)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def detail_instances(a, instance_health)
|
|
66
|
+
puts " Instances:"
|
|
67
|
+
ids = []
|
|
68
|
+
a[:instances].map { |i| ids.push i[:instance_id] }
|
|
69
|
+
|
|
70
|
+
unless ids.empty?
|
|
71
|
+
resp = @infra.query_instances(ids)
|
|
72
|
+
|
|
73
|
+
resp[:reservations].each do |r|
|
|
74
|
+
r[:instances].each do |i|
|
|
75
|
+
ip = i[:private_ip_address]
|
|
76
|
+
health = instance_health[i[:instance_id]] ? instance_health[i[:instance_id]] : "State is N/A (Not in LB)"
|
|
77
|
+
puts " InstanceID: #{i[:instance_id]} : #{ip} : #{health}"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require "aws-sdk"
|
|
2
|
+
|
|
3
|
+
module AsgDetailer
|
|
4
|
+
class Infra
|
|
5
|
+
def initialize
|
|
6
|
+
@asg = nil
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def query_asg(name)
|
|
10
|
+
# we save the asg because it's used more than once
|
|
11
|
+
@asg = Aws::AutoScaling::Client.new
|
|
12
|
+
@asg.describe_auto_scaling_groups ({
|
|
13
|
+
auto_scaling_group_names: [
|
|
14
|
+
name,
|
|
15
|
+
],
|
|
16
|
+
})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def query_lc(name)
|
|
20
|
+
@asg.describe_launch_configurations({
|
|
21
|
+
launch_configuration_names: [
|
|
22
|
+
name,
|
|
23
|
+
],
|
|
24
|
+
})
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def query_instance_health(name)
|
|
28
|
+
elb = Aws::ElasticLoadBalancing::Client.new
|
|
29
|
+
elb.describe_instance_health({load_balancer_name: name})
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def query_instances(ids)
|
|
33
|
+
ec2 = Aws::EC2::Client.new
|
|
34
|
+
ec2.describe_instances({ instance_ids: ids })
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: asg-detailer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Chris Horton
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-12-29 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.12'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.12'
|
|
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: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: aws-sdk
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '2.6'
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: 2.6.0
|
|
65
|
+
type: :runtime
|
|
66
|
+
prerelease: false
|
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - "~>"
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '2.6'
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 2.6.0
|
|
75
|
+
description: Produce details of an existing infrastructure built with typical ASG
|
|
76
|
+
& ELB setup.
|
|
77
|
+
email:
|
|
78
|
+
- hortoncd@gmail.com
|
|
79
|
+
executables:
|
|
80
|
+
- asg-detailer
|
|
81
|
+
extensions: []
|
|
82
|
+
extra_rdoc_files: []
|
|
83
|
+
files:
|
|
84
|
+
- ".gitignore"
|
|
85
|
+
- ".rspec"
|
|
86
|
+
- Gemfile
|
|
87
|
+
- README.md
|
|
88
|
+
- Rakefile
|
|
89
|
+
- asg-detailer.gemspec
|
|
90
|
+
- bin/asg-detailer
|
|
91
|
+
- bin/console
|
|
92
|
+
- bin/setup
|
|
93
|
+
- lib/asg-detailer.rb
|
|
94
|
+
- lib/asg-detailer/detailer.rb
|
|
95
|
+
- lib/asg-detailer/infra.rb
|
|
96
|
+
- lib/asg-detailer/version.rb
|
|
97
|
+
homepage: https://github.com/hortoncd/asg-detailer
|
|
98
|
+
licenses: []
|
|
99
|
+
metadata: {}
|
|
100
|
+
post_install_message:
|
|
101
|
+
rdoc_options: []
|
|
102
|
+
require_paths:
|
|
103
|
+
- lib
|
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - ">="
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '0'
|
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - ">="
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '0'
|
|
114
|
+
requirements: []
|
|
115
|
+
rubyforge_project:
|
|
116
|
+
rubygems_version: 2.6.8
|
|
117
|
+
signing_key:
|
|
118
|
+
specification_version: 4
|
|
119
|
+
summary: Deatil an existing infrastructure.
|
|
120
|
+
test_files: []
|