Exemplo n.º 1
0
def _get_pvs_info():
    """ Collect storage info from pvs command """
    for entry in _get_cmd_output(['pvs', '--noheadings', '--separator', r':'], ':', 6):
        pv, vg, fmt, attr, psize, pfree = entry
        yield PvsEntry(
            pv=pv,
            vg=vg,
            fmt=fmt,
            attr=attr,
            psize=psize,
            pfree=pfree)
Exemplo n.º 2
0
def test_get_pvs_info(monkeypatch):
    def get_cmd_output_mocked(cmd, delim, expected_len):
        return [
            ['/dev/vda2', 'rhel_ibm-p8-kvm-03-guest-02', 'lvm2', 'a--', '<39.00g', '4.00m']]

    monkeypatch.setattr(library, '_get_cmd_output', get_cmd_output_mocked)
    expected = [
        PvsEntry(
            pv='/dev/vda2',
            vg='rhel_ibm-p8-kvm-03-guest-02',
            fmt='lvm2',
            attr='a--',
            psize='<39.00g',
            pfree='4.00m')]
    assert expected == library._get_pvs_info()
Exemplo n.º 3
0
    def process(self):
        result = StorageInfo()

        partitions_path = '/proc/partitions'
        if self.is_file_readable(partitions_path):
            with open(partitions_path, 'r') as partitions:
                skipped_header = False
                for entry in partitions:
                    if entry.startswith('#'):
                        continue

                    if not skipped_header:
                        skipped_header = True
                        continue

                    entry = entry.strip()
                    if not entry:
                        continue

                    major, minor, blocks, name = entry.split()
                    result.partitions.append(
                        PartitionEntry(major=major,
                                       minor=minor,
                                       blocks=blocks,
                                       name=name))

        fstab_path = '/etc/fstab'
        if self.is_file_readable(fstab_path):
            with open(fstab_path, 'r') as fstab:
                for entry in fstab:
                    if entry.startswith('#'):
                        continue

                    entry = entry.strip()
                    if not entry:
                        continue

                    fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = entry.split(
                    )
                    result.fstab.append(
                        FstabEntry(fs_spec=fs_spec,
                                   fs_file=fs_file,
                                   fs_vfstype=fs_vfstype,
                                   fs_mntops=fs_mntops,
                                   fs_freq=fs_freq,
                                   fs_passno=fs_passno))

        for entry in self.get_cmd_output(['mount'], ' ', 6):
            name, _, mount, _, tp, options = entry
            result.mount.append(
                MountEntry(name=name, mount=mount, tp=tp, options=options))

        for entry in self.get_cmd_output(['lsblk', '-r', '--noheadings'], ' ',
                                         7):
            name, maj_min, rm, size, ro, tp, mountpoint = entry
            result.lsblk.append(
                LsblkEntry(name=name,
                           maj_min=maj_min,
                           rm=rm,
                           size=size,
                           ro=ro,
                           tp=tp,
                           mountpoint=mountpoint))

        for entry in self.get_cmd_output(
            ['pvs', '--noheadings', '--separator', r':'], ':', 6):
            pv, vg, fmt, attr, psize, pfree = entry
            result.pvs.append(
                PvsEntry(pv=pv,
                         vg=vg,
                         fmt=fmt,
                         attr=attr,
                         psize=psize,
                         pfree=pfree))

        for entry in self.get_cmd_output(
            ['vgs', '--noheadings', '--separator', r':'], ':', 7):
            vg, pv, lv, sn, attr, vsize, vfree = entry
            result.vgs.append(
                VgsEntry(vg=vg,
                         pv=pv,
                         lv=lv,
                         sn=sn,
                         attr=attr,
                         vsize=vsize,
                         vfree=vfree))

        for entry in self.get_cmd_output(
            ['lvdisplay', '-C', '--noheadings', '--separator', r':'], ':', 12):
            lv, vg, attr, lsize, pool, origin, data, meta, move, log, cpy_sync, convert = entry
            result.lvdisplay.append(
                LvdisplayEntry(lv=lv,
                               vg=vg,
                               attr=attr,
                               lsize=lsize,
                               pool=pool,
                               origin=origin,
                               data=data,
                               meta=meta,
                               move=move,
                               log=log,
                               cpy_sync=cpy_sync,
                               convert=convert))

        self.produce(result)
Exemplo n.º 4
0
    def process(self):
        result = StorageInfo()

        partitions_path = '/proc/partitions'
        if self.is_file_readable(partitions_path):
            with open(partitions_path, 'r') as partitions:
                skipped_header = False
                for entry in partitions:
                    if entry.startswith('#'):
                        continue

                    if not skipped_header:
                        skipped_header = True
                        continue

                    entry = entry.strip()
                    if not entry:
                        continue

                    major, minor, blocks, name = entry.split()
                    result.partitions.append(PartitionEntry(
                        major=major,
                        minor=minor,
                        blocks=blocks,
                        name=name))

        fstab_path = '/etc/fstab'
        if self.is_file_readable(fstab_path):
            with open(fstab_path, 'r') as fstab:
                for entry in fstab:
                    if entry.startswith('#'):
                        continue

                    entry = entry.strip()
                    if not entry:
                        continue

                    fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq, fs_passno = entry.split()
                    result.fstab.append(FstabEntry(
                        fs_spec=fs_spec,
                        fs_file=fs_file,
                        fs_vfstype=fs_vfstype,
                        fs_mntops=fs_mntops,
                        fs_freq=fs_freq,
                        fs_passno=fs_passno))

        for entry in self.get_cmd_output(['mount'], ' ', 6):
            name, _, mount, _, tp, options = entry
            result.mount.append(MountEntry(
                name=name,
                mount=mount,
                tp=tp,
                options=options))

        for entry in self.get_cmd_output(['lsblk', '-r', '--noheadings'], ' ', 7):
            name, maj_min, rm, size, ro, tp, mountpoint = entry
            result.lsblk.append(LsblkEntry(
                name=name,
                maj_min=maj_min,
                rm=rm,
                size=size,
                ro=ro,
                tp=tp,
                mountpoint=mountpoint))

        for entry in self.get_cmd_output(['pvs', '--noheadings', '--separator', r':'], ':', 6):
            pv, vg, fmt, attr, psize, pfree = entry
            result.pvs.append(PvsEntry(
                pv=pv,
                vg=vg,
                fmt=fmt,
                attr=attr,
                psize=psize,
                pfree=pfree))

        for entry in self.get_cmd_output(['vgs', '--noheadings', '--separator', r':'], ':', 7):
            vg, pv, lv, sn, attr, vsize, vfree = entry
            result.vgs.append(VgsEntry(
                vg=vg,
                pv=pv,
                lv=lv,
                sn=sn,
                attr=attr,
                vsize=vsize,
                vfree=vfree))

        for entry in self.get_cmd_output(['lvdisplay', '-C', '--noheadings', '--separator', r':'], ':', 12):
            lv, vg, attr, lsize, pool, origin, data, meta, move, log, cpy_sync, convert = entry
            result.lvdisplay.append(LvdisplayEntry(
                lv=lv,
                vg=vg,
                attr=attr,
                lsize=lsize,
                pool=pool,
                origin=origin,
                data=data,
                meta=meta,
                move=move,
                log=log,
                cpy_sync=cpy_sync,
                convert=convert))

        for entry in self.get_cmd_output(['systemd-mount', '--list'], ' ', 7):
            # We need to filter the entry because there is a ton of whitespace.
            node, path, model, wwn, fs_type, label, uuid = list(filter(lambda x: x != '', entry))
            if node == "NODE":
                # First row of the "systemd-mount --list" output is a header.
                # Just skip it.
                continue
            result.systemdmount.append(SystemdMountEntry(
                node=node,
                path=path,
                model=model,
                wwn=wwn,
                fs_type=fs_type,
                label=label,
                uuid=uuid))

        self.produce(result)