@defer.inlineCallbacks
    def provision(self, header, connection_id, request_info=None):

        log.msg('', system=LOG_SYSTEM)
        log.msg('Provision request. NSA: %s. Connection ID: %s' % (header.requester_nsa, connection_id), system=LOG_SYSTEM)

        conn = yield self.getConnection(connection_id)

        if conn.lifecycle_state == state.TERMINATED:
            raise error.ConnectionGoneError('Connection %s has been terminated' % connection_id)

        yield state.provisioning(conn)

        save_defs = []
        defs = []

        sub_connections = yield self.getSubConnectionsByConnectionKey(conn.id)

        for sc in sub_connections:
            # only bother saving stuff to db if the state is actually changed
            if sc.provision_state != state.PROVISIONING:
                save_defs.append( state.provisioning(sc) )
        if save_defs:
            yield defer.DeferredList(save_defs) #, consumeErrors=True)

        for sc in sub_connections:
            provider = self.getProvider(sc.provider_nsa)
            header = nsa.NSIHeader(self.nsa_.urn(), sc.provider_nsa, security_attributes=header.security_attributes)
            d = provider.provision(header, sc.connection_id, request_info) # request_info will only be passed locally
            d.addErrback(_logErrorResponse, connection_id, sc.provider_nsa, 'provision')
            defs.append(d)

        results = yield defer.DeferredList(defs, consumeErrors=True)
        successes = [ r[0] for r in results ]
        if all(successes):
            # this just means we got an ack from all children
            defer.returnValue(connection_id)
        else:
            n_success = sum( [ 1 for s in successes if s ] )
            log.msg('Connection %s. Provision failure. %i of %i connections successfully acked' % (connection_id, n_success, len(defs)), system=LOG_SYSTEM)
            provider_urns = [ sc.provider_nsa for sc in sub_connections ]
            raise _createAggregateException(connection_id, 'provision', results, provider_urns, error.ConnectionError)
dataset/ETHPy150Open NORDUnet/opennsa/opennsa/aggregator.py/Aggregator.provision/original