mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Adds support for subnet_groups and syntax changes
This commit is contained in:
parent
b7362ee59f
commit
7a5a371eb4
@ -313,6 +313,61 @@ def get_group_host(name, region=None, key=None, keyid=None, profile=None):
|
|||||||
return host
|
return host
|
||||||
|
|
||||||
|
|
||||||
|
def subnet_group_exists(name, tags=None, region=None, key=None, keyid=None, profile=None):
|
||||||
|
'''
|
||||||
|
Check to see if an ElastiCache subnet group exists.
|
||||||
|
|
||||||
|
CLI example::
|
||||||
|
|
||||||
|
salt myminion boto_elasticache.subnet_group_exists my-param-group \
|
||||||
|
region=us-east-1
|
||||||
|
'''
|
||||||
|
conn = _get_conn(region, key, keyid, profile)
|
||||||
|
if not conn:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
ec = conn.describe_cache_subnet_groups(cache_subnet_group_name=name)
|
||||||
|
if not ec:
|
||||||
|
msg = ('ElastiCache subnet group does not exist in region {0}'.format(region))
|
||||||
|
log.debug(msg)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
except boto.exception.BotoServerError as e:
|
||||||
|
log.debug(e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def create_subnet_group(name, description, subnet_ids, tags=None, region=None,
|
||||||
|
key=None, keyid=None, profile=None):
|
||||||
|
'''
|
||||||
|
Create an ElastiCache subnet group
|
||||||
|
|
||||||
|
CLI example to create an ElastiCache subnet group::
|
||||||
|
|
||||||
|
salt myminion boto_elasticache.create_subnet_group my-subnet-group \
|
||||||
|
"group description" '[subnet-12345678, subnet-87654321]' \
|
||||||
|
region=us-east-1
|
||||||
|
'''
|
||||||
|
conn = _get_conn(region, key, keyid, profile)
|
||||||
|
if not conn:
|
||||||
|
return False
|
||||||
|
if subnet_group_exists(name, tags, region, key, keyid, profile):
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
ec = conn.create_cache_subnet_group(name, description, subnet_ids)
|
||||||
|
if not ec:
|
||||||
|
msg = 'Failed to create ElastiCache subnet group {0}'.format(name)
|
||||||
|
log.error(msg)
|
||||||
|
return False
|
||||||
|
log.info('Created ElastiCache subnet group {0}'.format(name))
|
||||||
|
return True
|
||||||
|
except boto.exception.BotoServerError as e:
|
||||||
|
log.debug(e)
|
||||||
|
msg = 'Failed to create ElastiCache subnet group {0}'.format(name)
|
||||||
|
log.error(msg)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_cache_subnet_group(name, region=None, key=None, keyid=None,
|
def get_cache_subnet_group(name, region=None, key=None, keyid=None,
|
||||||
profile=None):
|
profile=None):
|
||||||
'''
|
'''
|
||||||
@ -359,6 +414,30 @@ def get_cache_subnet_group(name, region=None, key=None, keyid=None,
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def delete_subnet_group(name, region=None, key=None, keyid=None, profile=None):
|
||||||
|
'''
|
||||||
|
Delete an ElastiCache subnet group.
|
||||||
|
|
||||||
|
CLI example::
|
||||||
|
|
||||||
|
salt myminion boto_elasticache.delete_subnet_group my-subnet-group \
|
||||||
|
region=us-east-1
|
||||||
|
'''
|
||||||
|
conn = _get_conn(region, key, keyid, profile)
|
||||||
|
if not conn:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
conn.delete_cache_subnet_group(name)
|
||||||
|
msg = 'Deleted ElastiCache subnet group {0}.'.format(name)
|
||||||
|
log.info(msg)
|
||||||
|
return True
|
||||||
|
except boto.exception.BotoServerError as e:
|
||||||
|
log.debug(e)
|
||||||
|
msg = 'Failed to delete ElastiCache subnet group {0}'.format(name)
|
||||||
|
log.error(msg)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def create(name, num_cache_nodes=None, engine=None, cache_node_type=None,
|
def create(name, num_cache_nodes=None, engine=None, cache_node_type=None,
|
||||||
replication_group_id=None, engine_version=None,
|
replication_group_id=None, engine_version=None,
|
||||||
cache_parameter_group_name=None, cache_subnet_group_name=None,
|
cache_parameter_group_name=None, cache_subnet_group_name=None,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
'''
|
'''
|
||||||
Manage Elasticache
|
Manage Elasticache
|
||||||
|
==================
|
||||||
|
|
||||||
.. versionadded:: 2014.7.0
|
.. versionadded:: 2014.7.0
|
||||||
|
|
||||||
@ -247,13 +248,68 @@ def present(
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def absent(
|
def subnet_group_present(name, subnet_ids, description, tags=None, region=None,
|
||||||
name,
|
key=None, keyid=None, profile=None):
|
||||||
wait=True,
|
'''
|
||||||
region=None,
|
Ensure ElastiCache subnet group exists.
|
||||||
key=None,
|
|
||||||
keyid=None,
|
.. versionadded:: Beryllium
|
||||||
profile=None):
|
|
||||||
|
name
|
||||||
|
The name for the ElastiCache subnet group. This value is stored as a lowercase string.
|
||||||
|
|
||||||
|
subnet_ids
|
||||||
|
A list of VPC subnet IDs for the cache subnet group.
|
||||||
|
|
||||||
|
description
|
||||||
|
Subnet group description.
|
||||||
|
|
||||||
|
tags
|
||||||
|
A list of tags.
|
||||||
|
|
||||||
|
region
|
||||||
|
Region to connect to.
|
||||||
|
|
||||||
|
key
|
||||||
|
Secret key to be used.
|
||||||
|
|
||||||
|
keyid
|
||||||
|
Access key to be used.
|
||||||
|
|
||||||
|
profile
|
||||||
|
A dict with region, key and keyid, or a pillar key (string) that
|
||||||
|
contains a dict with region, key and keyid.
|
||||||
|
'''
|
||||||
|
ret = {'name': name,
|
||||||
|
'result': True,
|
||||||
|
'comment': '',
|
||||||
|
'changes': {}
|
||||||
|
}
|
||||||
|
|
||||||
|
exists = __salt__['boto_elasticache.subnet_group_exists'](name=name, tags=tags, region=region, key=key,
|
||||||
|
keyid=keyid, profile=profile)
|
||||||
|
if not exists:
|
||||||
|
if __opts__['test']:
|
||||||
|
ret['comment'] = 'Subnet group {0} is set to be created.'.format(name)
|
||||||
|
ret['result'] = None
|
||||||
|
return ret
|
||||||
|
created = __salt__['boto_elasticache.create_subnet_group'](name=name, subnet_ids=subnet_ids,
|
||||||
|
description=description, tags=tags,
|
||||||
|
region=region, key=key, keyid=keyid,
|
||||||
|
profile=profile)
|
||||||
|
if not created:
|
||||||
|
ret['result'] = False
|
||||||
|
ret['comment'] = 'Failed to create {0} subnet group.'.format(name)
|
||||||
|
return ret
|
||||||
|
ret['changes']['old'] = None
|
||||||
|
ret['changes']['new'] = name
|
||||||
|
ret['comment'] = 'Subnet group {0} created.'.format(name)
|
||||||
|
return ret
|
||||||
|
ret['comment'] = 'Subnet group present.'
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def absent(name, wait=True, region=None, key=None, keyid=None, profile=None):
|
||||||
'''
|
'''
|
||||||
Ensure the named elasticache cluster is deleted.
|
Ensure the named elasticache cluster is deleted.
|
||||||
|
|
||||||
@ -279,13 +335,11 @@ def absent(
|
|||||||
'''
|
'''
|
||||||
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
|
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
|
||||||
|
|
||||||
is_present = __salt__['boto_elasticache.exists'](name, region, key, keyid,
|
is_present = __salt__['boto_elasticache.exists'](name, region, key, keyid, profile)
|
||||||
profile)
|
|
||||||
|
|
||||||
if is_present:
|
if is_present:
|
||||||
if __opts__['test']:
|
if __opts__['test']:
|
||||||
ret['comment'] = 'Cache cluster {0} is set to be removed.'.format(
|
ret['comment'] = 'Cache cluster {0} is set to be removed.'.format(name)
|
||||||
name)
|
|
||||||
ret['result'] = None
|
ret['result'] = None
|
||||||
return ret
|
return ret
|
||||||
deleted = __salt__['boto_elasticache.delete'](name, wait, region, key,
|
deleted = __salt__['boto_elasticache.delete'](name, wait, region, key,
|
||||||
@ -298,17 +352,11 @@ def absent(
|
|||||||
ret['comment'] = 'Failed to delete {0} cache cluster.'.format(name)
|
ret['comment'] = 'Failed to delete {0} cache cluster.'.format(name)
|
||||||
else:
|
else:
|
||||||
ret['comment'] = '{0} does not exist in {1}.'.format(name, region)
|
ret['comment'] = '{0} does not exist in {1}.'.format(name, region)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def creategroup(name, primary_cluster_id, replication_group_description,
|
def creategroup(name, primary_cluster_id, replication_group_description, wait=None,
|
||||||
wait=None,
|
region=None, key=None, keyid=None, profile=None):
|
||||||
region=None,
|
|
||||||
key=None,
|
|
||||||
keyid=None,
|
|
||||||
profile=None):
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Ensure the a replication group is create.
|
Ensure the a replication group is create.
|
||||||
|
|
||||||
@ -346,19 +394,12 @@ def creategroup(name, primary_cluster_id, replication_group_description,
|
|||||||
ret['comment'] = 'Replication {0} is set to be created.'.format(
|
ret['comment'] = 'Replication {0} is set to be created.'.format(
|
||||||
name)
|
name)
|
||||||
ret['result'] = None
|
ret['result'] = None
|
||||||
created = __salt__['boto_elasticache.create_replication_group'](name,
|
created = __salt__['boto_elasticache.create_replication_group'](name, primary_cluster_id,
|
||||||
primary_cluster_id,
|
|
||||||
replication_group_description,
|
replication_group_description,
|
||||||
wait,
|
wait, region, key, keyid, profile)
|
||||||
region,
|
|
||||||
key,
|
|
||||||
keyid,
|
|
||||||
profile
|
|
||||||
)
|
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
config = __salt__['boto_elasticache.describe_replication_group'](name, region, key,
|
config = __salt__['boto_elasticache.describe_replication_group'](name, region, key, keyid, profile)
|
||||||
keyid, profile)
|
|
||||||
ret['changes']['old'] = None
|
ret['changes']['old'] = None
|
||||||
ret['changes']['new'] = config
|
ret['changes']['new'] = config
|
||||||
ret['result'] = True
|
ret['result'] = True
|
||||||
@ -368,5 +409,33 @@ def creategroup(name, primary_cluster_id, replication_group_description,
|
|||||||
else:
|
else:
|
||||||
ret['comment'] = '{0} replication group exists .'.format(name)
|
ret['comment'] = '{0} replication group exists .'.format(name)
|
||||||
ret['result'] = True
|
ret['result'] = True
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def subnet_group_absent(name, tags=None, region=None, key=None, keyid=None, profile=None):
|
||||||
|
ret = {'name': name,
|
||||||
|
'result': True,
|
||||||
|
'comment': '',
|
||||||
|
'changes': {}
|
||||||
|
}
|
||||||
|
|
||||||
|
exists = __salt__['boto_elasticache.subnet_group_exists'](name=name, tags=tags, region=region, key=key,
|
||||||
|
keyid=keyid, profile=profile)
|
||||||
|
if not exists:
|
||||||
|
ret['result'] = True
|
||||||
|
ret['comment'] = '{0} ElastiCache subnet group does not exist.'.format(name)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
if __opts__['test']:
|
||||||
|
ret['comment'] = 'ElastiCache subnet group {0} is set to be removed.'.format(name)
|
||||||
|
ret['result'] = None
|
||||||
|
return ret
|
||||||
|
deleted = __salt__['boto_elasticache.delete_subnet_group'](name, region, key, keyid, profile)
|
||||||
|
if not deleted:
|
||||||
|
ret['result'] = False
|
||||||
|
ret['comment'] = 'Failed to delete {0} ElastiCache subnet group.'.format(name)
|
||||||
|
return ret
|
||||||
|
ret['changes']['old'] = name
|
||||||
|
ret['changes']['new'] = None
|
||||||
|
ret['comment'] = 'ElastiCache subnet group {0} deleted.'.format(name)
|
||||||
return ret
|
return ret
|
||||||
|
Loading…
Reference in New Issue
Block a user