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.
This commit is contained in:
Daniel Wallace 2014-05-11 22:11:53 -05:00
parent e988137d90
commit 4c154fb55b
2 changed files with 47 additions and 0 deletions

View File

@ -202,6 +202,23 @@ def pvcreate(devices, **kwargs):
return out[0] 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): def vgcreate(vgname, devices, **kwargs):
''' '''
Create an LVM volume group Create an LVM volume group

View File

@ -69,6 +69,36 @@ def pv_present(name, **kwargs):
return ret 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): def vg_present(name, devices=None, **kwargs):
''' '''
Create an LVM volume group Create an LVM volume group