  def CreateImageFromDisk(
      self, src_disk: 'GoogleComputeDisk',
      name: Optional[str] = None) -> 'GoogleComputeImage':
    """Creates an image from a persistent disk.

    Args:
      src_disk (GoogleComputeDisk): Source disk for the image.
      name (str): Optional. Name of the image to create. Default
          is [src_disk.name]-[TIMESTAMP('%Y%m%d%H%M%S')].

    Returns:
      GoogleComputeImage: A Google Compute Image object.

    Raises:
      InvalidNameError: If the GCE Image name is invalid.
      ResourceAlreadyExistsError: If an image with the given name already
        exists in the project.
      ResourceCreationError: If the GCE Image cannot be inserted
    """

    if name:
      name = name[:common.COMPUTE_NAME_LIMIT]
      if not common.REGEX_DISK_NAME.match(name):
        raise errors.InvalidNameError(
            'Image name {0:s} does not comply with {1:s}'.format(
                name, common.REGEX_DISK_NAME.pattern),
            __name__)
    else:
      name = common.GenerateUniqueInstanceName(
          src_disk.name, common.COMPUTE_NAME_LIMIT)
    image_body = {
        'name':
            name,
        'sourceDisk':
            'projects/{project_id}/zones/{zone}/disks/{src_disk}'.format(
                project_id=src_disk.project_id,
                zone=src_disk.zone,
                src_disk=src_disk.name)
    }
    gce_image_client = self.GceApi().images() # pylint: disable=no-member
    request = gce_image_client.insert(
        project=self.project_id, body=image_body, forceCreate=True)

    try:
      response = request.execute()
    except HttpError as e:
      if e.resp.status == 409:
        # 409 - Resource already exists.
        # Message is
        #   `The resource 'projects/badcloud-hasher/global/images/<DISK_NAME>'
        #   already exists`
        msg = 'An image with name {0:s} already exists in project {1:s}'.format(
            name, self.project_id)
        raise errors.ResourceAlreadyExistsError(msg, __name__) from e
      msg = 'Error while creating image {0:s}'.format(name)
      raise errors.ResourceCreationError(msg, __name__) from e

    self.BlockOperation(response)
    return GoogleComputeImage(self.project_id, '', name)
Creates an image from a persistent disk.

Args:
src_disk (GoogleComputeDisk): Source disk for the image.
name (str): Optional. Name of the image to create. Default
is [src_disk.name]-[TIMESTAMP('%Y%m%d%H%M%S')].

Returns:
GoogleComputeImage: A Google Compute Image object.

Raises:
InvalidNameError: If the GCE Image name is invalid.
ResourceAlreadyExistsError: If an image with the given name already
exists in the project.
ResourceCreationError: If the GCE Image cannot be inserted
libcloudforensics/providers/gcp/internal/compute.py