# Path: oslo_middleware/healthcheck/opts.py
# HEALTHCHECK_OPTS = [
#     cfg.StrOpt('path',
#                default='/healthcheck',
#                deprecated_for_removal=True,
#                help='The path to respond to healtcheck requests on.'),
#     cfg.BoolOpt('detailed',
#                 default=False,
#                 help='Show more detailed information as part of the response. '
#                      'Security note: Enabling this option may expose '
#                      'sensitive details about the service being monitored. '
#                      'Be sure to verify that it will not violate your '
#                      'security policies.'),
#     cfg.ListOpt('backends',
#                 default=[],
#                 help='Additional backends that can perform health checks and '
#                      'report that information back as part of a request.'),
# ]
# DISABLE_BY_FILE_OPTS = [
#     cfg.StrOpt('disable_by_file_path',
#                default=None,
#                help='Check the presence of a file to determine if an '
#                     'application is running on a port. Used by '
#                     'DisableByFileHealthcheck plugin.'),
# ]
# DISABLE_BY_FILES_OPTS = [
#     cfg.ListOpt('disable_by_file_paths',
#                 default=[],
#                 help='Check the presence of a file based on a port to '
#                      'determine if an application is running on a port. '
#                      'Expects a "port:path" list of strings. Used by '
#                      'DisableByFilesPortsHealthcheck plugin.'),
# ]
# 
# Path: oslo_middleware/healthcheck/pluginbase.py
# class HealthcheckResult(object):
# class HealthcheckBaseExtension(metaclass=abc.ABCMeta):
#     def __init__(self, available, reason, details=None):
#     def __init__(self, oslo_conf, conf):
#     def healthcheck(self, server_port):
#     def _conf_get(self, key, group='healthcheck'):


import logging
import os
from oslo_middleware.healthcheck import opts
from oslo_middleware.healthcheck import pluginbase
        self.oslo_conf.register_opts(opts.DISABLE_BY_FILES_OPTS,
                                     group='healthcheck')
        self.status_files = {}
        paths = self._conf_get('disable_by_file_paths')
        self.status_files.update(self._iter_paths_ports(paths))

    @staticmethod
    def _iter_paths_ports(paths):
        for port_path in paths:
            port_path = port_path.strip()
            if port_path:
                # On windows, drive letters are followed by colons,
                # which makes split() return 3 elements in this case
                port, path = port_path.split(":", 1)
                port = int(port)
                yield (port, path)

    def healthcheck(self, server_port):
        path = self.status_files.get(server_port)
        if not path:
            LOG.warning('DisableByFilesPorts healthcheck middleware'
                        ' enabled without disable_by_file_paths set'
                        ' for port %s', server_port)
            return pluginbase.HealthcheckResult(available=True,
                                                reason="OK")
        else:
            if not os.path.exists(path):
                return pluginbase.HealthcheckResult(available=True,
                                                    reason="OK")
            else:

# Path: oslo_middleware/healthcheck/opts.py
# HEALTHCHECK_OPTS = [
#     cfg.StrOpt('path',
#                default='/healthcheck',
#                deprecated_for_removal=True,
#                help='The path to respond to healtcheck requests on.'),
#     cfg.BoolOpt('detailed',
#                 default=False,
#                 help='Show more detailed information as part of the response. '
#                      'Security note: Enabling this option may expose '
#                      'sensitive details about the service being monitored. '
#                      'Be sure to verify that it will not violate your '
#                      'security policies.'),
#     cfg.ListOpt('backends',
#                 default=[],
#                 help='Additional backends that can perform health checks and '
#                      'report that information back as part of a request.'),
# ]
# DISABLE_BY_FILE_OPTS = [
#     cfg.StrOpt('disable_by_file_path',
#                default=None,
#                help='Check the presence of a file to determine if an '
#                     'application is running on a port. Used by '
#                     'DisableByFileHealthcheck plugin.'),
# ]
# DISABLE_BY_FILES_OPTS = [
#     cfg.ListOpt('disable_by_file_paths',
#                 default=[],
#                 help='Check the presence of a file based on a port to '
#                      'determine if an application is running on a port. '
#                      'Expects a "port:path" list of strings. Used by '
#                      'DisableByFilesPortsHealthcheck plugin.'),
# ]
# 
# Path: oslo_middleware/healthcheck/pluginbase.py
# class HealthcheckResult(object):
# class HealthcheckBaseExtension(metaclass=abc.ABCMeta):
#     def __init__(self, available, reason, details=None):
#     def __init__(self, oslo_conf, conf):
#     def healthcheck(self, server_port):
#     def _conf_get(self, key, group='healthcheck'):


# Path: oslo_middleware/healthcheck/disable_by_file.py
import logging
import os
from oslo_middleware.healthcheck import opts
from oslo_middleware.healthcheck import pluginbase

        self.oslo_conf.register_opts(opts.DISABLE_BY_FILES_OPTS,
                                     group='healthcheck')
        self.status_files = {}
        paths = self._conf_get('disable_by_file_paths')
        self.status_files.update(self._iter_paths_ports(paths))

    @staticmethod
    def _iter_paths_ports(paths):
        for port_path in paths:
            port_path = port_path.strip()
            if port_path:
                # On windows, drive letters are followed by colons,
                # which makes split() return 3 elements in this case
                port, path = port_path.split(":", 1)
                port = int(port)
                yield (port, path)

    def healthcheck(self, server_port):
        path = self.status_files.get(server_port)
        if not path:
            LOG.warning('DisableByFilesPorts healthcheck middleware'
                        ' enabled without disable_by_file_paths set'
                        ' for port %s', server_port)
            return pluginbase.HealthcheckResult(available=True,
                                                reason="OK")
        else:
            if not os.path.exists(path):
                return pluginbase.HealthcheckResult(available=True,
                                                    reason="OK")
            else:

                return pluginbase.HealthcheckResult(available=False,