Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super(MdRaid, self).__init__(*args, **kwargs)
        self.type = 'dm'
        self._vol = {}
        self._pool = {}
        self._dev = {}
        self.hostname = socket.gethostname()
        self._binary = misc.check_binary(MDADM)
        self.default_pool_name = SSM_DM_DEFAULT_POOL
        self.attrs = [
            'dev_name', 'pool_name', 'dev_free', 'dev_used', 'dev_size'
        ]

        if not self._binary:
            return

        self.mounts = misc.get_mounts('/dev/md')
        self.swaps = misc.get_swaps()

        mdnumber = misc.get_dmnumber("md")

        for line in misc.get_partitions():
            devname = line[3]
            devsize = int(line[2])
            if line[0] == mdnumber:
                self._vol[devname] = self.get_volume_data(devname)
                for dev in misc.get_slaves(os.path.basename(devname)):
                    self._dev[dev] = self.get_device_data(dev, devsize)
Exemplo n.º 2
0
    def __init__(self, options, data=None):
        self.type = 'dm'
        self.data = data or {}
        self._vol = {}
        self._pool = {}
        self._dev = {}
        self.options = options
        self.hostname = socket.gethostname()
        self._binary = misc.check_binary(MDADM)
        self.default_pool_name = SSM_DM_DEFAULT_POOL
        self.attrs = [
            'dev_name', 'pool_name', 'dev_free', 'dev_used', 'dev_size'
        ]

        if not self._binary:
            return

        self.problem = problem.ProblemSet(options)
        self.mounts = misc.get_mounts('/dev/md')

        mdnumber = misc.get_dmnumber("md")

        for line in misc.get_partitions():
            devname = '/dev/' + line[3]
            devsize = int(line[2])
            if line[0] == mdnumber:
                self._vol[devname] = self.get_volume_data(devname)
                for dev in misc.get_slaves(os.path.basename(devname)):
                    self._dev[dev] = self.get_device_data(dev, devsize)
Exemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        super(DmObject, self).__init__(*args, **kwargs)
        self.type = 'crypt'
        self.mounts = misc.get_mounts('{0}/mapper'.format(DM_DEV_DIR))
        self.default_pool_name = SSM_CRYPT_DEFAULT_POOL

        if not misc.check_binary('dmsetup') or \
           not misc.check_binary('cryptsetup'):
            return
Exemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     super(LvsInfo, self).__init__(*args, **kwargs)
     command = [
         "lvm", "lvs", "--separator", "|", "--noheadings", "--nosuffix",
         "--units", "k", "-o",
         "vg_name,lv_size,stripes,stripesize,segtype,lv_name,origin,lv_attr,pool_lv"
     ]
     self.attrs = [
         'pool_name', 'vol_size', 'stripes', 'stripesize', 'type',
         'lv_name', 'origin', 'attr', 'pool_lv'
     ]
     self.handle_fs = True
     self.mounts = misc.get_mounts('{0}/mapper'.format(DM_DEV_DIR))
     self._parse_data(command)
Exemplo n.º 5
0
    def __init__(self, options, data=None):
        self.type = 'multipath'
        self.data = data or {}
        self._dev = {}
        self.options = options
        self.output = None
        self.problem = problem.ProblemSet(options)
        self.swaps = misc.get_swaps()
        self.mounts = misc.get_mounts('{0}/mapper'.format(DM_DEV_DIR))

        for mp_dev in self.get_mp_devices():
            mpname = self.get_real_device(mp_dev)
            self._dev[mp_dev] = self.get_volume_data(mp_dev)
            for devname in self._dev[mp_dev]['nodes']:
                self._dev[devname] = self.get_device_data(devname, mpname, 0)
