1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-11-22 20:40:41 +08:00

update summary output

This commit is contained in:
Septs 2020-05-24 22:04:25 +08:00
parent 476ddad70d
commit 89662c7b7c
3 changed files with 60 additions and 36 deletions

View file

@ -29,7 +29,7 @@ jobs:
eval "$(pyenv virtualenv-init -)" eval "$(pyenv virtualenv-init -)"
pyenv install 3.8.2 pyenv install 3.8.2
pyenv shell 3.8.2 pyenv shell 3.8.2
pip install toml pip install toml tabulate
- name: Run roa script - name: Run roa script
shell: bash shell: bash

View file

@ -29,7 +29,7 @@ jobs:
eval "$(pyenv virtualenv-init -)" eval "$(pyenv virtualenv-init -)"
pyenv install 3.8.2 pyenv install 3.8.2
pyenv shell 3.8.2 pyenv shell 3.8.2
pip install toml pip install toml tabulate
- name: Run roa script - name: Run roa script
shell: bash shell: bash

View file

@ -225,54 +225,78 @@ def make_roa_records(roa4, roa6):
def make_summary(): def make_summary():
from tabulate import tabulate
entities = load_entities() entities = load_entities()
asn_table = load_asn(entities) asn_table = load_asn(entities)
node_table = node_to_asn(set(asn_table.keys())) node_table = node_to_asn(set(asn_table.keys()))
stream = StringIO() stream = StringIO()
with redirect_stdout(stream): with redirect_stdout(stream):
print("Entity table:") print("Entity table:")
print("{:20}{:20}{}".format("Name", "Telegram", "Email")) entity_table = tabulate(
for entity in sorted( (
entities.values(), key=lambda entity: entity["name"].lower(), (
): entity["name"],
contact = entity.get("contact", {}) entity.get("contact", {}).get("email"),
email = contact.get("email", "") entity.get("contact", {}).get("telegram"),
telegram = contact.get("telegram", "") )
print("{:20}{:20}{}".format(entity["name"], telegram, email)) for entity in entities.values()
),
headers=["Name", "Email", "Telegram"],
tablefmt="presto",
)
print(entity_table)
print() print()
print("AS table:") print("AS table:")
print("{:15}{:<17}{:20}{}".format("Source", "ASN", "Owner", "Name")) as_table = tabulate(
for asn, entity in sorted(asn_table.items(), key=lambda item: item[0]): (
print( (entity["source"], "AS{}".format(asn), entity["owner"], entity["name"])
"{:15}AS{:<15}{:20}{}".format( for asn, entity in sorted(asn_table.items(), key=lambda item: item[0])
entity["source"], asn, entity["owner"], entity["name"] ),
) headers=["Source", "ASN", "Owner", "Name"],
) tablefmt="presto",
)
print(as_table)
print() print()
print("Node table:") print("Node table:")
print("{:<17}{}".format("ASN", "Name")) node_table = tabulate(
for name, asn in sorted(node_table.items(), key=lambda item: item[1]): (
print("AS{:<15}{}".format(asn, name)) ("AS{}".format(asn), name)
for name, asn in sorted(node_table.items(), key=lambda item: item[1])
),
headers=["ASN", "Name"],
tablefmt="presto",
)
print(node_table)
print() print()
print("Peer table:") print("Peer table:")
peers = { peer_table = tabulate(
item.stem: entity["to-peer"] for item, entity in iter_toml_file("peer") (
} (item.stem, downstream)
peers = [ for item, entity in iter_toml_file("peer")
(upstream, downstream) for downstream in entity["to-peer"]
for upstream, downstream_list in peers.items() ),
for downstream in downstream_list headers=["Upstream", "Downstream"],
] tablefmt="presto",
print("{:>20} ~ {}".format("Upstream", "Downstream")) colalign=("right",),
for upstream, downstream in peers: )
print("{:>20} ~ {}".format(upstream, downstream)) print(peer_table)
print() print()
print("Route table:") print("Route table:")
print("{:17}{:30}{:30}{}".format("ASN", "Name", "Prefix", "Supernet")) route_table = tabulate(
for entity in route_to_roa(asn_table): (
entity["prefix"] = str(entity["prefix"]) (
entity["supernet"] = str(entity["supernet"]) if entity["supernet"] else "" "AS{asn}".format_map(entity),
print("AS{asn:<15}{name:30}{prefix:30}{supernet}".format_map(entity)) entity["name"],
entity["prefix"] or "",
entity["supernet"] or "",
)
for entity in route_to_roa(asn_table)
),
headers=["ASN", "Name", "Prefix", "Supernet"],
tablefmt="presto",
)
print(route_table)
return stream.getvalue() return stream.getvalue()