1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge branch 'lvg_dm_names' of https://github.com/ajsalminen/ansible into ajsalminen-lvg_dm_names

This commit is contained in:
James Cammarata 2014-06-20 13:24:07 -05:00
commit 8e0148f084

View file

@ -89,10 +89,22 @@ def parse_vgs(data):
}) })
return vgs return vgs
def parse_pvs(data): def find_mapper_device_name(module, dm_device):
dmsetup_cmd = module.get_bin_path('dmsetup', True)
mapper_prefix = '/dev/mapper/'
rc, dm_name, err = module.run_command("%s info -C --noheadings -o name %s" % (dmsetup_cmd, dm_device))
if rc != 0:
module.fail_json(msg="Failed executing dmsetup command.", rc=rc, err=err)
mapper_device = mapper_prefix + dm_name.rstrip()
return mapper_device
def parse_pvs(module, data):
pvs = [] pvs = []
dm_prefix = '/dev/dm-'
for line in data.splitlines(): for line in data.splitlines():
parts = line.strip().split(';') parts = line.strip().split(';')
if parts[0].startswith(dm_prefix):
parts[0] = find_mapper_device_name(module, parts[0])
pvs.append({ pvs.append({
'name': parts[0], 'name': parts[0],
'vg_name': parts[1], 'vg_name': parts[1],
@ -139,7 +151,7 @@ def main():
module.fail_json(msg="Failed executing pvs command.",rc=rc, err=err) module.fail_json(msg="Failed executing pvs command.",rc=rc, err=err)
### check pv for devices ### check pv for devices
pvs = parse_pvs(current_pvs) pvs = parse_pvs(module, current_pvs)
used_pvs = [ pv for pv in pvs if pv['name'] in dev_list and pv['vg_name'] and pv['vg_name'] != vg ] used_pvs = [ pv for pv in pvs if pv['name'] in dev_list and pv['vg_name'] and pv['vg_name'] != vg ]
if used_pvs: if used_pvs:
module.fail_json(msg="Device %s is already in %s volume group."%(used_pvs[0]['name'],used_pvs[0]['vg_name'])) module.fail_json(msg="Device %s is already in %s volume group."%(used_pvs[0]['name'],used_pvs[0]['vg_name']))