<s> """<STR_LIT>""" <EOL> import time <EOL> from twisted . python import log , failure <EOL> from opennsa import nsa , error <EOL> from opennsa . shared import xmlhelper <EOL> from opennsa . protocols . shared import minisoap , soapresource <EOL> from opennsa . protocols . nsi2 import helper , queryhelper <EOL> from opennsa . protocols . nsi2 . bindings import actions , nsiconnection , p2pservices <EOL> LOG_SYSTEM = '<STR_LIT>' <EOL> class ProviderService : <EOL> def __init__ ( self , soap_resource , provider ) : <EOL> self . provider = provider <EOL> soap_resource . registerDecoder ( actions . RESERVE , self . reserve ) <EOL> soap_resource . registerDecoder ( actions . RESERVE_COMMIT , self . reserveCommit ) <EOL> soap_resource . registerDecoder ( actions . RESERVE_ABORT , self . reserveAbort ) <EOL> soap_resource . registerDecoder ( actions . PROVISION , self . provision ) <EOL> soap_resource . registerDecoder ( actions . RELEASE , self . release ) <EOL> soap_resource . registerDecoder ( actions . TERMINATE , self . terminate ) <EOL> soap_resource . registerDecoder ( actions . QUERY_SUMMARY , self . querySummary ) <EOL> soap_resource . registerDecoder ( actions . QUERY_SUMMARY_SYNC , self . querySummarySync ) <EOL> soap_resource . registerDecoder ( actions . QUERY_RECURSIVE , self . queryRecursive ) <EOL> def _createSOAPFault ( self , err , provider_nsa , connection_id = None , service_type = None ) : <EOL> log . msg ( '<STR_LIT>' % err . getErrorMessage ( ) , system = LOG_SYSTEM ) <EOL> se = helper . createServiceException ( err , provider_nsa , connection_id ) <EOL> ex_element = se . xml ( nsiconnection . serviceException ) <EOL> soap_fault = soapresource . SOAPFault ( err . getErrorMessage ( ) , ex_element ) <EOL> return soap_fault <EOL> def reserve ( self , soap_data , request_info ) : <EOL> t_start = time . time ( ) <EOL> header , reservation = helper . parseRequest ( soap_data ) <EOL> criteria = reservation . criteria <EOL> service_type = criteria . serviceType <EOL> p2ps = criteria . serviceDefinition <EOL> if type ( p2ps ) is not p2pservices . P2PServiceBaseType : <EOL> err = failure . Failure ( error . PayloadError ( '<STR_LIT>' ) ) <EOL> return self . _createSOAPFault ( err , header . provider_nsa , service_type = service_type ) <EOL> if p2ps . directionality in ( None , '<STR_LIT>' ) : <EOL> err = failure . Failure ( error . MissingParameterError ( '<STR_LIT>' ) ) <EOL> return self . _createSOAPFault ( err , header . provider_nsa ) <EOL> start_time = xmlhelper . parseXMLTimestamp ( criteria . schedule . startTime ) if criteria . schedule . startTime is not None else None <EOL> end_time = xmlhelper . parseXMLTimestamp ( criteria . schedule . endTime ) if criteria . schedule . endTime is not None else None <EOL> schedule = nsa . Schedule ( start_time , end_time ) <EOL> src_stp = helper . createSTP ( p2ps . sourceSTP ) <EOL> dst_stp = helper . createSTP ( p2ps . destSTP ) <EOL> if p2ps . ero : <EOL> err = failure . Failure ( error . PayloadError ( '<STR_LIT>' ) ) <EOL> return self . _createSOAPFault ( err , header . provider_nsa ) <EOL> params = [ ( p . type_ , p . value ) for p in p2ps . parameter ] if p2ps . parameter else None <EOL> symmetric = p2ps . symmetricPath or False <EOL> sd = nsa . Point2PointService ( src_stp , dst_stp , p2ps . capacity , p2ps . directionality , symmetric , None , params ) <EOL> crt = nsa . Criteria ( criteria . version , schedule , sd ) <EOL> t_delta = time . time ( ) - t_start <EOL> log . msg ( '<STR_LIT>' % round ( t_delta , <NUM_LIT:3> ) , profile = True , system = LOG_SYSTEM ) <EOL> d = self . provider . reserve ( header , reservation . connectionId , reservation . globalReservationId , reservation . description , crt , request_info ) <EOL> def createReserveAcknowledgement ( connection_id ) : <EOL> soap_header_element = helper . createProviderHeader ( header . requester_nsa , header . provider_nsa , None , header . correlation_id ) <EOL> reserve_response = nsiconnection . ReserveResponseType ( connection_id ) <EOL> reserve_response_element = reserve_response . xml ( nsiconnection . reserveResponse ) <EOL> payload = minisoap . createSoapPayload ( reserve_response_element , soap_header_element ) <EOL> return payload <EOL> d . addCallbacks ( createReserveAcknowledgement , self . _createSOAPFault , errbackArgs = ( header . provider_nsa , ) ) <EOL> return d <EOL> def reserveCommit ( self , soap_data , request_info ) : <EOL> header , confirm = helper . parseRequest ( soap_data ) <EOL> d = self . provider . reserveCommit ( header , confirm . connectionId , request_info ) <EOL> d . addCallbacks ( lambda _ : helper . createGenericProviderAcknowledgement ( header ) , self . _createSOAPFault , errbackArgs = ( header . provider_nsa , confirm . connectionId ) ) <EOL> return d <EOL> def reserveAbort ( self , soap_data , request_info ) : <EOL> header , request = helper . parseRequest ( soap_data ) <EOL> d = self . provider . reserveAbort ( header , request . connectionId , request_info ) <EOL> d . addCallbacks ( lambda _ : helper . createGenericProviderAcknowledgement ( header ) , self . _createSOAPFault , errbackArgs = ( header . provider_nsa , request . connectionId ) ) <EOL> return d <EOL> def provision ( self , soap_data , request_info ) : <EOL> header , request = helper . parseRequest ( soap_data ) <EOL> d = self . provider . provision ( header , request . connectionId , request_info ) <EOL> d . addCallbacks ( lambda _ : helper . createGenericProviderAcknowledgement ( header ) , self . _createSOAPFault , errbackArgs = ( header . provider_nsa , request . connectionId ) ) <EOL> return d <EOL> def release ( self , soap_data , request_info ) : <EOL> header , request = helper . parseRequest ( soap_data ) <EOL> d = self . provider . release ( header , request . connectionId , request_info ) <EOL> d . addCallbacks ( lambda _ : helper . createGenericProviderAcknowledgement ( header ) , self . _createSOAPFault , errbackArgs = ( header . provider_nsa , request . connectionId ) ) <EOL> return d <EOL> def terminate ( self , soap_data , request_info ) : <EOL> header , request = helper . parseRequest ( soap_data ) <EOL> d = self . provider . terminate ( header , request . connectionId , request_info ) <EOL> d . addCallbacks ( lambda _ : helper . createGenericProviderAcknowledgement ( header ) , self . _createSOAPFault , errbackArgs = ( header . provider_nsa , request . connectionId ) ) <EOL> return d <EOL> def querySummary ( self , soap_data , request_info ) : <EOL> header , query = helper . parseRequest ( soap_data ) <EOL> d = self . provider . querySummary ( header , query . connectionId , query . globalReservationId , request_info ) <EOL> d . addCallbacks ( lambda _ : helper . createGenericProviderAcknowledgement ( header ) , self . _createSOAPFault , errbackArgs = ( header . provider_nsa , ) ) <EOL> return d <EOL> def querySummarySync ( self , soap_data , request_info ) : <EOL> def gotReservations ( reservations , header ) : <EOL> soap_header_element = helper . createProviderHeader ( header . requester_nsa , header . provider_nsa , correlation_id = header . correlation_id ) <EOL> qs_reservations = queryhelper . buildQuerySummaryResultType ( reservations ) <EOL> qsct = nsiconnection . QuerySummaryConfirmedType ( qs_reservations ) <EOL> payload = minisoap . createSoapPayload ( qsct . xml ( nsiconnection . querySummarySyncConfirmed ) , soap_header_element ) <EOL> return payload <EOL> header , query = helper . parseRequest ( soap_data ) <EOL> d = self . provider . querySummarySync ( header , query . connectionId , query . globalReservationId , request_info ) <EOL> d . addCallbacks ( gotReservations , self . _createSOAPFault , callbackArgs = ( header , ) , errbackArgs = ( header . provider_nsa , ) ) <EOL> return d <EOL> def queryRecursive ( self , soap_data , request_info ) : <EOL> header , query = helper . parseRequest ( soap_data ) <EOL> d = self . provider . queryRecursive ( header , query . connectionId , query . globalReservationId , request_info ) <EOL> d . addCallbacks ( lambda _ : helper . createGenericProviderAcknowledgement ( header ) , self . _createSOAPFault , errbackArgs = ( header . provider_nsa , ) ) <EOL> return d </s>
