mirror of https://github.com/ceph/ceph-ansible.git
ceph-volume: add support for inventory command
Signed-off-by: Noah Watkins <nwatkins@redhat.com>pull/3455/head
parent
5419497726
commit
ba0af03b43
|
@ -3,6 +3,7 @@ import datetime
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import six
|
||||||
|
|
||||||
ANSIBLE_METADATA = {
|
ANSIBLE_METADATA = {
|
||||||
'metadata_version': '1.0',
|
'metadata_version': '1.0',
|
||||||
|
@ -36,9 +37,9 @@ options:
|
||||||
default: bluestore
|
default: bluestore
|
||||||
action:
|
action:
|
||||||
description:
|
description:
|
||||||
- The action to take. Either creating OSDs or zapping devices.
|
- The action to take. Creating OSDs and zapping or querying devices.
|
||||||
required: true
|
required: true
|
||||||
choices: ['create', 'zap', 'batch', 'prepare', 'activate', 'list']
|
choices: ['create', 'zap', 'batch', 'prepare', 'activate', 'list', 'inventory']
|
||||||
default: create
|
default: create
|
||||||
data:
|
data:
|
||||||
description:
|
description:
|
||||||
|
@ -127,6 +128,10 @@ options:
|
||||||
description:
|
description:
|
||||||
- List potential Ceph LVM metadata on a device
|
- List potential Ceph LVM metadata on a device
|
||||||
required: false
|
required: false
|
||||||
|
inventory:
|
||||||
|
description:
|
||||||
|
- List storage device inventory.
|
||||||
|
required: false
|
||||||
|
|
||||||
author:
|
author:
|
||||||
- Andrew Schoen (@andrewschoen)
|
- Andrew Schoen (@andrewschoen)
|
||||||
|
@ -208,8 +213,7 @@ def build_ceph_volume_cmd(action, container_image, cluster=None):
|
||||||
if cluster:
|
if cluster:
|
||||||
cmd.extend(['--cluster', cluster])
|
cmd.extend(['--cluster', cluster])
|
||||||
|
|
||||||
cmd.append('lvm')
|
cmd.extend(action if not isinstance(action, six.string_types) else [action])
|
||||||
cmd.append(action)
|
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
@ -285,7 +289,7 @@ def batch(module, container_image):
|
||||||
fatal('batch_devices must be provided if action is "batch"', module)
|
fatal('batch_devices must be provided if action is "batch"', module)
|
||||||
|
|
||||||
# Build the CLI
|
# Build the CLI
|
||||||
action = 'batch'
|
action = ['lvm', 'batch']
|
||||||
cmd = build_ceph_volume_cmd(action, container_image, cluster)
|
cmd = build_ceph_volume_cmd(action, container_image, cluster)
|
||||||
cmd.extend(['--%s' % objectstore])
|
cmd.extend(['--%s' % objectstore])
|
||||||
cmd.append('--yes')
|
cmd.append('--yes')
|
||||||
|
@ -356,6 +360,7 @@ def prepare_or_create_osd(module, action, container_image):
|
||||||
dmcrypt = module.params.get('dmcrypt', None)
|
dmcrypt = module.params.get('dmcrypt', None)
|
||||||
|
|
||||||
# Build the CLI
|
# Build the CLI
|
||||||
|
action = ['lvm', action]
|
||||||
cmd = build_ceph_volume_cmd(action, container_image, cluster)
|
cmd = build_ceph_volume_cmd(action, container_image, cluster)
|
||||||
cmd.extend(['--%s' % objectstore])
|
cmd.extend(['--%s' % objectstore])
|
||||||
cmd.append('--data')
|
cmd.append('--data')
|
||||||
|
@ -394,7 +399,7 @@ def list_osd(module, container_image):
|
||||||
data = get_data(data, data_vg)
|
data = get_data(data, data_vg)
|
||||||
|
|
||||||
# Build the CLI
|
# Build the CLI
|
||||||
action = 'list'
|
action = ['lvm', 'list']
|
||||||
cmd = build_ceph_volume_cmd(action, container_image, cluster)
|
cmd = build_ceph_volume_cmd(action, container_image, cluster)
|
||||||
if data:
|
if data:
|
||||||
cmd.append(data)
|
cmd.append(data)
|
||||||
|
@ -402,6 +407,16 @@ def list_osd(module, container_image):
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
def list_storage_inventory(module, container_image):
|
||||||
|
'''
|
||||||
|
List storage inventory.
|
||||||
|
'''
|
||||||
|
|
||||||
|
action = 'inventory'
|
||||||
|
cmd = build_ceph_volume_cmd(action, container_image)
|
||||||
|
cmd.append('--format=json')
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
|
||||||
def activate_osd():
|
def activate_osd():
|
||||||
'''
|
'''
|
||||||
|
@ -409,7 +424,7 @@ def activate_osd():
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# build the CLI
|
# build the CLI
|
||||||
action = 'activate'
|
action = ['lvm', 'activate']
|
||||||
container_image = None
|
container_image = None
|
||||||
cmd = build_ceph_volume_cmd(action, container_image)
|
cmd = build_ceph_volume_cmd(action, container_image)
|
||||||
cmd.append('--all')
|
cmd.append('--all')
|
||||||
|
@ -437,7 +452,7 @@ def zap_devices(module, container_image):
|
||||||
data = get_data(data, data_vg)
|
data = get_data(data, data_vg)
|
||||||
|
|
||||||
# build the CLI
|
# build the CLI
|
||||||
action = 'zap'
|
action = ['lvm', 'zap']
|
||||||
cmd = build_ceph_volume_cmd(action, container_image)
|
cmd = build_ceph_volume_cmd(action, container_image)
|
||||||
cmd.append('--destroy')
|
cmd.append('--destroy')
|
||||||
cmd.append(data)
|
cmd.append(data)
|
||||||
|
@ -463,7 +478,8 @@ def run_module():
|
||||||
objectstore=dict(type='str', required=False, choices=[
|
objectstore=dict(type='str', required=False, choices=[
|
||||||
'bluestore', 'filestore'], default='bluestore'),
|
'bluestore', 'filestore'], default='bluestore'),
|
||||||
action=dict(type='str', required=False, choices=[
|
action=dict(type='str', required=False, choices=[
|
||||||
'create', 'zap', 'batch', 'prepare', 'activate', 'list'], default='create'), # noqa 4502
|
'create', 'zap', 'batch', 'prepare', 'activate', 'list',
|
||||||
|
'inventory'], default='create'), # noqa 4502
|
||||||
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),
|
||||||
|
@ -559,6 +575,11 @@ def run_module():
|
||||||
rc, cmd, out, err = exec_command(
|
rc, cmd, out, err = exec_command(
|
||||||
module, list_osd(module, container_image))
|
module, list_osd(module, container_image))
|
||||||
|
|
||||||
|
elif action == 'inventory':
|
||||||
|
# List storage device inventory.
|
||||||
|
rc, cmd, out, err = exec_command(
|
||||||
|
module, list_storage_inventory(module, container_image))
|
||||||
|
|
||||||
elif action == 'batch':
|
elif action == 'batch':
|
||||||
# Batch prepare AND activate OSDs
|
# Batch prepare AND activate OSDs
|
||||||
report = module.params.get('report', None)
|
report = module.params.get('report', None)
|
||||||
|
@ -611,7 +632,7 @@ def run_module():
|
||||||
|
|
||||||
else:
|
else:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='State must either be "create" or "prepare" or "activate" or "list" or "zap" or "batch".', changed=False, rc=1) # noqa E501
|
msg='State must either be "create" or "prepare" or "activate" or "list" or "zap" or "batch" or "inventory".', changed=False, rc=1) # noqa E501
|
||||||
|
|
||||||
endd = datetime.datetime.now()
|
endd = datetime.datetime.now()
|
||||||
delta = endd - startd
|
delta = endd - startd
|
||||||
|
|
|
@ -132,6 +132,34 @@ class TestCephVolumeModule(object):
|
||||||
result = ceph_volume.list_osd(fake_module, fake_container_image)
|
result = ceph_volume.list_osd(fake_module, fake_container_image)
|
||||||
assert result == expected_command_list
|
assert result == expected_command_list
|
||||||
|
|
||||||
|
def test_list_storage_inventory(self):
|
||||||
|
fake_module = MagicMock()
|
||||||
|
fake_container_image = None
|
||||||
|
expected_command_list = ['ceph-volume',
|
||||||
|
'inventory',
|
||||||
|
'--format=json',
|
||||||
|
]
|
||||||
|
result = ceph_volume.list_storage_inventory(fake_module, fake_container_image)
|
||||||
|
assert result == expected_command_list
|
||||||
|
|
||||||
|
def test_list_storage_inventory_container(self):
|
||||||
|
fake_module = MagicMock()
|
||||||
|
fake_container_image = "docker.io/ceph/daemon:latest-luminous"
|
||||||
|
expected_command_list = ['docker', 'run', '--rm', '--privileged', '--net=host', # noqa E501
|
||||||
|
'-v', '/run/lock/lvm:/run/lock/lvm:z',
|
||||||
|
'-v', '/var/run/udev/:/var/run/udev/:z',
|
||||||
|
'-v', '/dev:/dev', '-v', '/etc/ceph:/etc/ceph:z', # noqa E501
|
||||||
|
'-v', '/run/lvm/lvmetad.socket:/run/lvm/lvmetad.socket', # noqa E501
|
||||||
|
'-v', '/var/lib/ceph/:/var/lib/ceph/:z',
|
||||||
|
'-v', '/var/log/ceph/:/var/log/ceph/:z',
|
||||||
|
'--entrypoint=ceph-volume',
|
||||||
|
'docker.io/ceph/daemon:latest-luminous',
|
||||||
|
'inventory',
|
||||||
|
'--format=json',
|
||||||
|
]
|
||||||
|
result = ceph_volume.list_storage_inventory(fake_module, fake_container_image)
|
||||||
|
assert result == expected_command_list
|
||||||
|
|
||||||
def test_create_osd_container(self):
|
def test_create_osd_container(self):
|
||||||
fake_module = MagicMock()
|
fake_module = MagicMock()
|
||||||
fake_module.params = {'data': '/dev/sda',
|
fake_module.params = {'data': '/dev/sda',
|
||||||
|
|
Loading…
Reference in New Issue