# Path: libcloudforensics/errors.py
# class ResourceNotFoundError(LCFError):
#   """Error when an issue with non-existent resource is encountered."""
# 
# Path: libcloudforensics/errors.py
# class ResourceCreationError(LCFError):
#   """Error when an issue with creating a new resource is encountered."""
# 
# Path: libcloudforensics/logging_utils.py
# def _GenerateColorSequences() -> List[str]:
#   def __init__(self,
#                colorize: bool = True,
#                random_color: bool = False,
#                **kwargs: str) -> None:
#   def format(self, record: logging.LogRecord) -> str:
# def SetUpLogger(name: str, no_newline: bool = False) -> None:
# def GetLogger(name: str) -> logging.Logger:
# COLOR_SEQS = _GenerateColorSequences()
# RESET_SEQ = '\u001b[0m'
# BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = COLOR_SEQS[8:16]
# BG_RED = '\u001b[41m'  # Red background
# BOLD = '\u001b[1m'  # Bold / bright modifier
# LOG_FORMAT = ('[%(asctime)s] [{0:s}{color:s}%(name)-20s{1:s}] %(levelname)-8s'
#               ' %(message)s')
# LEVEL_COLOR_MAP = {
#     'WARNING': YELLOW,
#     'INFO': WHITE,
#     'DEBUG': BLUE,
#     'CRITICAL': BOLD + BG_RED + WHITE,
#     'ERROR': RED
# }
# class Formatter(logging.Formatter):
# 
# Path: libcloudforensics/providers/azure/internal/account.py
# class AZAccount:
#   def __init__(self,
#                default_resource_group_name: str,
#                default_region: str = 'eastus',
#                profile_name: Optional[str] = None) -> None:
#   def compute(self) -> compute_module.AZCompute:
#   def monitoring(self) -> monitoring_module.AZMonitoring:
#   def network(self) -> network_module.AZNetwork:
#   def resource(self) -> resource_module.AZResource:
#   def storage(self) -> storage_module.AZStorage:
# 
# Path: tests/providers/azure/azure_cli.py
# class AzureCLIHelper:
#   def __init__(self, az: account.AZAccount) -> None:
#   def PrepareStartAnalysisVmCmd(
#       self,
#       instance_name: str,
#       attach_disks: Optional[List[str]] = None) -> str:
#   def PrepareCreateDiskCopyCmd(
#       self,
#       instance_name: Optional[str] = None,
#       disk_name: Optional[str] = None,
#       region: Optional[str] = None) -> str:
# 
# Path: tests/scripts/utils.py
# def ReadProjectInfo(keys: List[str]) -> Dict[str, str]:


import subprocess
import typing
import unittest
from time import sleep
from msrestazure import azure_exceptions  # pylint: disable=import-error
from libcloudforensics.errors import ResourceNotFoundError
from libcloudforensics.errors import ResourceCreationError
from libcloudforensics import logging_utils
from libcloudforensics.providers.azure.internal import account
from tests.providers.azure import azure_cli
from tests.scripts import utils
      return cls.az.compute.GetInstance(
          instance_name, cls.az.default_resource_group_name)
    except ResourceNotFoundError as error:
      raise ResourceNotFoundError(
          'Failed finding created VM in resource group {0:s}'.format(
              cls.az.default_resource_group_name), __name__) from error

  @classmethod
  @typing.no_type_check
  def _RunCreateDiskCopy(cls, instance_name=None, disk_name=None, region=None):
    cmd = cls.cli.PrepareCreateDiskCopyCmd(
        instance_name=instance_name, disk_name=disk_name, region=region)
    try:
      output = subprocess.check_output(
          cmd.split(), stderr=subprocess.STDOUT, shell=False)
    except subprocess.CalledProcessError as error:
      raise ResourceCreationError(
          'Failed copying disk: {0!s}'.format(error), __name__) from error
    if not output:
      raise ResourceCreationError(
          'Could not find disk copy result', __name__)
    disk_copy_name = output.decode('utf-8').split(' ')[-1]
    disk_copy_name = disk_copy_name[:disk_copy_name.rindex('copy') + 4]
    logger.info(output)
    logger.info("Disk successfully copied to {0:s}".format(
        disk_copy_name))
    try:
      return cls.az.compute.GetDisk(
          disk_copy_name, cls.az.default_resource_group_name)
    except ResourceNotFoundError as error:

