from gns3fy import Gns3Connector, Project from tabulate import tabulate server = Gns3Connector("http://localhost:3080") lab = Project(name="topology_container", connector=server) lab.get() print(lab) print('\n--------------------------------\n') nodes = lab.nodes_summary(is_print=False) print(tabulate(nodes)) print('\n--------------------------------\n') links = lab.links_summary(is_print=False) print(tabulate(links))
def main(): # Parse the arguments args = parse_args() topology_data = load_yaml(args.topology) # Collect lab name print(heading("Collecting topology data")) lab_name: str = topology_data["title"]["text"] print(f"The lab name would be: {lab_name}") # Collect nodes specs nodes_spec = get_nodes_spec(topology_data["icons"]) # Collect connections specs links_spec = get_links_spec(topology_data["connections"]) # Create Gns3Connector print(heading(f"Configuring lab on GNS3 server")) server = Gns3Connector(f"{args.protocol}://{args.server}:{args.port}") # Verify lab is not already created lab_project = server.get_project(name=lab_name) if lab_project: delete_lab = input( f"\nLab already created, do you want to delete it? (y/n): ") if delete_lab == "y": server.delete_project(lab_project["project_id"]) else: sys.exit("Exiting...") # Create the lab lab = Project(name=lab_name, connector=server) lab.create() print(f"Project created: {lab.name}\n") # Create the nodes for device in nodes_spec: node = Node( project_id=lab.project_id, connector=server, name=device["name"], template=device["template"], x=parsed_x(device["x"] - 10), y=parsed_y(device["y"] - 5), ) node.create() time.sleep(3) print(f"Device created: {node.name}") # Create the links for link in links_spec: lab.create_link(*link) # Summary print(heading("Nodes Summary")) nodes_summary: str = lab.nodes_summary(is_print=False) print( tabulate(nodes_summary, headers=["Device", "Status", "Console Port", "ID"])) print(heading("Links Summary")) links_summary: str = lab.links_summary(is_print=False) print( tabulate(links_summary, headers=["Device A", "Port A", "Device B", "Port B"])) return