def GetBlockDeviceMap(machine_type, root_volume_size_gb=None, image_id=None, region=None): """Returns the block device map to expose all devices for a given machine. Args: machine_type: The machine type to create a block device map for. root_volume_size_gb: The desired size of the root volume, in GiB, or None to the default provided by AWS. image_id: The image id (AMI) to use in order to lookup the default root device specs. This is only required if root_volume_size is specified. region: The region which contains the specified image. This is only required if image_id is specified. Returns: The json representation of the block device map for a machine compatible with the AWS CLI, or if the machine type has no local disks, it will return None. If root_volume_size_gb and image_id are provided, the block device map will include the specification for the root volume. Raises: ValueError: If required parameters are not passed. """ mappings = [] if root_volume_size_gb is not None: if image_id is None: raise ValueError( 'image_id must be provided if root_volume_size_gb is specified' ) if region is None: raise ValueError( 'region must be provided if image_id is specified') root_block_device = GetRootBlockDeviceSpecForImage(image_id, region) root_block_device['Ebs']['VolumeSize'] = root_volume_size_gb # The 'Encrypted' key must be removed or the CLI will complain root_block_device['Ebs'].pop('Encrypted') mappings.append(root_block_device) if (machine_type in NUM_LOCAL_VOLUMES and not aws_disk.LocalDriveIsNvme(machine_type)): for i in xrange(NUM_LOCAL_VOLUMES[machine_type]): od = OrderedDict() od['VirtualName'] = 'ephemeral%s' % i od['DeviceName'] = '/dev/xvd%s' % chr(ord(DRIVE_START_LETTER) + i) mappings.append(od) if mappings: return json.dumps(mappings) return None
def _GetNvmeBootIndex(self): if aws_disk.LocalDriveIsNvme(self.machine_type) and \ aws_disk.EbsDriveIsNvme(self.machine_type): # identify boot drive cmd = 'lsblk | grep "part /$" | grep -o "nvme[0-9]*"' boot_drive = self.RemoteCommand(cmd, ignore_failure=True)[0].strip() if len(boot_drive) > 0: # get the boot drive index by dropping the nvme prefix boot_idx = int(boot_drive[4:]) logging.info('found boot drive at nvme index %d', boot_idx) return boot_idx else: # boot drive is not nvme return 0
def _GetNvmeBootIndex(self): if aws_disk.LocalDriveIsNvme(self.machine_type) and \ aws_disk.EbsDriveIsNvme(self.machine_type): # identify boot drive # If this command ever fails consider 'findmnt -nM / -o source' cmd = ('realpath /dev/disk/by-label/cloudimg-rootfs ' '| grep --only-matching "nvme[0-9]*"') boot_drive = self.RemoteCommand(cmd, ignore_failure=True)[0].strip() if boot_drive: # get the boot drive index by dropping the nvme prefix boot_idx = int(boot_drive[4:]) logging.info('found boot drive at nvme index %d', boot_idx) return boot_idx else: logging.warning('Failed to identify NVME boot drive index. Assuming 0.') return 0