Add autoscaling delete_tags (#4122)
This commit is contained in:
parent
911d29cc33
commit
9bd38f8480
@ -908,7 +908,7 @@
|
|||||||
- [ ] delete_notification_configuration
|
- [ ] delete_notification_configuration
|
||||||
- [X] delete_policy
|
- [X] delete_policy
|
||||||
- [ ] delete_scheduled_action
|
- [ ] delete_scheduled_action
|
||||||
- [ ] delete_tags
|
- [X] delete_tags
|
||||||
- [ ] delete_warm_pool
|
- [ ] delete_warm_pool
|
||||||
- [ ] describe_account_limits
|
- [ ] describe_account_limits
|
||||||
- [ ] describe_adjustment_types
|
- [ ] describe_adjustment_types
|
||||||
|
@ -992,6 +992,14 @@ class AutoScalingBackend(BaseBackend):
|
|||||||
|
|
||||||
group.tags = new_tags
|
group.tags = new_tags
|
||||||
|
|
||||||
|
def delete_tags(self, tags):
|
||||||
|
for tag_to_delete in tags:
|
||||||
|
group_name = tag_to_delete["resource_id"]
|
||||||
|
key_to_delete = tag_to_delete["key"]
|
||||||
|
group = self.autoscaling_groups[group_name]
|
||||||
|
old_tags = group.tags
|
||||||
|
group.tags = [x for x in old_tags if x["key"] != key_to_delete]
|
||||||
|
|
||||||
def attach_load_balancers(self, group_name, load_balancer_names):
|
def attach_load_balancers(self, group_name, load_balancer_names):
|
||||||
group = self.autoscaling_groups[group_name]
|
group = self.autoscaling_groups[group_name]
|
||||||
group.load_balancers.extend(
|
group.load_balancers.extend(
|
||||||
|
@ -233,6 +233,13 @@ class AutoScalingResponse(BaseResponse):
|
|||||||
template = self.response_template(UPDATE_AUTOSCALING_GROUP_TEMPLATE)
|
template = self.response_template(UPDATE_AUTOSCALING_GROUP_TEMPLATE)
|
||||||
return template.render()
|
return template.render()
|
||||||
|
|
||||||
|
def delete_tags(self):
|
||||||
|
tags = self._get_list_prefix("Tags.member")
|
||||||
|
|
||||||
|
self.autoscaling_backend.delete_tags(tags)
|
||||||
|
template = self.response_template(UPDATE_AUTOSCALING_GROUP_TEMPLATE)
|
||||||
|
return template.render()
|
||||||
|
|
||||||
def describe_auto_scaling_instances(self):
|
def describe_auto_scaling_instances(self):
|
||||||
instance_states = self.autoscaling_backend.describe_auto_scaling_instances(
|
instance_states = self.autoscaling_backend.describe_auto_scaling_instances(
|
||||||
instance_ids=self._get_multi_param("InstanceIds.member")
|
instance_ids=self._get_multi_param("InstanceIds.member")
|
||||||
|
@ -2640,3 +2640,55 @@ def test_terminate_instance_in_auto_scaling_group_no_decrement():
|
|||||||
original_instance_id.shouldnt.be.within(
|
original_instance_id.shouldnt.be.within(
|
||||||
[x["InstanceId"] for x in response["LoadBalancerDescriptions"][0]["Instances"]]
|
[x["InstanceId"] for x in response["LoadBalancerDescriptions"][0]["Instances"]]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_autoscaling
|
||||||
|
@mock_ec2
|
||||||
|
def test_delete_tags_by_key():
|
||||||
|
mocked_networking = setup_networking()
|
||||||
|
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||||
|
client.create_launch_configuration(
|
||||||
|
LaunchConfigurationName="TestLC",
|
||||||
|
ImageId=EXAMPLE_AMI_ID,
|
||||||
|
InstanceType="t2.medium",
|
||||||
|
)
|
||||||
|
tag_to_delete = {
|
||||||
|
"ResourceId": "tag_test_asg",
|
||||||
|
"ResourceType": "auto-scaling-group",
|
||||||
|
"PropagateAtLaunch": True,
|
||||||
|
"Key": "TestDeleteTagKey1",
|
||||||
|
"Value": "TestTagValue1",
|
||||||
|
}
|
||||||
|
tag_to_keep = {
|
||||||
|
"ResourceId": "tag_test_asg",
|
||||||
|
"ResourceType": "auto-scaling-group",
|
||||||
|
"PropagateAtLaunch": True,
|
||||||
|
"Key": "TestTagKey1",
|
||||||
|
"Value": "TestTagValue1",
|
||||||
|
}
|
||||||
|
client.create_auto_scaling_group(
|
||||||
|
AutoScalingGroupName="tag_test_asg",
|
||||||
|
MinSize=1,
|
||||||
|
MaxSize=2,
|
||||||
|
LaunchConfigurationName="TestLC",
|
||||||
|
Tags=[tag_to_delete, tag_to_keep],
|
||||||
|
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||||
|
)
|
||||||
|
|
||||||
|
client.delete_tags(
|
||||||
|
Tags=[
|
||||||
|
{
|
||||||
|
"ResourceId": "tag_test_asg",
|
||||||
|
"ResourceType": "auto-scaling-group",
|
||||||
|
"PropagateAtLaunch": True,
|
||||||
|
"Key": "TestDeleteTagKey1",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
response = client.describe_auto_scaling_groups(
|
||||||
|
AutoScalingGroupNames=["tag_test_asg"]
|
||||||
|
)
|
||||||
|
group = response["AutoScalingGroups"][0]
|
||||||
|
tags = group["Tags"]
|
||||||
|
tags.should.contain(tag_to_keep)
|
||||||
|
tags.should_not.contain(tag_to_delete)
|
||||||
|
Loading…
Reference in New Issue
Block a user