More os_router module cleanup and fixes.

Added a RETURN section, corrected version_added value, removed use of
'result' in exit_json() calls.
This commit is contained in:
David Shrewsbury 2015-09-14 16:20:18 -04:00
parent 653060dc47
commit ef93fb1c14

View file

@ -28,7 +28,7 @@ DOCUMENTATION = '''
module: os_router module: os_router
short_description: Create or Delete routers from OpenStack short_description: Create or Delete routers from OpenStack
extends_documentation_fragment: openstack extends_documentation_fragment: openstack
version_added: "1.10" version_added: "2.0"
description: description:
- Create or Delete routers from OpenStack. Although Neutron allows - Create or Delete routers from OpenStack. Although Neutron allows
routers to share the same name, this module enforces name uniqueness routers to share the same name, this module enforces name uniqueness
@ -45,7 +45,7 @@ options:
required: true required: true
admin_state_up: admin_state_up:
description: description:
- Desired admin state of the created router. - Desired admin state of the created or existing router.
required: false required: false
default: true default: true
requirements: ["shade"] requirements: ["shade"]
@ -59,6 +59,13 @@ EXAMPLES = '''
admin_state_up=True admin_state_up=True
''' '''
RETURN = '''
id:
description: Router ID
returned: On success when I(state) is 'present'.
type: string
'''
def _needs_update(router, admin_state_up): def _needs_update(router, admin_state_up):
"""Decide if the given router needs an update. """Decide if the given router needs an update.
@ -110,29 +117,28 @@ def main():
if state == 'present': if state == 'present':
if not router: if not router:
router = cloud.create_router(name, admin_state_up) router = cloud.create_router(name, admin_state_up)
module.exit_json(changed=True, result="created", module.exit_json(changed=True, id=router['id'])
id=router['id'])
else: else:
if _needs_update(router, admin_state_up): if _needs_update(router, admin_state_up):
cloud.update_router(router['id'], cloud.update_router(router['id'],
admin_state_up=admin_state_up) admin_state_up=admin_state_up)
module.exit_json(changed=True, result="updated", module.exit_json(changed=True, id=router['id'])
id=router['id'])
else: else:
module.exit_json(changed=False, result="success", module.exit_json(changed=False, id=router['id'])
id=router['id'])
elif state == 'absent': elif state == 'absent':
if not router: if not router:
module.exit_json(changed=False, result="success") module.exit_json(changed=False)
else: else:
cloud.delete_router(name) cloud.delete_router(name)
module.exit_json(changed=True, result="deleted") module.exit_json(changed=True)
except shade.OpenStackCloudException as e: except shade.OpenStackCloudException as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
# this is magic, see lib/ansible/module_common.py # this is magic, see lib/ansible/module_common.py
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.openstack import * from ansible.module_utils.openstack import *
main() if __name__ == '__main__':
main()