aws-cache 0.0.07 → 0.0.08
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/aws-cache-version.rb +1 -1
- data/lib/aws-cache.rb +103 -132
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDUxM2E4MTcyYTE3NTQyNGFiNjg4ZGM3YTM0NDlhZmIyMDE4OWE0NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDYwNzZmNTdkYzZlNTYyMDI0ZDUzNjUyZTMyMTgwNTg2NDZjYzZmMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjE5MzQ2Zjc5ZThlMTg5OTAzMDJjNTA4YTczNGQ5MGQ4ZDkwMzZkODA4NmRk
|
10
|
+
OWRmMDE0YWMzYmRiNWEzZjRiZjhhOGIwNGU4ZmVkY2NlODVkMGE2NzBiZTUx
|
11
|
+
MzliYjYwMjIxYzNjN2IxNmZiNzg5NDM5MzliZDVmZmNmMzA0Yjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmM4MzczZTdkMTVlNjczYzJlM2Y3YTU0NGZhODFlNDgyMWM0OWM2Y2M1ZWRk
|
14
|
+
ZjI1Y2M0NzFmZTM1NGQyZGMwNTVlODcwMDc0OWY5M2EzZDhmNmNjYWRjZTQy
|
15
|
+
OGMwNzYwZGEzYTA4YjEwNTRhMGZjMDJiNmZhMmExZDk3NzRhZjk=
|
data/lib/aws-cache-version.rb
CHANGED
data/lib/aws-cache.rb
CHANGED
@@ -4,6 +4,7 @@ require 'aws-sdk'
|
|
4
4
|
require 'yaml'
|
5
5
|
require 'pry'
|
6
6
|
require 'aws-cache-version'
|
7
|
+
require 'awesome_print'
|
7
8
|
|
8
9
|
class AwsCache
|
9
10
|
# Please follow semantic versioning (semver.org).
|
@@ -20,162 +21,119 @@ class AwsCache
|
|
20
21
|
@region = optional_element(opts, ['region'], 'us-east-1')
|
21
22
|
end
|
22
23
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
pages.each do |page|
|
30
|
-
page =
|
31
|
-
page.data[:reservations].each do |res|
|
32
|
-
res[:instances].each do |instance|
|
33
|
-
list_to_hash!(instance, [:tags], :key)
|
34
|
-
list_to_hash!(instance, [:block_device_mappings], :device_name)
|
35
|
-
instances[instance[:instance_id]] = instance
|
36
|
-
end
|
37
|
-
end
|
24
|
+
def stack_auto_scaling_groups(stack_name)
|
25
|
+
autoscaling_groups = Array.new()
|
26
|
+
output = self.list_stack_resources(stack_name)
|
27
|
+
output.each do |entry|
|
28
|
+
if entry[:resource_type] == "AWS::AutoScaling::AutoScalingGroup"
|
29
|
+
autoscaling_groups.push(entry)
|
38
30
|
end
|
39
|
-
|
40
|
-
instances
|
41
31
|
end
|
32
|
+
return autoscaling_groups
|
33
|
+
end
|
42
34
|
|
43
|
-
|
35
|
+
def list_stack_resources( stack_name)
|
36
|
+
output = cache_get_2("list_stack_resources-#{stack_name}", 300) do
|
37
|
+
aws_object = Aws::CloudFormation::Client.new(region: @region)
|
38
|
+
pages = aws_object.list_stack_resources(stack_name: stack_name)
|
39
|
+
output = process_page( 'stack_resource_summaries', pages)
|
40
|
+
end
|
41
|
+
return output
|
44
42
|
end
|
45
43
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
|
45
|
+
def get_sub_stacks( stack_name)
|
46
|
+
substacks = Array.new()
|
47
|
+
stacks = self.list_stack_resources(stack_name)
|
48
|
+
stacks.each do |entry|
|
49
|
+
if entry[:resource_type] == "AWS::CloudFormation::Stack"
|
50
|
+
self.describe_stacks.each do |stack|
|
51
|
+
if entry[:physical_resource_id] == stack[:stack_id]
|
52
|
+
substacks.push(stack)
|
53
|
+
end
|
54
|
+
end
|
52
55
|
end
|
53
56
|
end
|
54
|
-
return
|
55
|
-
end
|
56
|
-
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
pages = autoscaling.describe_auto_scaling_groups
|
63
|
-
pages.each do |page|
|
64
|
-
page.data[:auto_scaling_groups].each do |group|
|
65
|
-
instances = Hash.new()
|
66
|
-
list_to_hash!(group, [:instances], :instance_id)
|
67
|
-
list_to_hash!(group, [:tags], :key)
|
68
|
-
groups[group[:auto_scaling_group_name]] = group
|
69
|
-
end
|
57
|
+
return substacks
|
58
|
+
end
|
59
|
+
|
60
|
+
def describe_stack(stack_name)
|
61
|
+
stacks = self.describe_stacks
|
62
|
+
stacks.each do |stack|
|
63
|
+
if stack[:stack_name] == stack_name
|
64
|
+
return stack
|
70
65
|
end
|
71
|
-
|
72
|
-
groups
|
73
66
|
end
|
67
|
+
return nil
|
68
|
+
end
|
74
69
|
|
75
|
-
|
70
|
+
def describe_stacks()
|
71
|
+
output = cache_get_2('get_stacks', 300) do
|
72
|
+
aws_object = Aws::CloudFormation::Client.new(region: @region)
|
73
|
+
pages = aws_object.describe_stacks
|
74
|
+
output = process_page( 'stacks', pages)
|
75
|
+
end
|
76
|
+
return output
|
76
77
|
end
|
77
78
|
|
78
|
-
def
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
stack_groups[name] = group
|
84
|
-
end
|
79
|
+
def describe_snapshots()
|
80
|
+
output = cache_get_2('get_snapshots', 300) do
|
81
|
+
aws_object = Aws::EC2::Client.new(region: @region)
|
82
|
+
pages = aws_object.describe_snapshots
|
83
|
+
output = process_page( 'snapshots', pages)
|
85
84
|
end
|
86
|
-
return
|
87
|
-
end
|
88
|
-
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
pages = cfn.describe_stacks
|
95
|
-
pages.each do |page|
|
96
|
-
page.data[:stacks].each do |stack|
|
97
|
-
list_to_hash!(stack, [:parameters], :parameter_key)
|
98
|
-
list_to_hash!(stack, [:outputs], :output_key)
|
99
|
-
list_to_hash!(stack, [:tags], :key)
|
100
|
-
cloudformation_stacks[stack[:stack_name]] = stack
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
cloudformation_stacks
|
85
|
+
return output
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_asg_instances(asg)
|
89
|
+
instances = Array.new()
|
90
|
+
asg = self.describe_auto_scaling_group(asg)
|
91
|
+
asg[:instances].each do |instance|
|
92
|
+
instances.push(instance)
|
105
93
|
end
|
94
|
+
return instances
|
95
|
+
end
|
106
96
|
|
107
|
-
|
97
|
+
def describe_auto_scaling_group(asg)
|
98
|
+
asgroups = self.describe_autoscaling_groups()
|
99
|
+
asgroups.each do |asgroup|
|
100
|
+
if asgroup[:auto_scaling_group_name] == asg then
|
101
|
+
return asgroup
|
102
|
+
end
|
103
|
+
end
|
104
|
+
return nil
|
108
105
|
end
|
109
106
|
|
110
|
-
def
|
111
|
-
|
112
|
-
|
107
|
+
def describe_autoscaling_groups()
|
108
|
+
output = cache_get_2('get_autoscaling_groups', 300) do
|
109
|
+
aws_object = Aws::AutoScaling::Client.new(region: @region)
|
110
|
+
pages = aws_object.describe_auto_scaling_groups
|
111
|
+
output = process_page( 'auto_scaling_groups', pages)
|
112
|
+
end
|
113
|
+
return output
|
113
114
|
end
|
114
115
|
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
-
|
116
|
+
def describe_instances()
|
117
|
+
output = cache_get_2('describe_instances', 300) do
|
118
|
+
aws_object = Aws::EC2::Client.new(region: @region)
|
119
|
+
pages = aws_object.describe_instances
|
120
|
+
output = process_page( 'reservations', pages)
|
121
|
+
end
|
122
|
+
return output
|
123
|
+
end
|
119
124
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
stack_resources
|
129
|
-
end
|
130
|
-
|
131
|
-
return stack_resources
|
132
|
-
end
|
133
|
-
|
134
|
-
# One way this is different than describe_stacks is that it includes
|
135
|
-
# deleted stacks.
|
136
|
-
def list_stacks
|
137
|
-
stacks = cache_get('aws_cloudformation_list_stacks', 900) do
|
138
|
-
# Can't return a hash, because some stacks will appear more
|
139
|
-
# than once, such as if the stack was deleted and recreated.
|
140
|
-
stacks = []
|
141
|
-
|
142
|
-
cfn = Aws::CloudFormation::Client.new(region: @region)
|
143
|
-
pages = cfn.list_stacks
|
144
|
-
pages.each do |page|
|
145
|
-
page.data[:stack_summaries].each do |stack|
|
146
|
-
stacks.push(stack)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
stacks
|
151
|
-
end
|
152
|
-
|
153
|
-
return stacks
|
154
|
-
end
|
155
|
-
|
156
|
-
def get_snapshots()
|
157
|
-
snapshots = cache_get('aws_ec2_snapshots', 9) do
|
158
|
-
snapshots = Hash.new()
|
159
|
-
ec2 = Aws::EC2::Client.new(region: @region)
|
160
|
-
pages = ec2.describe_snapshots
|
161
|
-
pages.each do |page|
|
162
|
-
page.data.each do |data|
|
163
|
-
data.each do |snap|
|
164
|
-
if snapshots.has_key?(snap[:volume_id]) then
|
165
|
-
snapshots[snap[:volume_id]].push(snap)
|
166
|
-
else
|
167
|
-
snapshots[snap[:volume_id]] = Array.new()
|
168
|
-
snapshots[snap[:volume_id]].push(snap)
|
169
|
-
end
|
170
|
-
end
|
125
|
+
def process_page( key, pages)
|
126
|
+
output = Array.new()
|
127
|
+
pages.each do |page|
|
128
|
+
page.each do |data|
|
129
|
+
data.data[key].each do |entry|
|
130
|
+
output.push(entry)
|
171
131
|
end
|
172
132
|
end
|
173
|
-
|
174
|
-
|
175
|
-
return snapshots
|
133
|
+
end
|
134
|
+
return output
|
176
135
|
end
|
177
136
|
|
178
|
-
|
179
137
|
private
|
180
138
|
def optional_element(hash, keys, default=nil)
|
181
139
|
keys.each do |key|
|
@@ -198,9 +156,22 @@ class AwsCache
|
|
198
156
|
return false
|
199
157
|
end
|
200
158
|
|
159
|
+
def cache_get_2(key, ttl)
|
160
|
+
vkey = "#{key}_#{@keyspace}"
|
161
|
+
output = @redis.get(vkey)
|
162
|
+
if output.nil?
|
163
|
+
output = yield
|
164
|
+
output = YAML.dump(output)
|
165
|
+
@redis.setex(vkey, ttl, output )
|
166
|
+
end
|
167
|
+
return YAML.load(output)
|
168
|
+
end
|
169
|
+
|
170
|
+
|
201
171
|
def cache_get(key, ttl)
|
202
172
|
vkey = "#{key}_#{@keyspace}"
|
203
173
|
hash = @redis.get(vkey)
|
174
|
+
ap hash.class.name
|
204
175
|
unless hash.nil?
|
205
176
|
hash = YAML.load(hash)
|
206
177
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.08
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen J. Smith
|
8
|
+
- Brian J. Schrock
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
12
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: aws-sdk
|