summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Brown <sb@ryansb.com>2016-09-12 18:26:13 -0400
committerRyan S. Brown <sb@ryansb.com>2016-09-13 10:50:29 -0400
commit61b43f134f6bd36403a1da14d03548cc4e94fdc9 (patch)
treeb0047f812ed29d44c9ec125f6533f83a5a00d1fb
parentf30362b15f12916cc224de115afeac56a19a2b9b (diff)
downloadansible-modules-core-61b43f134f6bd36403a1da14d03548cc4e94fdc9.tar.gz
Handle EC2 instances with multiple network interfaces (#4766)
Currently instances with multiple ENI's can't be started or stopped because sourceDestCheck is a per-interface attribute, but we use the boto global access to it (which only works when there's a single ENI). This patch handles multiple ENI's and applies the sourcedestcheck across all interfaces the same way. Fixes #3234
-rw-r--r--cloud/amazon/ec2.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/cloud/amazon/ec2.py b/cloud/amazon/ec2.py
index 2abd95e3..49811c65 100644
--- a/cloud/amazon/ec2.py
+++ b/cloud/amazon/ec2.py
@@ -1284,9 +1284,22 @@ def startstop_instances(module, ec2, instance_ids, state, instance_tags):
for inst in res.instances:
# Check "source_dest_check" attribute
- if inst.vpc_id is not None and inst.get_attribute('sourceDestCheck')['sourceDestCheck'] != source_dest_check:
- inst.modify_attribute('sourceDestCheck', source_dest_check)
- changed = True
+ try:
+ if inst.vpc_id is not None and inst.get_attribute('sourceDestCheck')['sourceDestCheck'] != source_dest_check:
+ inst.modify_attribute('sourceDestCheck', source_dest_check)
+ changed = True
+ except boto.exception.EC2ResponseError as exc:
+ # instances with more than one Elastic Network Interface will
+ # fail, because they have the sourceDestCheck attribute defined
+ # per-interface
+ if exc.code == 'InvalidInstanceID':
+ for interface in inst.interfaces:
+ if interface.source_dest_check != source_dest_check:
+ ec2.modify_network_interface_attribute(interface.id, "sourceDestCheck", source_dest_check)
+ changed = True
+ else:
+ module.fail_json(msg='Failed to handle source_dest_check state for instance {0}, error: {1}'.format(inst.id, exc),
+ exception=traceback.format_exc(exc))
# Check "termination_protection" attribute
if inst.get_attribute('disableApiTermination')['disableApiTermination'] != termination_protection: