def _get_elasticache_connection(self): """Get an elasticache connection""" try: return connect_to_region(region_name=self.region, **self.aws_connect_kwargs) except boto.exception.NoAuthHandlerFound as e: self.module.fail_json(msg=e.message)
def get_cache_cluster_endpoint(self, cache_cluster_id): """Get the first cache cluster node endpoint""" elasticache_conn = ec.connect_to_region(self.region, profile_name=self.aws_profile) cache_clusters = elasticache_conn.describe_cache_clusters( cache_cluster_id=cache_cluster_id, show_cache_node_info=True)['DescribeCacheClustersResponse']['DescribeCacheClustersResult']['CacheClusters'] # NOQA return cache_clusters[0]['CacheNodes'][0]['Endpoint']['Address']
def __init__(self, name, platform, env, region, cache_instance_class=None, nodes=1, destroy_confirmation=True): self.name = name self.platform = platform self.env = env self.cache_name = "%s-%s" % (self.name, self.env) if len(self.cache_name) > 20: raise ValueError("The cache cluster name must have less than 20 characters") self.region = region self.cache_instance_class = cache_instance_class self.connection = elasticache.connect_to_region(self.region) self.nodes = 1
def get_elasticache_instances_by_region(self, region): try: conn = elasticache.connect_to_region(region) if conn: response = conn.describe_cache_clusters(show_cache_node_info=True) instances = response['DescribeCacheClustersResponse']['DescribeCacheClustersResult']['CacheClusters'] for instance in instances: self.add_elasticache_instance(instance, region) except boto.exception.BotoServerError, e: if not e.reason == "Forbidden": print "Looks like AWS ElastiCache is down: " print e sys.exit(1)
def __init__(self, name, platform, env, region, cache_instance_class=None, nodes=1, destroy_confirmation=True): self.name = name self.platform = platform self.env = env self.cache_name = "%s-%s" % (self.name, self.env) if len(self.cache_name) > 20: raise ValueError( "The cache cluster name must have less than 20 characters") self.region = region self.cache_instance_class = cache_instance_class self.connection = elasticache.connect_to_region(self.region) self.nodes = 1
def main(): argument_spec = ec2_argument_spec() argument_spec.update(dict( state=dict(required=True, choices=['present', 'absent']), name=dict(required=True), description=dict(required=False), subnets=dict(required=False, type='list'), ) ) module = AnsibleModule(argument_spec=argument_spec) if not HAS_BOTO: module.fail_json(msg='boto required for this module') state = module.params.get('state') group_name = module.params.get('name').lower() group_description = module.params.get('description') group_subnets = module.params.get('subnets') or {} if state == 'present': for required in ['name', 'description', 'subnets']: if not module.params.get(required): module.fail_json(msg=str("Parameter %s required for state='present'" % required)) else: for not_allowed in ['description', 'subnets']: if module.params.get(not_allowed): module.fail_json(msg=str("Parameter %s not allowed for state='absent'" % not_allowed)) # Retrieve any AWS settings from the environment. region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module) if not region: module.fail_json(msg=str("Either region or AWS_REGION or EC2_REGION environment variable or boto config aws_region or ec2_region must be set.")) """Get an elasticache connection""" try: conn = connect_to_region(region_name=region, **aws_connect_kwargs) except boto.exception.NoAuthHandlerFound as e: module.fail_json(msg=e.message) try: changed = False exists = False try: matching_groups = conn.describe_cache_subnet_groups(group_name, max_records=100) exists = len(matching_groups) > 0 except BotoServerError as e: if e.error_code != 'CacheSubnetGroupNotFoundFault': module.fail_json(msg=e.error_message) if state == 'absent': if exists: conn.delete_cache_subnet_group(group_name) changed = True else: if not exists: new_group = conn.create_cache_subnet_group(group_name, cache_subnet_group_description=group_description, subnet_ids=group_subnets) changed = True else: changed_group = conn.modify_cache_subnet_group(group_name, cache_subnet_group_description=group_description, subnet_ids=group_subnets) changed = True except BotoServerError as e: if e.error_message != 'No modifications were requested.': module.fail_json(msg=e.error_message) else: changed = False module.exit_json(changed=changed)
def _connect_to_elasticache(self): self.cache = elasticache.connect_to_region( self.region, aws_access_key_id="AKIAJQF4ELAIIMGJABZA", aws_secret_access_key="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" )