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.

test_api 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. import gns3api
  3. api = gns3api.GNS3Api()
  4. # api = gns3api.GNS3Api("https", "remote", verify="server.cert")
  5. print("GNS3 controller = " + api.controller)
  6. print('')
  7. print('GET /v2/version')
  8. data = api.request('GET', '/v2/version')
  9. version = data['version']
  10. print("Status: {}".format(api.status_code))
  11. print(data)
  12. print('')
  13. print('POST /v2/version {"version": "0.1"}')
  14. try:
  15. data = api.request('POST', '/v2/version', {"version": "0.1"})
  16. print(data)
  17. except (gns3api.HTTPError) as err:
  18. print(str(err))
  19. print('')
  20. print('POST /v2/version {{"version": "{}"}}'.format(version))
  21. data = api.request('POST', '/v2/version', {"version": version})
  22. print(data)
  23. print('')
  24. print('GET /v2/projects')
  25. for project in api.request('GET', '/v2/projects'):
  26. print("Project name: " + project['name'])
  27. print(project)
  28. # Open the first project
  29. project = api.request('GET', '/v2/projects')[0]
  30. already_open = project['status'] == 'opened'
  31. if not already_open:
  32. api.request("POST", ("/v2/projects", project['project_id'], "open"))
  33. print('')
  34. print('GET nodes of project ' + project['name'])
  35. for node in api.request("GET", ("/v2/projects", project['project_id'], "nodes")):
  36. print(node)
  37. if not already_open:
  38. api.request("POST", ("/v2/projects", project['project_id'], "close"))