Esempio n. 1
0
    def get_all_physical_volumes(root_helper, vg_name=None):
        """Static method to get all PVs on a system.

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :returns: List of Dictionaries with PV info

        """
        cmd = ['env', 'LC_ALL=C', 'pvs', '--noheadings',
               '--unit=g',
               '-o', 'vg_name,name,size,free',
               '--separator', ':',
               '--nosuffix']

        (out, err) = putils.execute(*cmd,
                                    root_helper=root_helper,
                                    run_as_root=True)

        pvs = out.split()
        if vg_name is not None:
            pvs = [pv for pv in pvs if vg_name == pv.split(':')[0]]

        pv_list = []
        for pv in pvs:
            fields = pv.split(':')
            pv_list.append({'vg': fields[0],
                            'name': fields[1],
                            'size': float(fields[2]),
                            'available': float(fields[3])})
        return pv_list
Esempio n. 2
0
    def get_all_volume_groups(root_helper, vg_name=None):
        """Static method to get all VGs on a system.

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :returns: List of Dictionaries with VG info

        """
        cmd = ['env', 'LC_ALL=C', 'vgs', '--noheadings', '--unit=g',
               '-o', 'name,size,free,lv_count,uuid', '--separator', ':',
               '--nosuffix']

        if vg_name is not None:
            cmd.append(vg_name)

        (out, err) = putils.execute(*cmd,
                                    root_helper=root_helper,
                                    run_as_root=True)

        vg_list = []
        if out is not None:
            vgs = out.split()
            for vg in vgs:
                fields = vg.split(':')
                vg_list.append({'name': fields[0],
                                'size': float(fields[1]),
                                'available': float(fields[2]),
                                'lv_count': int(fields[3]),
                                'uuid': fields[4]})

        return vg_list
Esempio n. 3
0
File: lvm.py Progetto: e0ne/brick
    def get_all_volume_groups(root_helper, vg_name=None):
        """Static method to get all VGs on a system.

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :returns: List of Dictionaries with VG info

        """
        cmd = [
            'env', 'LC_ALL=C', 'vgs', '--noheadings', '--unit=g', '-o',
            'name,size,free,lv_count,uuid', '--separator', ':', '--nosuffix'
        ]

        if vg_name is not None:
            cmd.append(vg_name)

        (out, err) = putils.execute(*cmd,
                                    root_helper=root_helper,
                                    run_as_root=True)

        vg_list = []
        if out is not None:
            vgs = out.split()
            for vg in vgs:
                fields = vg.split(':')
                vg_list.append({
                    'name': fields[0],
                    'size': float(fields[1]),
                    'available': float(fields[2]),
                    'lv_count': int(fields[3]),
                    'uuid': fields[4]
                })

        return vg_list
Esempio n. 4
0
    def get_all_volumes(root_helper, vg_name=None):
        """Static method to get all LV's on a system.

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :returns: List of Dictionaries with LV info

        """

        cmd = ['env', 'LC_ALL=C', 'lvs', '--noheadings', '--unit=g',
               '-o', 'vg_name,name,size', '--nosuffix']

        if vg_name is not None:
            cmd.append(vg_name)

        (out, err) = putils.execute(*cmd,
                                    root_helper=root_helper,
                                    run_as_root=True)

        lv_list = []
        if out is not None:
            volumes = out.split()
            for vg, name, size in itertools.izip(*[iter(volumes)] * 3):
                lv_list.append({"vg": vg, "name": name, "size": size})

        return lv_list
Esempio n. 5
0
File: lvm.py Progetto: e0ne/brick
    def get_all_physical_volumes(root_helper, vg_name=None):
        """Static method to get all PVs on a system.

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :returns: List of Dictionaries with PV info

        """
        cmd = [
            'env', 'LC_ALL=C', 'pvs', '--noheadings', '--unit=g', '-o',
            'vg_name,name,size,free', '--separator', ':', '--nosuffix'
        ]

        (out, err) = putils.execute(*cmd,
                                    root_helper=root_helper,
                                    run_as_root=True)

        pvs = out.split()
        if vg_name is not None:
            pvs = [pv for pv in pvs if vg_name == pv.split(':')[0]]

        pv_list = []
        for pv in pvs:
            fields = pv.split(':')
            pv_list.append({
                'vg': fields[0],
                'name': fields[1],
                'size': float(fields[2]),
                'available': float(fields[3])
            })
        return pv_list
