Skip to content

Commit

Permalink
module_utils.direct_connect - Add minimal AWSRetry decorator to clien…
Browse files Browse the repository at this point in the history
…t calls (#139)
  • Loading branch information
tremble authored Aug 26, 2020
1 parent d3eaef3 commit 0e92411
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions plugins/module_utils/direct_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from .ec2 import AWSRetry


class DirectConnectError(Exception):
def __init__(self, msg, last_traceback=None, exception=None):
Expand All @@ -51,7 +53,7 @@ def __init__(self, msg, last_traceback=None, exception=None):

def delete_connection(client, connection_id):
try:
client.delete_connection(connectionId=connection_id)
AWSRetry.jittered_backoff()(client.delete_connection)(connectionId=connection_id)
except botocore.exceptions.ClientError as e:
raise DirectConnectError(msg="Failed to delete DirectConnection {0}.".format(connection_id),
last_traceback=traceback.format_exc(),
Expand All @@ -60,8 +62,8 @@ def delete_connection(client, connection_id):

def associate_connection_and_lag(client, connection_id, lag_id):
try:
client.associate_connection_with_lag(connectionId=connection_id,
lagId=lag_id)
AWSRetry.jittered_backoff()(client.associate_connection_with_lag)(connectionId=connection_id,
lagId=lag_id)
except botocore.exceptions.ClientError as e:
raise DirectConnectError(msg="Failed to associate Direct Connect connection {0}"
" with link aggregation group {1}.".format(connection_id, lag_id),
Expand All @@ -71,8 +73,8 @@ def associate_connection_and_lag(client, connection_id, lag_id):

def disassociate_connection_and_lag(client, connection_id, lag_id):
try:
client.disassociate_connection_from_lag(connectionId=connection_id,
lagId=lag_id)
AWSRetry.jittered_backoff()(client.disassociate_connection_from_lag)(connectionId=connection_id,
lagId=lag_id)
except botocore.exceptions.ClientError as e:
raise DirectConnectError(msg="Failed to disassociate Direct Connect connection {0}"
" from link aggregation group {1}.".format(connection_id, lag_id),
Expand All @@ -82,7 +84,7 @@ def disassociate_connection_and_lag(client, connection_id, lag_id):

def delete_virtual_interface(client, virtual_interface):
try:
client.delete_virtual_interface(virtualInterfaceId=virtual_interface)
AWSRetry.jittered_backoff()(client.delete_virtual_interface)(virtualInterfaceId=virtual_interface)
except botocore.exceptions.ClientError as e:
raise DirectConnectError(msg="Could not delete virtual interface {0}".format(virtual_interface),
last_traceback=traceback.format_exc(),
Expand Down

0 comments on commit 0e92411

Please sign in to comment.