Esempio n. 1
0
 def get_disk_identifier(self, device_filepath):
     """parse Disk identifier: 0x0001ab30"""
     id_re = re.compile("^Disk\s+identifier:\s(?P<identifier>\w+)")
     for line in run_cmd(SIZE_FROM_FDISK + [device_filepath]).splitlines():
         match = id_re.match(line)
         if match:
             return match.group("identifier").strip()
     return None
Esempio n. 2
0
 def _extract_relevant_device_lines_from_multipath(self, device_name):
     device_re = re.compile("(?P<device_name>\w+)\s+\(\w+\)\s+dm-\d+")
     lines = []
     device_found = False
     for line in run_cmd(MULTIPATH_LIST).strip().splitlines():
         m = device_re.search(line)
         if m:
             if m.group("device_name") == device_name:
                 device_found = True
             else:
                 device_found = False
         if device_found:
             lines.append(line.strip())
     return lines
Esempio n. 3
0
    def _extract_uuid_from_blkid(self, device_filepath):
        uuid_re = re.compile("^UUID=(?P<uuid>.*)$")
        try:
            output = run_cmd(BLKID + [device_filepath]).splitlines()
        except CalledProcessError as e:
            if e.returncode == 2:
                # blkid exit code is 2 if no uuid for that device
                return None
            raise

        for line in output:
            m = uuid_re.match(line)
            if m  is not None:
                return m.group("uuid")
        return None
Esempio n. 4
0
 def _extract_size_from_fdisk(self, device_filepath):
     """/dev/sd* or /dev/mapper/mpath*
     :returns: The size in bytes of the specified device
     :rtype: int or None if an error occured obtaining the value
     """
     #parse Disk /dev/sda: 8185 MB, 8185184256 bytes
     dev_re = re.compile("^Disk\s\/dev\/(sd|mapper\/).*:")
     for line in run_cmd(SIZE_FROM_FDISK + [device_filepath]).splitlines():
         if dev_re.match(line) is not None:
             size = line.split(",")[1].split()[0]
             try:
                 return int(size)
             except ValueError:
                 module_logger.warning("Cannot get size for device {0}.\
                                                         Output: {1}".format(device_filepath, size))
                 return None
     return None
Esempio n. 5
0
 def get_multipath_disks_details(self):
     dm_re = re.compile("\sdm-\d+\s")
     mp_disk_details = {}
     for line in run_cmd(MULTIPATH_LIST).splitlines():
         if dm_re.search(line):
             try:
                 alias, wwid, sysfs_name, vendor = line.split()[0:4]
             except ValueError:
                 # apparently we hit a dead/unmapped device
                 module_logger.warning('Skipping MP disk details in line {0}'.format(
                     line))
                 continue
             mp_disk_details[alias] = LinuxDMPDiskDetails(
                                                          wwid = wwid.strip("()"),
                                                          vendor = vendor,
                                                          sysfs_name = sysfs_name,
                                                          alias = alias
                                                          )
     return mp_disk_details