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:
Toshio Kuratomi 2015-05-11 12:15:53 -07:00 committed by Matt Clay
commit 5336217649
17 changed files with 186 additions and 114 deletions

View file

@ -47,6 +47,10 @@ options:
notes:
- Two environment variables can be used, DO_CLIENT_ID and DO_API_KEY.
- Version 1 of DigitalOcean API is used.
requirements:
- "python >= 2.6"
- dopy
'''
@ -74,15 +78,14 @@ EXAMPLES = '''
ip={{ test_droplet.droplet.ip_address }}
'''
import sys
import os
import time
try:
from dopy.manager import DoError, DoManager
HAS_DOPY = True
except ImportError as e:
print "failed=True msg='dopy required for this module'"
sys.exit(1)
HAS_DOPY = False
class TimeoutError(DoError):
def __init__(self, msg, id):
@ -229,6 +232,8 @@ def main():
['id', 'name'],
),
)
if not HAS_DOPY:
module.fail_json(msg='dopy required for this module')
try:
core(module)
@ -239,5 +244,5 @@ def main():
# import module snippets
from ansible.module_utils.basic import *
main()
if __name__ == '__main__':
main()