Exemplo n.º 6
0
    def __init__(self, options, data=None):
        self.type = 'crypt'
        self.data = data or {}
        self.output = None
        self.options = options
        self.mounts = misc.get_mounts('{0}/mapper'.format(DM_DEV_DIR))
        self.default_pool_name = SSM_CRYPT_DEFAULT_POOL
        self.problem = problem.ProblemSet(options)

        if not misc.check_binary('dmsetup') or \
           not misc.check_binary('cryptsetup'):
            return
        command = ['dmsetup', 'table']
        self.output = misc.run(command, stderr=False)[1]
        for line in self.output.split("\n"):
            if not line or line == "No devices found":
                break
            dm = {}
            array = line.split()
            dm['type'] = array[3]
            if dm['type'] != 'crypt':
                continue
            dm['vol_size'] = str(int(array[2]) / 2.0)
            devname = re.sub(":$", "",
                             "{0}/mapper/{1}".format(DM_DEV_DIR, array[0]))
            dm['dm_name'] = devname
            dm['pool_name'] = 'dm-crypt'
            dm['dev_name'] = misc.get_real_device(devname)
            dm['real_dev'] = dm['dev_name']
            if dm['real_dev'] in self.mounts:
                dm['mount'] = self.mounts[dm['real_dev']]['mp']

            # Check if the device really exists in the system. In some cases
            # (tests) DM_DEV_DIR can lie to us, if that is the case, simple
            # ignore the device.
            if not os.path.exists(devname):
                continue
            command = ['cryptsetup', 'status', devname]
            self._parse_cryptsetup(command, dm)
            self.data[dm['dev_name']] = dm
Exemplo n.º 7
0
    def __init__(self, *args, **kwargs):
        super(Btrfs, self).__init__(*args, **kwargs)
        self.type = 'btrfs'
        self.default_pool_name = SSM_BTRFS_DEFAULT_POOL
        self._vol = {}
        self._pool = {}
        self._dev = {}
        self._snap = {}
        self._subvolumes = {}
        self._binary = misc.check_binary('btrfs')
        self.modified_list_version = True

        if not self._binary:
            return

        self.mounts = misc.get_mounts('btrfs')
        command = ['btrfs', 'filesystem', 'show']
        self.output = misc.run(command, stderr=False)[1]

        vol = {}
        pool = {}
        dev = {}
        partitions = {}
        fs_size = pool_size = fs_used = 0
        pool_name = ''
        for line in misc.get_partitions():
            partitions[line[3]] = line

        for line in self.output.strip().split("\n"):
            if not line:
                continue
            array = line.split()

            if array[0] == 'Label:':
                if len(vol) > 0:
                    self._store_data(vol, pool, fs_used, fs_size, pool_size,
                                     pool_name)
                    vol = {}
                    pool = {}
                    fs_size = pool_size = 0
                    pool_name = ''

                label = array[1].strip("'")
                uuid = array[3]
                pool['uuid'] = vol['uuid'] = uuid

                try:
                    vol['real_dev'] = misc.get_device_by_uuid(uuid)

                    if vol['real_dev'] in self.mounts:
                        pool['mount'] = self.mounts[vol['real_dev']]['mp']
                        vol['mount'] = self.mounts[vol['real_dev']]['mp']

                    else:
                        for dev_i in self.mounts:
                            found = re.findall(
                                r'{0}:/.*'.format(vol['real_dev']), dev_i)
                            if found:
                                pool['mount'] = self.mounts[found[0]]['mp']
                                break
                except OSError:
                    # udev is "hard-to-work-with" sometimes so this is fallback
                    vol['real_dev'] = ""

                if label != 'none':
                    vol['label'] = label
                vol['ID'] = 0

            elif array[0] == 'Total':
                pool['dev_count'] = array[2]
                fs_used = float(misc.get_real_size(array[6]))

            elif array[0] == 'devid':
                # This is ugly hack to fix a problem with test suite and btrfs
                # where ?sometimes? btrfs prints out device name in the path
                # of the test suite rather than path in the real '/dev/'
                # directory. This should cover that without any impact on
                # real usage
                if not os.path.islink(array[7]):
                    array[7] = re.sub(r'.*/dev/', '/dev/', array[7])
                dev['dev_name'] = misc.get_real_device(array[7])

                if not pool_name:
                    pool_name = self._find_uniq_pool_name(label, array[7])
                dev['pool_name'] = pool_name

                # Fallback in case we could not find real_dev by uuid
                if 'mount' not in pool:
                    if dev['dev_name'] in self.mounts:
                        pool['mount'] = self.mounts[dev['dev_name']]['mp']
                        vol['real_dev'] = dev['dev_name']

                        if 'root' in self.mounts[dev['dev_name']]:
                            if self.mounts[dev['dev_name']]['root'] == '/':
                                vol['mount'] = self.mounts[
                                    dev['dev_name']]['mp']
                    else:
                        for dev_i in self.mounts:
                            found = re.findall(
                                r'{0}:/.*'.format(dev['dev_name']), dev_i)
                            if found:
                                pool['mount'] = self.mounts[found[0]]['mp']
                                vol['real_dev'] = found[0].split(':')[0]
                                break

                dev_used = float(misc.get_real_size(array[5]))
                dev['dev_used'] = str(dev_used)
                fs_size += float(misc.get_real_size(array[3]))

                dev_size = \
                    int(partitions[dev['dev_name']][2])
                pool_size += dev_size
                dev['dev_free'] = dev_size - dev_used
                dev['hide'] = False
                self._dev[dev['dev_name']] = dev
                dev = {}

        if len(vol) > 0:
            self._store_data(vol, pool, fs_used, fs_size, pool_size, pool_name)
