Skip to content

Commit

Permalink
Add utils for ec_vpc_peer* modules
Browse files Browse the repository at this point in the history
Signed-off-by: Alina Buzachis <[email protected]>
  • Loading branch information
alinabuzachis committed Sep 25, 2024
1 parent 8592624 commit 3565890
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/20240924-ec2-utils.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_vpc_peer* modules (https://github.com/ansible-collections/amazon.aws/pull/2303).
47 changes: 47 additions & 0 deletions plugins/module_utils/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,53 @@ def disassociate_vpc_cidr_block(client, association_id: str) -> Dict[str, Any]:
return client.disassociate_vpc_cidr_block(AssociationId=association_id)


# EC2 VPC Peering Connection
class EC2VpcPeeringErrorHandler(AWSErrorHandler):
_CUSTOM_EXCEPTION = AnsibleEC2Error

@classmethod
def _is_missing(cls):
return is_boto3_error_code("InvalidVpcPeeringConnectionID.NotFound", "InvalidVpcPeeringConnectionId.Malformed")


@EC2VpcPeeringErrorHandler.list_error_handler("describe vpc peering", [])
@AWSRetry.jittered_backoff()
def describe_vpc_peering_connections(client, **params: Dict[str, Any]) -> List[Dict[str, Any]]:
result = client.describe_vpc_peering_connections(
**params,
)
return result


@EC2VpcSubnetErrorHandler.common_error_handler("create vpc peering")
@AWSRetry.jittered_backoff()
def create_vpc_peering_connection(
client, **params: Dict[str, Union[str, bool, int, EC2TagSpecifications]]
) -> Dict[str, Any]:
return client.create_vpc_peering_connection(**params)["VpcPeeringConnection"]


@EC2VpcSubnetErrorHandler.deletion_error_handler("delete vpc peering")
@AWSRetry.jittered_backoff()
def delete_vpc_peering_connection(client, peering_id: str) -> bool:
client.delete_vpc_peering_connection(VpcPeeringConnectionId=peering_id)
return True


@EC2VpcSubnetErrorHandler.deletion_error_handler("accept vpc peering")
@AWSRetry.jittered_backoff()
def accept_vpc_peering_connection(client, peering_id: str) -> bool:
client.accept_vpc_peering_connection(VpcPeeringConnectionId=peering_id)
return True


@EC2VpcSubnetErrorHandler.deletion_error_handler("reject vpc peering")
@AWSRetry.jittered_backoff()
def reject_vpc_peering_connection(client, peering_id: str) -> bool:
client.reject_vpc_peering_connection(VpcPeeringConnectionId=peering_id)
return True


# EC2 Internet Gateway
class EC2InternetGatewayErrorHandler(AWSErrorHandler):
_CUSTOM_EXCEPTION = AnsibleEC2Error
Expand Down

0 comments on commit 3565890

Please sign in to comment.