def _disk_dev(self, ks_disk): # first we try to find a device that matches ks_disk # comparing by-id and by-path links matched = [ hu_disk['device'] for hu_disk in self.hu_disks if match_device(hu_disk, ks_disk) ] # if we can not find a device by its by-id and by-path links # we try to find a device by its name fallback = [ hu_disk['device'] for hu_disk in self.hu_disks if '/dev/%s' % ks_disk['name'] == hu_disk['device'] ] # Due to udevadm bugs it can return the same ids for different disks. # For instance for NVMe disks. In this case matched will contains # more than 1 disk and we should use info from fallback if len(matched) > 1 and len(fallback) == 1: found = fallback else: found = matched or fallback if not found or len(found) > 1: raise errors.DiskNotFoundError('Disk not found: %s' % ks_disk['name']) return found[0]
def _disk_partition(self, ks_partition): matched = [ hu_partition['name'] for hu_partition in self.hu_partitions if self._match_data_by_pattern(hu_partition, ks_partition) ] if not matched or len(matched) > 1: raise errors.DiskNotFoundError( 'Disk not found with %s: %s' % (ks_partition['id']['type'], ks_partition['id']['value'])) return matched[0]
def _disk_vg_dev(self, ks_vgs): # first we try to find a device that matches ks_disk # comparing by-id and by-path links matched = [ hu_vg['name'] for hu_vg in self.hu_vgs if self._match_data_by_pattern(hu_vg, ks_vgs) ] # if we can not find a device by its by-id and by-path links if not matched or len(matched) > 1: raise errors.DiskNotFoundError( 'Disk not found with %s: %s' % (ks_vgs['id']['type'], ks_vgs['id']['value'])) return matched[0]
def _verify_disk_size(parteds, hu_disks): for parted in parteds: disks = [d for d in hu_disks if d.get('name') == parted.name] if not disks: raise errors.DiskNotFoundError( 'No physical disks found matching: %s' % parted.name) disk_size_bytes = disks[0].get('bspec', {}).get('size64') if not disk_size_bytes: raise ValueError('Cannot read size of the disk: %s' % disks[0].get('name')) # It's safer to understate the physical disk size disk_size_mib = utils.B2MiB(disk_size_bytes, ceil=False) if parted.disk_size > disk_size_mib: raise errors.NotEnoughSpaceError( 'Partition scheme for: %(disk)s exceeds the size of the ' 'disk. Scheme size is %(scheme_size)s MiB, and disk size ' 'is %(disk_size)s MiB.' % { 'disk': parted.name, 'scheme_size': parted.disk_size, 'disk_size': disk_size_mib})