# Path: libcloudforensics/errors.py
# class LCFError(Exception):
# class CredentialsConfigurationError(LCFError):
# class InvalidFileFormatError(LCFError):
# class InvalidNameError(LCFError):
# class ResourceNotFoundError(LCFError):
# class ResourceCreationError(LCFError):
# class ResourceDeletionError(LCFError):
# class InstanceStateChangeError(LCFError):
# class ServiceAccountRemovalError(LCFError):
# class InstanceProfileCreationError(LCFError):
# class OperationFailedError(LCFError):
# class TransferCreationError(LCFError):
# class TransferExecutionError(LCFError):
# class ResourceAlreadyExistsError(LCFError):
#   def __init__(self,
#                message: str,
#                name: str) -> None:
# 
# Path: libcloudforensics/providers/azure/internal/common.py
# REGEX_DISK_NAME = re.compile('^[\\w]{1,80}$')
# REGEX_SNAPSHOT_NAME = re.compile('^(?=.{1,80}$)[a-zA-Z0-9]([\\w,-]*[\\w])?$')
# REGEX_ACCOUNT_STORAGE_NAME = re.compile('^[a-z0-9]{1,24}$')
# REGEX_COMPUTE_RESOURCE_ID = re.compile(
#     '/subscriptions/.+/resourceGroups/.+/providers/Microsoft.Compute/.+/.+')
# DEFAULT_DISK_COPY_PREFIX = 'evidence'
# UBUNTU_1804_SKU = '18.04-LTS'
# def _ParseCredentialsFile(profile_name: str) -> Dict[str, Any]:
# def _CheckAzureCliCredentials() -> Optional[str]:
# def GetCredentials(profile_name: Optional[str] = None
#                    ) -> Tuple[str, DefaultAzureCredential]:
# def ExecuteRequest(
#     client: Any,
#     func: str,
#     kwargs: Optional[Dict[str, str]] = None) -> List[Any]:
# def GenerateDiskName(snapshot: 'compute.AZComputeSnapshot',
#                      disk_name_prefix: Optional[str] = None) -> str:


from typing import TYPE_CHECKING, Optional, Tuple, Any, Dict
from azure.mgmt import network
from azure.core import exceptions as azure_exceptions
from libcloudforensics import errors
from libcloudforensics.providers.azure.internal import common
  from libcloudforensics.providers.azure.internal import account  # pylint: disable=cyclic-import
    except azure_exceptions.AzureError as exception:
      raise errors.ResourceCreationError(
          'Could not create network interface: {0!s}'.format(exception),
          __name__) from exception

    # pylint: disable=unbalanced-tuple-unpacking
    # IP address, virtual network, subnet, network security group
    public_ip, _, subnet, nsg = self._CreateNetworkInterfaceElements(
        name, region=region)
    # pylint: enable=unbalanced-tuple-unpacking

    creation_data = {
        'location': region,
        'ip_configurations': [{
            'name': ip_config_name,
            'public_ip_address': public_ip,
            'subnet': {
                'id': subnet.id
            }
        }],
        'networkSecurityGroup': nsg
    }

    try:
      request = self.network_client.network_interfaces.begin_create_or_update(
          self.az_account.default_resource_group_name,
          network_interface_name,
          creation_data)
      request.wait()
    except azure_exceptions.AzureError as exception:

# Path: libcloudforensics/errors.py
# class LCFError(Exception):
# class CredentialsConfigurationError(LCFError):
# class InvalidFileFormatError(LCFError):
# class InvalidNameError(LCFError):
# class ResourceNotFoundError(LCFError):
# class ResourceCreationError(LCFError):
# class ResourceDeletionError(LCFError):
# class InstanceStateChangeError(LCFError):
# class ServiceAccountRemovalError(LCFError):
# class InstanceProfileCreationError(LCFError):
# class OperationFailedError(LCFError):
# class TransferCreationError(LCFError):
# class TransferExecutionError(LCFError):
# class ResourceAlreadyExistsError(LCFError):
#   def __init__(self,
#                message: str,
#                name: str) -> None:
# 
# Path: libcloudforensics/providers/azure/internal/common.py
# REGEX_DISK_NAME = re.compile('^[\\w]{1,80}$')
# REGEX_SNAPSHOT_NAME = re.compile('^(?=.{1,80}$)[a-zA-Z0-9]([\\w,-]*[\\w])?$')
# REGEX_ACCOUNT_STORAGE_NAME = re.compile('^[a-z0-9]{1,24}$')
# REGEX_COMPUTE_RESOURCE_ID = re.compile(
#     '/subscriptions/.+/resourceGroups/.+/providers/Microsoft.Compute/.+/.+')
# DEFAULT_DISK_COPY_PREFIX = 'evidence'
# UBUNTU_1804_SKU = '18.04-LTS'
# def _ParseCredentialsFile(profile_name: str) -> Dict[str, Any]:
# def _CheckAzureCliCredentials() -> Optional[str]:
# def GetCredentials(profile_name: Optional[str] = None
#                    ) -> Tuple[str, DefaultAzureCredential]:
# def ExecuteRequest(
#     client: Any,
#     func: str,
#     kwargs: Optional[Dict[str, str]] = None) -> List[Any]:
# def GenerateDiskName(snapshot: 'compute.AZComputeSnapshot',
#                      disk_name_prefix: Optional[str] = None) -> str:


# Path: libcloudforensics/providers/azure/internal/network.py
from typing import TYPE_CHECKING, Optional, Tuple, Any, Dict
from azure.mgmt import network
from azure.core import exceptions as azure_exceptions
from libcloudforensics import errors
from libcloudforensics.providers.azure.internal import common
  from libcloudforensics.providers.azure.internal import account  # pylint: disable=cyclic-import

    except azure_exceptions.AzureError as exception:
      raise errors.ResourceCreationError(
          'Could not create network interface: {0!s}'.format(exception),
          __name__) from exception

    # pylint: disable=unbalanced-tuple-unpacking
    # IP address, virtual network, subnet, network security group
    public_ip, _, subnet, nsg = self._CreateNetworkInterfaceElements(
        name, region=region)
    # pylint: enable=unbalanced-tuple-unpacking

    creation_data = {
        'location': region,
        'ip_configurations': [{
            'name': ip_config_name,
            'public_ip_address': public_ip,
            'subnet': {
                'id': subnet.id
            }
        }],
        'networkSecurityGroup': nsg
    }

    try:
      request = self.network_client.network_interfaces.begin_create_or_update(
          self.az_account.default_resource_group_name,
          network_interface_name,
          creation_data)
      request.wait()
    except azure_exceptions.AzureError as exception:

      raise errors.ResourceCreationError(