示例#1
0
def parse_bgp_state(reader):  # {{{
    result = dict()
    k, v = util.parse_desc_colon_str(reader)
    result[k] = v
    v = util.parse_desc_lines(reader, BGP_DETAILS_RE, BGP_DETAILS_PARSERS)
    result['details'] = v
    return 'bgp', result
示例#2
0
文件: protocols.py 项目: cunha/client
def parse_bgp_state(reader):
    result = dict()
    k, v = util.parse_desc_colon_str(reader)
    result[k] = v
    v = util.parse_desc_lines(reader, BGP_DETAILS_RE, BGP_DETAILS_PARSERS)
    result["details"] = v
    return "bgp", result
示例#3
0
def show_route(reader, outfd):
    routes = list()
    network = None
    line = reader.readline()
    while line:
        m = re.match(route.SUMMARY_RE, line)
        assert m, "%s" % line
        if m.group(route.SUMMARY_NETWORK_KEY) is not None:
            network = m.group(route.SUMMARY_NETWORK_KEY)
        rt = m.groupdict()
        rt[route.SUMMARY_NETWORK_KEY] = network
        rt = dict((k, v.strip()) for k, v in rt.items() if v is not None)
        v = util.parse_desc_lines(
            reader, route.DETAILS_RE, route.DETAILS_PARSERS, route.SUMMARY_RE
        )
        rt["attributes"] = v
        line = reader.readline()
        routes.append(rt)
    json.dump(routes, outfd)
    return routes
示例#4
0
def show_protocols(reader, outfd):
    header = reader.readline()
    assert header.split() == proto.HEADER_LINE_FIELDS
    results = list()
    line = reader.readline()
    while line:
        m = re.match(proto.SUMMARY_RE, line)
        if not m:
            logging.debug("parse_proto: no match [%s]", line)
            line = reader.readline()
            continue
        line = reader.readline()
        if m.group("proto") not in proto.SUPPORTED:
            logging.debug("parse_proto: %s not supported", m.group("proto"))
            continue
        result = m.groupdict()
        v = util.parse_desc_lines(reader, proto.DETAILS_RE, proto.DETAILS_PARSERS)
        result["details"] = v
        results.append(result)
    json.dump(results, outfd, indent=2)
    return results
示例#5
0
def show_route(reader, outfd, return_json=False):  # {{{
    routes = list()
    network = None
    line = reader.readline()
    while line:
        m = re.match(route.SUMMARY_RE, line)
        assert m, '%s' % line
        if m.group(route.SUMMARY_NETWORK_KEY) is not None:
            network = m.group(route.SUMMARY_NETWORK_KEY)
        rt = m.groupdict()
        rt[route.SUMMARY_NETWORK_KEY] = network
        rt = dict((k, v.strip()) for k, v in rt.items() if v is not None)
        v = util.parse_desc_lines(reader, route.DETAILS_RE,
                                  route.DETAILS_PARSERS, route.SUMMARY_RE)
        rt['attributes'] = v
        line = reader.readline()
        json.dump(rt, outfd)
        if line:
            outfd.write('\n')
        if return_json:
            routes.append(rt)
    return routes