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.

432 lines
16 KiB

3 years ago
  1. Author: Pekka Helenius <pekka.helenius@fjordtek.com>
  2. Date: Sun, 6 Jun 2021 15:10:45 +0200
  3. Subject: [PATCH] GNS3 GUI: QEMU environment variables.
  4. Add support for QEMU environment variables for GNS3 GUI.
  5. --- a/tests/test_local_config.py
  6. +++ b/tests/test_local_config.py
  7. @@ -285,6 +285,7 @@
  8. "enable_kvm": True,
  9. "vms": [
  10. {
  11. + "env_vars": "",
  12. "kernel_image": "",
  13. "kernel_command_line": "",
  14. "first_port_name": "",
  15. @@ -323,6 +324,7 @@
  16. "platform": ""
  17. },
  18. {
  19. + "env_vars": "",
  20. "kernel_image": "",
  21. "kernel_command_line": "",
  22. "server": "vm",
  23. --- a/gns3/modules/qemu/settings.py
  24. +++ b/gns3/modules/qemu/settings.py
  25. @@ -27,6 +27,7 @@
  26. }
  27. QEMU_VM_SETTINGS = {
  28. + "env_vars": "",
  29. "name": "",
  30. "default_name_format": "{name}-{0}",
  31. "usage": "",
  32. --- a/gns3/modules/qemu/qemu_vm.py
  33. +++ b/gns3/modules/qemu/qemu_vm.py
  34. @@ -42,7 +42,8 @@
  35. self._linked_clone = True
  36. - qemu_vm_settings = {"usage": "",
  37. + qemu_vm_settings = {"env_vars": "",
  38. + "usage": "",
  39. "qemu_path": "",
  40. "hda_disk_image": "",
  41. "hdb_disk_image": "",
  42. --- a/gns3/modules/qemu/ui/qemu_vm_configuration_page_ui.py
  43. +++ b/gns3/modules/qemu/ui/qemu_vm_configuration_page_ui.py
  44. @@ -63,6 +63,12 @@
  45. self.uiCPULabel = QtWidgets.QLabel(self.uiGeneralSettingsTab)
  46. self.uiCPULabel.setObjectName("uiCPULabel")
  47. self.gridLayout_4.addWidget(self.uiCPULabel, 5, 0, 1, 1)
  48. + self.uiEnvvarLabel = QtWidgets.QLabel(self.uiGeneralSettingsTab)
  49. + self.uiEnvvarLabel.setObjectName("uiEnvvarLabel")
  50. + self.gridLayout_4.addWidget(self.uiEnvvarLabel, 9, 0, 1, 1)
  51. + self.uiEnvvarLineEdit = QtWidgets.QLineEdit(self.uiGeneralSettingsTab)
  52. + self.uiEnvvarLineEdit.setObjectName("uiEnvvarLineEdit")
  53. + self.gridLayout_4.addWidget(self.uiEnvvarLineEdit, 9, 1, 1, 1)
  54. self.uiCPUSpinBox = QtWidgets.QSpinBox(self.uiGeneralSettingsTab)
  55. self.uiCPUSpinBox.setMinimum(1)
  56. self.uiCPUSpinBox.setMaximum(255)
  57. @@ -93,7 +99,7 @@
  58. self.gridLayout_4.addWidget(self.uiOnCloseComboBox, 8, 1, 1, 1)
  59. self.uiConsoleTypeLabel = QtWidgets.QLabel(self.uiGeneralSettingsTab)
  60. self.uiConsoleTypeLabel.setObjectName("uiConsoleTypeLabel")
  61. - self.gridLayout_4.addWidget(self.uiConsoleTypeLabel, 9, 0, 1, 1)
  62. + self.gridLayout_4.addWidget(self.uiConsoleTypeLabel, 10, 0, 1, 1)
  63. self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
  64. self.horizontalLayout_2.setObjectName("horizontalLayout_2")
  65. self.uiConsoleTypeComboBox = QtWidgets.QComboBox(self.uiGeneralSettingsTab)
  66. @@ -107,9 +113,9 @@
  67. self.uiConsoleAutoStartCheckBox = QtWidgets.QCheckBox(self.uiGeneralSettingsTab)
  68. self.uiConsoleAutoStartCheckBox.setObjectName("uiConsoleAutoStartCheckBox")
  69. self.horizontalLayout_2.addWidget(self.uiConsoleAutoStartCheckBox)
  70. - self.gridLayout_4.addLayout(self.horizontalLayout_2, 9, 1, 1, 1)
  71. + self.gridLayout_4.addLayout(self.horizontalLayout_2, 10, 1, 1, 1)
  72. spacerItem = QtWidgets.QSpacerItem(263, 94, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
  73. - self.gridLayout_4.addItem(spacerItem, 10, 1, 1, 1)
  74. + self.gridLayout_4.addItem(spacerItem, 11, 1, 1, 1)
  75. self.uiQemutabWidget.addTab(self.uiGeneralSettingsTab, "")
  76. self.uiHddTab = QtWidgets.QWidget()
  77. self.uiHddTab.setObjectName("uiHddTab")
  78. @@ -462,6 +468,7 @@
  79. self.uiRamLabel.setText(_translate("QemuVMConfigPageWidget", "RAM:"))
  80. self.uiRamSpinBox.setSuffix(_translate("QemuVMConfigPageWidget", " MB"))
  81. self.uiCPULabel.setText(_translate("QemuVMConfigPageWidget", "vCPUs:"))
  82. + self.uiEnvvarLabel.setText(_translate("QemuVMConfigPageWidget", "Environment variables:"))
  83. self.uiQemuListLabel.setText(_translate("QemuVMConfigPageWidget", "Qemu binary:"))
  84. self.uiBootPriorityLabel.setText(_translate("QemuVMConfigPageWidget", "Boot priority:"))
  85. self.uiOnCloseLabel.setText(_translate("QemuVMConfigPageWidget", "On close:"))
  86. --- a/gns3/modules/qemu/ui/qemu_vm_configuration_page.ui
  87. +++ b/gns3/modules/qemu/ui/qemu_vm_configuration_page.ui
  88. @@ -24,26 +24,23 @@
  89. <string>General settings</string>
  90. </attribute>
  91. <layout class="QGridLayout" name="gridLayout_4">
  92. - <item row="0" column="0">
  93. - <widget class="QLabel" name="uiNameLabel">
  94. + <item row="1" column="0">
  95. + <widget class="QLabel" name="uiDefaultNameFormatLabel">
  96. <property name="text">
  97. - <string>Name:</string>
  98. + <string>Default name format:</string>
  99. </property>
  100. </widget>
  101. </item>
  102. - <item row="0" column="1">
  103. - <widget class="QLineEdit" name="uiNameLineEdit"/>
  104. + <item row="8" column="2">
  105. + <widget class="QComboBox" name="uiOnCloseComboBox"/>
  106. </item>
  107. - <item row="1" column="0">
  108. - <widget class="QLabel" name="uiDefaultNameFormatLabel">
  109. + <item row="0" column="0">
  110. + <widget class="QLabel" name="uiNameLabel">
  111. <property name="text">
  112. - <string>Default name format:</string>
  113. + <string>Name:</string>
  114. </property>
  115. </widget>
  116. </item>
  117. - <item row="1" column="1">
  118. - <widget class="QLineEdit" name="uiDefaultNameFormatLineEdit"/>
  119. - </item>
  120. <item row="2" column="0">
  121. <widget class="QLabel" name="uiSymbolLabel">
  122. <property name="text">
  123. @@ -51,64 +48,23 @@
  124. </property>
  125. </widget>
  126. </item>
  127. - <item row="2" column="1">
  128. - <layout class="QHBoxLayout" name="horizontalLayout_7">
  129. - <item>
  130. - <widget class="QLineEdit" name="uiSymbolLineEdit"/>
  131. - </item>
  132. - <item>
  133. - <widget class="QToolButton" name="uiSymbolToolButton">
  134. - <property name="text">
  135. - <string>&amp;Browse...</string>
  136. - </property>
  137. - <property name="toolButtonStyle">
  138. - <enum>Qt::ToolButtonTextOnly</enum>
  139. - </property>
  140. - </widget>
  141. - </item>
  142. - </layout>
  143. + <item row="7" column="2">
  144. + <widget class="QComboBox" name="uiBootPriorityComboBox"/>
  145. </item>
  146. - <item row="3" column="0">
  147. - <widget class="QLabel" name="uiCategoryLabel">
  148. - <property name="text">
  149. - <string>Category:</string>
  150. + <item row="6" column="2">
  151. + <widget class="QComboBox" name="uiQemuListComboBox">
  152. + <property name="sizePolicy">
  153. + <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
  154. + <horstretch>0</horstretch>
  155. + <verstretch>0</verstretch>
  156. + </sizepolicy>
  157. </property>
  158. </widget>
  159. </item>
  160. - <item row="3" column="1">
  161. + <item row="3" column="2">
  162. <widget class="QComboBox" name="uiCategoryComboBox"/>
  163. </item>
  164. - <item row="4" column="0">
  165. - <widget class="QLabel" name="uiRamLabel">
  166. - <property name="text">
  167. - <string>RAM:</string>
  168. - </property>
  169. - </widget>
  170. - </item>
  171. - <item row="4" column="1">
  172. - <widget class="QSpinBox" name="uiRamSpinBox">
  173. - <property name="suffix">
  174. - <string> MB</string>
  175. - </property>
  176. - <property name="minimum">
  177. - <number>32</number>
  178. - </property>
  179. - <property name="maximum">
  180. - <number>65535</number>
  181. - </property>
  182. - <property name="value">
  183. - <number>256</number>
  184. - </property>
  185. - </widget>
  186. - </item>
  187. - <item row="5" column="0">
  188. - <widget class="QLabel" name="uiCPULabel">
  189. - <property name="text">
  190. - <string>vCPUs:</string>
  191. - </property>
  192. - </widget>
  193. - </item>
  194. - <item row="5" column="1">
  195. + <item row="5" column="2">
  196. <widget class="QSpinBox" name="uiCPUSpinBox">
  197. <property name="minimum">
  198. <number>1</number>
  199. @@ -125,16 +81,33 @@
  200. </property>
  201. </widget>
  202. </item>
  203. - <item row="6" column="1">
  204. - <widget class="QComboBox" name="uiQemuListComboBox">
  205. - <property name="sizePolicy">
  206. - <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
  207. - <horstretch>0</horstretch>
  208. - <verstretch>0</verstretch>
  209. - </sizepolicy>
  210. + <item row="8" column="0">
  211. + <widget class="QLabel" name="uiOnCloseLabel">
  212. + <property name="text">
  213. + <string>On close:</string>
  214. </property>
  215. </widget>
  216. </item>
  217. + <item row="9" column="0">
  218. + <widget class="QLabel" name="uiConsoleTypeLabel">
  219. + <property name="text">
  220. + <string>Console type:</string>
  221. + </property>
  222. + </widget>
  223. + </item>
  224. + <item row="11" column="2">
  225. + <spacer name="spacer">
  226. + <property name="orientation">
  227. + <enum>Qt::Vertical</enum>
  228. + </property>
  229. + <property name="sizeHint" stdset="0">
  230. + <size>
  231. + <width>263</width>
  232. + <height>94</height>
  233. + </size>
  234. + </property>
  235. + </spacer>
  236. + </item>
  237. <item row="7" column="0">
  238. <widget class="QLabel" name="uiBootPriorityLabel">
  239. <property name="text">
  240. @@ -142,27 +115,67 @@
  241. </property>
  242. </widget>
  243. </item>
  244. - <item row="7" column="1">
  245. - <widget class="QComboBox" name="uiBootPriorityComboBox"/>
  246. + <item row="4" column="2">
  247. + <widget class="QSpinBox" name="uiRamSpinBox">
  248. + <property name="suffix">
  249. + <string> MB</string>
  250. + </property>
  251. + <property name="minimum">
  252. + <number>32</number>
  253. + </property>
  254. + <property name="maximum">
  255. + <number>65535</number>
  256. + </property>
  257. + <property name="value">
  258. + <number>256</number>
  259. + </property>
  260. + </widget>
  261. </item>
  262. - <item row="8" column="0">
  263. - <widget class="QLabel" name="uiOnCloseLabel">
  264. + <item row="0" column="2">
  265. + <widget class="QLineEdit" name="uiNameLineEdit"/>
  266. + </item>
  267. + <item row="3" column="0">
  268. + <widget class="QLabel" name="uiCategoryLabel">
  269. <property name="text">
  270. - <string>On close:</string>
  271. + <string>Category:</string>
  272. </property>
  273. </widget>
  274. </item>
  275. - <item row="8" column="1">
  276. - <widget class="QComboBox" name="uiOnCloseComboBox"/>
  277. + <item row="1" column="2">
  278. + <widget class="QLineEdit" name="uiDefaultNameFormatLineEdit"/>
  279. </item>
  280. - <item row="9" column="0">
  281. - <widget class="QLabel" name="uiConsoleTypeLabel">
  282. + <item row="4" column="0">
  283. + <widget class="QLabel" name="uiRamLabel">
  284. <property name="text">
  285. - <string>Console type:</string>
  286. + <string>RAM:</string>
  287. </property>
  288. </widget>
  289. </item>
  290. - <item row="9" column="1">
  291. + <item row="2" column="2">
  292. + <layout class="QHBoxLayout" name="horizontalLayout_7">
  293. + <item>
  294. + <widget class="QLineEdit" name="uiSymbolLineEdit"/>
  295. + </item>
  296. + <item>
  297. + <widget class="QToolButton" name="uiSymbolToolButton">
  298. + <property name="text">
  299. + <string>&amp;Browse...</string>
  300. + </property>
  301. + <property name="toolButtonStyle">
  302. + <enum>Qt::ToolButtonTextOnly</enum>
  303. + </property>
  304. + </widget>
  305. + </item>
  306. + </layout>
  307. + </item>
  308. + <item row="5" column="0">
  309. + <widget class="QLabel" name="uiCPULabel">
  310. + <property name="text">
  311. + <string>vCPUs:</string>
  312. + </property>
  313. + </widget>
  314. + </item>
  315. + <item row="9" column="2">
  316. <layout class="QHBoxLayout" name="horizontalLayout_2">
  317. <item>
  318. <widget class="QComboBox" name="uiConsoleTypeComboBox">
  319. @@ -202,18 +215,15 @@
  320. </item>
  321. </layout>
  322. </item>
  323. - <item row="10" column="1">
  324. - <spacer name="spacer">
  325. - <property name="orientation">
  326. - <enum>Qt::Vertical</enum>
  327. - </property>
  328. - <property name="sizeHint" stdset="0">
  329. - <size>
  330. - <width>263</width>
  331. - <height>94</height>
  332. - </size>
  333. + <item row="10" column="2">
  334. + <widget class="QLineEdit" name="uiEnvvarLineEdit"/>
  335. + </item>
  336. + <item row="10" column="0">
  337. + <widget class="QLabel" name="uiEnvvarLabel">
  338. + <property name="text">
  339. + <string>Environment variables:</string>
  340. </property>
  341. - </spacer>
  342. + </widget>
  343. </item>
  344. </layout>
  345. </widget>
  346. @@ -470,7 +480,16 @@
  347. <string>CD/DVD</string>
  348. </attribute>
  349. <layout class="QVBoxLayout" name="verticalLayout_4">
  350. - <property name="margin">
  351. + <property name="leftMargin">
  352. + <number>10</number>
  353. + </property>
  354. + <property name="topMargin">
  355. + <number>10</number>
  356. + </property>
  357. + <property name="rightMargin">
  358. + <number>10</number>
  359. + </property>
  360. + <property name="bottomMargin">
  361. <number>10</number>
  362. </property>
  363. <item>
  364. --- a/gns3/modules/qemu/pages/qemu_vm_configuration_page.py
  365. +++ b/gns3/modules/qemu/pages/qemu_vm_configuration_page.py
  366. @@ -444,6 +444,8 @@
  367. self.uiInitrdLineEdit.setText(settings["initrd"])
  368. self.uiKernelImageLineEdit.setText(settings["kernel_image"])
  369. else:
  370. + self.uiEnvvarLabel.hide()
  371. + self.uiEnvvarLineEdit.hide()
  372. self.uiNameLabel.hide()
  373. self.uiNameLineEdit.hide()
  374. self.uiHddTab.hide()
  375. @@ -542,6 +544,7 @@
  376. self.uiProcessPriorityComboBox.setCurrentIndex(index)
  377. self.uiQemuOptionsLineEdit.setText(settings["options"])
  378. self.uiUsageTextEdit.setPlainText(settings["usage"])
  379. + self.uiEnvvarLineEdit.setText(settings["env_vars"])
  380. def saveSettings(self, settings, node=None, group=False):
  381. """
  382. @@ -653,4 +656,5 @@
  383. settings["process_priority"] = self.uiProcessPriorityComboBox.currentText().lower()
  384. settings["options"] = self.uiQemuOptionsLineEdit.text()
  385. settings["usage"] = self.uiUsageTextEdit.toPlainText()
  386. + settings["env_vars"] = self.uiEnvvarLineEdit.text()
  387. return settings
  388. --- a/gns3/modules/qemu/pages/qemu_vm_preferences_page.py
  389. +++ b/gns3/modules/qemu/pages/qemu_vm_preferences_page.py
  390. @@ -117,7 +117,7 @@
  391. QtWidgets.QTreeWidgetItem(section_item, ["Base MAC address:", qemu_vm["mac_address"]])
  392. # fill out the Linux boot section
  393. - if qemu_vm["initrd"] or qemu_vm["kernel_image"] or qemu_vm["kernel_command_line"]:
  394. + if qemu_vm["initrd"] or qemu_vm["kernel_image"] or qemu_vm["kernel_command_line"] or qemu_vm["env_vars"]:
  395. section_item = self._createSectionItem("Linux boot")
  396. if qemu_vm["initrd"]:
  397. QtWidgets.QTreeWidgetItem(section_item, ["Initial RAM disk:", qemu_vm["initrd"]])
  398. @@ -125,6 +125,8 @@
  399. QtWidgets.QTreeWidgetItem(section_item, ["Kernel image:", qemu_vm["kernel_image"]])
  400. if qemu_vm["kernel_command_line"]:
  401. QtWidgets.QTreeWidgetItem(section_item, ["Kernel command line:", qemu_vm["kernel_command_line"]])
  402. + if qemu_vm["env_vars"]:
  403. + QtWidgets.QTreeWidgetItem(section_item, ["Environment variables:", qemu_vm["env_vars"]])
  404. # performance section
  405. section_item = self._createSectionItem("Optimizations")
  406. --- a/gns3/schemas/appliance.json
  407. +++ b/gns3/schemas/appliance.json
  408. @@ -329,6 +329,10 @@
  409. "title": "KVM requirements",
  410. "enum": ["require", "allow", "disable"]
  411. },
  412. + "env_vars": {
  413. + "type": "string",
  414. + "title": "Environment variables"
  415. + },
  416. "options": {
  417. "type": "string",
  418. "title": "Optional additional qemu command line options"