ceph-volume: adds `lvm list` support to the ceph_volume module

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
pull/3206/head
Andrew Schoen 2018-09-25 15:05:08 -05:00 committed by Sébastien Han
parent 8afef3d0de
commit 2ffad1b43a
1 changed files with 50 additions and 2 deletions

View File

@ -37,7 +37,7 @@ options:
description: description:
- The action to take. Either creating OSDs or zapping devices. - The action to take. Either creating OSDs or zapping devices.
required: true required: true
choices: ['create', 'zap', 'batch'] choices: ['create', 'zap', 'batch', 'list']
default: create default: create
data: data:
description: description:
@ -172,6 +172,52 @@ def get_wal(wal, wal_vg):
return wal return wal
def _list(module):
cmd = [
'ceph-volume',
'lvm',
'list',
'--format=json',
]
result = dict(
changed=False,
cmd=cmd,
stdout='',
stderr='',
rc='',
start='',
end='',
delta='',
)
if module.check_mode:
return result
startd = datetime.datetime.now()
rc, out, err = module.run_command(cmd, encoding=None)
endd = datetime.datetime.now()
delta = endd - startd
result = dict(
cmd=cmd,
stdout=out.rstrip(b"\r\n"),
stderr=err.rstrip(b"\r\n"),
rc=rc,
start=str(startd),
end=str(endd),
delta=str(delta),
changed=True,
)
if rc != 0:
module.fail_json(msg='non-zero return code', **result)
module.exit_json(**result)
def batch(module): def batch(module):
cluster = module.params['cluster'] cluster = module.params['cluster']
objectstore = module.params['objectstore'] objectstore = module.params['objectstore']
@ -430,7 +476,7 @@ def run_module():
module_args = dict( module_args = dict(
cluster=dict(type='str', required=False, default='ceph'), cluster=dict(type='str', required=False, default='ceph'),
objectstore=dict(type='str', required=False, choices=['bluestore', 'filestore'], default='bluestore'), objectstore=dict(type='str', required=False, choices=['bluestore', 'filestore'], default='bluestore'),
action=dict(type='str', required=False, choices=['create', 'zap', 'batch'], default='create'), action=dict(type='str', required=False, choices=['create', 'zap', 'batch', 'list'], default='create'),
data=dict(type='str', required=False), data=dict(type='str', required=False),
data_vg=dict(type='str', required=False), data_vg=dict(type='str', required=False),
journal=dict(type='str', required=False), journal=dict(type='str', required=False),
@ -461,6 +507,8 @@ def run_module():
zap_devices(module) zap_devices(module)
elif action == "batch": elif action == "batch":
batch(module) batch(module)
elif action == "list":
_list(module)
module.fail_json(msg='State must either be "present" or "absent".', changed=False, rc=1) module.fail_json(msg='State must either be "present" or "absent".', changed=False, rc=1)