Skip to content

Commit

Permalink
Add utils for ec2_placement_group (#2322)
Browse files Browse the repository at this point in the history
SUMMARY


This PR adds utils for ec2_placement_group
ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Bikouo Aubin
Reviewed-by: Alina Buzachis
  • Loading branch information
GomathiselviS authored Oct 11, 2024
1 parent 6177d1a commit 04a2ffb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/add_utils_ec2_placement_group.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- module_utils/ec2 - add utils for the ec2_placement_group* modules (https://github.com/ansible-collections/amazon.aws/pull/2322).
30 changes: 30 additions & 0 deletions plugins/module_utils/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,36 @@ def replace_network_acl_association(client, network_acl_id: str, association_id:
]


# EC2 Placement Group
class EC2PlacementGroupErrorHandler(AWSErrorHandler):
_CUSTOM_EXCEPTION = AnsibleEC2Error

@classmethod
def _is_missing(cls):
return is_boto3_error_code("InvalidPlacementGroup.Unknown")


@EC2PlacementGroupErrorHandler.list_error_handler("describe placement group", [])
@AWSRetry.jittered_backoff()
def describe_ec2_placement_groups(
client, **params: Dict[str, Union[List[str], int, List[Dict[str, Union[str, List[str]]]]]]
) -> List[Dict[str, Any]]:
return client.describe_placement_groups(**params)["PlacementGroups"]


@EC2PlacementGroupErrorHandler.deletion_error_handler("delete placement group")
@AWSRetry.jittered_backoff()
def delete_ec2_placement_group(client, group_name: str) -> bool:
client.delete_placement_group(GroupName=group_name)
return True


@EC2PlacementGroupErrorHandler.common_error_handler("create placement group")
@AWSRetry.jittered_backoff()
def create_ec2_placement_group(client, **params: Dict[str, Union[str, EC2TagSpecifications]]) -> Dict[str, Any]:
return client.create_placement_group(**params)["PlacementGroup"]


def get_ec2_security_group_ids_from_names(sec_group_list, ec2_connection, vpc_id=None, boto3=None):
"""Return list of security group IDs from security group names. Note that security group names are not unique
across VPCs. If a name exists across multiple VPCs and no VPC ID is supplied, all matching IDs will be returned. This
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
time=10m

cloud/aws
# This test will be replaced by the target in community.aws after migration
disabled

ec2_instance_info
ec2_instance

0 comments on commit 04a2ffb

Please sign in to comment.