added update_and_create_tags() to autoscale groups
This commit is contained in:
parent
0efea0af2b
commit
1d2042876e
3 changed files with 102 additions and 6 deletions
|
|
@ -441,12 +441,25 @@ class AutoScalingBackend(BaseBackend):
|
|||
self.elb_backend.deregister_instances(elb.name, elb_instace_ids - group_instance_ids)
|
||||
|
||||
def create_or_update_tags(self, tags):
|
||||
|
||||
for tag in tags:
|
||||
group_name = tag["ResourceId"]
|
||||
group_name = tag["resource_id"]
|
||||
group = self.autoscaling_groups[group_name]
|
||||
updated_tags = group.tags.copy()
|
||||
updated_tags.update(tag)
|
||||
group.tags = updated_tags
|
||||
old_tags = group.tags
|
||||
|
||||
new_tags = []
|
||||
#if key was in old_tags, update old tag
|
||||
for old_tag in old_tags:
|
||||
if old_tag["key"] == tag["key"]:
|
||||
new_tags.append(tag)
|
||||
else:
|
||||
new_tags.append(old_tag)
|
||||
|
||||
#if key was never in old_tag's add it (create tag)
|
||||
if not any(new_tag['key'] == tag['key'] for new_tag in new_tags):
|
||||
new_tags.append(tag)
|
||||
|
||||
group.tags = new_tags
|
||||
|
||||
autoscaling_backends = {}
|
||||
for region, ec2_backend in ec2_backends.items():
|
||||
|
|
|
|||
|
|
@ -106,9 +106,11 @@ class AutoScalingResponse(BaseResponse):
|
|||
return template.render()
|
||||
|
||||
def create_or_update_tags(self):
|
||||
tags = self._get_param('Tags')
|
||||
tags = self._get_list_prefix('Tags.member')
|
||||
|
||||
self.autoscaling_backend.create_or_update_tags(tags)
|
||||
return None
|
||||
template = self.response_template(UPDATE_AUTOSCALING_GROUP_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
def describe_auto_scaling_instances(self):
|
||||
instance_states = self.autoscaling_backend.describe_autoscaling_instances()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue