def pvremove(pvname): pv = filter(lambda x: x['name'] == pvname, pvdisplay()) # check if pv exists if not pv: raise errors.PVNotFoundError( 'Error while removing pv: pv %s not found' % pvname) # check if pv is attached to some vg if pv[0]['vg'] is not None: raise errors.PVBelongsToVGError('Error while removing pv: ' 'pv belongs to vg %s' % pv[0]['vg']) utils.execute('pvremove', '-ff', '-y', pvname, check_exit_code=[0])
def _vg_attach_validate(pvnames): pvs = pvdisplay() # check if all necessary pv exist if not set(pvnames).issubset(set([pv['name'] for pv in pvs])): raise errors.PVNotFoundError( 'Error while creating vg: at least one of pv is not found') # check if all necessary pv are not already attached to some vg if not set(pvnames).issubset( set([pv['name'] for pv in pvs if pv['vg'] is None])): raise errors.PVBelongsToVGError( 'Error while creating vg: at least one of pvs is ' 'already attached to some vg')
def pvremove(pvname): pv = get_first_by_key_value(pvdisplay(), 'name', pvname) # check if pv exists if not pv: raise errors.PVNotFoundError( 'Error while removing pv: pv %s not found' % pvname) # check if pv is attached to some vg if pv['vg'] is not None: raise errors.PVBelongsToVGError('Error while removing pv: ' 'pv belongs to vg %s' % pv['vg']) utils.execute('pvremove', '-ff', '-y', pvname, check_exit_code=[0])
def vgreduce(vgname, pvname, *args): # check if vg exists if not filter(lambda x: x['name'] == vgname, vgdisplay()): raise errors.VGNotFoundError( 'Error while reducing vg: vg %s not found' % vgname) pvnames = [pvname] + list(args) # check if all necessary pv are attached to vg if not set(pvnames).issubset( set([pv['name'] for pv in pvdisplay() if pv['vg'] == vgname])): raise errors.PVNotFoundError( 'Error while reducing vg: at least one of pv is ' 'not attached to vg') utils.execute('vgreduce', '-f', vgname, *pvnames, check_exit_code=[0])