Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elbv2 boto3 client - implement new api for ip address type #310

Merged
merged 6 commits into from
Apr 19, 2021
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions plugins/module_utils/elbv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ def __init__(self, connection, module):
if self.elb is not None:
self.elb_attributes = self.get_elb_attributes()
self.elb['tags'] = self.get_elb_tags()
self.elb_ip_addr_type = self.get_elb_ip_address_type()
else:
self.elb_attributes = None
self.elb_ip_addr_type = None

def wait_for_status(self, elb_arn):
"""
Expand Down Expand Up @@ -107,6 +109,15 @@ def get_elb_attributes(self):
# Replace '.' with '_' in attribute key names to make it more Ansibley
return dict((k.replace('.', '_'), v) for k, v in elb_attributes.items())

def get_elb_ip_address_type(self):
"""
Retrieve load balancer ip address type using describe_load_balancers

:return:
"""

return self.elb.get('IpAddressType', None)

def update_elb_attributes(self):
"""
Update the elb_attributes parameter
Expand Down Expand Up @@ -232,6 +243,21 @@ def update(self):
self.elb = get_elb(self.connection, self.module, self.module.params.get("name"))
self.elb['tags'] = self.get_elb_tags()

def modify_ip_address_type(self, ip_addr_type):
"""
Modify ELB ip address type
:return:
"""
if self.elb_ip_addr_type != ip_addr_type:
try:
AWSRetry.jittered_backoff()(
self.connection.set_ip_address_type
)(LoadBalancerArn=self.elb['LoadBalancerArn'], IpAddressType=ip_addr_type)
except (BotoCoreError, ClientError) as e:
self.module.fail_json_aws(e)

self.changed = True


class ApplicationLoadBalancer(ElasticLoadBalancerV2):

Expand Down