summaryrefslogtreecommitdiff
path: root/boto/ec2/networkinterface.py
diff options
context:
space:
mode:
Diffstat (limited to 'boto/ec2/networkinterface.py')
-rw-r--r--boto/ec2/networkinterface.py47
1 files changed, 40 insertions, 7 deletions
diff --git a/boto/ec2/networkinterface.py b/boto/ec2/networkinterface.py
index 6ffc79af..98368050 100644
--- a/boto/ec2/networkinterface.py
+++ b/boto/ec2/networkinterface.py
@@ -23,6 +23,7 @@
"""
Represents an EC2 Elastic Network Interface
"""
+from boto.exception import BotoClientError
from boto.ec2.ec2object import TaggedEC2Object
from boto.resultset import ResultSet
from boto.ec2.group import Group
@@ -165,8 +166,11 @@ class NetworkInterface(TaggedEC2Object):
else:
setattr(self, name, value)
- def delete(self):
- return self.connection.delete_network_interface(self.id)
+ def delete(self, dry_run=False):
+ return self.connection.delete_network_interface(
+ self.id,
+ dry_run=dry_run
+ )
class PrivateIPAddress(object):
@@ -196,13 +200,15 @@ class NetworkInterfaceCollection(list):
def build_list_params(self, params, prefix=''):
for i, spec in enumerate(self):
- full_prefix = '%sNetworkInterface.%s.' % (prefix, i+1)
+ full_prefix = '%sNetworkInterface.%s.' % (prefix, i)
if spec.network_interface_id is not None:
params[full_prefix + 'NetworkInterfaceId'] = \
str(spec.network_interface_id)
if spec.device_index is not None:
params[full_prefix + 'DeviceIndex'] = \
str(spec.device_index)
+ else:
+ params[full_prefix + 'DeviceIndex'] = 0
if spec.subnet_id is not None:
params[full_prefix + 'SubnetId'] = str(spec.subnet_id)
if spec.description is not None:
@@ -218,20 +224,47 @@ class NetworkInterfaceCollection(list):
str(spec.private_ip_address)
if spec.groups is not None:
for j, group_id in enumerate(spec.groups):
- query_param_key = '%sSecurityGroupId.%s' % (full_prefix, j+1)
+ query_param_key = '%sSecurityGroupId.%s' % (full_prefix, j)
params[query_param_key] = str(group_id)
if spec.private_ip_addresses is not None:
for k, ip_addr in enumerate(spec.private_ip_addresses):
query_param_key_prefix = (
- '%sPrivateIpAddresses.%s' % (full_prefix, k+1))
+ '%sPrivateIpAddresses.%s' % (full_prefix, k))
params[query_param_key_prefix + '.PrivateIpAddress'] = \
str(ip_addr.private_ip_address)
if ip_addr.primary is not None:
params[query_param_key_prefix + '.Primary'] = \
'true' if ip_addr.primary else 'false'
+
+ # Associating Public IPs have special logic around them:
+ #
+ # * Only assignable on an device_index of ``0``
+ # * Only on one interface
+ # * Only if there are no other interfaces being created
+ # * Only if it's a new interface (which we can't really guard
+ # against)
+ #
+ # More details on http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-RunInstances.html
if spec.associate_public_ip_address is not None:
- params[full_prefix + 'AssociatePublicIpAddress'] = \
- 'true' if spec.associate_public_ip_address else 'false'
+ if not params[full_prefix + 'DeviceIndex'] in (0, '0'):
+ raise BotoClientError(
+ "Only the interface with device index of 0 can " + \
+ "be provided when using " + \
+ "'associate_public_ip_address'."
+ )
+
+ if len(self) > 1:
+ raise BotoClientError(
+ "Only one interface can be provided when using " + \
+ "'associate_public_ip_address'."
+ )
+
+ key = full_prefix + 'AssociatePublicIpAddress'
+
+ if spec.associate_public_ip_address:
+ params[key] = 'true'
+ else:
+ params[key] = 'false'
class NetworkInterfaceSpecification(object):