aws_instance_list 0.1.0 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile.lock +26 -1
- data/README.md +45 -2
- data/aws_instance_list.gemspec +5 -0
- data/lib/aws_instance_list/list.rb +43 -0
- data/lib/aws_instance_list/metric.rb +43 -0
- data/lib/aws_instance_list/rds.rb +71 -0
- data/lib/aws_instance_list/region.rb +26 -0
- data/lib/aws_instance_list/version.rb +1 -1
- data/lib/aws_instance_list.rb +12 -2
- data/lib/config/default_settings.yaml +8 -0
- metadata +77 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a88a496e99edde8c7d285a465cfe304c38fbf82
|
4
|
+
data.tar.gz: c5db25fd4d65f23a849fd817636f180e5e65f676
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f2bff084b04f818baafcddd07bd24ed8635bcb48d43b473da90e2e8c26cf7acb063a1d532e85a8af6298dc372c36de1e621a9562e75bd8ccd6890926e20c52d
|
7
|
+
data.tar.gz: '02487fda68e8e17d02758a7e384f586d8f42e9b7be6c90d783facff877f3d11d855ec0173e2a5dd8133efbe82ddbd0a68eacce935ed708ebb7e41b926a5b726b'
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
aws_instance_list (
|
4
|
+
aws_instance_list (1.2.6)
|
5
|
+
aws-sdk-cloudwatch (~> 1.6)
|
6
|
+
aws-sdk-ec2 (~> 1.37)
|
7
|
+
aws-sdk-rds (~> 1.23)
|
8
|
+
dotenv (~> 2.5)
|
5
9
|
|
6
10
|
GEM
|
7
11
|
remote: https://rubygems.org/
|
8
12
|
specs:
|
13
|
+
aws-eventstream (1.0.1)
|
14
|
+
aws-partitions (1.95.0)
|
15
|
+
aws-sdk-cloudwatch (1.6.0)
|
16
|
+
aws-sdk-core (~> 3)
|
17
|
+
aws-sigv4 (~> 1.0)
|
18
|
+
aws-sdk-core (3.22.1)
|
19
|
+
aws-eventstream (~> 1.0)
|
20
|
+
aws-partitions (~> 1.0)
|
21
|
+
aws-sigv4 (~> 1.0)
|
22
|
+
jmespath (~> 1.0)
|
23
|
+
aws-sdk-ec2 (1.38.0)
|
24
|
+
aws-sdk-core (~> 3)
|
25
|
+
aws-sigv4 (~> 1.0)
|
26
|
+
aws-sdk-rds (1.23.0)
|
27
|
+
aws-sdk-core (~> 3)
|
28
|
+
aws-sigv4 (~> 1.0)
|
29
|
+
aws-sigv4 (1.0.3)
|
30
|
+
byebug (10.0.2)
|
9
31
|
diff-lcs (1.3)
|
32
|
+
dotenv (2.5.0)
|
33
|
+
jmespath (1.4.0)
|
10
34
|
rake (10.5.0)
|
11
35
|
rspec (3.7.0)
|
12
36
|
rspec-core (~> 3.7.0)
|
@@ -28,6 +52,7 @@ PLATFORMS
|
|
28
52
|
DEPENDENCIES
|
29
53
|
aws_instance_list!
|
30
54
|
bundler (~> 1.16)
|
55
|
+
byebug (~> 10.0)
|
31
56
|
rake (~> 10.0)
|
32
57
|
rspec (~> 3.0)
|
33
58
|
|
data/README.md
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
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_instance_list`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
|
-
|
5
|
+
This gem is an easy way to get AWS instance list in all regions.
|
6
|
+
The class AwsIntanceList::List runs one Thread by region to get the data in each one. Finally join all in one Array.
|
7
|
+
|
8
|
+
Using the AWS describe instance we can get the instances but the metrics are not available.
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
@@ -22,7 +25,47 @@ Or install it yourself as:
|
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
|
28
|
+
As a library you need require it after install the gem.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
|
32
|
+
require 'aws_instance_list'
|
33
|
+
|
34
|
+
list= AwsInstanceList::List.new
|
35
|
+
|
36
|
+
# sample to get all rds instances
|
37
|
+
|
38
|
+
list.db_list # will return an array like this
|
39
|
+
|
40
|
+
# db_instance_identifier, engine, storage (GBytes), status, free storage available, region
|
41
|
+
|
42
|
+
#\>
|
43
|
+
[
|
44
|
+
["db1", "mysql", 50, "available", 45.3829460144043, "eu-west-1"],
|
45
|
+
["db2", "mysql", 50, "available", 44.111881256103516, "eu-west-1"],
|
46
|
+
["db3", "mysql", 20, "available", 15.590309143066406, "eu-west-2"],
|
47
|
+
["db4", "mysql", 100, "available", 94.48283767700195, "eu-west-2"]
|
48
|
+
]
|
49
|
+
|
50
|
+
```
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
## Test
|
55
|
+
Add a test.env file with:
|
56
|
+
|
57
|
+
```bash
|
58
|
+
DB_INSTANCE_IDENTIFIER=identifier_name_db
|
59
|
+
REGION=aws_region_to_test # sample: eu-central-1
|
60
|
+
LONG_REGION=aws_region_with_pagination_to_test # sample: eu-west-1
|
61
|
+
|
62
|
+
```
|
63
|
+
|
64
|
+
And run
|
65
|
+
|
66
|
+
```bash
|
67
|
+
rspec
|
68
|
+
```
|
26
69
|
|
27
70
|
## Development
|
28
71
|
|
data/aws_instance_list.gemspec
CHANGED
@@ -34,5 +34,10 @@ Gem::Specification.new do |spec|
|
|
34
34
|
|
35
35
|
spec.add_development_dependency "bundler", "~> 1.16"
|
36
36
|
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "byebug", "~> 10.0"
|
37
38
|
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
spec.add_dependency "aws-sdk-rds", "~> 1.23"
|
40
|
+
spec.add_dependency "aws-sdk-ec2", "~> 1.37"
|
41
|
+
spec.add_dependency "aws-sdk-cloudwatch", "~> 1.6"
|
42
|
+
spec.add_dependency "dotenv", "~> 2.5"
|
38
43
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module AwsInstanceList
|
2
|
+
|
3
|
+
class List
|
4
|
+
|
5
|
+
attr_accessor :regions
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@regions=AwsInstanceList::Region.list
|
9
|
+
@db_list={}
|
10
|
+
end
|
11
|
+
|
12
|
+
def db_list
|
13
|
+
|
14
|
+
if @db_list.empty?
|
15
|
+
|
16
|
+
threads = []
|
17
|
+
|
18
|
+
regions.each do |region|
|
19
|
+
|
20
|
+
threads << Thread.new do
|
21
|
+
@db_list[region]=rds_db_list region: region
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
loop do
|
27
|
+
break if threads.count { |th| th.alive? } == 0
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
@db_list.values.flatten(1)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def rds_db_list region:
|
37
|
+
rds=AwsInstanceList::RDS.new region: region
|
38
|
+
rds.db_instances
|
39
|
+
rds.db_list
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'aws-sdk-cloudwatch'
|
2
|
+
|
3
|
+
module AwsInstanceList
|
4
|
+
|
5
|
+
class Metric
|
6
|
+
|
7
|
+
attr_accessor :client
|
8
|
+
|
9
|
+
def initialize region: 'eu-west-1'
|
10
|
+
@client=Aws::CloudWatch::Client.new region: region
|
11
|
+
end
|
12
|
+
|
13
|
+
def statistics options
|
14
|
+
client.get_metric_statistics options
|
15
|
+
end
|
16
|
+
|
17
|
+
def list options
|
18
|
+
client.list_metrics options
|
19
|
+
end
|
20
|
+
|
21
|
+
def free_storage_space db_instance_identifier
|
22
|
+
resp=statistics( {
|
23
|
+
namespace: "AWS/RDS",
|
24
|
+
metric_name: "FreeStorageSpace",
|
25
|
+
dimensions: [
|
26
|
+
{
|
27
|
+
name: "DBInstanceIdentifier",
|
28
|
+
value: db_instance_identifier,
|
29
|
+
},
|
30
|
+
],
|
31
|
+
start_time: Time.now - 600,
|
32
|
+
end_time: Time.now ,
|
33
|
+
period: 60,
|
34
|
+
statistics: ["Minimum"]
|
35
|
+
})
|
36
|
+
|
37
|
+
resp.datapoints.last.minimum / ( 1024.0 ** 3)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'aws-sdk-rds'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module AwsInstanceList
|
5
|
+
|
6
|
+
class RDS
|
7
|
+
|
8
|
+
attr_accessor :client, :region
|
9
|
+
|
10
|
+
def initialize region: 'eu-west-1'
|
11
|
+
|
12
|
+
@region=region
|
13
|
+
|
14
|
+
@client=Aws::RDS::Client.new region: region
|
15
|
+
|
16
|
+
@db_instances = []
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def db_descriptions options={}
|
21
|
+
client.describe_db_instances(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def db_instances options={}
|
25
|
+
descriptions=db_descriptions(options)
|
26
|
+
@db_instances+=descriptions.db_instances
|
27
|
+
if descriptions.marker
|
28
|
+
options[:marker]=descriptions.marker
|
29
|
+
db_instances(options)
|
30
|
+
else
|
31
|
+
@db_instances
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def db_list options: {}, fields: nil
|
36
|
+
|
37
|
+
fields||=load_db_fields
|
38
|
+
|
39
|
+
db_instances(options).map do |i|
|
40
|
+
fields.map { |f| i.send(f) } << free_storage_space(i.db_instance_identifier) << region
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_db_fields
|
45
|
+
yaml['db']['fields']
|
46
|
+
end
|
47
|
+
|
48
|
+
def yaml
|
49
|
+
@yaml||=yaml_default.merge(yaml_file)[demodulize]
|
50
|
+
end
|
51
|
+
|
52
|
+
def yaml_default
|
53
|
+
YAML.load_file AwsInstanceList::DEFAULT_SETTINGS
|
54
|
+
end
|
55
|
+
|
56
|
+
def yaml_file
|
57
|
+
ENV.has_key?('AWS_INSTANCE_LIST_YAML') ? YAML.load_file(ENV['AWS_INSTANCE_LIST_YAML']) : {}
|
58
|
+
end
|
59
|
+
|
60
|
+
def demodulize
|
61
|
+
self.class.name.split('::').last
|
62
|
+
end
|
63
|
+
|
64
|
+
def free_storage_space db_instance_identifier
|
65
|
+
metric = AwsInstanceList::Metric.new region: region
|
66
|
+
metric.free_storage_space db_instance_identifier
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'aws-sdk-ec2'
|
2
|
+
|
3
|
+
module AwsInstanceList
|
4
|
+
|
5
|
+
class Region
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def ec2
|
10
|
+
@ec2||=Aws::EC2::Client.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def descriptions
|
14
|
+
@descriptions||=ec2.describe_regions
|
15
|
+
end
|
16
|
+
|
17
|
+
def list
|
18
|
+
descriptions.regions.map do |description|
|
19
|
+
description.region_name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/aws_instance_list.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'aws_instance_list/list'
|
2
|
+
require 'aws_instance_list/region'
|
3
|
+
require 'aws_instance_list/metric'
|
4
|
+
require 'aws_instance_list/rds'
|
5
|
+
require 'aws_instance_list/version'
|
6
|
+
|
7
|
+
require 'dotenv/load'
|
8
|
+
|
9
|
+
Dotenv.load
|
2
10
|
|
3
11
|
module AwsInstanceList
|
4
|
-
|
12
|
+
|
13
|
+
DEFAULT_SETTINGS= File.join(File.dirname(__FILE__),%w(config default_settings.yaml))
|
14
|
+
|
5
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_instance_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego PL
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,62 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aws-sdk-rds
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.23'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.23'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aws-sdk-ec2
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.37'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.37'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: aws-sdk-cloudwatch
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.6'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.6'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: dotenv
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.5'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.5'
|
55
125
|
description: The target is get the instance lists of AWS accounts. Return array of
|
56
126
|
data.
|
57
127
|
email:
|
@@ -74,7 +144,12 @@ files:
|
|
74
144
|
- bin/console
|
75
145
|
- bin/setup
|
76
146
|
- lib/aws_instance_list.rb
|
147
|
+
- lib/aws_instance_list/list.rb
|
148
|
+
- lib/aws_instance_list/metric.rb
|
149
|
+
- lib/aws_instance_list/rds.rb
|
150
|
+
- lib/aws_instance_list/region.rb
|
77
151
|
- lib/aws_instance_list/version.rb
|
152
|
+
- lib/config/default_settings.yaml
|
78
153
|
homepage: https://github.com/diegopiccinini/aws_instance_list
|
79
154
|
licenses:
|
80
155
|
- MIT
|