gns3api - Simple python module to access the GNS3 API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

#!/usr/bin/env python3
import gns3api
api = gns3api.GNS3Api()
# api = gns3api.GNS3Api("https://remote", verify="server.cert")
print("GNS3 controller = " + api.controller)
print()
print('GET /v2/version')
data = api.request('GET', '/v2/version')
version = data['version']
print("Status: {}".format(api.status_code))
print(data)
print()
print('POST /v2/version {"version": "0.1"}')
try:
data = api.request('POST', '/v2/version', {"version": "0.1"})
print(data)
except gns3api.HTTPError as err:
print(str(err))
print()
print('POST /v2/version {{"version": "{}"}}'.format(version))
data = api.request('POST', '/v2/version', {"version": version})
print(data)
print()
print('GET /v2/projects')
for project in api.request('GET', '/v2/projects'):
print("Project name: " + project['name'])
print(project)
# Open the first project
project = api.request('GET', '/v2/projects')[0]
already_open = project['status'] == 'opened'
if not already_open:
api.request("POST", ("/v2/projects", project['project_id'], "open"))
print()
print('GET nodes of project ' + project['name'])
for node in api.request("GET", ("/v2/projects", project['project_id'], "nodes")):
print(node)
if not already_open:
api.request("POST", ("/v2/projects", project['project_id'], "close"))