mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 22:00:22 -07:00
Several cleanups to many modules:
* Fix docs to specify when python2.6+ is required (due to a library dep). This helps us know when it is okay to use python2.6+ syntax in the file. * remove BabyJson returns. See #1211 This commit fixes all but the openstack modules. * Use if __name__ == '__main__' to only run the main part of the module if the module is run as a program. This allows for the potential to unittest the code later.
This commit is contained in:
parent
0567404c03
commit
5336217649
17 changed files with 186 additions and 114 deletions
|
@ -102,7 +102,9 @@ options:
|
|||
default: null
|
||||
aliases: []
|
||||
|
||||
requirements: [ "libcloud" ]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "apache-libcloud >= 0.13.3"
|
||||
author: Eric Johnson <erjohnso@google.com>
|
||||
'''
|
||||
|
||||
|
@ -123,18 +125,15 @@ EXAMPLES = '''
|
|||
|
||||
'''
|
||||
|
||||
import sys
|
||||
|
||||
try:
|
||||
from libcloud.compute.types import Provider
|
||||
from libcloud.compute.providers import get_driver
|
||||
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
|
||||
ResourceExistsError, ResourceNotFoundError
|
||||
_ = Provider.GCE
|
||||
HAS_LIBCLOUD = True
|
||||
except ImportError:
|
||||
print("failed=True " + \
|
||||
"msg='libcloud with GCE support required for this module.'")
|
||||
sys.exit(1)
|
||||
HAS_LIBCLOUD = False
|
||||
|
||||
def format_allowed_section(allowed):
|
||||
"""Format each section of the allowed list"""
|
||||
|
@ -182,6 +181,9 @@ def main():
|
|||
)
|
||||
)
|
||||
|
||||
if not HAS_LIBCLOUD:
|
||||
module.exit_json(msg='libcloud with GCE support (0.13.3+) required for this module')
|
||||
|
||||
gce = gce_connect(module)
|
||||
|
||||
allowed = module.params.get('allowed')
|
||||
|
@ -281,11 +283,11 @@ def main():
|
|||
changed = True
|
||||
|
||||
json_output['changed'] = changed
|
||||
print json.dumps(json_output)
|
||||
sys.exit(0)
|
||||
module.exit_json(**json_output)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.gce import *
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue