# Path: os_brick/exception.py
# LOG = logging.getLogger(__name__)
# class BrickException(Exception):
# class NotFound(BrickException):
# class Invalid(BrickException):
# class InvalidParameterValue(Invalid):
# class NoFibreChannelHostsFound(BrickException):
# class NoFibreChannelVolumeDeviceFound(BrickException):
# class VolumeNotDeactivated(BrickException):
# class VolumeDeviceNotFound(BrickException):
# class VolumePathsNotFound(BrickException):
# class VolumePathNotRemoved(BrickException):
# class ProtocolNotSupported(BrickException):
# class TargetPortalNotFound(BrickException):
# class TargetPortalsNotFound(TargetPortalNotFound):
# class FailedISCSITargetPortalLogin(BrickException):
# class BlockDeviceReadOnly(BrickException):
# class VolumeGroupNotFound(BrickException):
# class VolumeGroupCreationFailed(BrickException):
# class CommandExecutionFailed(BrickException):
# class VolumeDriverException(BrickException):
# class InvalidIOHandleObject(BrickException):
# class VolumeEncryptionNotSupported(Invalid):
# class VolumeLocalCacheNotSupported(Invalid):
# class InvalidConnectorProtocol(ValueError):
# class ExceptionChainer(BrickException):
# class ExecutionTimeout(putils.ProcessExecutionError):
#     def __init__(self, message=None, **kwargs):
#     def __init__(self, *args, **kwargs):
#     def __repr__(self):
#     def __nonzero__(self) -> bool:
#     def add_exception(self, exc_type, exc_val, exc_tb) -> None:
#     def context(self,
#                 catch_exception: bool,
#                 msg: str = '',
#                 *msg_args: Iterable):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_val, exc_tb):
# 
# Path: os_brick/i18n.py
# DOMAIN = 'os-brick'
# 
# Path: os_brick/initiator/connectors/base_rbd.py
# LOG = logging.getLogger(__name__)
# class RBDConnectorMixin(object):
#     def _sanitize_mon_hosts(hosts):
#         def _sanitize_host(host):
#     def _get_rbd_args(cls, connection_properties, conf=None):
# 
# Path: os_brick/initiator/windows/base.py
# LOG = logging.getLogger(__name__)
#     DEFAULT_DEVICE_SCAN_INTERVAL = 2
# class BaseWindowsConnector(initiator_connector.InitiatorConnector):
#     def __init__(self, root_helper=None, *args, **kwargs):
#     def check_multipath_support(enforce_multipath):
#     def get_connector_properties(*args, **kwargs):
#     def _get_scsi_wwn(self, device_number):
#     def check_valid_device(self, path, *args, **kwargs):
#     def get_all_available_volumes(self):
#     def _check_device_paths(self, device_paths):
#     def extend_volume(self, connection_properties):
#     def get_search_path(self):
# 
# Path: os_brick/utils.py
# def _sleep(secs: float) -> None:
#     def __init__(self, codes: Union[int, Tuple[int, ...]]):
#     def _check_exit_code(self, exc: Type[Exception]) -> bool:
# def retry(retry_param: Union[None,
#                              Type[Exception],
#                              Tuple[Type[Exception], ...],
#                              int,
#                              Tuple[int, ...]],
#           interval: float = 1,
#           retries: int = 3,
#           backoff_rate: float = 2,
#           retry: Callable = tenacity.retry_if_exception_type) -> Callable:
#     def _decorator(f):
#         def _wrapper(*args, **kwargs):
# def platform_matches(current_platform: str, connector_platform: str) -> bool:
# def os_matches(current_os: str, connector_os: str) -> bool:
# def merge_dict(dict1: dict, dict2: dict) -> dict:
# def trace(f: Callable) -> Callable:
#     def trace_logging_wrapper(*args, **kwargs):
# def convert_str(text: Union[bytes, str]) -> str:
# def get_host_nqn():
# LOG = logging.getLogger(__name__)
# class retry_if_exit_code(tenacity.retry_if_exception):


import ctypes
import errno
import json
from oslo_concurrency import processutils
from oslo_log import log as logging
from oslo_service import loopingcall
from os_brick import exception
from os_brick.i18n import _
from os_brick.initiator.connectors import base_rbd
from os_brick.initiator.windows import base as win_conn_base
from os_brick import utils

        def _check_rbd_device():
            rbd_dev_path = self.get_device_name(
                connection_properties, expect=False)
            if rbd_dev_path:
                try:
                    # Under high load, it can take a second before the disk
                    # becomes accessible.
                    with open(rbd_dev_path, 'rb'):
                        pass

                    nonlocal dev_path
                    dev_path = rbd_dev_path
                    raise loopingcall.LoopingCallDone()
                except FileNotFoundError:
                    LOG.debug("The RBD image %(image)s mapped to local device "
                              "%(dev)s isn't available yet.",
                              {'image': connection_properties['name'],
                               'dev': rbd_dev_path})
            nonlocal attempt
            attempt += 1
            if attempt >= self.device_scan_attempts:
                msg = _("The mounted RBD image isn't available: %s")
                raise exception.VolumeDeviceNotFound(
                    msg % connection_properties['name'])

        timer = loopingcall.FixedIntervalLoopingCall(_check_rbd_device)
        timer.start(interval=self.device_scan_interval).wait()
        return dev_path