# Path: libcloudforensics/errors.py
# class ResourceNotFoundError(LCFError):
#   """Error when an issue with non-existent resource is encountered."""
# 
# Path: libcloudforensics/errors.py
# class ResourceCreationError(LCFError):
#   """Error when an issue with creating a new resource is encountered."""
# 
# Path: libcloudforensics/logging_utils.py
# def _GenerateColorSequences() -> List[str]:
#   def __init__(self,
#                colorize: bool = True,
#                random_color: bool = False,
#                **kwargs: str) -> None:
#   def format(self, record: logging.LogRecord) -> str:
# def SetUpLogger(name: str, no_newline: bool = False) -> None:
# def GetLogger(name: str) -> logging.Logger:
# COLOR_SEQS = _GenerateColorSequences()
# RESET_SEQ = '\u001b[0m'
# BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = COLOR_SEQS[8:16]
# BG_RED = '\u001b[41m'  # Red background
# BOLD = '\u001b[1m'  # Bold / bright modifier
# LOG_FORMAT = ('[%(asctime)s] [{0:s}{color:s}%(name)-20s{1:s}] %(levelname)-8s'
#               ' %(message)s')
# LEVEL_COLOR_MAP = {
#     'WARNING': YELLOW,
#     'INFO': WHITE,
#     'DEBUG': BLUE,
#     'CRITICAL': BOLD + BG_RED + WHITE,
#     'ERROR': RED
# }
# class Formatter(logging.Formatter):
# 
# Path: libcloudforensics/providers/azure/internal/account.py
# class AZAccount:
#   def __init__(self,
#                default_resource_group_name: str,
#                default_region: str = 'eastus',
#                profile_name: Optional[str] = None) -> None:
#   def compute(self) -> compute_module.AZCompute:
#   def monitoring(self) -> monitoring_module.AZMonitoring:
#   def network(self) -> network_module.AZNetwork:
#   def resource(self) -> resource_module.AZResource:
#   def storage(self) -> storage_module.AZStorage:
# 
# Path: tests/providers/azure/azure_cli.py
# class AzureCLIHelper:
#   def __init__(self, az: account.AZAccount) -> None:
#   def PrepareStartAnalysisVmCmd(
#       self,
#       instance_name: str,
#       attach_disks: Optional[List[str]] = None) -> str:
#   def PrepareCreateDiskCopyCmd(
#       self,
#       instance_name: Optional[str] = None,
#       disk_name: Optional[str] = None,
#       region: Optional[str] = None) -> str:
# 
# Path: tests/scripts/utils.py
# def ReadProjectInfo(keys: List[str]) -> Dict[str, str]:


# Path: tests/providers/azure/e2e_cli.py
import subprocess
import typing
import unittest
from time import sleep
from msrestazure import azure_exceptions  # pylint: disable=import-error
from libcloudforensics.errors import ResourceNotFoundError
from libcloudforensics.errors import ResourceCreationError
from libcloudforensics import logging_utils
from libcloudforensics.providers.azure.internal import account
from tests.providers.azure import azure_cli
from tests.scripts import utils

      return cls.az.compute.GetInstance(
          instance_name, cls.az.default_resource_group_name)
    except ResourceNotFoundError as error:
      raise ResourceNotFoundError(
          'Failed finding created VM in resource group {0:s}'.format(
              cls.az.default_resource_group_name), __name__) from error

  @classmethod
  @typing.no_type_check
  def _RunCreateDiskCopy(cls, instance_name=None, disk_name=None, region=None):
    cmd = cls.cli.PrepareCreateDiskCopyCmd(
        instance_name=instance_name, disk_name=disk_name, region=region)
    try:
      output = subprocess.check_output(
          cmd.split(), stderr=subprocess.STDOUT, shell=False)
    except subprocess.CalledProcessError as error:
      raise ResourceCreationError(
          'Failed copying disk: {0!s}'.format(error), __name__) from error
    if not output:
      raise ResourceCreationError(
          'Could not find disk copy result', __name__)
    disk_copy_name = output.decode('utf-8').split(' ')[-1]
    disk_copy_name = disk_copy_name[:disk_copy_name.rindex('copy') + 4]
    logger.info(output)
    logger.info("Disk successfully copied to {0:s}".format(
        disk_copy_name))
    try:
      return cls.az.compute.GetDisk(
          disk_copy_name, cls.az.default_resource_group_name)
    except ResourceNotFoundError as error:

      raise ResourceNotFoundError(