def make_endpoint_query(endpoint, event_types): """ Makes query for an endpoint with event_type. @param endpoint: L{periscope.topology.models.EndPointPair} or L{psapi.protocol.EndPointPair} @param event_types: list of events from L{psapi.protocol.events} @returns: list of L{psapi.query.Query}. """ if not isinstance(endpoint, EndPointPair) and not isinstance(endpoint, psEndPointPair): raise ValueError("Each element of endpoints must be of type " "periscope.topology.models.EndPointPair or " "psapi.protocol.EndPointPair.") if not isinstance(event_types, list): event_types = [event_types] endpoint_queries = [] if isinstance(endpoint, psEndPointPair): subjects = [endpoint] else: subjects = [] src_addresses = endpoint.src.toRealType().addresses.all() dst_addresses = endpoint.dst.toRealType().addresses.all() for src_address in src_addresses: for dst_address in dst_addresses: src = src_address.value dst = dst_address.value endpoints = psEndPointPair(src=src, dst=dst) # it's safer to set this to None endpoints.src_type = None endpoints.dst_type = None subjects.append(endpoints) for event_type in event_types: for subject in subjects: query = None if event_type == events.IPERF2: query = IPerfQuery(endpointpair=subject) elif event_type == events.OWAMP: query = OWAMPQuery(endpointpair=subject) elif event_type == events.TRACEROUTE: query = TracerouteQuery(endpointpair=subject) else: logger.warn("Cannot make query of event type " + event_type) if query: endpoint_queries.append(query) return endpoint_queries
def extract_endpoint(src, dst): """ Reads endpoint pair object from user input data. If the endpoint has existing matching endpointpair in UNIS it will be returned instead. @returns: None, L{periscope.topology.models.EndPointPair}, or L{psapi.protocol.EndPointPair} """ if not src and not dst: return None endpoint = find_endpoint(src, dst) if endpoint: return endpoint endpoint = psEndPointPair(src=src, dst=dst) endpoint.src_type = None endpoint.dst_type = None return endpoint