# Path: os_brick/exception.py
# LOG = logging.getLogger(__name__)
# class BrickException(Exception):
# class NotFound(BrickException):
# class Invalid(BrickException):
# class InvalidParameterValue(Invalid):
# class NoFibreChannelHostsFound(BrickException):
# class NoFibreChannelVolumeDeviceFound(BrickException):
# class VolumeNotDeactivated(BrickException):
# class VolumeDeviceNotFound(BrickException):
# class VolumePathsNotFound(BrickException):
# class VolumePathNotRemoved(BrickException):
# class ProtocolNotSupported(BrickException):
# class TargetPortalNotFound(BrickException):
# class TargetPortalsNotFound(TargetPortalNotFound):
# class FailedISCSITargetPortalLogin(BrickException):
# class BlockDeviceReadOnly(BrickException):
# class VolumeGroupNotFound(BrickException):
# class VolumeGroupCreationFailed(BrickException):
# class CommandExecutionFailed(BrickException):
# class VolumeDriverException(BrickException):
# class InvalidIOHandleObject(BrickException):
# class VolumeEncryptionNotSupported(Invalid):
# class VolumeLocalCacheNotSupported(Invalid):
# class InvalidConnectorProtocol(ValueError):
# class ExceptionChainer(BrickException):
# class ExecutionTimeout(putils.ProcessExecutionError):
#     def __init__(self, message=None, **kwargs):
#     def __init__(self, *args, **kwargs):
#     def __repr__(self):
#     def __nonzero__(self) -> bool:
#     def add_exception(self, exc_type, exc_val, exc_tb) -> None:
#     def context(self,
#                 catch_exception: bool,
#                 msg: str = '',
#                 *msg_args: Iterable):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_val, exc_tb):
# 
# Path: os_brick/i18n.py
# DOMAIN = 'os-brick'
# 
# Path: os_brick/initiator/connectors/base_rbd.py
# LOG = logging.getLogger(__name__)
# class RBDConnectorMixin(object):
#     def _sanitize_mon_hosts(hosts):
#         def _sanitize_host(host):
#     def _get_rbd_args(cls, connection_properties, conf=None):
# 
# Path: os_brick/initiator/windows/base.py
# LOG = logging.getLogger(__name__)
#     DEFAULT_DEVICE_SCAN_INTERVAL = 2
# class BaseWindowsConnector(initiator_connector.InitiatorConnector):
#     def __init__(self, root_helper=None, *args, **kwargs):
#     def check_multipath_support(enforce_multipath):
#     def get_connector_properties(*args, **kwargs):
#     def _get_scsi_wwn(self, device_number):
#     def check_valid_device(self, path, *args, **kwargs):
#     def get_all_available_volumes(self):
#     def _check_device_paths(self, device_paths):
#     def extend_volume(self, connection_properties):
#     def get_search_path(self):
# 
# Path: os_brick/utils.py
# def _sleep(secs: float) -> None:
#     def __init__(self, codes: Union[int, Tuple[int, ...]]):
#     def _check_exit_code(self, exc: Type[Exception]) -> bool:
# def retry(retry_param: Union[None,
#                              Type[Exception],
#                              Tuple[Type[Exception], ...],
#                              int,
#                              Tuple[int, ...]],
#           interval: float = 1,
#           retries: int = 3,
#           backoff_rate: float = 2,
#           retry: Callable = tenacity.retry_if_exception_type) -> Callable:
#     def _decorator(f):
#         def _wrapper(*args, **kwargs):
# def platform_matches(current_platform: str, connector_platform: str) -> bool:
# def os_matches(current_os: str, connector_os: str) -> bool:
# def merge_dict(dict1: dict, dict2: dict) -> dict:
# def trace(f: Callable) -> Callable:
#     def trace_logging_wrapper(*args, **kwargs):
# def convert_str(text: Union[bytes, str]) -> str:
# def get_host_nqn():
# LOG = logging.getLogger(__name__)
# class retry_if_exit_code(tenacity.retry_if_exception):


# Path: os_brick/initiator/windows/rbd.py
import ctypes
import errno
import json
from oslo_concurrency import processutils
from oslo_log import log as logging
from oslo_service import loopingcall
from os_brick import exception
from os_brick.i18n import _
from os_brick.initiator.connectors import base_rbd
from os_brick.initiator.windows import base as win_conn_base
from os_brick import utils


        def _check_rbd_device():
            rbd_dev_path = self.get_device_name(
                connection_properties, expect=False)
            if rbd_dev_path:
                try:
                    # Under high load, it can take a second before the disk
                    # becomes accessible.
                    with open(rbd_dev_path, 'rb'):
                        pass

                    nonlocal dev_path
                    dev_path = rbd_dev_path
                    raise loopingcall.LoopingCallDone()
                except FileNotFoundError:
                    LOG.debug("The RBD image %(image)s mapped to local device "
                              "%(dev)s isn't available yet.",
                              {'image': connection_properties['name'],
                               'dev': rbd_dev_path})
            nonlocal attempt
            attempt += 1
            if attempt >= self.device_scan_attempts:
                msg = _("The mounted RBD image isn't available: %s")
                raise exception.VolumeDeviceNotFound(
                    msg % connection_properties['name'])

        timer = loopingcall.FixedIntervalLoopingCall(_check_rbd_device)
        timer.start(interval=self.device_scan_interval).wait()
        return dev_path


    @utils.trace