Esempio n. 6
0
File: lvm.py Progetto: e0ne/brick
    def get_all_volumes(root_helper, vg_name=None):
        """Static method to get all LV's on a system.

        :param root_helper: root_helper to use for execute
        :param vg_name: optional, gathers info for only the specified VG
        :returns: List of Dictionaries with LV info

        """

        cmd = [
            'env', 'LC_ALL=C', 'lvs', '--noheadings', '--unit=g', '-o',
            'vg_name,name,size', '--nosuffix'
        ]

        if vg_name is not None:
            cmd.append(vg_name)

        (out, err) = putils.execute(*cmd,
                                    root_helper=root_helper,
                                    run_as_root=True)

        lv_list = []
        if out is not None:
            volumes = out.split()
            for vg, name, size in itertools.izip(*[iter(volumes)] * 3):
                lv_list.append({"vg": vg, "name": name, "size": size})

        return lv_list
Esempio n. 7
0
    def temporary_chown(self, path, owner_uid=None):
        """Temporarily chown a path.

        :params path: The path to chown
        :params owner_uid: UID of temporary owner (defaults to current user)
        """
        if owner_uid is None:
            owner_uid = os.getuid()

        orig_uid = os.stat(path).st_uid

        if orig_uid != owner_uid:
            putils.execute('chown', owner_uid, path,
                           root_helper=self._root_helper, run_as_root=True)
        try:
            yield
        finally:
            if orig_uid != owner_uid:
                putils.execute('chown', orig_uid, path,
                               root_helper=self._root_helper, run_as_root=True)
Esempio n. 8
0
    def get_lvm_version(root_helper):
        """Static method to get LVM version from system.

        :param root_helper: root_helper to use for execute
        :returns: version 3-tuple

        """

        cmd = ['env', 'LC_ALL=C', 'vgs', '--version']
        (out, err) = putils.execute(*cmd,
                                    root_helper=root_helper,
                                    run_as_root=True)
        lines = out.split('\n')

        for line in lines:
            if 'LVM version' in line:
                version_list = line.split()
                # NOTE(gfidente): version is formatted as follows:
                # major.minor.patchlevel(library API version)[-customisation]
                version = version_list[2]
                version_filter = r"(\d+)\.(\d+)\.(\d+).*"
                r = re.search(version_filter, version)
                version_tuple = tuple(map(int, r.group(1, 2, 3)))
                return version_tuple
Esempio n. 9
0
File: lvm.py Progetto: e0ne/brick
    def get_lvm_version(root_helper):
        """Static method to get LVM version from system.

        :param root_helper: root_helper to use for execute
        :returns: version 3-tuple

        """

        cmd = ['env', 'LC_ALL=C', 'vgs', '--version']
        (out, err) = putils.execute(*cmd,
                                    root_helper=root_helper,
                                    run_as_root=True)
        lines = out.split('\n')

        for line in lines:
            if 'LVM version' in line:
                version_list = line.split()
                # NOTE(gfidente): version is formatted as follows:
                # major.minor.patchlevel(library API version)[-customisation]
                version = version_list[2]
                version_filter = r"(\d+)\.(\d+)\.(\d+).*"
                r = re.search(version_filter, version)
                version_tuple = tuple(map(int, r.group(1, 2, 3)))
                return version_tuple
Esempio n. 10
0
def execute(*cmd, **kwargs):
    """Convenience wrapper around oslo's execute() method."""
    if 'run_as_root' in kwargs and 'root_helper' not in kwargs:
        kwargs['root_helper'] = get_root_helper()
    return processutils.execute(*cmd, **kwargs)
Esempio n. 11
0
File: utils.py Progetto: e0ne/brick
def execute(*cmd, **kwargs):
    """Convenience wrapper around oslo's execute() method."""
    if 'run_as_root' in kwargs and 'root_helper' not in kwargs:
        kwargs['root_helper'] = get_root_helper()
    return processutils.execute(*cmd, **kwargs)