From 4c154fb55b64ab5b25428455555b8400a3e56826 Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Sun, 11 May 2014 22:11:53 -0500 Subject: [PATCH] Include a pvremove module and pvabsent state This is usefull for ensuring that the block device is removed from all kernel memory. This is required for detaching vdb's in xen. --- salt/modules/linux_lvm.py | 17 +++++++++++++++++ salt/states/lvm.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/salt/modules/linux_lvm.py b/salt/modules/linux_lvm.py index 330e3a78b9..a0496ff5dc 100644 --- a/salt/modules/linux_lvm.py +++ b/salt/modules/linux_lvm.py @@ -202,6 +202,23 @@ def pvcreate(devices, **kwargs): return out[0] +def pvremove(devices): + ''' + Remove a physical device being used as an LVM physical volume + + CLI Examples: + + .. code-block:: bash + + salt mymachine lvm.pvremove /dev/sdb1,/dev/sdb2 + ''' + cmd = 'pvremove -y' + for device in devices.split(','): + cmd += ' {0}'.format(device) + out = __salt__['cmd.run'](cmd).splitlines() + return out[0] + + def vgcreate(vgname, devices, **kwargs): ''' Create an LVM volume group diff --git a/salt/states/lvm.py b/salt/states/lvm.py index 6e63e2128d..68f59c0a8c 100644 --- a/salt/states/lvm.py +++ b/salt/states/lvm.py @@ -69,6 +69,36 @@ def pv_present(name, **kwargs): return ret +def pv_absent(name): + ''' + Ensure that a Physical Device is not being used by lvm + + name + The device name to initialize. + ''' + ret = {'changes': {}, + 'comment': '', + 'name': name, + 'result': True} + + if not __salt__['lvm.pvdisplay'](name): + ret['comment'] = 'Physical Volume {0} does not exist'.format(name) + elif __opts__['test']: + ret['comment'] = 'Physical Volume {0} is set to be removed'.format(name) + ret['result'] = None + return ret + else: + changes = __salt__['lvm.pvremove'](name) + + if not __salt__['lvm.pvdisplay'](name): + ret['comment'] = 'Failed to remove Physical Volume {0}'.format(name) + ret['result'] = False + else: + ret['comment'] = 'Removed Physical Volume {0}'.format(name) + ret['changes'] = changes + return ret + + def vg_present(name, devices=None, **kwargs): ''' Create an LVM volume group