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

Fix issue with network interfaces #1874

Merged
merged 1 commit into from
Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 19 additions & 12 deletions awscli/customizations/ec2runinstances.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,27 @@ def _fix_args(params, **kwargs):
# allows them to specify the security group by name or by id.
# However, in this scenario we can only support id because
# we can't place a group name in the NetworkInterfaces structure.
network_interface_params = [
'PrivateIpAddresses',
'SecondaryPrivateIpAddressCount',
'AssociatePublicIpAddress'
]
if 'NetworkInterfaces' in params:
ni = params['NetworkInterfaces']
if 'AssociatePublicIpAddress' in ni[0]:
if 'SubnetId' in params:
ni[0]['SubnetId'] = params['SubnetId']
del params['SubnetId']
if 'SecurityGroupIds' in params:
ni[0]['Groups'] = params['SecurityGroupIds']
del params['SecurityGroupIds']
if 'PrivateIpAddress' in params:
ip_addr = {'PrivateIpAddress': params['PrivateIpAddress'],
'Primary': True}
ni[0]['PrivateIpAddresses'] = [ip_addr]
del params['PrivateIpAddress']
for network_interface_param in network_interface_params:
if network_interface_param in ni[0]:
if 'SubnetId' in params:
ni[0]['SubnetId'] = params['SubnetId']
del params['SubnetId']
if 'SecurityGroupIds' in params:
ni[0]['Groups'] = params['SecurityGroupIds']
del params['SecurityGroupIds']
if 'PrivateIpAddress' in params:
ip_addr = {'PrivateIpAddress': params['PrivateIpAddress'],
'Primary': True}
ni[0]['PrivateIpAddresses'] = [ip_addr]
del params['PrivateIpAddress']
return


EVENTS = [
Expand Down
31 changes: 26 additions & 5 deletions tests/functional/ec2/test_run_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,24 @@ def test_secondary_ip_address(self):
args += '--secondary-private-ip-addresses 10.0.2.106'
args_list = (self.prefix + args).split()
result = {
'NetworkInterface.1.DeviceIndex': 0,
'NetworkInterface.1.PrivateIpAddresses.1.Primary': 'false',
'NetworkInterface.1.PrivateIpAddresses.1.PrivateIpAddress': '10.0.2.106',
'ImageId': 'ami-foobar',
'NetworkInterfaces': [
{'DeviceIndex': 0,
'PrivateIpAddresses': [
{'Primary': False, 'PrivateIpAddress': '10.0.2.106'}]}],
'MaxCount': 1,
'MinCount': 1
}
'MinCount': 1}
self.assert_params_for_cmd(args_list, result)

def test_secondary_ip_address_with_subnet(self):
args = ' --image-id ami-foobar --count 1 --subnet subnet-12345678 '
args += '--secondary-private-ip-addresses 10.0.2.106'
args_list = (self.prefix + args).split()
result = {
'ImageId': 'ami-foobar',
'NetworkInterfaces': [
{'DeviceIndex': 0,
'SubnetId': 'subnet-12345678',
'PrivateIpAddresses': [
{'Primary': False, 'PrivateIpAddress': '10.0.2.106'}]}],
'MaxCount': 1,
Expand Down Expand Up @@ -152,6 +159,20 @@ def test_secondary_ip_address_count(self):
}
self.assert_params_for_cmd(args_list, result)

def test_secondary_ip_address_count_with_subnet(self):
args = ' --image-id ami-foobar --count 1 --subnet subnet-12345678 '
args += '--secondary-private-ip-address-count 4'
args_list = (self.prefix + args).split()
result = {
'NetworkInterfaces': [{'DeviceIndex': 0,
'SubnetId': 'subnet-12345678',
'SecondaryPrivateIpAddressCount': 4}],
'ImageId': 'ami-foobar',
'MaxCount': 1,
'MinCount': 1
}
self.assert_params_for_cmd(args_list, result)

def test_associate_public_ip_address(self):
args = ' --image-id ami-foobar --count 1 --subnet-id subnet-12345678 '
args += '--associate-public-ip-address'
Expand Down