# Path: netl2api/lib/config.py
# ENVVAR_CFGBASE  = "NETL2API_CFG_BASE"
# DEFAULT_CFGBASE = "/etc/netl2api"
# _LOG_CFG        = { "debug": logging.DEBUG,
#                     "info":  logging.INFO,
#                     "warn":  logging.WARN,
#                     "error": logging.ERROR }
# def config_check_perm(config_file=None, chmod=600):
# def get_cfg(cfgfile, check_permission=None):
# def section(cfg, cfg_section):
# def get_netl2server_cfg():
#     def __init__(self, db=7, timeout=3):
#     def get_connection(self):
# def get_devices_cfg():
# def setup_logger(cfg, component):
# def setup_netl2server_logger(cfg):
# def setup_persistence_ctrl_logger(cfg):
# class UnprotectedConfigFile(Exception):
# class RedisClient(object):


import re
import threading
from uuid import uuid4
from collections import deque
from netl2api.lib import config
    return _thr_local.l2api_ctx_uid


def get_context_uid():
    try:
        return _thr_local.l2api_ctx_uid
    except AttributeError:
        return


def get_sw_handler_class(sw_classname=None):
    sw_classname = sw_classname.split(".")
    sw_module = __import__(".".join(sw_classname[:-1]), fromlist=[sw_classname[-1:][0]])
    return sw_module.__getattribute__(sw_classname[-1:][0])


def get_switch_instance(device):
    switches = config.get_devices_cfg()
    if not switches.has_key(device):
        raise DeviceNotFound("Switch not known/configured => '%s'" % device)
    if not switches[device].get("mgmt-api") or not switches[device].get("mgmt-user") \
            or not switches[device].get("mgmt-pass"):
        raise MisconfiguredDevice("The device '%s' are misconfigured - see the devices.cfg or redis-devices.cfg" % device)
    swapi = get_sw_handler_class(switches[device]["mgmt-api"])
    return swapi(host=switches[device]["mgmt-host"], port=int(switches[device]["mgmt-port"]),
                 username=switches[device]["mgmt-user"], passwd=switches[device]["mgmt-pass"])

class MisconfiguredDevice(Exception):
    pass


# Path: netl2api/lib/config.py
# ENVVAR_CFGBASE  = "NETL2API_CFG_BASE"
# DEFAULT_CFGBASE = "/etc/netl2api"
# _LOG_CFG        = { "debug": logging.DEBUG,
#                     "info":  logging.INFO,
#                     "warn":  logging.WARN,
#                     "error": logging.ERROR }
# def config_check_perm(config_file=None, chmod=600):
# def get_cfg(cfgfile, check_permission=None):
# def section(cfg, cfg_section):
# def get_netl2server_cfg():
#     def __init__(self, db=7, timeout=3):
#     def get_connection(self):
# def get_devices_cfg():
# def setup_logger(cfg, component):
# def setup_netl2server_logger(cfg):
# def setup_persistence_ctrl_logger(cfg):
# class UnprotectedConfigFile(Exception):
# class RedisClient(object):


# Path: netl2api/lib/utils.py
import re
import threading
from uuid import uuid4
from collections import deque
from netl2api.lib import config

    return _thr_local.l2api_ctx_uid


def get_context_uid():
    try:
        return _thr_local.l2api_ctx_uid
    except AttributeError:
        return


def get_sw_handler_class(sw_classname=None):
    sw_classname = sw_classname.split(".")
    sw_module = __import__(".".join(sw_classname[:-1]), fromlist=[sw_classname[-1:][0]])
    return sw_module.__getattribute__(sw_classname[-1:][0])


def get_switch_instance(device):
    switches = config.get_devices_cfg()
    if not switches.has_key(device):
        raise DeviceNotFound("Switch not known/configured => '%s'" % device)
    if not switches[device].get("mgmt-api") or not switches[device].get("mgmt-user") \
            or not switches[device].get("mgmt-pass"):
        raise MisconfiguredDevice("The device '%s' are misconfigured - see the devices.cfg or redis-devices.cfg" % device)
    swapi = get_sw_handler_class(switches[device]["mgmt-api"])
    return swapi(host=switches[device]["mgmt-host"], port=int(switches[device]["mgmt-port"]),
                 username=switches[device]["mgmt-user"], passwd=switches[device]["mgmt-pass"])

class MisconfiguredDevice(Exception):
    pass


class DeviceNotFound(Exception):