From 3b54dd0375f83fd7b275926ad80919f712d05ea6 Mon Sep 17 00:00:00 2001 From: Zaius Dr Date: Fri, 11 Nov 2016 16:54:10 +0100 Subject: Improve `ec2` module Python3 Support (#5497) Imported six module from ansible module_utils for backwards compatibility. (cherry picked from commit 135c70bdd8c9398fa0e716602d940edc5c82183f) --- cloud/amazon/ec2.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cloud/amazon/ec2.py b/cloud/amazon/ec2.py index f2407c7a..ec0e7d34 100644 --- a/cloud/amazon/ec2.py +++ b/cloud/amazon/ec2.py @@ -580,6 +580,8 @@ EXAMPLES = ''' import time from ast import literal_eval +from ansible.module_utils.six import iteritems +from ansible.module_utils.six import get_function_code try: import boto.ec2 @@ -607,7 +609,7 @@ def find_running_instances_by_count_tag(module, ec2, count_tag, zone=None): def _set_none_to_blank(dictionary): result = dictionary - for k in result.iterkeys(): + for k in result: if type(result[k]) == dict: result[k] = _set_none_to_blank(result[k]) elif not result[k]: @@ -637,14 +639,14 @@ def get_reservations(module, ec2, tags=None, state=None, zone=None): for x in tags: if type(x) is dict: x = _set_none_to_blank(x) - filters.update(dict(("tag:"+tn, tv) for (tn,tv) in x.iteritems())) + filters.update(dict(("tag:"+tn, tv) for (tn,tv) in iteritems(x))) else: filters.update({"tag-key": x}) # if dict, add the key and value to the filter if type(tags) is dict: tags = _set_none_to_blank(tags) - filters.update(dict(("tag:"+tn, tv) for (tn,tv) in tags.iteritems())) + filters.update(dict(("tag:"+tn, tv) for (tn,tv) in iteritems(tags))) if state: # http://stackoverflow.com/questions/437511/what-are-the-valid-instancestates-for-the-amazon-ec2-api @@ -744,7 +746,7 @@ def boto_supports_profile_name_arg(ec2): True if Boto library accept instance_profile_name argument, else false """ run_instances_method = getattr(ec2, 'run_instances') - return 'instance_profile_name' in run_instances_method.func_code.co_varnames + return 'instance_profile_name' in get_function_code(run_instances_method).co_varnames def create_block_device(module, ec2, volume): # Not aware of a way to determine this programatically @@ -794,7 +796,7 @@ def boto_supports_param_in_spot_request(ec2, param): True if boto library has the named param as an argument on the request_spot_instances method, else False """ method = getattr(ec2, 'request_spot_instances') - return param in method.func_code.co_varnames + return param in get_function_code(method).co_varnames def await_spot_requests(module, ec2, spot_requests, count): """ -- cgit v1.2.1