add the ability to set default ASG scaling policies and notification policies in a pillar. Small bugfix for the dynamo module

This commit is contained in:
Mike Demmitt 2015-03-12 11:45:20 -07:00
parent 396e8a5938
commit 78aacdb5d7
3 changed files with 91 additions and 9 deletions

View File

@ -163,8 +163,9 @@ def create(name, launch_config_name, availability_zones, min_size, max_size,
health_check_type=None, health_check_period=None, health_check_type=None, health_check_period=None,
placement_group=None, vpc_zone_identifier=None, tags=None, placement_group=None, vpc_zone_identifier=None, tags=None,
termination_policies=None, suspended_processes=None, termination_policies=None, suspended_processes=None,
scaling_policies=None, region=None, key=None, keyid=None, scaling_policies=None, region=None,
profile=None): notification_arn=None, notification_types=None,
key=None, keyid=None, profile=None):
''' '''
Create an autoscale group. Create an autoscale group.
@ -221,6 +222,9 @@ def create(name, launch_config_name, availability_zones, min_size, max_size,
conn.create_auto_scaling_group(_asg) conn.create_auto_scaling_group(_asg)
# create scaling policies # create scaling policies
_create_scaling_policies(conn, name, scaling_policies) _create_scaling_policies(conn, name, scaling_policies)
# create notifications
if notification_arn and notification_types:
conn.put_notification_configuration(_asg, notification_arn, notification_types)
log.info('Created ASG {0}'.format(name)) log.info('Created ASG {0}'.format(name))
return True return True
except boto.exception.BotoServerError as e: except boto.exception.BotoServerError as e:
@ -236,8 +240,8 @@ def update(name, launch_config_name, availability_zones, min_size, max_size,
placement_group=None, vpc_zone_identifier=None, tags=None, placement_group=None, vpc_zone_identifier=None, tags=None,
termination_policies=None, suspended_processes=None, termination_policies=None, suspended_processes=None,
scaling_policies=None, scaling_policies=None,
region=None, key=None, keyid=None, notification_arn=None, notification_types=None,
profile=None): region=None, key=None, keyid=None, profile=None):
''' '''
Update an autoscale group. Update an autoscale group.
@ -292,6 +296,8 @@ def update(name, launch_config_name, availability_zones, min_size, max_size,
placement_group=placement_group, tags=_tags, placement_group=placement_group, tags=_tags,
vpc_zone_identifier=vpc_zone_identifier, vpc_zone_identifier=vpc_zone_identifier,
termination_policies=termination_policies) termination_policies=termination_policies)
if notification_arn and notification_types:
conn.put_notification_configuration(_asg, notification_arn, notification_types)
_asg.update() _asg.update()
# Seems the update call doesn't handle tags, so we'll need to update # Seems the update call doesn't handle tags, so we'll need to update
# that separately. # that separately.

View File

@ -142,11 +142,11 @@ def create_table(table_name, region=None, key=None, keyid=None, profile=None,
'write': write_capacity_units 'write': write_capacity_units
} }
local_table_indexes = [] local_table_indexes = []
# Add the table's key
local_table_indexes.append(
AllIndex(primary_index_name, parts=primary_index_fields)
)
if local_indexes: if local_indexes:
# Add the table's key
local_table_indexes.append(
AllIndex(primary_index_name, parts=primary_index_fields)
)
for index in local_indexes: for index in local_indexes:
local_table_indexes.append(_extract_index(index)) local_table_indexes.append(_extract_index(index))
global_table_indexes = [] global_table_indexes = []

View File

@ -229,12 +229,17 @@ def present(
termination_policies=None, termination_policies=None,
suspended_processes=None, suspended_processes=None,
scaling_policies=None, scaling_policies=None,
scaling_policies_from_pillar="boto_asg_scaling_policies",
alarms=None, alarms=None,
alarms_from_pillar='boto_asg_alarms', alarms_from_pillar='boto_asg_alarms',
region=None, region=None,
key=None, key=None,
keyid=None, keyid=None,
profile=None): profile=None
notification_arn=None,
notification_arn_from_pillar="boto_asg_notification_arn",
notification_types=None,
notification_types_from_pillar="boto_asg_notification_types"):
''' '''
Ensure the autoscale group exists. Ensure the autoscale group exists.
@ -309,6 +314,10 @@ def present(
List of scaling policies. Each policy is a dict of key-values described by List of scaling policies. Each policy is a dict of key-values described by
http://boto.readthedocs.org/en/latest/ref/autoscale.html#boto.ec2.autoscale.policy.ScalingPolicy http://boto.readthedocs.org/en/latest/ref/autoscale.html#boto.ec2.autoscale.policy.ScalingPolicy
scaling_policies_from_pillar:
name of pillar dict that contains scaling policy settings. Scaling policies defined for
this specific state will override those from pillar.
alarms: alarms:
a dictionary of name->boto_cloudwatch_alarm sections to be associated with this ASG. a dictionary of name->boto_cloudwatch_alarm sections to be associated with this ASG.
All attributes should be specified except for dimension which will be All attributes should be specified except for dimension which will be
@ -331,6 +340,26 @@ def present(
profile profile
A dict with region, key and keyid, or a pillar key (string) A dict with region, key and keyid, or a pillar key (string)
that contains a dict with region, key and keyid. that contains a dict with region, key and keyid.
notification_arn
The aws arn that notifications will be sent to
notification_arn_from_pillar
name of the pillar dict that contains notifcation_arn settings. A notification_arn
defined for this specific state will override the one from pillar.
notification_types
A list of event names that will trigger a notification. The list of valid
notification types is:
"autoscaling:EC2_INSTANCE_LAUNCH",
"autoscaling:EC2_INSTANCE_LAUNCH_ERROR",
"autoscaling:EC2_INSTANCE_TERMINATE",
"autoscaling:EC2_INSTANCE_TERMINATE_ERROR",
"autoscaling:TEST_NOTIFICATION"
notification_types_from_pillar
name of the pillar dict that contains notifcation_types settings. Notification_types
defined for this specific state will override those from the pillar.
''' '''
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
if vpc_zone_identifier: if vpc_zone_identifier:
@ -392,6 +421,16 @@ def present(
ret['comment'] = msg ret['comment'] = msg
ret['result'] = None ret['result'] = None
return ret return ret
notification_arn, notification_types = _determine_notification_info(
notification_arn,
notification_arn_from_pillar,
notification_types,
notification_types_from_pillar
)
scaling_policies = _determine_scaling_policies(
scaling_policies,
scaling_policies_from_pillar
)
created = __salt__['boto_asg.create'](name, launch_config_name, created = __salt__['boto_asg.create'](name, launch_config_name,
availability_zones, min_size, availability_zones, min_size,
max_size, desired_capacity, max_size, desired_capacity,
@ -403,6 +442,7 @@ def present(
termination_policies, termination_policies,
suspended_processes, suspended_processes,
scaling_policies, region, scaling_policies, region,
notification_arn, notification_types,
key, keyid, profile) key, keyid, profile)
if created: if created:
ret['changes']['old'] = None ret['changes']['old'] = None
@ -461,6 +501,17 @@ def present(
ret['comment'] = msg ret['comment'] = msg
ret['result'] = None ret['result'] = None
return ret return ret
# add in alarms
notification_arn, notification_types = _determine_notification_info(
notification_arn,
notification_arn_from_pillar,
notification_types,
notification_types_from_pillar
)
scaling_policies = _determine_scaling_policies(
scaling_policies,
scaling_policies_from_pillar
)
updated, msg = __salt__['boto_asg.update'](name, launch_config_name, updated, msg = __salt__['boto_asg.update'](name, launch_config_name,
availability_zones, min_size, availability_zones, min_size,
max_size, desired_capacity, max_size, desired_capacity,
@ -473,6 +524,7 @@ def present(
termination_policies, termination_policies,
suspended_processes, suspended_processes,
scaling_policies, region, scaling_policies, region,
notification_arn, notification_types,
key, keyid, profile) key, keyid, profile)
if asg['launch_config_name'] != launch_config_name: if asg['launch_config_name'] != launch_config_name:
# delete the old launch_config_name # delete the old launch_config_name
@ -499,6 +551,30 @@ def present(
return ret return ret
def _determine_scaling_policies(scaling_policies, scaling_policies_from_pillar):
'''helper method for present. ensure that scaling_policies are set'''
pillar_scaling_policies = __salt__['config.option'](scaling_policies_from_pillar, {})
if not scaling_policies and len(pillar_scaling_policies) > 0:
scaling_policies = pillar_scaling_policies
return scaling_policies
def _determine_notification_info(
notification_arn,
notification_arn_from_pillar,
notification_types,
notification_types_from_pillar):
'''helper method for present. ensure that notification_configs are set'''
pillar_arn_list = __salt__['config.option'](notification_arn_from_pillar, {})
pillar_arn = None
if len(pillar_arn_list) > 0:
pillar_arn = pillar_arn_list[0]
pillar_notification_types = __salt__['config.option'](notification_types_from_pillar, {})
arn = notification_arn if notification_arn else pillar_arn
types = notification_types if notification_types else pillar_notification_types
return (arn, types)
def _alarms_present(name, alarms, alarms_from_pillar, region, key, keyid, profile): def _alarms_present(name, alarms, alarms_from_pillar, region, key, keyid, profile):
'''helper method for present. ensure that cloudwatch_alarms are set''' '''helper method for present. ensure that cloudwatch_alarms are set'''
# load data from alarms_from_pillar # load data from alarms_from_pillar