11/30/2021

Python Gns3

Connect Python to GNS3 for Automation in Win10 July 26th, 2019 in Knowledge In this lab we will learn how to program Python (version 3) to telnet to GNS3 router in Windows 10 and do some configuration commands like create an interface on GNS3 router. Our topology is very simple with only R1 router and a cloud (represented our real laptop/desktop). GNS3 and the GNS3 Academy became that place. Learn your tech in the Academy with industry leading instructors, install the software, deploy the Proof Of Concept and present your solution.That's what I use GNS3 for, almost every day.

PythonLatest version

Released:

Python wrapper around GNS3 Server API

Project description

Python wrapper around GNS3 Server API. Minimal GNS3 version is 2.2.

Its main objective is to interact with the GNS3 server in a programatic way, so it can be integrated with the likes of Ansible, docker and scripts. Ideal for network CI/CD pipeline tooling.

Documentation

Check out the Documentation to explore use cases and the API Reference

Use cases

Here are some examples where gns3fy is used in a programmatic way:

  • Ansible-collection-gns3: Useful for CI/CD pipelines to interact with GNS3 server using Ansible. It can create/delete projects, nodes and links in an ansible playbook.
  • Terraform: Coming soon... (although it might be a Go version of it)
  • Check server usage before turning up resource-hungry nodes
  • Manipulate project snapshots like create, delete or list the snapshots configured for the project.

Install

Development version

Use poetry to install the package when cloning it.

How it works

You can start the library and use the Gns3Connector object and the Project object.

For example:

Take a look at the API documentation for complete information about the attributes retrieved.

Usage of Node and Link objects

You have access to the Node and Link objects as well, this gives you the ability to start, stop, suspend the individual element in a GNS3 project.

Useful functions

You also have some commodity methods like the nodes_summary and links_summary, that if used with a library like tabulate you can see the following:

Gns3 python for network engineers

Release historyRelease notifications RSS feed

0.7.1

0.7.0

0.6.0

0.5.2

0.5.1

0.5.0

0.4.1

0.4.0

0.3.0

0.2.0

Python

0.1.1

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gns3fy, version 0.7.1
Filename, sizeFile typePython versionUpload dateHashes
Filename, size gns3fy-0.7.1-py3-none-any.whl (15.5 kB) File type Wheel Python version py3 Upload dateHashes
Filename, size gns3fy-0.7.1.tar.gz (18.3 kB) File type Source Python version None Upload dateHashes
Close

Hashes for gns3fy-0.7.1-py3-none-any.whl

Hashes for gns3fy-0.7.1-py3-none-any.whl
AlgorithmHash digest
SHA2565737dbdf6358d305bcfda2faebe65b5ce3f98a540798996dc822e8eba516a197
MD5b2f8a2b137e3fae715570a0810b33204
BLAKE2-256a96cb4f08612d1c106c3aedb7619d9e0d84a3026aba2af996262da8526d4d912
Close

Hashes for gns3fy-0.7.1.tar.gz

Hashes for gns3fy-0.7.1.tar.gz
AlgorithmHash digest
SHA256abe77e8955625938d9703b3c198ab22940ecfde700480f9de7b184ce1e8a6874
MD508a5383e4f3c5b508d866238785da90c
BLAKE2-256d33eb0577e8a0e703e3b33b63cfabace409b1dcce6b4b68d8c8a05aa42f11334
Latest version

Released:

