Class: Automan::ElastiCache::Router
- Defined in:
- lib/automan/elasticache/router.rb
Constant Summary
Constants included from Mixins::AwsCaller
Instance Attribute Summary
Attributes inherited from Base
Attributes included from Mixins::AwsCaller
#as, #cfn, #eb, #ec, #ec2, #elb, #r53, #rds, #s3
Instance Method Summary collapse
- #node_name_from_elasticache_environment(env) ⇒ Object
- #run ⇒ Object
-
#update_dns_alias(zone_name, redis_cname, primary_endpoint) ⇒ Object
be sure alias_name ends in period.
Methods inherited from Base
add_option, #initialize, #log_options, #wait_until
Methods included from Mixins::AwsCaller
#account, #configure_aws, #looks_like_s3_path?, #parse_s3_path, #s3_object_exists?, #s3_read
Constructor Details
This class inherits a constructor from Automan::Base
Instance Method Details
#node_name_from_elasticache_environment(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/automan/elasticache/router.rb', line 10 def node_name_from_elasticache_environment(env) opts = { cache_cluster_id: "redis-#{env}", show_cache_node_info: true } response = ec.client.describe_cache_clusters opts unless response.successful? raise RequestFailedError, "describe_cache_clusters failed: #{response.error}" end cluster=response.data[:cache_clusters] if cluster.empty? return nil end nodes=Hash[*cluster][:cache_nodes] if nodes.empty? return nil end endpoint=Hash[*nodes][:endpoint] if endpoint.empty? return nil end logger.info "found redis endpoint at #{endpoint[:address]}" endpoint[:address] end |
#run ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/automan/elasticache/router.rb', line 61 def run logger.info "getting redis primary node name..." primary_endpoint = node_name_from_elasticache_environment environment if primary_endpoint.nil? false else update_dns_alias( hosted_zone_name, redis_host, primary_endpoint ) true end end |
#update_dns_alias(zone_name, redis_cname, primary_endpoint) ⇒ Object
be sure alias_name ends in period
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/automan/elasticache/router.rb', line 43 def update_dns_alias(zone_name, redis_cname, primary_endpoint) zone = r53.hosted_zones.select {|z| z.name == zone_name}.first rrset = zone.rrsets[redis_cname + '.', 'CNAME'] if rrset.exists? logger.info "removing old record at #{redis_cname}" rrset.delete end logger.info "creating record #{redis_cname} -> #{primary_endpoint}" zone.rrsets.create( redis_cname + '.', 'CNAME', :ttl => 300, :resource_records => [{:value => primary_endpoint}] ) end |