Merge pull request #25315 from ruzarowski/2015.8-EC2-ENI-Move-handling-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
This commit is contained in:
Nicole Thomas 2015-07-13 08:38:47 -06:00
commit 0a0f8b0cf0

View File

@ -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,
@ -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'):