Exemplo n.º 1
0
def unmount_lvm2(vg):
    """
    Remove logical volume data from system.

    Parameters
    ----------
    vg: dict
        Volume group with list of logical volumes.

    Returns
    -------
        bool: True on Success, exception otherwise.
    """
    _logger.debug('__ Remove %s from system.' % vg)
    try:
        #
        # make unavailable
        for vg_name in list(vg.keys()):
            vgchange_args = ['--activate', 'n', vg_name]
            vgchange_res = system_tools.exec_vgchange(vgchange_args)
            _logger.debug('vgchange: %s' % vgchange_res)
        #
        # remove physical volume: clear cache, if necessary
        if system_tools.exec_pvscan(['--cache']):
            _logger.debug('pvscan clear succeeded')
        else:
            _logger.error('  pvscan failed')
    except Exception as e:
        _logger.error('  Failed to release lvms %s: %s' % (vg, str(e)))
        error_msg('Failed to release lvms %s: %s' % (vg, str(e)))
Exemplo n.º 2
0
def mount_lvm2(devname):
    """
    Create the mountpoints /mnt/<last part of lvm partitions> and mount the
    partitions on those mountpoints, if possible.

    Parameters
    ----------
    devname: str
        The full path of the device

    Returns
    -------
        list: The list of mounted partitions.
        ?? need to collect lvm2 list this way??
    """
    _logger.debug('__ Running mount lvm2 %s' % devname)
    try:
        _, nbcols = terminal_dimension()
        mountwait = ProgressBar(int(nbcols),
                                0.2,
                                progress_chars=['mounting lvm'])
        mountwait.start()
        #
        # physical volumes
        if system_tools.exec_pvscan(['--cache'], devname):
            _logger.debug('pvscan %s succeeded' % devname)
        else:
            _logger.critical('   pvscan %s failed' % devname)
        #
        pause_msg('pvscan test')
        #
        # volume groups
        if system_tools.exec_vgscan(['--verbose']):
            _logger.debug('vgscan succeeded')
        else:
            _logger.critical('   vgscan failed')
        #
        pause_msg('vgscan test')
        #
        # logical volumes
        vgs = new_volume_groups()
        if bool(vgs):
            _logger.debug('lvscan succeeded: %s' % vgs)
        else:
            _logger.critical('   lvscan failed')
        #
        pause_msg('lvscan test')
        #
        # make available
        vgchange_args = ['--activate', 'y']
        vgchange_res = system_tools.exec_vgchange(vgchange_args)
        _logger.debug('vgchange:\n%s' % vgchange_res)
        #
        pause_msg('vgchange_res test')
        vgfound = False
        if vgchange_res is not None:
            for resline in vgchange_res.splitlines():
                _logger.debug('vgchange line: %s' % resline)
                for vg in list(vgs.keys()):
                    if vg in resline:
                        _logger.debug('vgfound set to True')
                        vgfound = True
                    else:
                        _logger.debug('vg %s not in l' % vg)
            _logger.debug('vgchange: %s found: %s' % (vgchange_res, vgfound))
            #
            # for the sake of testing
            pause_msg('vgchange_res test')
        else:
            _logger.critical('   vgchange failed')
        return vgs
    except Exception as e:
        _logger.critical('   Mount lvm %s failed: %s' % (devname, str(e)))
        raise OciMigrateException('Mount lvm %s failed: %s' %
                                  (devname, str(e)))
    finally:
        if system_tools.is_thread_running(mountwait):
            mountwait.stop()