# 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):


import datetime
from opennsa import error
        assert end_time   is None or type(end_time)   is datetime.datetime, 'End time must be a datetime object or None, not %s' % str(type(end_time))

        if start_time is not None:
            assert start_time.tzinfo is None, 'Start time must NOT have time zone.'
        if end_time is not None:
            assert end_time.tzinfo   is None, 'End time must NOT have time zone.'


    def addReservation(self, resource, start_time, end_time):
        self._checkArgs(resource, start_time, end_time)

        reservation = (resource, start_time, end_time)
        self.reservations.append(reservation)


    def removeReservation(self, resource, start_time, end_time):
        self._checkArgs(resource, start_time, end_time)

        reservation = (resource, start_time, end_time)
        try:
            self.reservations.remove(reservation)
        except ValueError:
            raise ValueError('Reservation (%s, %s, %s) does not exist. Cannot remove' % (resource, start_time, end_time))


    def checkReservation(self, resource, start_time, end_time):
        self._checkArgs(resource, start_time, end_time)

        # check start time is before end time
        if start_time is not None and end_time is not None and start_time > end_time:

# 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/backends/common/calendar.py
import datetime
from opennsa import error

        assert end_time   is None or type(end_time)   is datetime.datetime, 'End time must be a datetime object or None, not %s' % str(type(end_time))

        if start_time is not None:
            assert start_time.tzinfo is None, 'Start time must NOT have time zone.'
        if end_time is not None:
            assert end_time.tzinfo   is None, 'End time must NOT have time zone.'


    def addReservation(self, resource, start_time, end_time):
        self._checkArgs(resource, start_time, end_time)

        reservation = (resource, start_time, end_time)
        self.reservations.append(reservation)


    def removeReservation(self, resource, start_time, end_time):
        self._checkArgs(resource, start_time, end_time)

        reservation = (resource, start_time, end_time)
        try:
            self.reservations.remove(reservation)
        except ValueError:
            raise ValueError('Reservation (%s, %s, %s) does not exist. Cannot remove' % (resource, start_time, end_time))


    def checkReservation(self, resource, start_time, end_time):
        self._checkArgs(resource, start_time, end_time)

        # check start time is before end time
        if start_time is not None and end_time is not None and start_time > end_time:

            raise error.PayloadError('Invalid request: Reverse duration (end time before start time)')