issue #994: use HAS_BOTO to determine if import was successful: - removed import of sys module. - HAS_BOTO constant to check if import was successful. - trigger a failure when import fails. - removed unnecessary imports.

This commit is contained in:
steenzout
2015-04-01 17:16:54 -06:00
committed by Matt Clay
parent 0a48d54c1c
commit 67f769d9a6
21 changed files with 121 additions and 74 deletions

View File

@@ -487,7 +487,6 @@ EXAMPLES = '''
'''
import sys
import time
from ast import literal_eval
@@ -496,9 +495,10 @@ try:
from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping
from boto.exception import EC2ResponseError
from boto.vpc import VPCConnection
HAS_BOTO = True
except ImportError:
print "failed=True msg='boto required for this module'"
sys.exit(1)
HAS_BOTO = False
def find_running_instances_by_count_tag(module, ec2, count_tag, zone=None):
@@ -782,7 +782,6 @@ def create_instances(module, ec2, vpc, override_count=None):
# group_id and group_name are exclusive of each other
if group_id and group_name:
module.fail_json(msg = str("Use only one type of parameter (group_name) or (group_id)"))
sys.exit(1)
vpc_id = None
if vpc_subnet_id:
@@ -1203,6 +1202,9 @@ def main():
],
)
if not HAS_BOTO:
module.fail_json(msg='boto required for this module')
ec2 = ec2_connect(module)
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module)