### Install Dependencies with uv Source: https://github.com/davidban77/gns3fy/blob/develop/CLAUDE.md Installs project dependencies using the uv package manager. Ensure uv is installed and configured for the project. ```bash # Install dependencies uv sync --group dev ``` -------------------------------- ### Node.start Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Starts the node. ```APIDOC ## start ### Description Starts the node. ### Method POST ### Endpoint `/v2/projects/{project_id}/nodes/{node_id}/start` ### Required Attributes - `project_id` - `connector` - `node_id` ``` -------------------------------- ### Start a Node Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Initiates the operation of a GNS3 node. ```python | @verify_connector_and_id | start() ``` -------------------------------- ### Node.start Source: https://context7.com/davidban77/gns3fy/llms.txt Starts a stopped GNS3 node. ```APIDOC ## Node.start ### Description Starts the specified node on the GNS3 server. ### Method `Node.start()` ### Request Example ```python alpine1.start() print(alpine1.status) # Output: started ``` ``` -------------------------------- ### Install gns3fy Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/index.md Install the gns3fy package using pip. This is the standard way to add the library to your Python environment. ```bash pip install gns3fy ``` -------------------------------- ### Start All Project Nodes Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Starts all nodes in the project. `poll_wait_time` controls the delay between status queries. ```python | @verify_connector_and_id | start_nodes(poll_wait_time=5) ``` -------------------------------- ### Get All Templates Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Fetch a list of all templates configured on the GNS3 server. ```python | get_templates() ``` -------------------------------- ### Initialize and Get Node Information Source: https://github.com/davidban77/gns3fy/blob/develop/README.md Create a Node object for a specific project and server, then retrieve its details. This allows for individual node management. ```python from gns3fy import Node, Link, Gns3Connector PROJECT_ID = "" server = Gns3Connector("http://:3080") alpine1 = Node(project_id=PROJECT_ID, name="alpine-1", connector=server) alpine1.get() print(alpine1) ``` ```text "Node(name='alpine-1', node_type='docker', node_directory= ...)" ``` -------------------------------- ### Link Object Initialization and Get Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Initializes a Link object and retrieves its information from the GNS3 API. Requires project_id, link_id, and a Gns3Connector instance. The 'get' method fetches link details. ```python >>> link = Link(project_id=, link_id= connector=) >>> link.get() >>> print(link.link_type) 'ethernet' ``` -------------------------------- ### DHCP Configuration for eth1 (Commented) Source: https://github.com/davidban77/gns3fy/blob/develop/tests/data/files.txt Example of a commented-out DHCP configuration for the eth1 interface. Uncomment lines to enable. ```bash # auto eth1 # iface eth1 inet dhcp ``` -------------------------------- ### Get All Projects Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Fetch a list of all projects currently defined on the GNS3 server. ```python | get_projects() ``` -------------------------------- ### Static IP Configuration for eth1 (Commented) Source: https://github.com/davidban77/gns3fy/blob/develop/tests/data/files.txt Example of a commented-out static IP configuration for the eth1 interface. Uncomment lines to enable. ```bash #auto eth1 #iface eth1 inet static # address 192.168.1.2 # netmask 255.255.255.0 # gateway 192.168.1.1 # up echo nameserver 192.168.1.1 > /etc/resolv.conf ``` -------------------------------- ### start_nodes Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Starts all nodes within the project, with an optional delay for polling node status. ```APIDOC ## start_nodes ### Description Starts all the nodes inside the project. ### Method start_nodes(poll_wait_time=5) ### Parameters #### Query Parameters - **poll_wait_time** (integer) - Optional - Delay in seconds when performing the next query of the nodes status. Defaults to 5. ``` -------------------------------- ### Create and List Project Snapshots in GNS3 Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Manage project snapshots using the `Project` instance. This example demonstrates creating a new snapshot and then listing all existing snapshots with their creation times. ```python from datetime import datetime from gns3fy import Gns3Connector, Project lab = Project(name="test3", connector=Gns3Connector(url="http://gns3server01:3080")) lab.get() # Create snapshot lab.create_snapshot(name="snap3") # Show configured snapshots for snapshot in lab.snapshots: _time = datetime.utcfromtimestamp(snapshot['created_at']).strftime('%Y-%m-%d %H:%M:%S') print(f"Snapshot: {snapshot['name']}, created at: {_time}") ``` -------------------------------- ### Quick Start: Connect and Interact with GNS3 Project Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/index.md Connect to a GNS3 server, load a project, retrieve its details, and manipulate its status. Ensure the GNS3 server address is correctly specified. ```python >>> import gns3fy # Define the server object to establish the connection >>> gns3_server = gns3fy.Gns3Connector("http://:3080") # Define the lab you want to load and assign the server connector >>> lab = gns3fy.Project(name="API_TEST", connector=gns3_server) # Retrieve its information and display >>> lab.get() >>> print(lab) "Project(project_id='4b21dfb3-675a-4efa-8613-2f7fb32e76fe', name='API_TEST', status='opened', ...)" # Access the project attributes >>> print(f"Name: {lab.name} -- Status: {lab.status} -- Is auto_closed?: {lab.auto_close}") "Name: API_TEST -- Status: closed -- Is auto_closed?: False" # Open the project >>> lab.open() >>> lab.status opened # Verify the stats >>> lab.stats {'drawings': 0, 'links': 4, 'nodes': 6, 'snapshots': 0} # List the names and status of all the nodes in the project >>> for node in lab.nodes: ... print(f"Node: {node.name} -- Node Type: {node.node_type} -- Status: {node.status}") "Node: Ethernetswitch-1 -- Node Type: ethernet_switch -- Status: started" ... ``` -------------------------------- ### Get Templates Summary with Tabulate Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Retrieves a summary of available templates on the server and prints it in a formatted table using the tabulate library. Set is_print=False to get the data. ```python >>> print( tabulate( server.templates_summary(is_print=False), headers=[ "Template Name", "Template ID", "Type", "Builtin", "Console", "Category", ], ) ) ``` ```text " Template Name Template ID Type Builtin Console Category ------------------ ------------------------------------ ------------------ --------- --------- ---------- IOU-L3 8504c605-7914-4a8f-9cd4-a2638382db0e iou False telnet router IOU-L2 92cccfb2-6401-48f2-8964-3c75323be3cb iou False telnet switch vEOS c6203d4b-d0ce-4951-bf18-c44369d46804 qemu False telnet router alpine 847e5333-6ac9-411f-a400-89838584371b docker False telnet guest Cloud 39e257dc-8412-3174-b6b3-0ee3ed6a43e9 cloud True N/A guest NAT df8f4ea9-33b7-3e96-86a2-c39bc9bb649c nat True N/A guest VPCS 19021f99-e36f-394d-b4a1-8aaa902ab9cc vpcs True N/A guest Ethernet switch 1966b864-93e7-32d5-965f-001384eec461 ethernet_switch True none switch Ethernet hub b4503ea9-d6b6-3695-9fe4-1db3b39290b0 ethernet_hub True N/A switch Frame Relay switch dd0f6f3a-ba58-3249-81cb-a1dd88407a47 frame_relay_switch True N/A switch ATM switch aaa764e2-b383-300f-8a0e-3493bbfdb7d2 atm_switch True N/A switch " ``` -------------------------------- ### Bulk Node Control (Start, Stop, Reload, Suspend) Source: https://context7.com/davidban77/gns3fy/llms.txt Manages the state of all nodes in a project simultaneously. Allows for starting, stopping, reloading, or suspending nodes with optional polling waits. ```python from gns3fy import Gns3Connector, Project server = Gns3Connector(url="http://localhost:3080") lab = Project(name="ospf_lab", connector=server) lab.get() # Start all nodes and wait 10 seconds before refreshing status lab.start_nodes(poll_wait_time=10) for node in lab.nodes: print(f"{node.name}: {node.status}") # Stop all lab.stop_nodes() # Reload (restart) all lab.reload_nodes(poll_wait_time=8) # Suspend all lab.suspend_nodes() ``` -------------------------------- ### Monitor server compute resources Source: https://context7.com/davidban77/gns3fy/llms.txt Samples CPU and memory usage over a period to make decisions about starting nodes. Requires the 'time' module for delays. ```python import time from gns3fy import Gns3Connector, Project server = Gns3Connector(url="http://gns3server01:3080") lab = Project(name="test_lab", connector=server) lab.get() hungry_router = lab.get_node(name="hungry_router") # Sample CPU/memory over 5 seconds cpu_usage, memory_usage = [], [] for _ in range(5): compute = server.get_compute(compute_id="local") cpu_usage.append(compute["cpu_usage_percent"]) memory_usage.append(compute["memory_usage_percent"]) time.sleep(1) cpu_avg = round(sum(cpu_usage) / len(cpu_usage), 2) mem_avg = round(sum(memory_usage) / len(memory_usage), 2) if cpu_avg <= 40.0 and mem_avg <= 50.0: hungry_router.start() print(f"Started hungry_router (CPU avg: {cpu_avg}%, Mem avg: {mem_avg}%)") else: print(f"Resources too high — CPU: {cpu_avg}%, Memory: {mem_avg}%") ``` -------------------------------- ### Get Nodes Inventory Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Returns an inventory-style dictionary of the project's nodes. ```python | nodes_inventory() ``` -------------------------------- ### Get Project by Name or ID Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieve a specific project using either its name or its unique project ID. ```python | get_project(name=None, project_id=None) ``` -------------------------------- ### Node and Link Object Interaction Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Demonstrates how to interact with Node and Link objects, including getting their details, starting/stopping nodes, and accessing link information. ```APIDOC ### Node and Link objects ### Description Accessing and manipulating `Node` and `Link` objects to control individual elements within a GNS3 project. ### Method ```python PROJECT_ID = "4b21dfb3-675a-4efa-8613-2f7fb32e76fe" alpine1 = Node(project_id=PROJECT_ID, name="alpine-1", connector=server) alpine1.get() print(alpine1) # Accessing attributes print(f"Name: {alpine1.name} -- Status: {alpine1.status} -- Console: {alpine1.console}") # Stop and start the node alpine1.stop() print(alpine1.status) alpine1.start() print(alpine1.status) # Accessing links associated with the node print(alpine1.links) # Interacting with a Link object link1 = alpine1.links[0] print(f"Link Type: {link1.link_type} -- Capturing?: {link1.capturing} -- Endpoints: {link1.nodes}") ``` ### Response Example ```python Node(name='alpine-1', node_type='docker', node_directory= ...) ``` ``` Name: alpine-1 -- Status: started -- Console: 5005 ``` ``` stopped ``` ``` started ``` ```python [Link(link_id='4d9f1235-7fd1-466b-ad26-0b4b08beb778', link_type='ethernet', ...)] ``` ``` Link Type: ethernet -- Capturing?: False -- Endpoints: [{'adapter_number': 2, ...}] ``` ``` -------------------------------- ### Get Links Summary Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Returns a summary of links in the project. If `is_print` is False, returns a list of tuples. ```python | links_summary(is_print=True) ``` -------------------------------- ### Initialize Gns3Connector Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Instantiate the Gns3Connector to connect to a GNS3 server. Requires the server URL. You can then use the connector to get server version information. ```python >>> server = Gns3Connector(url="http://
:3080") >>> print(server.get_version()) {'local': False, 'version': '2.2.0b4'} ``` -------------------------------- ### Get Compute Images Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Lists the available images for a given compute resource and emulator type. Specify the emulator (e.g., 'qemu', 'iou', 'docker') and optionally the compute_id (defaults to 'local'). ```python | get_compute_images(emulator, compute_id="local") ``` -------------------------------- ### Get Project Snapshots Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieves a list of all snapshots for the current project. Requires the project instance to have 'project_id' and 'connector' attributes. ```python | @verify_connector_and_id | get_snapshots() ``` -------------------------------- ### Get Templates Summary Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Obtain a summary of all available templates on the GNS3 server. If `is_print` is `False`, it returns a list of template details. ```python | templates_summary(is_print=True) ``` -------------------------------- ### Get Project Information Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieves project information, with options to include links, nodes, and stats. If stats are included, it also checks for snapshots and drawings. ```python | get(get_links=True, get_nodes=True, get_stats=True) ``` -------------------------------- ### Get Projects Summary Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieve a summary of all projects on the GNS3 server. By default, it prints a summary; setting `is_print` to `False` returns a list of project details. ```python | projects_summary(is_print=True) ``` -------------------------------- ### Link Get Method Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieves information for a specific link using its project_id, connector, and link_id. This method is decorated with '@verify_connector_and_id' for validation. ```python | @verify_connector_and_id | get() ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/davidban77/gns3fy/blob/develop/CLAUDE.md Serves the generated documentation locally for preview. This is useful for checking the appearance and content of the documentation before deployment. ```bash task docs-show # Serve docs locally ``` -------------------------------- ### Gns3Connector API Calls Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Examples of direct API calls using the Gns3Connector object to get server version and templates. ```APIDOC ## Gns3Connector as an interface ### Description Using the `Gns3Connector` as a direct interface to the GNS3 server REST API. ### Method ```python # Get server version server.get_version() # Get available templates server.get_templates() ``` ### Response Example ```json { "local": false, "version": "2.2.0b4" } ``` ```json [ { "adapter_type": "e1000", "adapters": 13, "bios_image": "", "boot_priority": "c", "builtin": false, "category": "router", "cdrom_image": "", "compute_id": "local", ... } ] ``` ``` -------------------------------- ### Manage Individual Node Lifecycle Source: https://context7.com/davidban77/gns3fy/llms.txt Demonstrates the lifecycle management of a GNS3 node, including retrieval, starting, stopping, reloading, suspending, updating attributes, creating new nodes from templates, and deleting nodes. ```python from gns3fy import Node, Gns3Connector server = Gns3Connector(url="http://localhost:3080") PROJECT_ID = "4b21dfb3-675a-4efa-8613-2f7fb32e76fe" # Retrieve existing node by name alpine1 = Node(project_id=PROJECT_ID, name="alpine-1", connector=server) alpine1.get() print(f"Name: {alpine1.name} | Type: {alpine1.node_type} | Status: {alpine1.status} | Console: {alpine1.console}") # Name: alpine-1 | Type: docker | Status: started | Console: 5005 # Start / stop / reload / suspend alpine1.stop() print(alpine1.status) # stopped alpine1.start() print(alpine1.status) # started alpine1.reload() alpine1.suspend() print(alpine1.status) # suspended # Update node attributes alpine1.update(name="alpine-host-1", console_auto_start=True) # Create a new node directly (requires template to be configured on GNS3) new_node = Node( project_id=PROJECT_ID, connector=server, name="vpcs-host", template="VPCS", ) new_node.create() print(new_node.node_id) # UUID assigned by server # Delete the node new_node.delete() print(new_node.node_id) # None ``` -------------------------------- ### Project Initialization and Creation Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Initializes a Project instance and creates the project on the GNS3 server. The project status can be checked after creation. ```python >>> lab = Project(name="lab", connector=) >>> lab.create() >>> print(lab.status) 'opened' ``` -------------------------------- ### Initialize GNS3 Connector and Project Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Set up the connection to the GNS3 server and initialize a project object. This is the first step for interacting with GNS3 via the library. ```python >>> server = Gns3Connector(url="http://localhost:3080")] >>> print(server) '' >>> lab = Project(name="lab", connector=server) ``` -------------------------------- ### Get Links Summary with Tabulate Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Retrieves a summary of links in the lab and prints it in a formatted table using the tabulate library. Set is_print=False to get the data. ```python >>> links_summary = lab.links_summary(is_print=False) >>> print( ... tabulate(links_summary, headers=["Node A", "Port A", "Node B", "Port B"]) ... ) ``` ```text " Node A Port A Node B Port B -------------- ----------- ---------------- ----------- IOU1 Ethernet1/0 IOU2 Ethernet1/0 vEOS-4.21.5F-1 Management1 Ethernetswitch-1 Ethernet0 vEOS-4.21.5F-1 Ethernet1 alpine-1 eth0 Cloud-1 eth1 Ethernetswitch-1 Ethernet7 " ``` -------------------------------- ### Connect to GNS3 Server and List Projects Source: https://github.com/davidban77/gns3fy/blob/develop/README.md Establish a connection to the GNS3 server and display a summary of available projects. Requires the 'tabulate' library for formatted output. ```python import gns3fy from tabulate import tabulate # Define the server object to establish the connection gns3_server = gns3fy.Gns3Connector("http://:3080") # Show the available projects on the server print( tabulate( gns3_server.projects_summary(is_print=False), headers=["Project Name", "Project ID", "Total Nodes", "Total Links", "Status"], ) ) ``` ```text """ Project Name Project ID Total Nodes Total Links Status -------------- ------------------------------------ ------------- ------------- -------- test2 c9dc56bf-37b9-453b-8f95-2845ce8908e3 10 9 opened API_TEST 4b21dfb3-675a-4efa-8613-2f7fb32e76fe 6 4 opened mpls-bgpv2 f5de5917-0ac5-4850-82b1-1d7e3c777fa1 30 40 closed """ ``` -------------------------------- ### Get a tabular summary of project nodes Source: https://context7.com/davidban77/gns3fy/llms.txt Generates a formatted table of nodes within a project, including their status, console port, and unique ID. Requires the 'tabulate' library for display. ```python from tabulate import tabulate from gns3fy import Gns3Connector, Project server = Gns3Connector(url="http://localhost:3080") lab = Project(name="ospf_lab", connector=server) lab.get() # Tabular summary print( tabulate( lab.nodes_summary(is_print=False), headers=["Node", "Status", "Console Port", "ID"], ) ) # Node Status Console Port ID # ---------------- -------- -------------- ------------------------------------ # Ethernetswitch-1 started 5000 da28e1c0-9465-4f7c-b42c-49b2f4e1c64d # IOU1 started 5001 de23a89a-aa1f-446a-a950-31d4bf98653c ``` -------------------------------- ### Get Nodes Summary with Tabulate Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Retrieves a summary of nodes in the lab and prints it in a formatted table using the tabulate library. Set is_print=False to get the data. ```python >>> from tabulate import tabulate >>> nodes_summary = lab.nodes_summary(is_print=False) >>> print( ... tabulate(nodes_summary, headers=["Node", "Status", "Console Port", "ID"]) ... ) ``` ```text " Node Status Console Port ID ---------------- -------- -------------- ------------------------------------ Ethernetswitch-1 started 5000 da28e1c0-9465-4f7c-b42c-49b2f4e1c64d IOU1 started 5001 de23a89a-aa1f-446a-a950-31d4bf98653c IOU2 started 5002 0d10d697-ef8d-40af-a4f3-fafe71f5458b vEOS-4.21.5F-1 started 5003 8283b923-df0e-4bc1-8199-be6fea40f500 alpine-1 started 5005 ef503c45-e998-499d-88fc-2765614b313e Cloud-1 started cde85a31-c97f-4551-9596-a3ed12c08498 " ``` -------------------------------- ### Initialize Gns3Connector and List Projects Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Establishes a connection to the GNS3 server and displays a summary of available projects. Ensure the GNS3 server is running and accessible at the specified address. ```python >>> from gns3fy import Gns3Connector, Project >>> from tabulate import tabulate >>> server = Gns3Connector("http://localhost:3080") # To show the available projects on the server >>> print( tabulate( server.projects_summary(is_print=False), headers=["Project Name", "Project ID", "Total Nodes", "Total Links", "Status"], ) ) """ Project Name Project ID Total Nodes Total Links Status -------------- ------------------------------------ ------------- ------------- -------- test2 c9dc56bf-37b9-453b-8f95-2845ce8908e3 10 9 opened API_TEST 4b21dfb3-675a-4efa-8613-2f7fb32e76fe 6 4 opened mpls-bgpv2 f5de5917-0ac5-4850-82b1-1d7e3c777fa1 30 40 closed """ ``` -------------------------------- ### Open Project Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Opens the specified project on the GNS3 server. ```python | @verify_connector_and_id | open() ``` -------------------------------- ### Create Link using Link Instance Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Manually create a link by instantiating the `Link` class. This requires the project ID, the GNS3 connector, and a list of nodes with their respective adapter and port numbers. ```python >>> nodes = [ dict(node_id=switch.node_id, adapter_number=0, port_number=1), dict(node_id=alpine.node_id, adapter_number=0, port_number=0) ] >>> extra_link = Link(project_id=lab.project_id, connector=server, nodes=nodes) >>> extra_link.create() >>> extra_link Link(link_id='edf38e1a-67e7-4060-8493-0e222ec22072', link_type='ethernet', project_id='6e75bca5'...) ``` -------------------------------- ### Get Project Nodes Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieves all nodes within the current project. ```python | @verify_connector_and_id | get_nodes() ``` -------------------------------- ### Project.open Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Opens the project on the GNS3 server. ```APIDOC ## Project.open ### Description Opens the project on the server. ### Method Signature ```python open() ``` ``` -------------------------------- ### Project.create Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Creates a new GNS3 project. ```APIDOC ## Project.create ### Description Creates the project on the GNS3 server. ### Method Signature ```python create() ``` ### Required Attributes - `name` - `connector` ``` -------------------------------- ### Get Project Stats Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieves the statistics for a specific project on the GNS3 server. ```python | @verify_connector_and_id | get_stats() ``` -------------------------------- ### Creating a New Project Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Steps to create a new project (lab) on the GNS3 server using the Project interface. ```APIDOC ### Project creation ### Description Creating a new lab on the GNS3 server. ### Method ```python lab = Project(name="test_lab", connector=server) lab.create() print(lab) ``` ### Response Example ```python Project(project_id='e83f1275-3a6f-48f7-88ee-36386ee27a55', name='test_lab', status='opened',...) ``` ### Note For a complete list of the attributes, refer to the API Reference for Project objects. ``` -------------------------------- ### Get Nodes in Project Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieve a list of all nodes within a specified project, identified by its `project_id`. ```python | get_nodes(project_id) ``` -------------------------------- ### Get Nodes Summary Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Returns a summary of nodes in the project. If `is_print` is False, returns a list of tuples. ```python | nodes_summary(is_print=True) ``` -------------------------------- ### create_project Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Creates a new project on the GNS3 server. Requires a dictionary with at least a 'name' attribute. ```APIDOC ## create_project ### Description Creates a new project on the GNS3 server. ### Parameters #### Request Body - **name** (str) - Required - The name of the project to create. - **kwargs** (dict) - Optional - Additional project parameters. ### Returns JSON project information. ``` -------------------------------- ### Get Specific Link Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Fetch details of a particular link within a project using both the `project_id` and the `link_id`. ```python | get_link(project_id, link_id) ``` -------------------------------- ### Create and Initialize a Node Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Instantiate a Node object and create it within a GNS3 project. Requires node name, type, template, project ID, and a GNS3Connector instance. ```python >>> alpine = Node(name="alpine1", node_type="docker", template="alpine", project_id=, connector=) >>> alpine.create() >>> print(alpine.node_id) 'SOME-UUID-GENERATED' ``` -------------------------------- ### Get Links in Project Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieve a list of all links defined within a specified project, identified by its `project_id`. ```python | get_links(project_id) ``` -------------------------------- ### create_project Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Creates a new project. ```APIDOC ## create_project ### Description Creates a new project. ### Method Signature `create_project(**kwargs)` ### Parameters - `**kwargs`: Attributes for the new project. ``` -------------------------------- ### Get Specific Node Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Fetch details of a particular node within a project using both the `project_id` and the `node_id`. ```python | get_node(project_id, node_id) ``` -------------------------------- ### Get Specific Link Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieves a Link object by its ID. Run `get_links()` to refresh the link list if necessary. ```python | get_link(link_id) ``` -------------------------------- ### Run Full Test Suite Source: https://github.com/davidban77/gns3fy/blob/develop/CLAUDE.md Executes the complete test suite, including linting, formatting checks, and unit tests. This command should be run before committing code. ```bash # Run full test suite (lint + format check + tests) task test ``` -------------------------------- ### Get Template by Name or ID Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieve a specific template using either its name or its unique template ID. ```python | get_template(name=None, template_id=None) ``` -------------------------------- ### Gns3Connector and Project Interaction Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Demonstrates how to initialize a Gns3Connector, retrieve a summary of available projects, and interact with a specific Project object. ```APIDOC ## Gns3Connector and Project objects ### Description Example of defining a connector object and a project that is already configured on a local GNS3 server. ### Method ```python from gns3fy import Gns3Connector, Project from tabulate import tabulate server = Gns3Connector("http://localhost:3080") # To show the available projects on the server print( tabulate( server.projects_summary(is_print=False), headers=["Project Name", "Project ID", "Total Nodes", "Total Links", "Status"], ) ) lab = Project(name="API_TEST", connector=server) # Retrieve its information and display lab.get() print(lab) # Access the project attributes print(f"Name: {lab.name} -- Status: {lab.status} -- Is auto_closed?: {lab.auto_close}") # Open the project lab.open() print(lab.status) # Verify the stats print(lab.stats) # List the names and status of all the nodes in the project for node in lab.nodes: print(f"Node: {node.name} -- Node Type: {node.node_type} -- Status: {node.status}") ``` ### Response Example ``` Project Name Project ID Total Nodes Total Links Status -------------- ------------------------------------ ------------- ------------- -------- test2 c9dc56bf-37b9-453b-8f95-2845ce8908e3 10 9 opened API_TEST 4b21dfb3-675a-4efa-8613-2f7fb32e76fe 6 4 opened mpls-bgpv2 f5de5917-0ac5-4850-82b1-1d7e3c777fa1 30 40 closed ``` ``` Project(project_id='4b21dfb3-675a-4efa-8613-2f7fb32e76fe', name='API_TEST', status='opened', ...) ``` ``` Name: API_TEST -- Status: closed -- Is auto_closed?: False ``` ``` opened ``` ``` {'drawings': 0, 'links': 4, 'nodes': 6, 'snapshots': 0} ``` ``` Node: Ethernetswitch-1 -- Node Type: ethernet_switch -- Status: started ... ``` ``` -------------------------------- ### Create Project Snapshot Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Creates a new snapshot of the current project. Requires the project instance to have 'project_id' and 'connector' attributes, and a 'name' for the snapshot. ```python | @verify_connector_and_id | create_snapshot(name) ``` -------------------------------- ### Get Project Drawings Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieves a list of all drawings for the current project. Requires the project instance to have 'project_id' and 'connector' attributes. ```python | @verify_connector_and_id | get_drawings() ``` -------------------------------- ### Load and inspect an existing GNS3 project Source: https://context7.com/davidban77/gns3fy/llms.txt Loads an existing project by its name and populates its attributes, including status, node count, and link count. Requires a running GNS3 server connection. ```python from gns3fy import Gns3Connector, Project server = Gns3Connector(url="http://localhost:3080") # Load existing project by name lab = Project(name="ospf_lab", connector=server) lab.get() # fetches project, nodes, links, stats, snapshots, drawings print(lab) # Project(project_id='4b21dfb3-675a-4efa-8613-2f7fb32e76fe', name='ospf_lab', status='opened', ...) print(f"Status: {lab.status}, Nodes: {lab.stats['nodes']}, Links: {lab.stats['links']}") # Status: opened, Nodes: 6, Links: 4 ``` -------------------------------- ### Get Specific Node Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieves a Node object by its name or node ID. Run `get_nodes()` to refresh the node list if necessary. ```python | get_node(name=None, node_id=None) ``` -------------------------------- ### Create Project Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Use this function to create a new project in GNS3. A dictionary containing project parameters, including the required 'name', must be provided. ```python | create_project(**kwargs) ``` -------------------------------- ### Update a template attribute Source: https://context7.com/davidban77/gns3fy/llms.txt Modifies an existing template on the GNS3 server. This example changes the console type of the 'alpine' template to 'telnet'. ```python new_server.update_template(name="alpine", console_type="telnet") ``` -------------------------------- ### Project.get Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieves the projects information, with options to include links, nodes, and statistics. ```APIDOC ## Project.get ### Description Retrieves the projects information. It can optionally query for links, nodes, and statistics within the project. ### Method Signature ```python get(get_links=True, get_nodes=True, get_stats=True) ``` ### Parameters - **get_links** (bool) - Optional - When true it also queries for the links inside the project. - **get_nodes** (bool) - Optional - When true it also queries for the nodes inside the project. - **get_stats** (bool) - Optional - When true it also queries for the stats inside the project. ### Notes If `get_stats` is set to `True`, it also verifies if snapshots and drawings are inside the project and stores them in their respective attributes (`snapshots` and `drawings`). ``` -------------------------------- ### Project Source: https://context7.com/davidban77/gns3fy/llms.txt Full project lifecycle management, including opening, closing, node and link management, snapshots, drawings, and file I/O. ```APIDOC ## Project — full project lifecycle management The `Project` dataclass wraps a GNS3 project and provides methods for open/close, node and link management, snapshots, drawings, and file I/O. Pass `name` or `project_id` plus a `connector` to instantiate it, then call `get()` to populate all attributes. ### Methods ```python __init__(name=None, project_id=None, connector=None) get() create() open() close() delete() update(**kwargs) ``` ### Description This class provides comprehensive control over GNS3 projects, from creation and deletion to managing their state and content. ### Example ```python from gns3fy import Gns3Connector, Project server = Gns3Connector(url="http://localhost:3080") # Load existing project by name lab = Project(name="ospf_lab", connector=server) lab.get() # fetches project, nodes, links, stats, snapshots, drawings print(lab) # Project(project_id='4b21dfb3-675a-4efa-8613-2f7fb32e76fe', name='ospf_lab', status='opened', ...) print(f"Status: {lab.status}, Nodes: {lab.stats['nodes']}, Links: {lab.stats['links']}") # Status: opened, Nodes: 6, Links: 4 # Open / close lab.close() print(lab.status) # closed lab.open() print(lab.status) # opened # Update project attributes lab.update(auto_close=True, show_interface_labels=True) # Create a new project from scratch new_lab = Project(name="ci_test_lab", connector=server) new_lab.create() print(new_lab.project_id) # newly assigned UUID # Delete project new_lab.delete() print(new_lab.project_id) # None ``` ``` -------------------------------- ### Get Project Node Inventory Source: https://context7.com/davidban77/gns3fy/llms.txt Retrieves an inventory of all nodes within a GNS3 project. Useful for understanding the current state and configuration of nodes. ```python inventory = lab.nodes_inventory() print(inventory) ``` -------------------------------- ### Generate SVG Line Source: https://context7.com/davidban77/gns3fy/llms.txt Use `generate_line_svg` to create an SVG string for a line. Specify start and end points, width, height, and stroke color. ```python # Horizontal line 300px wide line = generate_line_svg(height=0, width=300, x1=0, x2=300, y1=0, y2=0, stroke="#ff0000") print(line) ``` -------------------------------- ### Manage GNS3 Projects at Server Level Source: https://context7.com/davidban77/gns3fy/llms.txt Use create_project() and delete_project() for direct server-level project management without instantiating a Project object. Prefer the Project class for full lifecycle management. ```python server = gns3fy.Gns3Connector(url="http://localhost:3080") # Create a bare project new_proj = server.create_project(name="temp_lab", auto_close=False) print(new_proj["project_id"]) # e83f1275-3a6f-48f7-88ee-36386ee27a55 # Delete it by UUID server.delete_project(project_id=new_proj["project_id"]) ``` -------------------------------- ### Display GNS3 Server Projects Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Retrieves and displays a summary of all projects configured on the GNS3 server. Requires the 'tabulate' library for formatted output. ```python from tabulate import tabulate projects_summary = server.projects_summary(is_print=False) print( tabulate( server.projects_summary(is_print=False), headers=[ "Project Name", "Project ID", "Total Nodes", "Total Links", "Status", ], ) ) ``` -------------------------------- ### Manipulate Node Status and Properties Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Interact with a specific node within a project. This includes retrieving its status, starting it, and accessing its connector object for further operations. ```python # Retrieve the lab information and print the amount of nodes configured >>> lab.get() >>> print(len(lab.nodes)) 2 # Assign one of the nodes to a varaible and start manipulating it >>> node_1 = lab.nodes[0] >>> print(node_1.status) 'stopped' >>> node_1.start() >>> print(node_1.status) 'started' >>> print(node_1.connector) '' ``` -------------------------------- ### Create and Manage Drawings in a Project Source: https://context7.com/davidban77/gns3fy/llms.txt Demonstrates creating SVG-based drawings (rectangles, ellipses) and managing them within a GNS3 project. Includes listing, updating, and deleting drawings. ```python rect_svg = generate_rectangle_svg(height=80, width=160, fill="#4a90d9", stroke="#1a4a7a") lab.create_drawing(svg=rect_svg, x=50, y=50, z=1) # Created drawing: a3f2b1c0-... ellipse_svg = generate_ellipse_svg(height=100.0, width=100.0, fill="#f5a623") lab.create_drawing(svg=ellipse_svg, x=200, y=100) # List current drawings lab.get_drawings() for d in lab.drawings: print(d["drawing_id"], d["x"], d["y"]) # Update drawing position drawing_id = lab.drawings[0]["drawing_id"] lab.update_drawing(drawing_id=drawing_id, x=300, y=150) # Delete a drawing lab.delete_drawing(drawing_id=drawing_id) ``` -------------------------------- ### Gns3Connector.create_project / delete_project Source: https://context7.com/davidban77/gns3fy/llms.txt Provides low-level helpers to create and delete projects directly at the server level without creating a `Project` object. ```APIDOC ## Gns3Connector.create_project / delete_project ### Description Low-level helpers that POST/DELETE directly without creating a `Project` object. Prefer the `Project` class for full lifecycle management. ### Method ```python server = gns3fy.Gns3Connector(url="http://localhost:3080") # Create a bare project new_proj = server.create_project(name="temp_lab", auto_close=False) print(new_proj["project_id"]) # e83f1275-3a6f-48f7-88ee-36386ee27a55 # Delete it by UUID server.delete_project(project_id=new_proj["project_id"]) ``` ``` -------------------------------- ### Get Computes Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/api_reference.md Retrieves a list of all available compute resources in GNS3. The returned list contains dictionaries with attributes such as CPU and memory usage for each compute. ```python | get_computes() ``` -------------------------------- ### Retrieve All Links in Project Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Fetch all links associated with the current project. This is useful for verifying link creation or inspecting existing connections. ```python >>> lab.get_links() # You can see the 2 links created earlier >>> lab.links [Link(link_id='b0d0df11-8ed8-4d1d-98e4-3776c9b7bdce', link_type='ethernet'... Link(link_id='=', link_type='ethernet'...] ``` -------------------------------- ### Create Link using Lab Object Source: https://github.com/davidban77/gns3fy/blob/develop/docs/content/user-guide.md Use the `create_link` method on a Project instance to establish a connection between two devices. This method requires the names of the source and destination nodes and their respective interfaces. ```python >>> lab.create_link('Ethernet-switch', 'Ethernet0', 'alpine-host1', 'eth1') "Created Link-ID: b0d0df11-8ed8-4d1d-98e4-3776c9b7bdce -- Type: ethernet" ``` ```python >>> lab.links [Link(link_id='b0d0df11-8ed8-4d1d-98e4-3776c9b7bdce', link_type='ethernet', project_id='6e7'...)] ``` -------------------------------- ### Project.get_nodes / nodes_summary / nodes_inventory Source: https://context7.com/davidban77/gns3fy/llms.txt Inspect nodes within a project. Includes methods to refresh the node list, get a tabular summary, and retrieve an Ansible-compatible inventory. ```APIDOC ## Project.get_nodes / nodes_summary / nodes_inventory — inspect nodes `get_nodes()` refreshes the `nodes` list with `Node` instances. `nodes_summary()` returns a tabular summary. `nodes_inventory()` returns an Ansible-compatible inventory dict. ### Methods ```python get_nodes() nodes_summary(is_print=True) nodes_inventory() ``` ### Description These methods provide different ways to view and interact with the nodes present in a GNS3 project. ### Example ```python from tabulate import tabulate from gns3fy import Gns3Connector, Project server = Gns3Connector(url="http://localhost:3080") lab = Project(name="ospf_lab", connector=server) lab.get() # Tabular summary print( tabulate( lab.nodes_summary(is_print=False), headers=["Node", "Status", "Console Port", "ID"], ) ) # Node Status Console Port ID # ---------------- -------- -------------- ------------------------------------ # Ethernetswitch-1 started 5000 da28e1c0-9465-4f7c-b42c-49b2f4e1c64d # IOU1 started 5001 de23a89a-aa1f-446a-a950-31d4bf98653c ``` ``` -------------------------------- ### Project.start_nodes / stop_nodes / reload_nodes / suspend_nodes Source: https://context7.com/davidban77/gns3fy/llms.txt These methods provide bulk control over all nodes within a project. They can send a single command to all nodes, optionally wait for a specified duration, and then refresh the state of each node. ```APIDOC ## Project.start_nodes / stop_nodes / reload_nodes / suspend_nodes — bulk node control Sends a single bulk command to all nodes in the project, then polls and refreshes state after an optional wait. ### Method - `start_nodes(poll_wait_time: int = 0)` - `stop_nodes(poll_wait_time: int = 0)` - `reload_nodes(poll_wait_time: int = 0)` - `suspend_nodes(poll_wait_time: int = 0)` ### Parameters #### Optional Parameters - `poll_wait_time` (int) - The time in seconds to wait before refreshing node status after the bulk command is issued. ### Request Example ```python from gns3fy import Gns3Connector, Project server = Gns3Connector(url="http://localhost:3080") lab = Project(name="ospf_lab", connector=server) lab.get() # Start all nodes and wait 10 seconds before refreshing status lab.start_nodes(poll_wait_time=10) for node in lab.nodes: print(f"{node.name}: {node.status}") # Stop all lab.stop_nodes() # Reload (restart) all lab.reload_nodes(poll_wait_time=8) # Suspend all lab.suspend_nodes() ``` ### Response This method does not return a specific value but updates the status of nodes within the `Project.nodes` list. ```