def GenerateDiskName(snapshot: 'compute.AZComputeSnapshot',
                     disk_name_prefix: Optional[str] = None) -> str:
  """Generate a new disk name for the disk to be created from the Snapshot.

  The disk name must comply with the following RegEx:
      - ^[\\w]{1-80}$

  i.e., it must be between 1 and 80 chars, and can only contain alphanumeric
  characters and underscores.

  Args:
    snapshot (AZComputeSnapshot): A disk's Snapshot.
    disk_name_prefix (str): Optional. A prefix for the disk name.

  Returns:
    str: A name for the disk.

  Raises:
    InvalidNameError: If the disk name does not comply with the RegEx.
  """

  # Max length of disk names in Azure is 80 characters
  subscription_id = snapshot.az_account.subscription_id
  disk_id = subscription_id + snapshot.disk.resource_id
  disk_id_crc32 = '{0:08x}'.format(
      binascii.crc32(disk_id.encode()) & 0xffffffff)
  truncate_at = 80 - len(disk_id_crc32) - len('_copy') - 1
  if disk_name_prefix:
    disk_name_prefix += '_'
    if len(disk_name_prefix) > truncate_at:
      # The disk name prefix is too long
      disk_name_prefix = disk_name_prefix[:truncate_at]
    truncate_at -= len(disk_name_prefix)
    disk_name = '{0:s}{1:s}_{2:s}_copy'.format(
        disk_name_prefix, snapshot.name[:truncate_at], disk_id_crc32)
  else:
    disk_name = '{0:s}_{1:s}_copy'.format(
        snapshot.name[:truncate_at], disk_id_crc32)
  # Azure doesn't allow dashes in disk names, only underscores. If the
  # name of the source snapshot contained dashes, we need to replace them.
  disk_name = disk_name.replace('-', '_')
  if not REGEX_DISK_NAME.match(disk_name):
    raise errors.InvalidNameError(
        'Disk name {0:s} does not comply with '
        '{1:s}'.format(disk_name, REGEX_DISK_NAME.pattern), __name__)

  return disk_name
Generate a new disk name for the disk to be created from the Snapshot.

The disk name must comply with the following RegEx:
- ^[\\w]{1-80}$

i.e., it must be between 1 and 80 chars, and can only contain alphanumeric
characters and underscores.

Args:
snapshot (AZComputeSnapshot): A disk's Snapshot.
disk_name_prefix (str): Optional. A prefix for the disk name.

Returns:
str: A name for the disk.

Raises:
InvalidNameError: If the disk name does not comply with the RegEx.
libcloudforensics/providers/azure/internal/common.py