def _query(self, header, connection_ids, global_reservation_ids, request_info=None): # generic query mechanism for summary and recursive # TODO: Match stps/ports that can be used with credentials and return connections using these STPs if connection_ids: conns = yield GenericBackendConnections.find(where=[ 'source_network = ? AND dest_network = ? AND requester_nsa = ? AND connection_id IN ?', self.network, self.network, header.requester_nsa, tuple(connection_ids) ]) elif global_reservation_ids: conns = yield GenericBackendConnections.find(where=[ 'source_network = ? AND dest_network = ? AND requester_nsa = ? AND global_reservation_ids IN ?', self.network, self.network, header.requester_nsa, tuple(global_reservation_ids) ]) else: raise error.MissingParameterError( 'Must specify connectionId or globalReservationId') reservations = [] for c in conns: source_stp = nsa.STP(c.source_network, c.source_port, c.source_label) dest_stp = nsa.STP(c.dest_network, c.dest_port, c.dest_label) schedule = nsa.Schedule(c.start_time, c.end_time) sd = nsa.Point2PointService(source_stp, dest_stp, c.bandwidth, cnt.BIDIRECTIONAL, False, None) criteria = nsa.QueryCriteria(c.revision, schedule, sd) data_plane_status = (c.data_plane_active, c.revision, True) states = (c.reservation_state, c.provision_state, c.lifecycle_state, data_plane_status) notification_id = self.getNotificationId() result_id = notification_id # whatever provider_nsa = cnt.URN_OGF_PREFIX + self.network.replace( 'topology', 'nsa') # hack on reservations.append( nsa.ConnectionInfo(c.connection_id, c.global_reservation_id, c.description, cnt.EVTS_AGOLE, [criteria], provider_nsa, c.requester_nsa, states, notification_id, result_id)) defer.returnValue(reservations)
def buildCriteria(r_criteria, include_children=False): schedule = buildSchedule(r_criteria.schedule) service_def = buildServiceDefinition(r_criteria.serviceDefinition) children = [] if include_children: for r_child in sorted(r_criteria.children, key=lambda c : c.order): # print 'child', r_child.connectionId, r_child.providerNSA, len(r_child.criteria), [ c.children for c in r_child.criteria ] crit = r_child.criteria[0] # we only use this for service type, so should be ok c_crits = [ buildCriteria(rc, include_children) for rc in r_child.criteria ] states = buildConnectionStates(r_child.connectionStates) ci = nsa.ConnectionInfo(r_child.connectionId, None, None, crit.serviceType, c_crits, r_child.providerNSA, None, states, None, None) children.append( ci ) crit = nsa.QueryCriteria(int(r_criteria.version), schedule, service_def, children) return crit