def lvcreate(vgname, lvname, size): vg = get_first_by_key_value(vgdisplay(), 'name', vgname) # check if vg exists if not vg: raise errors.VGNotFoundError( 'Error while creating vg: vg %s not found' % vgname) # check if enough space is available if vg['free'] < size: raise errors.NotEnoughSpaceError( 'Error while creating lv: vg %s has only %s m of free space, ' 'but at least %s m is needed' % (vgname, vg['free'], size)) # check if lv already exists if next( (x for x in lvdisplay() if x['name'] == lvname and x['vg'] == vgname), False): raise errors.LVAlreadyExistsError( 'Error while creating lv: lv %s already exists' % lvname) # NOTE(agordeev): by default, lvcreate is configured to wipe signature # on allocated volume. '--yes' should be passed to avoid waiting for # user's confirmation: # "WARNING: <signature> signature detected on <device>. Wipe it? [y/n]" # FIXME: the version of lvm2 shipped with Ubuntu 14.04 does not support # --yes option. fuel-agent should properly decomission the storage # (Ubuntu installer does that just fine). stdout, stderr = utils.execute('lvcreate', '--help') force_opt = '--yes' if '--yes' in stdout else '' cmd = 'lvcreate {force_opt} -L {size}m -n {lvname} {vgname}'.format( size=size, lvname=lvname, vgname=vgname, force_opt=force_opt) utils.execute(*cmd.split(), check_exit_code=[0])
def lvcreate(vgname, lvname, size): vg = filter(lambda x: x['name'] == vgname, vgdisplay()) # check if vg exists if not vg: raise errors.VGNotFoundError( 'Error while creating vg: vg %s not found' % vgname) # check if enough space is available if vg[0]['free'] < size: raise errors.NotEnoughSpaceError( 'Error while creating lv: vg %s has only %s m of free space, ' 'but at least %s m is needed' % (vgname, vg[0]['free'], size)) # check if lv already exists if filter(lambda x: x['name'] == lvname and x['vg'] == vgname, lvdisplay()): raise errors.LVAlreadyExistsError( 'Error while creating lv: lv %s already exists' % lvname) # NOTE(agordeev): by default, lvcreate is configured to wipe signature # on allocated volume. '--yes' should be passed to avoid waiting for # user's confirmation: # "WARNING: <signature> signature detected on <device>. Wipe it? [y/n]" utils.execute('lvcreate', '--yes', '-L', '%sm' % size, '-n', lvname, vgname, check_exit_code=[0])
def lvcreate(vgname, lvname, size): vg = filter(lambda x: x['name'] == vgname, vgdisplay()) # check if vg exists if not vg: raise errors.VGNotFoundError( 'Error while creating vg: vg %s not found' % vgname) # check if enough space is available if vg[0]['free'] < size: raise errors.NotEnoughSpaceError( 'Error while creating lv: vg %s has only %s m of free space, ' 'but at least %s m is needed' % (vgname, vg[0]['free'], size)) # check if lv already exists if filter(lambda x: x['name'] == lvname, lvdisplay()): raise errors.LVAlreadyExistsError( 'Error while creating lv: lv %s already exists' % lvname) utils.execute('lvcreate', '-L', '%sm' % size, '-n', lvname, vgname, check_exit_code=[0])