mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50: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
|
@ -99,7 +99,10 @@ options:
|
|||
|
||||
notes:
|
||||
- Two environment variables can be used, DO_API_KEY and DO_API_TOKEN. They both refer to the v2 token.
|
||||
requirements: [ dopy ]
|
||||
- Version 2 of DigitalOcean API is used.
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- dopy
|
||||
'''
|
||||
|
||||
|
||||
|
@ -161,20 +164,18 @@ EXAMPLES = '''
|
|||
image_id=fedora-19-x64
|
||||
'''
|
||||
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
HAS_DOPY = True
|
||||
try:
|
||||
import dopy
|
||||
from dopy.manager import DoError, DoManager
|
||||
except ImportError, e:
|
||||
print "failed=True msg='dopy >= 0.3.2 required for this module'"
|
||||
sys.exit(1)
|
||||
|
||||
if dopy.__version__ < '0.3.2':
|
||||
print "failed=True msg='dopy >= 0.3.2 required for this module'"
|
||||
sys.exit(1)
|
||||
if LooseVersion(dopy.__version__) < LooseVersion('0.3.2'):
|
||||
HAS_DOPY = False
|
||||
except ImportError:
|
||||
HAS_DOPY = False
|
||||
|
||||
class TimeoutError(DoError):
|
||||
def __init__(self, msg, id):
|
||||
|
@ -420,6 +421,8 @@ def main():
|
|||
['id', 'name'],
|
||||
),
|
||||
)
|
||||
if not HAS_DOPY:
|
||||
module.fail_json(msg='dopy >= 0.3.2 required for this module')
|
||||
|
||||
try:
|
||||
core(module)
|
||||
|
@ -431,4 +434,5 @@ def main():
|
|||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -47,6 +47,9 @@ 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
|
||||
'''
|
||||
|
||||
|
||||
|
@ -64,15 +67,14 @@ EXAMPLES = '''
|
|||
|
||||
'''
|
||||
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
|
||||
try:
|
||||
from dopy.manager import DoError, DoManager
|
||||
except ImportError as e:
|
||||
print "failed=True msg='dopy required for this module'"
|
||||
sys.exit(1)
|
||||
HAS_DOPY = True
|
||||
except ImportError:
|
||||
HAS_DOPY = False
|
||||
|
||||
class TimeoutError(DoError):
|
||||
def __init__(self, msg, id):
|
||||
|
@ -165,6 +167,8 @@ def main():
|
|||
['id', 'name'],
|
||||
),
|
||||
)
|
||||
if not HAS_DOPY:
|
||||
module.fail_json(msg='dopy required for this module')
|
||||
|
||||
try:
|
||||
core(module)
|
||||
|
@ -175,5 +179,5 @@ def main():
|
|||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue