Skip to content

Commit

Permalink
Merge pull request #25315 from ruzarowski/2015.8-EC2-ENI-Move-handlin…
Browse files Browse the repository at this point in the history
…g-of-AssociatePublicIpAddress-to-associate_eip-allocate_new_eip-logic

[cloud:EC2] Move handling of AssociatePublicIpAddress to associate_eip/allocate_new_eip logic depending on value type
  • Loading branch information
Nicole Thomas committed Jul 13, 2015
2 parents e5d7ba0 + 2506585 commit 0a0f8b0
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions salt/cloud/clouds/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,15 +1184,6 @@ def _create_eni_if_necessary(interface):
if k in interface:
params.update(_param_from_config(k, interface[k]))

if 'AssociatePublicIpAddress' in interface:
# Associating a public address in a VPC only works when the interface is not
# created beforehand, but as a part of the machine creation request.
for k in ('DeviceIndex', 'AssociatePublicIpAddress', 'NetworkInterfaceId'):
if k in interface:
params[k] = interface[k]
params['DeleteOnTermination'] = interface.get('delete_interface_on_terminate', True)
return params

params['Action'] = 'CreateNetworkInterface'

result = aws.query(params,
Expand All @@ -1216,9 +1207,13 @@ def _create_eni_if_necessary(interface):
if 'SourceDestCheck' in interface:
_modify_interface_source_dest_check(eni_id, interface['SourceDestCheck'])

if interface.get('associate_eip'):
associate_public_ip = interface.get('AssociatePublicIpAddress', False)
if type(associate_public_ip) is str:
# Assume id of EIP as value
_associate_eip_with_interface(eni_id, associate_public_ip)
elif interface.get('associate_eip'):
_associate_eip_with_interface(eni_id, interface.get('associate_eip'))
elif interface.get('allocate_new_eip'):
elif interface.get('allocate_new_eip') or associate_public_ip:
_new_eip = _request_eip(interface)
_associate_eip_with_interface(eni_id, _new_eip)
elif interface.get('allocate_new_eips'):
Expand Down

0 comments on commit 0a0f8b0

Please sign in to comment.