GNS3 API Helper

GNS3 Helper (API & WEB-UI)

This API Helper supports API call to GNS3 Server, Controaller, Computes and Emulators. Using this application you can insert new appliances and projects to GNS3. It's very usefull in terms of optimizing human efforts as well as to import hundreds of preconfigured projects for lab simulation. Any gns3 appliances like IOU, IOSv(Virl), XRv, vMX, VPCS nodes could be installed directly from here. This API helper can also inport preconfigured projects directly into GNS3. Thanks to the GNS3 Restful API.

This API helper use an Asynchronus Web Based API to interact with GNS3 API, which need CORS(Cross-Origin Resource Sharing) to be enabled at the GNS3 VM(Controller) and Local Server and the IP Address of GNS3 Local Server & VM to be supplied manually.


Enable CORS(Cross-Origine Resource Sharing)

You can use a tool called HttpModifire to enable CORS. The setting has been described below. Otherwise GNS3 API supports CORS by default, only you have to whitelist the API Helper URL(http://networklab.in, http://networklab.in).

Method 1:
Download and Install HttpModifire v1.0 setup file in your windows computer. This tool is absolutely free.
From Mirror 1

HttpModifier.exe7.61 MB

From Mirror 2

HttpModifier.exe7.61 MB

After installation, give three octates of your GNS3 IPs(http://192.168.x.) as a match condition and remove the origin(Origin: http://networklab.in) field of the request header and replace it with whitelisted origin(Origin: http://127.0.0.1:8080). In the response header filed add access control header(Access-Control-Allow-Origin: http://networklab.in). Then start the application.



Method 2:
You have to SSH the IP address of the VM and navigate to the menue, then open the shell prompt(CLI).

The GNS Controaller has API Handlers which process the HTTP response. These API responses are controalled by Python runtime. The Python script called web_server.py, which process the HTTP Response header. We have to find the script from packange distribution and whitelist the API Helper url. You can run the below command directly.

sudo nano /usr/local/lib/python3.6/dist-packages/gns3server/web/web_server.py
Otherwise you need to locate the file in package distribution.
#-------------- Command to find the API Filepath -----------------------#
gns3@gns3vm:~$ sudo find / -iname api
/usr/share/perl/5.26.1/Test2/API
/usr/share/perl/5.26.1/CPAN/API
/usr/local/lib/python3.6/dist-packages/gns3server/handlers/api
gns3@gns3vm:~$
gns3@gns3vm:~$ cd /usr/local/lib/python3.6/dist-packages/
gns3@gns3vm:/usr/local/lib/python3.6/dist-packages$
#-------------- Command to find CORS Configuration  -----------------------#
gns3@gns3vm:/usr/local/lib/python3.6/dist-packages$ sudo grep -iRl "Allow CORS"
gns3server/web/web_server.py
gns3@gns3vm:/usr/local/lib/python3.6/dist-packages$
#-------------- Command to modify CORS Configuration  ---------------------#
gns3@gns3vm:/usr/local/lib/python3.6/dist-packages$ cd gns3server/web/
gns3@gns3vm:/usr/local/lib/python3.6/dist-packages/gns3server/web$ ls
documentation.py  logger.py    response.py  web_server.py
__init__.py       __pycache__  route.py
gns3@gns3vm:/usr/local/lib/python3.6/dist-packages/gns3server/web$ sudo nano web_server.py
#------ Search(Ctlr+W) for "CORS"  and modify CORS Configuration  -----------#
#------ Add two more lines below the lst resource options  -----------#
       # Allow CORS for this domains
        cors = aiohttp_cors.setup(self._app, defaults={
            # Default web server for web gui dev
            "http://127.0.0.1:8080": resource_options,
            "http://localhost:8080": resource_options,
            "http://127.0.0.1:4200": resource_options,
            "http://localhost:4200": resource_options,
            "http://gns3.github.io": resource_options,
            "https://gns3.github.io": resource_options,
            
            "http://networklab.in": resource_options,
            "https://networklab.in": resource_options
            
        })
#------ Save config(Ctlr+X) -> Y -> Enter -----------#
#------ Reload GNS3 VM -----------#

During configuration, be careful about the syntax. If the VM doesn't load after GNS3 Controaller then run the below command. It will display critical errors and syntax mismatch as well. Once synax error is corrected you have to restart the VM once again.

gns3@gns3vm:~$ gns3server
2020-02-23 04:43:47 INFO run.py:219 GNS3 server version 2.2.5
2020-02-23 04:43:47 INFO run.py:221 Copyright (c) 2007-2020 GNS3 Technologies Inc.
2020-02-23 04:43:47 INFO run.py:224 Config file /home/gns3/.config/GNS3/2.2/gns3_server.conf loaded
2020-02-23 04:43:47 INFO run.py:245 Running with Python 3.6.9 and has PID 1646
2020-02-23 04:43:47 INFO run.py:79 Current locale is en_US.UTF-8
2020-02-23 04:43:47 INFO web_server.py:296 Starting server on 0.0.0.0:3080
2020-02-23 04:43:47 INFO __init__.py:62 Load controller configuration file /home/gns3/.config/GNS3/2.2/gns3_controller.conf
2020-02-23 04:43:47 INFO __init__.py:66 Controller is starting
2020-02-23 04:43:47 INFO compute.py:63 Create compute local
2020-02-23 04:43:47 INFO compute.py:360 Connecting to compute 'local'
2020-02-23 04:43:47 CRITICAL web_server.py:87 Could not start the server: [Errno 98] error while attempting to bind on address ('0.0.0.0', 3080): address already in use
gns3@gns3vm:~$



Find IP Address of GNS3 Local Server and VM(Controaller)

To find the VM IP Address, go to VMware Workstation or any other hypervisor where you have hosted the GNS3 Server VM. Once you starts the VM it will show the server information along with the IP details. To find the GNS3 Local Server IP and Port Number from GNS3 GUI, go to Edit » Preference Tab » Server. Port 3080 is the default port number.



Once both of the above steps are completed, fill the IP Address in the input parameters and port adrress in case required, then use the API methods as per your convenience. Checkout the gns3 Architecture below for your reference.

Compute Hypervisor


Local GNS3 Server

Local IP (192.168.x.x)

Compute Hypervisor


Emulator

GNS3 Controller

VM IP (192.168.x.x)

Builtin Docker

Docker Container

Emulator

Emulator

+---------------+                  +----------+     +------+
|               |                  | COMPUTE  +-----> QEMU |
|  GNS3 GUI     |              +---> SERVER 1 |     +------+
|  QT interface +-----+        |   +----------+
|               |     |        |                    +---+
+---------------+    +v--------++               +--->IOU|
                     |CONTROLLER|               |   +---+
      +---------+    +^--------++  +---------+  |
      | GNS3 WEB+-----+        |   | COMPUTE +--+
      +---------+              +---> SERVER 2+--+   +--------+
                                   +---------+  +--->DYNAMIPS|
                                                    +--------+

Install Appliance Template

GNS3 GUI (Local Server)

API Base URL:

NA

GNS3 GUI Version:

NA

GNS3 Local Compute:

NA

GNS3 VM ( Controller, Compute, Emulators)

API Base URL:

NA

GNS3 VM Version:

NA

GNS3 VM Compute:

NA

Download Virtual Appliances
  • Appliances for more than 10 Hardware Vendors like Cisco, Juniper, Huawaei, HP, Palo-Alto, F5, Checkpoint, Alcatell-Lucent, Erricson, Riverbed etc.
Manual Upload Image Files to GNS3 VM or Local Server and Create a Template

  • Upload correct appliance to GNS3 VM. Only DYNAMIPS, IOU and QEMU Templates are supported here.