Add RETURN section, fix identation and apply flake8 recommendations (#20148)

pull/4420/head
Jasper Lievisse Adriaanse 2017-01-12 23:58:07 +01:00 committed by Matt Davis
parent d8733a5455
commit 232cb764da
1 changed files with 33 additions and 10 deletions

View File

@ -36,33 +36,33 @@ options:
required: false required: false
choices: [ yes, no ] choices: [ yes, no ]
description: description:
- Force a given operation (where supported by imgadm(1M)). - Force a given operation (where supported by imgadm(1M)).
pool: pool:
required: false required: false
default: zones default: zones
description: description:
- zpool to import to or delete images from. - zpool to import to or delete images from.
source: source:
required: false required: false
description: description:
- URI for the image source. - URI for the image source.
state: state:
required: true required: true
choices: [ present, absent, deleted, imported, updated, vacuumed ] choices: [ present, absent, deleted, imported, updated, vacuumed ]
description: description:
- State the object operated on should be in. C(imported) is an alias for - State the object operated on should be in. C(imported) is an alias for
for C(present) and C(deleted) for C(absent). When set to C(vacuumed) for C(present) and C(deleted) for C(absent). When set to C(vacuumed)
and C(uuid) to C(*), it will remove all unused images. and C(uuid) to C(*), it will remove all unused images.
type: type:
required: false required: false
choices: [ imgapi, docker, dsapi ] choices: [ imgapi, docker, dsapi ]
default: imgapi default: imgapi
description: description:
- Type for image sources. - Type for image sources.
uuid: uuid:
required: false required: false
description: description:
- Image UUID. Can either be a full UUID or C(*) for all images. - Image UUID. Can either be a full UUID or C(*) for all images.
requirements: requirements:
- python >= 2.6 - python >= 2.6
''' '''
@ -105,6 +105,25 @@ EXAMPLES = '''
state: absent state: absent
''' '''
RETURN = '''
source:
description: Source that is managed.
returned: When not managing an image.
type: string
sample: https://datasets.project-fifo.net
uuid:
description: UUID for an image operated on.
returned: When not managing an image source.
type: string
sample: 70e3ae72-96b6-11e6-9056-9737fd4d0764
state:
description: State of the target, after execution.
returned: success
type: string
sample: 'present'
'''
from ansible.module_utils.basic import AnsibleModule
import re import re
# Shortcut for the imgadm(1M) command. While imgadm(1M) supports a # Shortcut for the imgadm(1M) command. While imgadm(1M) supports a
@ -113,6 +132,7 @@ import re
# the stacktrace, which breaks the parsers. # the stacktrace, which breaks the parsers.
IMGADM = 'imgadm' IMGADM = 'imgadm'
# Helper method to massage stderr # Helper method to massage stderr
def errmsg(stderr): def errmsg(stderr):
match = re.match('^imgadm .*?: error \(\w+\): (.*): .*', stderr) match = re.match('^imgadm .*?: error \(\w+\): (.*): .*', stderr)
@ -121,6 +141,7 @@ def errmsg(stderr):
else: else:
return 'Unexpected failure' return 'Unexpected failure'
def update_images(module): def update_images(module):
uuid = module.params['uuid'] uuid = module.params['uuid']
cmd = IMGADM + ' update' cmd = IMGADM + ' update'
@ -135,6 +156,7 @@ def update_images(module):
# Note that 'imgadm -v' produces unparseable JSON... # Note that 'imgadm -v' produces unparseable JSON...
return rc, stdout, errmsg(stderr), True return rc, stdout, errmsg(stderr), True
def manage_sources(module, present): def manage_sources(module, present):
force = module.params['force'] force = module.params['force']
source = module.params['source'] source = module.params['source']
@ -181,6 +203,7 @@ def manage_sources(module, present):
return (rc, stdout, errmsg(stderr), changed) return (rc, stdout, errmsg(stderr), changed)
def manage_images(module, present): def manage_images(module, present):
uuid = module.params['uuid'] uuid = module.params['uuid']
pool = module.params['pool'] pool = module.params['pool']
@ -236,6 +259,7 @@ def manage_images(module, present):
return (rc, stdout, errmsg(stderr), changed) return (rc, stdout, errmsg(stderr), changed)
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
@ -264,7 +288,7 @@ def main():
stderr = stdout = '' stderr = stdout = ''
rc = 0 rc = 0
result = { 'state': state } result = {'state': state}
changed = False changed = False
# Perform basic UUID validation upfront. # Perform basic UUID validation upfront.
@ -298,7 +322,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__': if __name__ == '__main__':
main() main()