Merge pull request #25319 from ruzarowski/2015.8-Move-SourceDestCheck-logic-to-_update_enis-to-make-it-work-with-prealloc-enis

[cloud:EC2] Move SourceDest logic to _update_enis and add  alias for delete_interface_on_terminate
This commit is contained in:
Mike Place 2015-07-13 15:19:18 -06:00
commit 88f4e68622

View File

@ -1204,9 +1204,6 @@ def _create_eni_if_necessary(interface):
) )
) )
if 'SourceDestCheck' in interface:
_modify_interface_source_dest_check(eni_id, interface['SourceDestCheck'])
associate_public_ip = interface.get('AssociatePublicIpAddress', False) associate_public_ip = interface.get('AssociatePublicIpAddress', False)
if type(associate_public_ip) is str: if type(associate_public_ip) is str:
# Assume id of EIP as value # Assume id of EIP as value
@ -1266,14 +1263,20 @@ def _list_interface_private_addresses(eni_desc):
return addresses return addresses
def _modify_interface_source_dest_check(eni_id, source_dest_check=True): def _modify_eni_properties(eni_id, properties=None):
''' '''
Change the state of SourceDestCheck Flag in the interface Change properties of the interface
with id eni_id to the value of source_dest_check with id eni_id to the values in properties dict
''' '''
if type(properties) is not dict:
raise SaltCloudException(
'ENI properties must be a dictionary'
)
params = {'Action': 'ModifyNetworkInterfaceAttribute', params = {'Action': 'ModifyNetworkInterfaceAttribute',
'NetworkInterfaceId': eni_id, 'NetworkInterfaceId': eni_id}
'SourceDestCheck.Value': source_dest_check} for k, v in properties.iteritems():
params[k] = v
retries = 5 retries = 5
while retries > 0: while retries > 0:
@ -1284,12 +1287,12 @@ def _modify_interface_source_dest_check(eni_id, source_dest_check=True):
time.sleep(1) time.sleep(1)
continue continue
return None return result
raise SaltCloudException( raise SaltCloudException(
'Could not change SourceDestCheck attribute ' 'Could not change interface <{0}> attributes '
'interface=<{0}> SourceDestCheck=<{1}>'.format( '<{1!r}> after 5 retries'.format(
eni_id, source_dest_check eni_id, properties
) )
) )
@ -1363,16 +1366,19 @@ def _update_enis(interfaces, instance):
instance_enis.append((query_enis['networkInterfaceId'], query_enis['attachment'])) instance_enis.append((query_enis['networkInterfaceId'], query_enis['attachment']))
for eni_id, eni_data in instance_enis: for eni_id, eni_data in instance_enis:
params = {'Action': 'ModifyNetworkInterfaceAttribute', delete_on_terminate = True
'NetworkInterfaceId': eni_id, if 'DeleteOnTermination' in config_enis[eni_data['deviceIndex']]:
'Attachment.AttachmentId': eni_data['attachmentId'], delete_on_terminate = config_enis[eni_data['deviceIndex']]['DeleteOnTermination']
'Attachment.DeleteOnTermination': config_enis[eni_data['deviceIndex']].setdefault('delete_interface_on_terminate', True)} elif 'delete_interface_on_terminate' in config_enis[eni_data['deviceIndex']]:
set_eni_attributes = aws.query(params, delete_on_terminate = config_enis[eni_data['deviceIndex']]['delete_interface_on_terminate']
return_root=True,
location=get_location(), params_attachment = {'Attachment.AttachmentId': eni_data['attachmentId'],
provider=get_provider(), 'Attachment.DeleteOnTermination': delete_on_terminate}
opts=__opts__, set_eni_attachment_attributes = _modify_eni_properties(eni_id, params_attachment)
sigver='4')
if 'SourceDestCheck' in config_enis[eni_data['deviceIndex']]:
params_sourcedest = {'SourceDestCheck.Value': config_enis[eni_data['deviceIndex']]['SourceDestCheck']}
set_eni_sourcedest_property = _modify_eni_properties(eni_id, params_sourcedest)
return None return None