Fix modules' use of BOOLEANS*

* The canonical location of BOOLEANS has moved.  Switch imports to use that.
* clean up argument_spec use of booleans.
* Clean up imports to not use wildcards
* Remove usage of get_exception
This commit is contained in:
Toshio Kuratomi 2017-07-14 16:42:00 -07:00
commit d64e291274
17 changed files with 98 additions and 102 deletions

View file

@ -140,20 +140,24 @@ import json
import traceback
try:
import boto3
import botocore
HAS_BOTO3 = True
except ImportError:
HAS_BOTO3 = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import boto3_conn, ec2_argument_spec, get_aws_connection_info
from ansible.module_utils._text import to_native
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(dict(
name = dict(),
function_arn = dict(),
wait = dict(choices=BOOLEANS, default=True, type='bool'),
tail_log = dict(choices=BOOLEANS, default=False, type='bool'),
dry_run = dict(choices=BOOLEANS, default=False, type='bool'),
wait = dict(default=True, type='bool'),
tail_log = dict(default=False, type='bool'),
dry_run = dict(default=False, type='bool'),
version_qualifier = dict(),
payload = dict(default={}, type='dict'),
))
@ -192,7 +196,7 @@ def main():
client = boto3_conn(module, conn_type='client', resource='lambda',
region=region, endpoint=ec2_url, **aws_connect_kwargs)
except (botocore.exceptions.ClientError, botocore.exceptions.ValidationError) as e:
module.fail_json(msg="Failure connecting boto3 to AWS", exception=traceback.format_exc())
module.fail_json(msg="Failure connecting boto3 to AWS: %s" % to_native(e), exception=traceback.format_exc())
invoke_params = {}
@ -282,9 +286,6 @@ def main():
module.exit_json(changed=True, result=results)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.ec2 import *
if __name__ == '__main__':
main()

View file

@ -352,7 +352,7 @@ def main():
healthchecks=dict(type='list', required=True),
service_account_email=dict(),
service_account_permissions=dict(type='list'),
enable_cdn=dict(type='bool', choices=[True, False]),
enable_cdn=dict(type='bool'),
port_name=dict(type='str'),
protocol=dict(type='str', default='TCP',
choices=['HTTP', 'HTTPS', 'SSL', 'TCP']),

View file

@ -431,7 +431,13 @@ lxc_container:
sample: True
"""
import os
import os.path
import re
import shutil
import subprocess
import tempfile
import time
try:
import lxc
@ -440,6 +446,10 @@ except ImportError:
else:
HAS_LXC = True
# import module bits
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE
# LXC_COMPRESSION_MAP is a map of available compression types when creating
# an archive of a container.
@ -562,11 +572,6 @@ def create_script(command):
:type command: ``str``
"""
import os
import os.path as path
import subprocess
import tempfile
(fd, script_file) = tempfile.mkstemp(prefix='lxc-attach-script')
f = os.fdopen(fd, 'wb')
try:
@ -682,7 +687,7 @@ class LxcContainerManagement(object):
variables.pop(v, None)
return_dict = dict()
false_values = [None, ''] + BOOLEANS_FALSE
false_values = BOOLEANS_FALSE.union([None, ''])
for k, v in variables.items():
_var = self.module.params.get(k)
if _var not in false_values:
@ -1761,7 +1766,5 @@ def main():
lxc_manage.run()
# import module bits
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()