core-cli: add geo position to node output for query session and node

This commit is contained in:
Blake Harnden 2022-03-21 21:35:05 -07:00
parent 2df8aa4379
commit 6d8ae4af2e

View file

@ -212,9 +212,11 @@ def query_session(core: CoreGrpcClient, args: Namespace) -> None:
print_json(session) print_json(session)
else: else:
print("Nodes") print("Nodes")
print("Node ID | Node Name | Node Type") print("ID | Name | Type | XY | Geo")
for node in session.nodes.values(): for node in session.nodes.values():
print(f"{node.id:<7} | {node.name:<9} | {node.type.name}") xy_pos = f"{int(node.position.x)},{int(node.position.y)}"
geo_pos = f"{node.geo.lon:.7f},{node.geo.lat:.7f},{node.geo.alt:f}"
print(f"{node.id:<7} | {node.name[:7]:<7} | {node.type.name[:7]:<7} | {xy_pos:<9} | {geo_pos}")
print("\nLinks") print("\nLinks")
for link in session.links: for link in session.links:
n1 = session.nodes[link.node1_id].name n1 = session.nodes[link.node1_id].name
@ -243,12 +245,10 @@ def query_node(core: CoreGrpcClient, args: Namespace) -> None:
ifaces = [protobuf_to_json(x.to_proto()) for x in ifaces] ifaces = [protobuf_to_json(x.to_proto()) for x in ifaces]
print_json(dict(node=node, ifaces=ifaces)) print_json(dict(node=node, ifaces=ifaces))
else: else:
print("ID | Name | Type | XY") print("ID | Name | Type | XY | Geo")
xy_pos = f"{int(node.position.x)},{int(node.position.y)}" xy_pos = f"{int(node.position.x)},{int(node.position.y)}"
print(f"{node.id:<4} | {node.name[:7]:<7} | {node.type.name[:7]:<7} | {xy_pos}") geo_pos = f"{node.geo.lon:.7f},{node.geo.lat:.7f},{node.geo.alt:f}"
if node.geo: print(f"{node.id:<7} | {node.name[:7]:<7} | {node.type.name[:7]:<7} | {xy_pos:<9} | {geo_pos}")
print("Geo")
print(f"{node.geo.lon:.7f},{node.geo.lat:.7f},{node.geo.alt:f}")
if ifaces: if ifaces:
print("Interfaces") print("Interfaces")
print("Connected To | ", end="") print("Connected To | ", end="")