Skip to content

Commit

Permalink
Merge pull request #30036 from rallytime/bp-29995
Browse files Browse the repository at this point in the history
Back-port #29995 to 2015.8
  • Loading branch information
Mike Place committed Dec 28, 2015
2 parents 27b0bd2 + 129a6d7 commit c846e7b
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions salt/cloud/clouds/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,15 +1209,15 @@ def block_device_mappings(vm_):
)


def _request_eip(interface):
def _request_eip(interface, vm_):
'''
Request and return Elastic IP
'''
params = {'Action': 'AllocateAddress'}
params['Domain'] = interface.setdefault('domain', 'vpc')
eips = aws.query(params,
return_root=True,
location=get_location(),
location=get_location(vm_),
provider=get_provider(),
opts=__opts__,
sigver='4')
Expand All @@ -1227,7 +1227,7 @@ def _request_eip(interface):
return None


def _create_eni_if_necessary(interface):
def _create_eni_if_necessary(interface, vm_):
'''
Create an Elastic Interface if necessary and return a Network Interface Specification
'''
Expand All @@ -1238,7 +1238,7 @@ def _create_eni_if_necessary(interface):
params = {'Action': 'DescribeSubnets'}
subnet_query = aws.query(params,
return_root=True,
location=get_location(),
location=get_location(vm_),
provider=get_provider(),
opts=__opts__,
sigver='4')
Expand Down Expand Up @@ -1276,7 +1276,7 @@ def _create_eni_if_necessary(interface):

result = aws.query(params,
return_root=True,
location=get_location(),
location=get_location(vm_),
provider=get_provider(),
opts=__opts__,
sigver='4')
Expand All @@ -1295,20 +1295,20 @@ def _create_eni_if_necessary(interface):
associate_public_ip = interface.get('AssociatePublicIpAddress', False)
if isinstance(associate_public_ip, str):
# Assume id of EIP as value
_associate_eip_with_interface(eni_id, associate_public_ip)
_associate_eip_with_interface(eni_id, associate_public_ip, vm_=vm_)

if interface.get('associate_eip'):
_associate_eip_with_interface(eni_id, interface.get('associate_eip'))
_associate_eip_with_interface(eni_id, interface.get('associate_eip'), vm_=vm_)
elif interface.get('allocate_new_eip'):
_new_eip = _request_eip(interface)
_associate_eip_with_interface(eni_id, _new_eip)
_new_eip = _request_eip(interface, vm_)
_associate_eip_with_interface(eni_id, _new_eip, vm_=vm_)
elif interface.get('allocate_new_eips'):
addr_list = _list_interface_private_addrs(eni_desc)
eip_list = []
for idx, addr in enumerate(addr_list):
eip_list.append(_request_eip(interface))
eip_list.append(_request_eip(interface, vm_))
for idx, addr in enumerate(addr_list):
_associate_eip_with_interface(eni_id, eip_list[idx], addr)
_associate_eip_with_interface(eni_id, eip_list[idx], addr, vm_=vm_)

if 'Name' in interface:
tag_params = {'Action': 'CreateTags',
Expand All @@ -1317,7 +1317,7 @@ def _create_eni_if_necessary(interface):
'Tag.0.Value': interface['Name']}
tag_response = aws.query(tag_params,
return_root=True,
location=get_location(),
location=get_location(vm_),
provider=get_provider(),
opts=__opts__,
sigver='4')
Expand Down Expand Up @@ -1352,7 +1352,7 @@ def _list_interface_private_addrs(eni_desc):
return addresses


def _modify_eni_properties(eni_id, properties=None):
def _modify_eni_properties(eni_id, properties=None, vm_=None):
'''
Change properties of the interface
with id eni_id to the values in properties dict
Expand All @@ -1373,7 +1373,7 @@ def _modify_eni_properties(eni_id, properties=None):

result = aws.query(params,
return_root=True,
location=get_location(),
location=get_location(vm_),
provider=get_provider(),
opts=__opts__,
sigver='4')
Expand All @@ -1392,7 +1392,7 @@ def _modify_eni_properties(eni_id, properties=None):
)


def _associate_eip_with_interface(eni_id, eip_id, private_ip=None):
def _associate_eip_with_interface(eni_id, eip_id, private_ip=None, vm_=None):
'''
Accept the id of a network interface, and the id of an elastic ip
address, and associate the two of them, such that traffic sent to the
Expand All @@ -1414,7 +1414,7 @@ def _associate_eip_with_interface(eni_id, eip_id, private_ip=None):
retries = retries - 1
result = aws.query(params,
return_root=True,
location=get_location(),
location=get_location(vm_),
provider=get_provider(),
opts=__opts__,
sigver='4')
Expand Down Expand Up @@ -1442,7 +1442,7 @@ def _associate_eip_with_interface(eni_id, eip_id, private_ip=None):
)


def _update_enis(interfaces, instance):
def _update_enis(interfaces, instance, vm_=None):
config_enis = {}
instance_enis = []
for interface in interfaces:
Expand All @@ -1469,11 +1469,11 @@ def _update_enis(interfaces, instance):

params_attachment = {'Attachment.AttachmentId': eni_data['attachmentId'],
'Attachment.DeleteOnTermination': delete_on_terminate}
set_eni_attachment_attributes = _modify_eni_properties(eni_id, params_attachment)
set_eni_attachment_attributes = _modify_eni_properties(eni_id, params_attachment, vm_=vm_)

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)
set_eni_sourcedest_property = _modify_eni_properties(eni_id, params_sourcedest, vm_=vm_)

return None

Expand Down Expand Up @@ -1707,7 +1707,7 @@ def request_instance(vm_=None, call=None):
eni_devices = []
for interface in network_interfaces:
log.debug('Create network interface: {0}'.format(interface))
_new_eni = _create_eni_if_necessary(interface)
_new_eni = _create_eni_if_necessary(interface, vm_)
eni_devices.append(_new_eni)
params.update(_param_from_config(spot_prefix + 'NetworkInterface',
eni_devices))
Expand Down Expand Up @@ -1748,7 +1748,7 @@ def request_instance(vm_=None, call=None):
}
try:
rd_data = aws.query(rd_params,
location=get_location(),
location=get_location(vm_),
provider=get_provider(),
opts=__opts__,
sigver='4')
Expand Down Expand Up @@ -2444,7 +2444,7 @@ def create(vm_=None, call=None):
)

if network_interfaces:
_update_enis(network_interfaces, data)
_update_enis(network_interfaces, data, vm_)

# At this point, the node is created and tagged, and now needs to be
# bootstrapped, once the necessary port is available.
Expand Down

0 comments on commit c846e7b

Please sign in to comment.