Author: Pekka Helenius Date: Sun, 6 Jun 2021 15:10:45 +0200 Subject: [PATCH] GNS3 GUI: QEMU environment variables. Add support for QEMU environment variables for GNS3 GUI. --- a/tests/test_local_config.py +++ b/tests/test_local_config.py @@ -285,6 +285,7 @@ "enable_kvm": True, "vms": [ { + "env_vars": "", "kernel_image": "", "kernel_command_line": "", "first_port_name": "", @@ -323,6 +324,7 @@ "platform": "" }, { + "env_vars": "", "kernel_image": "", "kernel_command_line": "", "server": "vm", --- a/gns3/modules/qemu/settings.py +++ b/gns3/modules/qemu/settings.py @@ -27,6 +27,7 @@ } QEMU_VM_SETTINGS = { + "env_vars": "", "name": "", "default_name_format": "{name}-{0}", "usage": "", --- a/gns3/modules/qemu/qemu_vm.py +++ b/gns3/modules/qemu/qemu_vm.py @@ -42,7 +42,8 @@ self._linked_clone = True - qemu_vm_settings = {"usage": "", + qemu_vm_settings = {"env_vars": "", + "usage": "", "qemu_path": "", "hda_disk_image": "", "hdb_disk_image": "", --- a/gns3/modules/qemu/ui/qemu_vm_configuration_page_ui.py +++ b/gns3/modules/qemu/ui/qemu_vm_configuration_page_ui.py @@ -63,6 +63,12 @@ self.uiCPULabel = QtWidgets.QLabel(self.uiGeneralSettingsTab) self.uiCPULabel.setObjectName("uiCPULabel") self.gridLayout_4.addWidget(self.uiCPULabel, 5, 0, 1, 1) + self.uiEnvvarLabel = QtWidgets.QLabel(self.uiGeneralSettingsTab) + self.uiEnvvarLabel.setObjectName("uiEnvvarLabel") + self.gridLayout_4.addWidget(self.uiEnvvarLabel, 9, 0, 1, 1) + self.uiEnvvarLineEdit = QtWidgets.QLineEdit(self.uiGeneralSettingsTab) + self.uiEnvvarLineEdit.setObjectName("uiEnvvarLineEdit") + self.gridLayout_4.addWidget(self.uiEnvvarLineEdit, 9, 1, 1, 1) self.uiCPUSpinBox = QtWidgets.QSpinBox(self.uiGeneralSettingsTab) self.uiCPUSpinBox.setMinimum(1) self.uiCPUSpinBox.setMaximum(255) @@ -93,7 +99,7 @@ self.gridLayout_4.addWidget(self.uiOnCloseComboBox, 8, 1, 1, 1) self.uiConsoleTypeLabel = QtWidgets.QLabel(self.uiGeneralSettingsTab) self.uiConsoleTypeLabel.setObjectName("uiConsoleTypeLabel") - self.gridLayout_4.addWidget(self.uiConsoleTypeLabel, 9, 0, 1, 1) + self.gridLayout_4.addWidget(self.uiConsoleTypeLabel, 10, 0, 1, 1) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.uiConsoleTypeComboBox = QtWidgets.QComboBox(self.uiGeneralSettingsTab) @@ -107,9 +113,9 @@ self.uiConsoleAutoStartCheckBox = QtWidgets.QCheckBox(self.uiGeneralSettingsTab) self.uiConsoleAutoStartCheckBox.setObjectName("uiConsoleAutoStartCheckBox") self.horizontalLayout_2.addWidget(self.uiConsoleAutoStartCheckBox) - self.gridLayout_4.addLayout(self.horizontalLayout_2, 9, 1, 1, 1) + self.gridLayout_4.addLayout(self.horizontalLayout_2, 10, 1, 1, 1) spacerItem = QtWidgets.QSpacerItem(263, 94, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) - self.gridLayout_4.addItem(spacerItem, 10, 1, 1, 1) + self.gridLayout_4.addItem(spacerItem, 11, 1, 1, 1) self.uiQemutabWidget.addTab(self.uiGeneralSettingsTab, "") self.uiHddTab = QtWidgets.QWidget() self.uiHddTab.setObjectName("uiHddTab") @@ -462,6 +468,7 @@ self.uiRamLabel.setText(_translate("QemuVMConfigPageWidget", "RAM:")) self.uiRamSpinBox.setSuffix(_translate("QemuVMConfigPageWidget", " MB")) self.uiCPULabel.setText(_translate("QemuVMConfigPageWidget", "vCPUs:")) + self.uiEnvvarLabel.setText(_translate("QemuVMConfigPageWidget", "Environment variables:")) self.uiQemuListLabel.setText(_translate("QemuVMConfigPageWidget", "Qemu binary:")) self.uiBootPriorityLabel.setText(_translate("QemuVMConfigPageWidget", "Boot priority:")) self.uiOnCloseLabel.setText(_translate("QemuVMConfigPageWidget", "On close:")) --- a/gns3/modules/qemu/ui/qemu_vm_configuration_page.ui +++ b/gns3/modules/qemu/ui/qemu_vm_configuration_page.ui @@ -24,26 +24,23 @@ General settings - - + + - Name: + Default name format: - - + + - - + + - Default name format: + Name: - - - @@ -51,64 +48,23 @@ - - - - - - - - - &Browse... - - - Qt::ToolButtonTextOnly - - - - + + - - - - Category: + + + + + 0 + 0 + - + - - - - RAM: - - - - - - - MB - - - 32 - - - 65535 - - - 256 - - - - - - - vCPUs: - - - - + 1 @@ -125,16 +81,33 @@ - - - - - 0 - 0 - + + + + On close: + + + + Console type: + + + + + + + Qt::Vertical + + + + 263 + 94 + + + + @@ -142,27 +115,67 @@ - - + + + + MB + + + 32 + + + 65535 + + + 256 + + - - + + + + + - On close: + Category: - - + + - - + + - Console type: + RAM: - + + + + + + + + + &Browse... + + + Qt::ToolButtonTextOnly + + + + + + + + + vCPUs: + + + + @@ -202,18 +215,15 @@ - - - - Qt::Vertical - - - - 263 - 94 - + + + + + + + Environment variables: - + @@ -470,7 +480,16 @@ CD/DVD - + + 10 + + + 10 + + + 10 + + 10 --- a/gns3/modules/qemu/pages/qemu_vm_configuration_page.py +++ b/gns3/modules/qemu/pages/qemu_vm_configuration_page.py @@ -444,6 +444,8 @@ self.uiInitrdLineEdit.setText(settings["initrd"]) self.uiKernelImageLineEdit.setText(settings["kernel_image"]) else: + self.uiEnvvarLabel.hide() + self.uiEnvvarLineEdit.hide() self.uiNameLabel.hide() self.uiNameLineEdit.hide() self.uiHddTab.hide() @@ -542,6 +544,7 @@ self.uiProcessPriorityComboBox.setCurrentIndex(index) self.uiQemuOptionsLineEdit.setText(settings["options"]) self.uiUsageTextEdit.setPlainText(settings["usage"]) + self.uiEnvvarLineEdit.setText(settings["env_vars"]) def saveSettings(self, settings, node=None, group=False): """ @@ -653,4 +656,5 @@ settings["process_priority"] = self.uiProcessPriorityComboBox.currentText().lower() settings["options"] = self.uiQemuOptionsLineEdit.text() settings["usage"] = self.uiUsageTextEdit.toPlainText() + settings["env_vars"] = self.uiEnvvarLineEdit.text() return settings --- a/gns3/modules/qemu/pages/qemu_vm_preferences_page.py +++ b/gns3/modules/qemu/pages/qemu_vm_preferences_page.py @@ -117,7 +117,7 @@ QtWidgets.QTreeWidgetItem(section_item, ["Base MAC address:", qemu_vm["mac_address"]]) # fill out the Linux boot section - if qemu_vm["initrd"] or qemu_vm["kernel_image"] or qemu_vm["kernel_command_line"]: + if qemu_vm["initrd"] or qemu_vm["kernel_image"] or qemu_vm["kernel_command_line"] or qemu_vm["env_vars"]: section_item = self._createSectionItem("Linux boot") if qemu_vm["initrd"]: QtWidgets.QTreeWidgetItem(section_item, ["Initial RAM disk:", qemu_vm["initrd"]]) @@ -125,6 +125,8 @@ QtWidgets.QTreeWidgetItem(section_item, ["Kernel image:", qemu_vm["kernel_image"]]) if qemu_vm["kernel_command_line"]: QtWidgets.QTreeWidgetItem(section_item, ["Kernel command line:", qemu_vm["kernel_command_line"]]) + if qemu_vm["env_vars"]: + QtWidgets.QTreeWidgetItem(section_item, ["Environment variables:", qemu_vm["env_vars"]]) # performance section section_item = self._createSectionItem("Optimizations") --- a/gns3/schemas/appliance.json +++ b/gns3/schemas/appliance.json @@ -329,6 +329,10 @@ "title": "KVM requirements", "enum": ["require", "allow", "disable"] }, + "env_vars": { + "type": "string", + "title": "Environment variables" + }, "options": { "type": "string", "title": "Optional additional qemu command line options"