1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/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"))
|