# Path: netman/core/objects/switch_descriptor.py
# class SwitchDescriptor(Model):
#     def __init__(self, model, hostname, username=None, password=None, port=None, netman_server=None):
#         self.model = model
#         self.hostname = hostname
#         self.username = username
#         self.password = password
#         self.port = port
#         self.netman_server = netman_server


import logging
from flask import request
from netman.api.api_utils import BadRequest
from netman.core.objects.switch_descriptor import SwitchDescriptor
        self.sessions_manager = sessions_manager

    def hook_to(self, server):
        raise NotImplemented()

    @property
    def logger(self):
        return logging.getLogger(__name__)

    def _get_switch_descriptor_from_request_headers(self, hostname):
        headers_present = [h in request.headers for h in ['Netman-Model', 'Netman-Username', 'Netman-Password']]

        if not any(headers_present):
            return None

        if not all(headers_present):
            raise BadRequest('For anonymous switch usage, please specify headers: Netman-Model, Netman-Username and Netman-Password.')

        port = None
        if "Netman-Port" in request.headers:
            try:
                port = int(request.headers["Netman-Port"])
            except ValueError:
                raise BadRequest('Netman-Port optional header should be an integer')

        netman_server = request.headers.get("Netman-Proxy-Server", None)
        if netman_server is not None and "," in netman_server:
            netman_server = [e.strip() for e in netman_server.split(",")]

        self.logger.info("Anonymous Switch Access ({}) {}@{}".format(request.headers['Netman-Model'], request.headers['Netman-Username'], hostname))

# Path: netman/core/objects/switch_descriptor.py
# class SwitchDescriptor(Model):
#     def __init__(self, model, hostname, username=None, password=None, port=None, netman_server=None):
#         self.model = model
#         self.hostname = hostname
#         self.username = username
#         self.password = password
#         self.port = port
#         self.netman_server = netman_server


# Path: netman/api/switch_api_base.py
import logging
from flask import request
from netman.api.api_utils import BadRequest
from netman.core.objects.switch_descriptor import SwitchDescriptor

        self.sessions_manager = sessions_manager

    def hook_to(self, server):
        raise NotImplemented()

    @property
    def logger(self):
        return logging.getLogger(__name__)

    def _get_switch_descriptor_from_request_headers(self, hostname):
        headers_present = [h in request.headers for h in ['Netman-Model', 'Netman-Username', 'Netman-Password']]

        if not any(headers_present):
            return None

        if not all(headers_present):
            raise BadRequest('For anonymous switch usage, please specify headers: Netman-Model, Netman-Username and Netman-Password.')

        port = None
        if "Netman-Port" in request.headers:
            try:
                port = int(request.headers["Netman-Port"])
            except ValueError:
                raise BadRequest('Netman-Port optional header should be an integer')

        netman_server = request.headers.get("Netman-Proxy-Server", None)
        if netman_server is not None and "," in netman_server:
            netman_server = [e.strip() for e in netman_server.split(",")]

        self.logger.info("Anonymous Switch Access ({}) {}@{}".format(request.headers['Netman-Model'], request.headers['Netman-Username'], hostname))

        return SwitchDescriptor(