diff options
| author | Qiu Yu <qiuyu@ebaysf.com> | 2016-01-25 17:09:55 -0700 |
|---|---|---|
| committer | Sam Yaple <sam@yaple.net> | 2016-01-28 04:34:16 +0000 |
| commit | 428b484397b20876599a336e7d56a4062d6c6922 (patch) | |
| tree | 455ee2a2c1ddd33353b9bfe4ed3362172ce7a602 | |
| parent | 2361fddcffbae32fa681db1b2de4530bb65cd0e5 (diff) | |
| download | kolla-428b484397b20876599a336e7d56a4062d6c6922.tar.gz kolla-428b484397b20876599a336e7d56a4062d6c6922.zip | |
Enable find_disks module to match by filesystem label
Currently the only consumer of ansible find_disks module is Ceph. And
Ceph OSD deployment in kolla uses GPT partition label to detect and
identify disks for Ceph OSD use. This is not always true for all the
deployment.
The change here extended the find_disks module by:
- adding `name` argument to find disk by either partition name or
filesystem label matching
- `partition_name` argument now becomes an alias to `name`
- adding `match_mode` argument to allow prefix matching. It is used for
swift disk detection.
- return `fs_label` key / value in result for disk mounting purpose
Change-Id: I9c93400c1826f5148acf09e9fbe555e358dfdfcc
Partially-Implements: blueprint swift-physical-disk
| -rw-r--r-- | docker/kolla-ansible/find_disks.py | 76 |
1 files changed, 59 insertions, 17 deletions
diff --git a/docker/kolla-ansible/find_disks.py b/docker/kolla-ansible/find_disks.py index d5761ceb0..6ebf2b6a2 100644 --- a/docker/kolla-ansible/find_disks.py +++ b/docker/kolla-ansible/find_disks.py @@ -20,16 +20,24 @@ DOCUMENTATION = ''' --- module: find_disks -short_description: Return list of devices containing a specfied label +short_description: Return list of devices containing a specfied name or label description: - - This will return a list of all devices with a GPT partition label with - the name specified. + - This will return a list of all devices with either GPT partition name + or filesystem label of the name specified. options: - partition_name: + match_mode: description: - - Partition name + - Label match mode, either strict or prefix + default: 'strict' + required: False + choices: [ "strict", "prefix" ] + type: str + name: + description: + - Partition name or filesystem label required: True - type: bool + type: str + aliases: [ 'partition_name' ] author: Sam Yaple ''' @@ -37,9 +45,23 @@ EXAMPLES = ''' - hosts: ceph-osd tasks: - name: Return all valid formated devices with the name KOLLA_CEPH_OSD - ceph_osd_list: - partition_name: 'KOLLA_CEPH_OSD' + find_disks: + name: 'KOLLA_CEPH_OSD' register: osds + +- hosts: swift-object-server + tasks: + - name: Return all valid devices with the name KOLLA_SWIFT + find_disks: + name: 'KOLLA_SWIFT' + register: swift_disks + +- hosts: swift-object-server + tasks: + - name: Return all valid devices with wildcard name 'swift_d*' + find_disks: + name: 'swift_d' match_mode: 'prefix' + register: swift_disks ''' import json @@ -48,21 +70,41 @@ import pyudev def main(): argument_spec = dict( - partition_name=dict(required=True, type='str') + match_mode=dict(required=False, choices=['strict', 'prefix'], + default='strict'), + name=dict(aliases=['partition_name'], required=True, type='str') ) module = AnsibleModule(argument_spec) - partition_name = module.params.get('partition_name') + match_mode = module.params.get('match_mode') + name = module.params.get('name') + + def is_dev_matched_by_name(dev, name): + if dev.get('DEVTYPE', '') == 'partition': + dev_name = dev.get('ID_PART_ENTRY_NAME', '') + else: + dev_name = dev.get('ID_FS_LABEL', '') + + if match_mode == 'strict': + return dev_name == name + elif match_mode == 'prefix': + return dev_name.startswith(name) + else: + return False try: ret = list() ct = pyudev.Context() - for dev in ct.list_devices(subsystem='block', DEVTYPE='partition'): - if dev.get('ID_PART_ENTRY_NAME') == partition_name: - fs_uuid = dev.get('ID_FS_UUID') - if not fs_uuid: - fs_uuid = '' - dev_parent = dev.find_parent('block').device_node - ret.append({'device': dev_parent, 'fs_uuid': fs_uuid}) + for dev in ct.list_devices(subsystem='block'): + if is_dev_matched_by_name(dev, name): + fs_uuid = dev.get('ID_FS_UUID', '') + fs_label = dev.get('ID_FS_LABEL', '') + if dev.get('DEVTYPE', '') == 'partition': + device_node = dev.find_parent('block').device_node + else: + device_node = dev.device_node + ret.append({'device': device_node, + 'fs_uuid': fs_uuid, + 'fs_label': fs_label}) module.exit_json(disks=json.dumps(ret)) except Exception as e: module.exit_json(failed=True, msg=repr(e)) |
