Custom patches for GNS3 network topology simulator & planning software.
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.

130 lines
4.6 KiB

2 years ago
  1. Author: Pekka Helenius <pekka.helenius@fjordtek.com>
  2. Date: Sun, 6 Jun 2021 15:09:21 +0200
  3. Subject: [PATCH] GNS3 Server: QEMU environment variables.
  4. Add support for QEMU environment variables for GNS3 Server.
  5. --- a/gns3server/schemas/qemu.py
  6. +++ b/gns3server/schemas/qemu.py
  7. @@ -65,6 +65,10 @@
  8. "description": "Console type",
  9. "enum": ["telnet", "vnc", "spice"]
  10. },
  11. + "env_vars": {
  12. + "description": "Environment variables",
  13. + "type": "string",
  14. + },
  15. "hda_disk_image": {
  16. "description": "QEMU hda disk image path",
  17. "type": "string",
  18. @@ -250,6 +254,10 @@
  19. "description": "Whether the VM is a linked clone or not",
  20. "type": "boolean"
  21. },
  22. + "env_vars": {
  23. + "description": "Environment variables",
  24. + "type": "string",
  25. + },
  26. "hda_disk_image": {
  27. "description": "QEMU hda disk image path",
  28. "type": "string",
  29. @@ -434,6 +442,10 @@
  30. "description": "Platform to emulate",
  31. "enum": QEMU_PLATFORMS
  32. },
  33. + "env_vars": {
  34. + "description": "Environment variables",
  35. + "type": "string",
  36. + },
  37. "hda_disk_image": {
  38. "description": "QEMU hda disk image path",
  39. "type": "string",
  40. @@ -603,6 +615,7 @@
  41. "qemu_path",
  42. "platform",
  43. "console_type",
  44. + "env_vars",
  45. "hda_disk_image",
  46. "hdb_disk_image",
  47. "hdc_disk_image",
  48. --- a/gns3server/schemas/qemu_template.py
  49. +++ b/gns3server/schemas/qemu_template.py
  50. @@ -22,6 +22,11 @@
  51. QEMU_TEMPLATE_PROPERTIES = {
  52. + "env_vars": {
  53. + "description": "Environment variables",
  54. + "type": "string",
  55. + "default": ""
  56. + },
  57. "qemu_path": {
  58. "description": "Path to QEMU",
  59. "type": "string",
  60. --- a/gns3server/compute/qemu/qemu_vm.py
  61. +++ b/gns3server/compute/qemu/qemu_vm.py
  62. @@ -93,6 +93,7 @@
  63. else:
  64. self.platform = platform
  65. + self._env_vars = ""
  66. self._hda_disk_image = ""
  67. self._hdb_disk_image = ""
  68. self._hdc_disk_image = ""
  69. @@ -219,6 +220,32 @@
  70. disk_image=value))
  71. @property
  72. + def env_vars(self):
  73. + """
  74. + Returns the environment variables for this QEMU VM.
  75. +
  76. + :returns: QEMU env vars
  77. + """
  78. +
  79. + return self._env_vars
  80. +
  81. + @env_vars.setter
  82. + def env_vars(self, env_vars):
  83. + """
  84. + Sets the environment variables for this QEMU VM.
  85. +
  86. + :param env vars: QEMU env vars
  87. + """
  88. +
  89. + log.info('QEMU VM "{name}" [{id}] has set the QEMU environment variables to {env_vars}'.format(name=self._name,
  90. + id=self._id,
  91. + env_vars=env_vars))
  92. + if sys.platform.startswith("linux"):
  93. + self._env_vars = env_vars.strip()
  94. + else:
  95. + self._env_vars = ""
  96. +
  97. + @property
  98. def hda_disk_image(self):
  99. """
  100. Returns the hda disk image path for this QEMU VM.
  101. @@ -912,7 +939,7 @@
  102. with open(self._stdout_file, "w", encoding="utf-8") as fd:
  103. fd.write("Start QEMU with {}\n\nExecution log:\n".format(command_string))
  104. self.command_line = ' '.join(command)
  105. - self._process = await asyncio.create_subprocess_exec(*command,
  106. + self._process = await asyncio.create_subprocess_shell(command_string,
  107. stdout=fd,
  108. stderr=subprocess.STDOUT,
  109. cwd=self.working_dir)
  110. @@ -1651,7 +1678,10 @@
  111. additional_options = additional_options.replace("%vm-id%", self._id)
  112. additional_options = additional_options.replace("%project-id%", self.project.id)
  113. additional_options = additional_options.replace("%project-path%", '"' + self.project.path.replace('"', '\\"') + '"')
  114. - command = [self.qemu_path]
  115. + command = []
  116. + if self._env_vars:
  117. + command.extend([self._env_vars])
  118. + command.extend([self.qemu_path])
  119. command.extend(["-name", self._name])
  120. command.extend(["-m", "{}M".format(self._ram)])
  121. command.extend(["-smp", "cpus={}".format(self._cpus)])