# Path: opennsa/error.py
# LOG_SYSTEM = 'error'
# NSI_ERROR_CODE_TABLE = {
#     '00100' : PayloadError,
#     '00101' : MissingParameterError,
#     '00200' : ConnectionError,
#     '00201' : InvalidTransitionError,
#     '00202' : ConnectionExistsError,
#     '00203' : ConnectionNonExistentError,
#     '00204' : ConnectionGoneError,
#     '00205' : ConnectionCreateError,
#     '00300' : SecurityError,
#     '00301' : AuthenticationFailure,
#     '00302' : UnauthorizedError,
#     '00400' : TopologyError,
#     '00401' : UnknownSTPError,                      # compat
#     '00402' : STPResolutionError,                   # compat
#     '00403' : NoPathFoundError,
#     '00404' : VLANInterchangeNotSupportedError,     # compat
#     '00500' : InternalServerError,
#     '00501' : InternalNRMError,
#     '00600' : ResourceUnavailableError,
#     '00601' : STPUnavailableError,                  # compat
#     '00602' : BandwidthUnavailableError,            # compat
#     '00700' : ServiceError,
#     '00701' : UnknownSTPError,
#     '00702' : STPResolutionError,
#     '00703' : VLANInterchangeNotSupportedError,
#     '00704' : STPUnavailableError,
#     '00705' : BandwidthUnavailableError             # compat
# }
# class CallbackTimeoutError(Exception):
# class NSIError(Exception):
# class UnknownNSIError(NSIError):
# class PayloadError(NSIError):
# class MissingParameterError(PayloadError):
# class UnsupportedParameter(PayloadError):
# class ConnectionError(NSIError):
# class InvalidTransitionError(ConnectionError):
# class ConnectionExistsError(ConnectionError):
# class ConnectionNonExistentError(ConnectionError):
# class ConnectionGoneError(ConnectionError):
# class ConnectionCreateError(ConnectionError):
# class SecurityError(NSIError):
# class AuthenticationFailure(SecurityError):
# class UnauthorizedError(SecurityError):
# class TopologyError(NSIError):
# class NoPathFoundError(NSIError):
# class InternalServerError(NSIError):
# class InternalNRMError(InternalServerError):
# class DownstreamNSAError(InternalServerError):
# class ResourceUnavailableError(NSIError):
# class ServiceError(NSIError): # only use this if nothing else applies
# class UnknownSTPError(ServiceError):
# class STPResolutionError(NSIError):
# class VLANInterchangeNotSupportedError(TopologyError):
# class STPUnavailableError(ServiceError, TopologyError): # need this to be a topology error internally
# class BandwidthUnavailableError(ServiceError): # NSI error name is CAPACITY_UNAVAILABLE
#     def __init__(self, message, nsa_id=None, connection_id=None, variables=None):
# def lookup(error_code):


from twisted.python import log
from opennsa import error
        # But I think the old had the same issue, and it is not done currently
        self.providers = {} # network_id -> provider
        self.provider_urns = {} # network_id -> provider_urn
        # in theory the latter mapping might not be needed, but it is hard to do without
        self.provider_factories = provider_factories # { provider_type : provider_spawn_func }


    def addProvider(self, nsi_agent_urn, network_id, provider):
        """
        Directly add a provider. Probably only needed by setup.py
        """
        if network_id in self.providers:
            raise ValueError('Provider for network {} already registered')

        log.msg('Adding new provider for network {}, nsa urn {}'.format(network_id, nsi_agent_urn), system=LOG_SYSTEM)
        self.providers[network_id] = provider
        self.provider_urns[network_id] = nsi_agent_urn


    def getProvider(self, network_id):
        """
        Get a provider from a network id
        """
        if network_id.endswith(':nsa'):
            raise ValueError('look like you were trying to a provider via an nsa id')

        try:
            return self.providers[network_id]
        except KeyError:
            log.msg('Cannot provider for network {}, have providers for {}'.format(network_id, ','.join(self.providers.keys())), debug=True, system=LOG_SYSTEM)

# Path: opennsa/error.py
# LOG_SYSTEM = 'error'
# NSI_ERROR_CODE_TABLE = {
#     '00100' : PayloadError,
#     '00101' : MissingParameterError,
#     '00200' : ConnectionError,
#     '00201' : InvalidTransitionError,
#     '00202' : ConnectionExistsError,
#     '00203' : ConnectionNonExistentError,
#     '00204' : ConnectionGoneError,
#     '00205' : ConnectionCreateError,
#     '00300' : SecurityError,
#     '00301' : AuthenticationFailure,
#     '00302' : UnauthorizedError,
#     '00400' : TopologyError,
#     '00401' : UnknownSTPError,                      # compat
#     '00402' : STPResolutionError,                   # compat
#     '00403' : NoPathFoundError,
#     '00404' : VLANInterchangeNotSupportedError,     # compat
#     '00500' : InternalServerError,
#     '00501' : InternalNRMError,
#     '00600' : ResourceUnavailableError,
#     '00601' : STPUnavailableError,                  # compat
#     '00602' : BandwidthUnavailableError,            # compat
#     '00700' : ServiceError,
#     '00701' : UnknownSTPError,
#     '00702' : STPResolutionError,
#     '00703' : VLANInterchangeNotSupportedError,
#     '00704' : STPUnavailableError,
#     '00705' : BandwidthUnavailableError             # compat
# }
# class CallbackTimeoutError(Exception):
# class NSIError(Exception):
# class UnknownNSIError(NSIError):
# class PayloadError(NSIError):
# class MissingParameterError(PayloadError):
# class UnsupportedParameter(PayloadError):
# class ConnectionError(NSIError):
# class InvalidTransitionError(ConnectionError):
# class ConnectionExistsError(ConnectionError):
# class ConnectionNonExistentError(ConnectionError):
# class ConnectionGoneError(ConnectionError):
# class ConnectionCreateError(ConnectionError):
# class SecurityError(NSIError):
# class AuthenticationFailure(SecurityError):
# class UnauthorizedError(SecurityError):
# class TopologyError(NSIError):
# class NoPathFoundError(NSIError):
# class InternalServerError(NSIError):
# class InternalNRMError(InternalServerError):
# class DownstreamNSAError(InternalServerError):
# class ResourceUnavailableError(NSIError):
# class ServiceError(NSIError): # only use this if nothing else applies
# class UnknownSTPError(ServiceError):
# class STPResolutionError(NSIError):
# class VLANInterchangeNotSupportedError(TopologyError):
# class STPUnavailableError(ServiceError, TopologyError): # need this to be a topology error internally
# class BandwidthUnavailableError(ServiceError): # NSI error name is CAPACITY_UNAVAILABLE
#     def __init__(self, message, nsa_id=None, connection_id=None, variables=None):
# def lookup(error_code):


# Path: opennsa/provreg.py
from twisted.python import log
from opennsa import error

        # But I think the old had the same issue, and it is not done currently
        self.providers = {} # network_id -> provider
        self.provider_urns = {} # network_id -> provider_urn
        # in theory the latter mapping might not be needed, but it is hard to do without
        self.provider_factories = provider_factories # { provider_type : provider_spawn_func }


    def addProvider(self, nsi_agent_urn, network_id, provider):
        """
        Directly add a provider. Probably only needed by setup.py
        """
        if network_id in self.providers:
            raise ValueError('Provider for network {} already registered')

        log.msg('Adding new provider for network {}, nsa urn {}'.format(network_id, nsi_agent_urn), system=LOG_SYSTEM)
        self.providers[network_id] = provider
        self.provider_urns[network_id] = nsi_agent_urn


    def getProvider(self, network_id):
        """
        Get a provider from a network id
        """
        if network_id.endswith(':nsa'):
            raise ValueError('look like you were trying to a provider via an nsa id')

        try:
            return self.providers[network_id]
        except KeyError:
            log.msg('Cannot provider for network {}, have providers for {}'.format(network_id, ','.join(self.providers.keys())), debug=True, system=LOG_SYSTEM)

            raise error.STPResolutionError('Could not resolve a provider for network %s' % network_id)