aws-cache 0.0.09 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aws-cache-version.rb +1 -1
- data/lib/aws-cache.rb +61 -64
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 074f3e44e9c0408c2628efb4cd1759b9c7f3204f
|
4
|
+
data.tar.gz: 621bf372a11bb8185d6f9f3bf515931de610277c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91188cf3cc8479beb07b8fcfdfddb1fa7c49a3f516e3852bf694592032a36c4876fee53fbf185c8045b388fdb755fcd21b8175d6a3293ae9ae643be4ee130c97
|
7
|
+
data.tar.gz: 841119d4bd4da1a18ee7e741957a103295f841ae1ee115dbf25d18e1007a8cc82837bc11d32cb9e52fa98346c24b4a76c6694640848c55283ed0eaab7d92a60b
|
data/lib/aws-cache-version.rb
CHANGED
data/lib/aws-cache.rb
CHANGED
@@ -21,16 +21,16 @@ class AwsCache
|
|
21
21
|
@region = optional_element(opts, ['region'], 'us-east-1')
|
22
22
|
end
|
23
23
|
|
24
|
+
#Returns a hash describing the instance requested.
|
24
25
|
def describe_instance( instance_id)
|
25
26
|
instances = self.describe_instances()
|
26
|
-
instances.
|
27
|
-
|
28
|
-
return instance[:instances][0]
|
29
|
-
end
|
27
|
+
instance = instances.select do |entry|
|
28
|
+
entry[:instances][0][:instance_id] == instance_id
|
30
29
|
end
|
31
|
-
return
|
30
|
+
return instance[0]
|
32
31
|
end
|
33
32
|
|
33
|
+
#Returns an array of hashes describing the autoscaling groups for the selected stack.
|
34
34
|
def stack_auto_scaling_groups(stack_name)
|
35
35
|
autoscaling_groups = Array.new()
|
36
36
|
output = self.list_stack_resources(stack_name)
|
@@ -42,16 +42,7 @@ class AwsCache
|
|
42
42
|
return autoscaling_groups
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
output = cache_get_2("list_stack_resources-#{stack_name}", 300) do
|
47
|
-
aws_object = Aws::CloudFormation::Client.new(region: @region)
|
48
|
-
pages = aws_object.list_stack_resources(stack_name: stack_name)
|
49
|
-
output = process_page( 'stack_resource_summaries', pages)
|
50
|
-
end
|
51
|
-
return output
|
52
|
-
end
|
53
|
-
|
54
|
-
|
45
|
+
#Returns an array of hashes describing the substacks for the selected stack.
|
55
46
|
def get_sub_stacks( stack_name)
|
56
47
|
substacks = Array.new()
|
57
48
|
stacks = self.list_stack_resources(stack_name)
|
@@ -66,7 +57,8 @@ class AwsCache
|
|
66
57
|
end
|
67
58
|
return substacks
|
68
59
|
end
|
69
|
-
|
60
|
+
|
61
|
+
#Returns a hash describing the stack requested.
|
70
62
|
def describe_stack(stack_name)
|
71
63
|
stacks = self.describe_stacks
|
72
64
|
stacks.each do |stack|
|
@@ -77,17 +69,30 @@ class AwsCache
|
|
77
69
|
return nil
|
78
70
|
end
|
79
71
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
72
|
+
#Returns an array of hashes of instances.
|
73
|
+
def get_asg_instances(asg)
|
74
|
+
instances = Array.new()
|
75
|
+
asg_instances = self.describe_auto_scaling_group(asg)
|
76
|
+
asg_instances[:instances].each do |instance|
|
77
|
+
instances.push(instance)
|
85
78
|
end
|
86
|
-
return
|
79
|
+
return instances
|
80
|
+
end
|
81
|
+
|
82
|
+
#Returns Aws::AutoScaling::Types::AutoScalingGroup
|
83
|
+
def describe_auto_scaling_group(asg)
|
84
|
+
asgroups = self.describe_autoscaling_groups()
|
85
|
+
target_asg = asgroups.select do |record|
|
86
|
+
record[:auto_scaling_group_name] == asg
|
87
|
+
end
|
88
|
+
if target_asg then
|
89
|
+
return target_asg[0]
|
90
|
+
end
|
91
|
+
return nil
|
87
92
|
end
|
88
93
|
|
89
94
|
def describe_snapshots()
|
90
|
-
output =
|
95
|
+
output = cache_get('get_snapshots', 300) do
|
91
96
|
aws_object = Aws::EC2::Client.new(region: @region)
|
92
97
|
pages = aws_object.describe_snapshots
|
93
98
|
output = process_page( 'snapshots', pages)
|
@@ -95,27 +100,38 @@ class AwsCache
|
|
95
100
|
return output
|
96
101
|
end
|
97
102
|
|
98
|
-
def
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
+
def list_stack_resources( stack_name)
|
104
|
+
output = cache_get("list_stack_resources-#{stack_name}", 300) do
|
105
|
+
aws_object = Aws::CloudFormation::Client.new(region: @region)
|
106
|
+
pages = aws_object.list_stack_resources(stack_name: stack_name)
|
107
|
+
output = process_page( 'stack_resource_summaries', pages)
|
103
108
|
end
|
104
|
-
return
|
109
|
+
return output
|
105
110
|
end
|
106
111
|
|
107
|
-
def
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
112
|
+
def describe_stacks()
|
113
|
+
output = cache_get('get_stacks', 300) do
|
114
|
+
aws_object = Aws::CloudFormation::Client.new(region: @region)
|
115
|
+
pages = aws_object.describe_stacks
|
116
|
+
output = process_page( 'stacks', pages)
|
113
117
|
end
|
114
|
-
return
|
118
|
+
return output
|
115
119
|
end
|
116
120
|
|
121
|
+
|
122
|
+
def describe_auto_scaling_instances()
|
123
|
+
output = cache_get("describe_auto_scaling_instances", 300) do
|
124
|
+
aws_object = Aws::AutoScaling::Client.new(region: @region)
|
125
|
+
pages = aws_object.describe_auto_scaling_instances()
|
126
|
+
output = process_page( 'auto_scaling_instances', pages)
|
127
|
+
end
|
128
|
+
return output
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
#Returns an Array of Hashes containing auto scaling group structures
|
117
133
|
def describe_autoscaling_groups()
|
118
|
-
output =
|
134
|
+
output = cache_get('get_autoscaling_groups', 300) do
|
119
135
|
aws_object = Aws::AutoScaling::Client.new(region: @region)
|
120
136
|
pages = aws_object.describe_auto_scaling_groups
|
121
137
|
output = process_page( 'auto_scaling_groups', pages)
|
@@ -123,8 +139,9 @@ class AwsCache
|
|
123
139
|
return output
|
124
140
|
end
|
125
141
|
|
142
|
+
#Returns an Array of Hashes containing instance structures
|
126
143
|
def describe_instances()
|
127
|
-
output =
|
144
|
+
output = cache_get('describe_instances', 300) do
|
128
145
|
aws_object = Aws::EC2::Client.new(region: @region)
|
129
146
|
pages = aws_object.describe_instances
|
130
147
|
output = process_page( 'reservations', pages)
|
@@ -135,10 +152,9 @@ class AwsCache
|
|
135
152
|
def process_page( key, pages)
|
136
153
|
output = Array.new()
|
137
154
|
pages.each do |page|
|
138
|
-
page.
|
139
|
-
|
140
|
-
|
141
|
-
end
|
155
|
+
data = page.send( key)
|
156
|
+
data.each do |asg|
|
157
|
+
output.push(asg)
|
142
158
|
end
|
143
159
|
end
|
144
160
|
return output
|
@@ -166,37 +182,18 @@ class AwsCache
|
|
166
182
|
return false
|
167
183
|
end
|
168
184
|
|
169
|
-
def
|
185
|
+
def cache_get(key, ttl)
|
170
186
|
vkey = "#{key}_#{@keyspace}"
|
171
187
|
output = @redis.get(vkey)
|
172
188
|
if output.nil?
|
173
189
|
output = yield
|
174
|
-
output =
|
190
|
+
output = Psych.dump(output)
|
175
191
|
@redis.setex(vkey, ttl, output )
|
176
192
|
end
|
177
|
-
return
|
193
|
+
return Psych.load(output)
|
178
194
|
end
|
179
195
|
|
180
196
|
|
181
|
-
def cache_get(key, ttl)
|
182
|
-
vkey = "#{key}_#{@keyspace}"
|
183
|
-
hash = @redis.get(vkey)
|
184
|
-
ap hash.class.name
|
185
|
-
unless hash.nil?
|
186
|
-
hash = YAML.load(hash)
|
187
|
-
end
|
188
|
-
|
189
|
-
if hash.nil?
|
190
|
-
hash = yield
|
191
|
-
|
192
|
-
hash = hash.to_yaml
|
193
|
-
@redis.setex(vkey, ttl, hash)
|
194
|
-
hash = YAML.load(hash)
|
195
|
-
end
|
196
|
-
|
197
|
-
return hash
|
198
|
-
end
|
199
|
-
|
200
197
|
def list_to_hash!(src, keys, by_key)
|
201
198
|
hash = {}
|
202
199
|
last_key = keys.pop
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen J. Smith
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|