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)
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)
def __init__(self, *args, **kwargs): super(DmCryptDevice, self).__init__(*args, **kwargs) for line in misc.get_partitions(): device = {} devname = line[3] signature = misc.get_signature(devname) if signature in CRYPT_SIGNATURES: device['hide'] = False device['dev_name'] = devname device['pool_name'] = self.default_pool_name device['dev_free'] = '0' device['dev_used'] = str(misc.get_device_size(devname)) self.data[devname] = device
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)
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)