Skip to content
Snippets Groups Projects
Commit 102dbff6 authored by Robert Latta's avatar Robert Latta
Browse files

added circuit tree

parent f07ef2c6
No related branches found
No related tags found
No related merge requests found
import os
from operator import itemgetter
import click
from tree_format import format_tree
from inventory_provider.db.ims import IMS, CIRCUIT_PROPERTIES
username = 'TEST05'
password = ''
bt = os.getenv('IMS_BT')
ds = IMS('http://83.97.94.128:2080/api', username, password, bt)
NAV_PROPS = [
CIRCUIT_PROPERTIES['Speed'],
CIRCUIT_PROPERTIES['Product']
]
@click.command()
@click.option('-c', 'carriers', is_flag=True)
@click.argument('root_circuit_id', type=click.INT, required=True)
def cli(carriers, root_circuit_id):
if carriers:
children_prop = 'carriercircuits'
childid = 'carriercircuitid'
NAV_PROPS.append(CIRCUIT_PROPERTIES['CarrierCircuits'])
else:
children_prop = 'subcircuits'
childid = 'subcircuitid'
NAV_PROPS.append(CIRCUIT_PROPERTIES['SubCircuits'])
def _get_childcircuit_tree(circuit_id):
circuit = ds.get_entity_by_id(
'circuit', circuit_id, navigation_properties=NAV_PROPS)
_tree = [
f'{circuit["id"]} -- {circuit["name"]} -- '
f'prod. {circuit["product"]["name"]} -- '
f'spd. {circuit["speed"]["name"]}'
]
if circuit[children_prop]:
children = []
for child_circuit in circuit[children_prop]:
children.append(_get_childcircuit_tree(
child_circuit[childid]
))
_tree.append(children)
else:
_tree.append([])
return _tree
tree = _get_childcircuit_tree(root_circuit_id)
print(format_tree(
tree, format_node=itemgetter(0), get_children=itemgetter(1))
)
if __name__ == '__main__':
# 659386
cli()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment