Collection of GNS3 GUI Tools
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.

36 lines
970 B

  1. #!/usr/local/bin/python3
  2. """
  3. Close Project - close GNS3 project
  4. """
  5. import os
  6. import sys
  7. import gns3api
  8. from qt_widgets import SimpleWidgets
  9. def die(text):
  10. """ terminate program with error message """
  11. SimpleWidgets().alert(None, text)
  12. sys.exit(text)
  13. # get command line parameter
  14. if len(sys.argv) < 4:
  15. die("usage: close_project version parameter-file project-id [sel-item ...]")
  16. try:
  17. with open(sys.argv[2], "r") as file:
  18. cntl_url, cntl_user, cntl_passwd, *_ = file.read(512).splitlines()
  19. if sys.argv[2].endswith(".tmp"):
  20. os.remove(sys.argv[2])
  21. except (OSError, ValueError) as err:
  22. die("Can't get controller connection params: {}".format(err))
  23. project_id = sys.argv[3]
  24. # connect to GNS3 controller
  25. try:
  26. api = gns3api.GNS3Api(cntl_url, cntl_user, cntl_passwd)
  27. except gns3api.GNS3ApiException as err:
  28. die("Can't connect to GNS3 controller: {}".format(err))
  29. api.request("POST", ("/v2/projects", project_id, "close"))