def _post(self, request, response): try: data = request.body.getvalue().decode() properties, endpoints = EPSLite.parse_input(data) except Exception as e: logging.warning("Failed to parse input %s", str(request.body)) return errors.bad_request(response, exception=e) try: properties = properties & self.prop_urls.keys() prop_urls = {prop: self.prop_urls[prop] for prop in properties} mapping, vtags = EPSLite.setup_pid_mapping(prop_urls) except Exception as e: logging.error("Failed to setup mapping") return errors.server_error(response, exception=e) meta_out = {"dependent-vtags": vtags} data_out = {} for ep in endpoints: family, address = decode_addr(ep) if not correct_inet_format(family, address): logging.warning("Bad format %s: %s", family, address) continue props = {} for prop in properties: prop_map = mapping[prop][family] if not address in prop_map: continue props.update({prop: prop_map[address]}) if len(props) > 0: data_out[ep] = props return {"meta": meta_out, "endpoint-properties": data_out}
def reverse_networkmap(networkmap_data, mapping = {}): for pid, groups in networkmap_data.items(): for family, prefixes in groups.items(): if not family in mapping: mapping[family] = SubnetTree.SubnetTree() prefixes = [ p for p in prefixes if correct_inet_format(family, p) ] for p in prefixes: mapping[family][p] = pid return mapping
def find_pid(mapping, addresses): pids = {} for _addr in addresses: family, addr = decode_addr(_addr) if not family in mapping: logging.warning("Family %s not supported", family) continue if not correct_inet_format(family, addr): logging.warning("Bad %s address format %s", family, addr) continue if not family in pids: pids[family] = {} pids[family][addr] = mapping[family][addr] return pids