Class: AwsCache
- Inherits:
-
Object
- Object
- AwsCache
- Defined in:
- lib/aws-cache.rb
Constant Summary collapse
- VERSION =
Please follow semantic versioning (semver.org).
AwsCacheVersion::VERSION
Instance Method Summary collapse
-
#describe_auto_scaling_group(asg) ⇒ Object
Returns Aws::AutoScaling::Types::AutoScalingGroup.
- #describe_auto_scaling_instances ⇒ Object
-
#describe_autoscaling_groups ⇒ Object
Returns an Array of Hashes containing auto scaling group structures.
-
#describe_instance(instance_id) ⇒ Object
Returns a hash describing the instance requested.
-
#describe_instances ⇒ Object
Returns an Array of Hashes containing instance structures.
- #describe_snapshots ⇒ Object
-
#describe_stack(stack_name) ⇒ Object
Returns a hash describing the stack requested.
- #describe_stacks ⇒ Object
-
#get_asg_instances(asg) ⇒ Object
Returns an array of hashes of instances.
-
#get_sub_stacks(stack_name) ⇒ Object
Returns an array of hashes describing the substacks for the selected stack.
-
#initialize(opts) ⇒ AwsCache
constructor
A new instance of AwsCache.
- #list_stack_resources(stack_name) ⇒ Object
- #process_page(key, pages) ⇒ Object
-
#stack_auto_scaling_groups(stack_name) ⇒ Object
Returns an array of hashes describing the autoscaling groups for the selected stack.
Constructor Details
#initialize(opts) ⇒ AwsCache
Returns a new instance of AwsCache.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/aws-cache.rb', line 13 def initialize(opts) unless opts.has_key?('port') then opts['port'] = 6379 end unless opts.has_key?('host') then opts['host'] = 'aws-cache' end @redis = optional_element(opts, ['redis']) if @redis.nil? @redis = Redis.new(url: "redis://#{opts['host']}:#{opts['port']}/0") end @keyspace = optional_element(opts, ['keyspace'], AwsCache::VERSION) @region = optional_element(opts, ['region'], 'us-east-1') end |
Instance Method Details
#describe_auto_scaling_group(asg) ⇒ Object
Returns Aws::AutoScaling::Types::AutoScalingGroup
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/aws-cache.rb', line 83 def describe_auto_scaling_group(asg) asgroups = self.describe_autoscaling_groups() target_asg = asgroups.select do |record| record[:auto_scaling_group_name] == asg end if target_asg then return target_asg[0] end return nil end |
#describe_auto_scaling_instances ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/aws-cache.rb', line 122 def describe_auto_scaling_instances() output = cache_get("describe_auto_scaling_instances", 300) do aws_object = Aws::AutoScaling::Client.new(region: @region) pages = aws_object.describe_auto_scaling_instances() output = process_page( 'auto_scaling_instances', pages) end return output end |
#describe_autoscaling_groups ⇒ Object
Returns an Array of Hashes containing auto scaling group structures
133 134 135 136 137 138 139 140 |
# File 'lib/aws-cache.rb', line 133 def describe_autoscaling_groups() output = cache_get('get_autoscaling_groups', 300) do aws_object = Aws::AutoScaling::Client.new(region: @region) pages = aws_object.describe_auto_scaling_groups output = process_page( 'auto_scaling_groups', pages) end return output end |
#describe_instance(instance_id) ⇒ Object
Returns a hash describing the instance requested.
25 26 27 28 29 30 31 |
# File 'lib/aws-cache.rb', line 25 def describe_instance( instance_id) instances = self.describe_instances() instance = instances.select do |entry| entry[:instances][0][:instance_id] == instance_id end return instance[0] end |
#describe_instances ⇒ Object
Returns an Array of Hashes containing instance structures
143 144 145 146 147 148 149 150 |
# File 'lib/aws-cache.rb', line 143 def describe_instances() output = cache_get('describe_instances', 300) do aws_object = Aws::EC2::Client.new(region: @region) pages = aws_object.describe_instances output = process_page( 'reservations', pages) end return output end |
#describe_snapshots ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/aws-cache.rb', line 94 def describe_snapshots() output = cache_get('get_snapshots', 300) do aws_object = Aws::EC2::Client.new(region: @region) pages = aws_object.describe_snapshots output = process_page( 'snapshots', pages) end return output end |
#describe_stack(stack_name) ⇒ Object
Returns a hash describing the stack requested.
62 63 64 65 66 67 68 69 70 |
# File 'lib/aws-cache.rb', line 62 def describe_stack(stack_name) stacks = self.describe_stacks stacks.each do |stack| if stack[:stack_name] == stack_name return stack end end return nil end |
#describe_stacks ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/aws-cache.rb', line 112 def describe_stacks() output = cache_get('get_stacks', 300) do aws_object = Aws::CloudFormation::Client.new(region: @region) pages = aws_object.describe_stacks output = process_page( 'stacks', pages) end return output end |
#get_asg_instances(asg) ⇒ Object
Returns an array of hashes of instances.
73 74 75 76 77 78 79 80 |
# File 'lib/aws-cache.rb', line 73 def get_asg_instances(asg) instances = Array.new() asg_instances = self.describe_auto_scaling_group(asg) asg_instances[:instances].each do |instance| instances.push(instance) end return instances end |
#get_sub_stacks(stack_name) ⇒ Object
Returns an array of hashes describing the substacks for the selected stack.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/aws-cache.rb', line 46 def get_sub_stacks( stack_name) substacks = Array.new() stacks = self.list_stack_resources(stack_name) stacks.each do |entry| if entry[:resource_type] == "AWS::CloudFormation::Stack" self.describe_stacks.each do |stack| if entry[:physical_resource_id] == stack[:stack_id] substacks.push(stack) end end end end return substacks end |
#list_stack_resources(stack_name) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/aws-cache.rb', line 103 def list_stack_resources( stack_name) output = cache_get("list_stack_resources-#{stack_name}", 300) do aws_object = Aws::CloudFormation::Client.new(region: @region) pages = aws_object.list_stack_resources(stack_name: stack_name) output = process_page( 'stack_resource_summaries', pages) end return output end |
#process_page(key, pages) ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/aws-cache.rb', line 152 def process_page( key, pages) output = Array.new() pages.each do |page| data = page.send( key) data.each do |asg| output.push(asg) end end return output end |
#stack_auto_scaling_groups(stack_name) ⇒ Object
Returns an array of hashes describing the autoscaling groups for the selected stack.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/aws-cache.rb', line 34 def stack_auto_scaling_groups(stack_name) autoscaling_groups = Array.new() output = self.list_stack_resources(stack_name) output.each do |entry| if entry[:resource_type] == "AWS::AutoScaling::AutoScalingGroup" autoscaling_groups.push(entry) end end return autoscaling_groups end |