GNS3 Proxy based on proxy.py by Abhinav Singh (https://github.com/abhinavsingh/proxy.py)

Project description

Proof-of-concept for a Proxy Server for GNS3. The proxy is configured as aregular remote server in the GNS3-GUI, as the GNS3-GUI client does not yetsupport proxies gns3-gui issue #2696. Basic ideais to allow the use of central GNS3 server backends for classroom / lab setups,as used, e.g., in the Network Laboratory of Fulda University of AppliedSciences. Students can connect to the proxy and requests will be authenticated,filtered and forwarded to appropriate backend servers. Proxy authenticationalso circumvents the current lack of multi-user support in GNS3. Without theproxy, due to the multi user limitations (see 'Multiple Users Environment'in GNS3 Security),users will have to use the same admin credentials for GNS3 to access thebackend. Also, requests cannot be filtered and authorized (e.g., to denydeletion/creation of projects etc.). As GNS3 does not support proxies, severaltweaks were necessary to the forked proxy.py project to allow transparentREST and WebSocket passthrough.

Features

Inherited from proxy.py:

  • Distributed as a single file module
  • No external dependency other than standard Python library
  • Support for http, https and websockets request proxy
  • Optimized for large file uploads and downloads
  • IPv4 and IPv6 support

Changes/enhancements to proxy.py:

  • Redirect requests to backend servers (fixed proxying independent from request URL)
  • Definition of users (username and password used in GNS3-GUI) for authentication and authorization at the proxy, proxy replaces credentials for backend servers
  • Selection (mapping) of GNS3 backend server and possibility of load-balancing based on username (using regexp)
  • Filtering of denied requests to server backends (based on username, REST/HTTP method/URL path/headers/body (using regexp)
  • Configuration file to allow basic proxy configuration as well as GNS3 backend server, users, mappings and request filters
  • Support for REST calls (GET requests with body etc., not handled by proxy.py)
  • Fixes and tweaks to allow the connection to GNS3 backends, especially keeping connections alive and leaving HTTP headers to support direct passthrough of WebSocket connections
  • Basic access logging/status monitoring support

Further utilities provided to use the proxy:

  • gns3_proxy_manage_projects.py allows management of projects on backend servers, e.g., bulk import, export,start, stop, delete projects on all or certain backend servers based on regexp.
  • gns3_proxy_replicate_projects.py supports replication of projects across backend servers.

gns3_proxy_manage_project.py and gns3_proxy_replicate_projects.py be combined with cron entry to run tasks periodically.

Concept

In our Network Laboratory we use several network emulators (besides GNS3 esp., mininet, CML-P and EVE-NG) and simulatorsfor courses and lab sessions as well as individual research or students' projects. As GNS3 is focusing on single userinstallations, several changes were necessary to provide lab session in class as well as to students working fromat home. The following figure describes our setup:

Using gns3-proxy, we can use separate credentials for users accessing the proxy without needing to share the singleadmin user provided by the standard gns3 server. However, no modifications are necessary to the standard GNS3 serverused in our backends and for the GNS3 client GUI. Users defined in the proxy, e.g., a group of students workingtogether in a group or on individual projects from at home, will be mapped to an individual backend server allowingload balancing and failover, since GNS3 compared to other network emulation environments does not offer a cluster setupto spread running projects and contained resources. The proxy also allows to filter and hence deny requests thatcontain modifications to projects. Prepared projects are periodically synced to all server backends using cron and thereplication utility gns3_proxy_replicate_projects.py.

Installation

You can clone this repository or simply copy gns3_proxy.py and gns3_proxy_config.ini to a host that has Python >=3.4installed.

Gns3

Even easier is the installation using a Docker container. Simply install and run the latest version of the gns3-proxycontainer imagefrom Docker Hub, e.g., using

$ docker pull flex/gns3-proxy

$ docker run -p 0.0.0.0:14080:14080/tcp flex/gns3-proxy

You can use a bootstrap script to install the sample scripts, pull the container image an run it:

$ bash <(curl -s https://raw.githubusercontent.com/srieger1/gns3-proxy/develop/scripts/docker-container-example/bootstrap-gns3-proxy-container)

Also, you can install the gns3-proxy from PyPI using

$ pip install gns3-proxy

Gns3 Python For Network Engineers

Configuration

Settings of the proxy are stored in gns3_proxy_config.ini.The [proxy] section contains following parameters for gns3-proxy:

  • hostname: IP address or corresponding hostname the proxy should bind to, listening for incoming requests (default: 0.0.0.0)
  • port TCP port the proxy will listen on (default: 14080)
  • backend_user Username to use to connect to GNS3 server backend (default: admin, standard GNS3 server user)
  • backend_password Password to use to connect to GNS3 server backend (default: password)
  • backend_port TCP port the backend servers listen on (default: 3080, standard GNS3 server port)
  • default_server Default server backend to use if no individual mapping for the user was found. Can be omitted to use explicit mapping (default: gns3-1)
  • backlog Backlog of the proxy. Increase to allow the processing of more concurrent requests (default: 1000)
  • server-recvbuf-size Server receive buffer size (TCP socket) of the proxy in bytes. Increase this value for better performance of large responses from backend servers (default: 8192, recommended for production: 1048576)
  • client-recvbuf-size Client receive buffer size (TCP socket) of the proxy in bytes. Increase this value for better performance of large requests from clients (default: 8192, recommended for production: 1048576)
  • open-file-limit Maximum number of parallel open files (socket fds) of the proxy (default: 1024)
  • log-level Log level. Increase to DEBUG for debugging output. (default: INFO)

The [servers] section contains the defined backend servers (server_name=ip_address), e.g.:

The [users] section defines the users allowed to access the proxy and their passwords (username=password), e.g.:

The [mapping] section maps users to the backend servers (mapping_id='user regexp':'server_name'), e.g.:

The [project-filter] section allows for filtering projects shown in the project list for individual users. Onlyprojects matching the filter (filter_id='username regexp':'project name filter') are listed.

The [deny] section defines requests that should be filtered and hence denied by the proxy (rule_id='user regexp':'http_request_method':'url regexp':'header regexp':'body regexp'), e.g. to deny modification to existing projects as well as deletion and creation of projects:

Installing a new server backend

Deploy the GNS3 server appliance as usual. You can find further information regarding the installation of a serverfor multiple clients in the GNS3 server for multiple clients docu.Make sure to allow VT-x/AMD-V for the backend server. If configured correctly, 'KVM support available: true' should bedisplayed in the menu after starting the server. The server should be configured to use a static IP address. This canbe done using the Shell or selecting the option 'Network' (Configure network settings) from the GNS3 menu. Configurestatic IP addresses using the template in /etc/netplan/90_gns3vm_static_netcfg.yaml.

Afterwards you can use 'Migrate' from another GNS3 host to migrate setup and images and projects to the new backend.

To configure the backend directly for gns3-proxy, an easier option is to use the provided setup-backend.shscript, e.g., by running:

$ ./setup-backend.sh gns3_proxy_config.ini 192.168.229.12

The first argument should lead to a gns3-proxy config containing backend port, username, password to use. Secondargument is the the IP address of the new backend to be configured.

You can use gns3_proxy_replicate_images.pyand gns3_proxy_replicate_templates.pyto replicate all templates and images of an existing backend server to new server. These scripts can also be usedperiodically using cron to replicate images and templates to all gns3-proxy backends.

gns3_proxy_manage_images.py andgns_proxy_manage_templates.pyadditionally offer im- and export as well as deletion and listing of all images and templates on backend servers.

Manual configuration of GNS3 server backends

The only change necessary in the GNS3 server backends, is to edit the regulargns3_server.conf (available in the appliance terminal and, e.g., used tochange username password etc., see alsoGNS3 server configuration file)and change the hostname from 0.0.0.0 to the IP address the server shouldlisten on, e.g.:

host = 192.168.1.100

After you changed the config of the GNS3 backend servers and restarted them, configure gns3_proxy_config.ini basedon your needs and run gns3_proxy.py. You can then, configure GNS3-GUI to use the proxy as a remote GNS3 server.By default, the proxy listens on 0.0.0.0 and TCP port 14080.

Python Gns3

Deploying and managing projects on gns3-proxy backends

gns3_proxy_replicate_projects.py facilitates the replication of projects across backend servers.Command syntax is:

The provided example crontab contains examples touse gns3_proxy_replicate_projects.py. For example:

will replicate all GNS3 project names beginning with 'KommProt' from the backend server gns3-master as the source toall backend servers matching the regular expression 'gns3-.(.*)'. The option --force tells the utility to overwrite existingprojects with the same name on the targets without further notice. The option --regenerate-mac-address searches for thegiven MAC address in the projects and creates a new locally administered MAC address. This is especially necessary forlinks to cloud node types in the project. Otherwise all projects will use the same address leading to duplicate MAC andconsequently duplicated IP addresses.

gns3_proxy_manage_projects.py facilitates the management of projects on backend servers.Command syntax is:

The provided example crontab contains examples touse gns3_proxy_manage_projects.py. For example:

Python Gns3

will show the status of all projects on all backend server.

will start the project with the name TestProject on the server gns3-1 defined as a backend in gns3_proxy_config.ini.Can be used, e.g., together with cron to start the project ahead of time for lab sessions or courses, avoidingwaiting for projects to be ready for use when students take the lab.

will export the project TestProject from gns3-1 to a ZIP file that can be used as a backup, e.g. to import later usingGNS3 GUI, or --import-from-file option, like:

will import GNS3 project exported in file project.zip to backend server gns3-1. The specified project-id (must be a valid UUID v4in GNS3) will be used for the import.

Release historyRelease notifications RSS feed

0.8

0.7

0.6

0.5

0.3

0.2

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gns3-proxy, version 0.8
Filename, sizeFile typePython versionUpload dateHashes
Filename, size gns3_proxy-0.8-py3-none-any.whl (32.6 kB) File type Wheel Python version py3 Upload dateHashes
Filename, size gns3-proxy-0.8.tar.gz (22.4 kB) File type Source Python version None Upload dateHashes
Close

Hashes for gns3_proxy-0.8-py3-none-any.whl

Hashes for gns3_proxy-0.8-py3-none-any.whl
AlgorithmHash digest
SHA256507e4889b8934ee34422a4270e22266b3e814142aa98a3aa82c16570b0c911a5
MD55055bfe8ca46b84ae0c8957e1a2114ea
BLAKE2-256438e56b7bbd0006c083858f922975d9983388ec9d6ba6d9162db01c25ca496bb

Python Gns3

Close

Hashes for gns3-proxy-0.8.tar.gz

Hashes for gns3-proxy-0.8.tar.gz
AlgorithmHash digest
SHA256d2cbe8631f20d9c4ef82686aca7a3d7185dc5926de8b4ad4558f174f472ff4a1
MD546264056c2e5848d1df3767458420f59
BLAKE2-256dd0a02a07989c3a2865c874132ecb2b5a0f881c53295d549715adc846eba102a