Exemplo n.º 8
0
    def __init__(self, options, data=None):
        self.type = 'btrfs'
        self.data = data or {}
        self.options = options
        self.default_pool_name = SSM_BTRFS_DEFAULT_POOL
        self._vol = {}
        self._pool = {}
        self._dev = {}
        self._snap = {}
        self._subvolumes = {}
        self._binary = misc.check_binary('btrfs')
        self.problem = problem.ProblemSet(options)
        self.modified_list_version = True

        if not self._binary:
            return

        self.mounts = misc.get_mounts('/dev/')
        command = ['btrfs', 'filesystem', 'show']
        self.output = misc.run(command, stderr=False)[1]

        vol = {}
        pool = {}
        dev = {}
        partitions = {}
        fs_size = pool_size = fs_used = 0
        pool_name = ''
        for line in misc.get_partitions():
            partitions[line[3]] = line

        for line in self.output.strip().split("\n"):
            if not line:
                continue
            array = line.split()

            if array[0] == 'Label:':
                if len(vol) > 0:
                    self._store_data(vol, pool, fs_used, fs_size, pool_size,
                                     pool_name)
                    vol = {}
                    pool = {}
                    fs_size = pool_size = 0
                    pool_name = ''

                label = array[1].strip("'")
                uuid = array[3]
                pool['uuid'] = vol['uuid'] = uuid

                try:
                    fallback = False
                    vol['real_dev'] = misc.get_device_by_uuid(uuid)

                    if vol['real_dev'] in self.mounts:
                        pool['mount'] = self.mounts[vol['real_dev']]['mp']
                        vol['mount'] = self.mounts[vol['real_dev']]['mp']
                    else:
                        for dev_i in self.mounts:
                            found = re.findall(
                                r'{0}:/.*'.format(vol['real_dev']), dev_i)
                            if found:
                                pool['mount'] = self.mounts[found[0]]['mp']
                                break
                except OSError:
                    # udev is "hard-to-work-with" sometimes so this is fallback
                    fallback = True
                    vol['real_dev'] = ""

                if label != 'none':
                    vol['label'] = label
                vol['ID'] = 0

            elif array[0] == 'Total':
                pool['dev_count'] = array[2]
                fs_used = get_real_number(array[6])

            elif array[0] == 'devid':
                dev['dev_name'] = array[7]

                if not pool_name:
                    pool_name = self._find_uniq_pool_name(label, array[7])
                dev['pool_name'] = pool_name

                # Fallback in case we could not find real_dev by uuid
                if fallback and 'mount' not in pool:
                    if dev['dev_name'] in self.mounts:
                        pool['mount'] = self.mounts[dev['dev_name']]['mp']
                        vol['real_dev'] = dev['dev_name']

                        if 'root' in self.mounts[dev['dev_name']]:
                            if self.mounts[dev['dev_name']]['root'] == '/':
                                vol['mount'] = self.mounts[
                                    dev['dev_name']]['mp']
                    else:
                        for dev_i in self.mounts:
                            found = re.findall(
                                r'{0}:/.*'.format(dev['dev_name']), dev_i)
                            if found:
                                pool['mount'] = self.mounts[found[0]]['mp']
                                break

                dev_used = get_real_number(array[5])
                dev['dev_used'] = str(dev_used)
                fs_size += get_real_number(array[3])

                dev_size = \
                    int(partitions[dev['dev_name'].rpartition("/")[-1]][2])
                pool_size += dev_size
                dev['dev_free'] = dev_size - dev_used
                self._dev[dev['dev_name']] = dev
                dev = {}

        if len(vol) > 0:
            self._store_data(vol, pool, fs_used, fs_size, pool_size, pool_name)