예제 #1
0
파일: lvm.py 프로젝트: frescof/freezer
def get_lvm_info(backup_opt_dict):
    """
    Take a file system path as argument as backup_opt_dict.path_to_backup
    and return a dictionary containing dictionary['lvm_srcvol']
    and dictionary['lvm_volgroup'] where the path is mounted on.

    :param backup_opt_dict: backup_opt_dict.path_to_backup, the file system
    path
    :returns: the dictionary backup_opt_dict containing keys lvm_srcvol
              and lvm_volgroup with respective values
    """

    mount_point_path = get_mount_from_path(backup_opt_dict.lvm_auto_snap)
    with open('/proc/mounts', 'r') as mount_fd:
        mount_points = mount_fd.readlines()

    for mount_line in mount_points:
        device, mount_path = mount_line.split(' ')[0:2]
        if mount_point_path.strip() == mount_path.strip():
            mount_match = re.search(
                r'/dev/mapper/(\w.+?\w)-(\w.+?\w)$', device)
            if mount_match:
                backup_opt_dict.__dict__['lvm_volgroup'] = \
                    mount_match.group(1).replace('--', '-')
                lvm_srcvol = mount_match.group(2).replace('--', '-')
                backup_opt_dict.__dict__['lvm_srcvol'] = \
                    u'/dev/{0}/{1}'.format(
                    backup_opt_dict.lvm_volgroup, lvm_srcvol)
                return backup_opt_dict

    raise Exception("Cannot find {0} in {1}".format(
        mount_point_path, mount_points))
예제 #2
0
파일: lvm.py 프로젝트: stannie42/freezer
def get_lvm_info(backup_opt_dict):
    """
    Take a file system path as argument as backup_opt_dict.src_file
    and return a dictionary containing dictionary['lvm_srcvol']
    and dictionary['lvm_volgroup'] where the path is mounted on.

    :param backup_opt_dict: backup_opt_dict.src_file, the file system path
    :returns: the dictionary backup_opt_dict containing keys lvm_srcvol
              and lvm_volgroup with respective values
    """

    mount_point_path = get_mount_from_path(backup_opt_dict.lvm_auto_snap)
    with open('/proc/mounts', 'r') as mount_fd:
        mount_points = mount_fd.readlines()

    for mount_line in mount_points:
        device, mount_path = mount_line.split(' ')[0:2]
        if mount_point_path.strip() == mount_path.strip():
            mount_match = re.search(
                r'/dev/mapper/(\w.+?\w)-(\w.+?\w)$', device)
            if mount_match:
                backup_opt_dict.__dict__['lvm_volgroup'] = \
                    mount_match.group(1).replace('--', '-')
                lvm_srcvol = mount_match.group(2).replace('--', '-')
                backup_opt_dict.__dict__['lvm_srcvol'] = \
                    u'/dev/{0}/{1}'.format(
                    backup_opt_dict.lvm_volgroup, lvm_srcvol)
                break

    return backup_opt_dict
예제 #3
0
파일: lvm.py 프로젝트: sl4shme/freezer
def get_lvm_info(lvm_auto_snap):
    """
    Take a file system path as argument as backup_opt_dict.path_to_backup
    and return a list containing lvm_srcvol, lvm_volgroup
    where the path is mounted on.

    :param lvm_auto_snap: the original file system path where backup needs
    to be executed
    :returns: a list containing the items lvm_volgroup, lvm_srcvol, lvm_device
    """

    mount_point_path = get_mount_from_path(lvm_auto_snap)
    with open("/proc/mounts", "r") as mount_fd:
        mount_points = mount_fd.readlines()
        lvm_volgroup, lvm_srcvol, lvm_device = lvm_guess(mount_point_path, mount_points, "/proc/mounts")

    if not lvm_device:
        mount_process = subprocess.Popen(["mount"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os.environ)
        mount_out, mount_err = mount_process.communicate()
        mount_points = mount_out.split("\n")
        lvm_volgroup, lvm_srcvol, lvm_device = lvm_guess(mount_point_path, mount_points, "mount")

    if not lvm_device:
        raise Exception(
            "Cannot find {0} in {1}, please provide volume group and "
            "volume name explicitly".format(mount_point_path, mount_points)
        )

    return lvm_volgroup, lvm_srcvol, lvm_device
예제 #4
0
파일: lvm.py 프로젝트: kelepirci/freezer
def get_lvm_info(lvm_auto_snap):
    """
    Take a file system path as argument as backup_opt_dict.path_to_backup
    and return a list containing lvm_srcvol, lvm_volgroup
    where the path is mounted on.

    :param lvm_auto_snap: the original file system path where backup needs
    to be executed
    :returns: a dict containing the keys 'volgroup', 'srcvol' and 'snap_path'
    """

    mount_point_path, snap_path = utils.get_mount_from_path(lvm_auto_snap)

    with open('/proc/mounts', 'r') as mount_fd:
        mount_points = mount_fd.readlines()
        lvm_volgroup, lvm_srcvol, lvm_device = lvm_guess(
            mount_point_path, mount_points, '/proc/mounts')

    if not lvm_device:
        mount_process = subprocess.Popen(
            ['mount'], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            env=os.environ)
        mount_out, mount_err = mount_process.communicate()
        mount_points = mount_out.split('\n')
        lvm_volgroup, lvm_srcvol, lvm_device = lvm_guess(
            mount_point_path, mount_points, 'mount')

    if not lvm_device:
        raise Exception(
            'Cannot find {0} in {1}, please provide volume group and '
            'volume name explicitly'.format(mount_point_path, mount_points))

    lvm_params = {'volgroup': lvm_volgroup,
                  'srcvol': lvm_device,
                  'snap_path': snap_path}

    return lvm_params
예제 #5
0
 def test_get_mount_from_path(self):
     dir1 = '/tmp'
     dir2 = '/tmp/nonexistentpathasdf'
     assert type(utils.get_mount_from_path(dir1)[0]) is str
     assert type(utils.get_mount_from_path(dir1)[1]) is str
     self.assertRaises(Exception, utils.get_mount_from_path, dir2)
예제 #6
0
    def test_get_mount_from_path(self):

        dir1 = '/tmp'
        dir2 = '/tmp/nonexistentpathasdf'
        assert type(get_mount_from_path(dir1)) is str
        pytest.raises(Exception, get_mount_from_path, dir2)