gns3_worker

GNS3 Network Topology Management Module

This module provides asynchronous functionality for creating and configuring network topologies in GNS3, including device creation, configuration, and network infrastructure setup.

Attributes

logger

Exceptions

GNS3WorkerError

Custom exception for GNS3 Worker related errors.

ContainerConfigurationError

Exception raised for errors during container configuration.

Functions

invoker(servername, gns3_url, switches, prj_id, ...)

Synchronous entry point for creating GNS3 project nodes and connections.

main_job(servername, gns3_url, switches, prj_id, ...)

Asynchronously create GNS3 nodes, configure containers, and establish connections.

docker_api_config(switch, docker_client[, servername])

Configure Docker container with switch startup configuration.

make_a_gns3_node(switch, session, gns3_url, nodex, ...)

Create a GNS3 node for a switch.

gns3_post(session, url, method, **kwargs)

Send an async request to GNS3 server.

Module Contents

gns3_worker.logger[source]
exception gns3_worker.GNS3WorkerError[source]

Bases: Exception

Custom exception for GNS3 Worker related errors.

exception gns3_worker.ContainerConfigurationError[source]

Bases: GNS3WorkerError

Exception raised for errors during container configuration.

gns3_worker.invoker(servername, gns3_url, switches, prj_id, connections)[source]

Synchronous entry point for creating GNS3 project nodes and connections.

This function provides a synchronous wrapper for the asynchronous main_job, allowing the module to be called from synchronous code.

Parameters:
  • servername (str) – The name of the aiohttp.ClientSession object

  • gns3_url (str) – The URL for the GNS3 server

  • switches (List[Switch]) – List of Switch objects to be emulated

  • prj_id (str) – The GNS3 project ID

  • connections (List[Connection]) – List of connections to make between nodes

Returns:

Status message indicating completion or error

Return type:

str

Raises:

GNS3WorkerError – If there are issues during the GNS3 project setup

async gns3_worker.main_job(servername, gns3_url, switches, prj_id, connections)[source]

Asynchronously create GNS3 nodes, configure containers, and establish connections.

Parameters:
  • servername (str) – The name of the aiohttp.ClientSession object

  • gns3_url (str) – The URL for the GNS3 server

  • switches (List[Switch]) – List of Switch objects to be emulated

  • prj_id (str) – The GNS3 project ID

  • connections (List[Connection]) – List of connections to make between nodes

Returns:

Status message indicating completion

Return type:

str

async gns3_worker.docker_api_config(switch, docker_client, servername='localhost')[source]

Configure Docker container with switch startup configuration.

Parameters:
  • switch (Switch) – Switch object containing configuration

  • docker_client (aiodocker.Docker) – Docker client for API interactions

  • servername (str, optional) – Docker daemon hostname. Defaults to ‘localhost’.

Returns:

Configuration status

Return type:

str

async gns3_worker.make_a_gns3_node(switch, session, gns3_url, nodex, nodey, prj_id)[source]

Create a GNS3 node for a switch.

Parameters:
  • switch (Switch) – Switch to create a node for

  • session (aiohttp.ClientSession) – Async HTTP session

  • gns3_url (str) – Base URL for GNS3 API

  • nodex (int) – X coordinate for node placement

  • nodey (int) – Y coordinate for node placement

  • prj_id (str) – GNS3 project ID

Returns:

Updated switch with GNS3 node details

Return type:

Switch

async gns3_worker.gns3_post(session, url, method, **kwargs)[source]

Send an async request to GNS3 server.

Parameters:
  • session (aiohttp.ClientSession) – Async HTTP session

  • url (str) – URL to send request to

  • method (str) – HTTP method (get, post, put)

  • **kwargs – Additional arguments for the request

Raises:

GNS3WorkerError – If request fails

Return type:

None