def __init__(self, parent): super().__init__(parent) self.setupUi(self) self.setWizardStyle(QtWidgets.QWizard.ModernStyle) if sys.platform.startswith("darwin"): # we want to see the cancel button on OSX self.setOptions(QtWidgets.QWizard.NoDefaultButton) self._server = Servers.instance().localServer() self.uiGNS3VMDownloadLinkUrlLabel.setText('') self.uiRefreshPushButton.clicked.connect(self._refreshVMListSlot) self.uiVmwareRadioButton.clicked.connect(self._listVMwareVMsSlot) self.uiVirtualBoxRadioButton.clicked.connect(self._listVirtualBoxVMsSlot) self.uiVMwareBannerButton.clicked.connect(self._VMwareBannerButtonClickedSlot) settings = parent.settings() self.uiShowCheckBox.setChecked(settings["hide_setup_wizard"]) # by default all radio buttons are unchecked self.uiVmwareRadioButton.setAutoExclusive(False) self.uiVirtualBoxRadioButton.setAutoExclusive(False) self.uiVmwareRadioButton.setChecked(False) self.uiVirtualBoxRadioButton.setChecked(False) if sys.platform.startswith("darwin"): self.uiVMwareBannerButton.setIcon(QtGui.QIcon(":/images/vmware_fusion_banner.jpg")) else: self.uiVMwareBannerButton.setIcon(QtGui.QIcon(":/images/vmware_workstation_banner.jpg"))
def setClassicStyle(self): """ Sets the classic GUI style. """ self._mw.setStyleSheet("") self._mw.uiNewProjectAction.setIcon(self._getStyleIcon(":/classic_icons/new-project.svg", ":/classic_icons/new-project-hover.svg")) self._mw.uiOpenProjectAction.setIcon(self._getStyleIcon(":/classic_icons/open.svg", ":/classic_icons/open-hover.svg")) self._mw.uiOpenApplianceAction.setIcon(self._getStyleIcon(":/classic_icons/open.svg", ":/classic_icons/open-hover.svg")) self._mw.uiNewTemplateAction.setIcon(self._getStyleIcon(":/classic_icons/plus.svg", ":/classic_icons/plus-hover.svg")) self._mw.uiSaveProjectAsAction.setIcon(self._getStyleIcon(":/classic_icons/save-as-project.svg", ":/classic_icons/save-as-project-hover.svg")) self._mw.uiEditProjectAction.setIcon(self._getStyleIcon(":/classic_icons/edit.svg", ":/classic_icons/edit-hover.svg")) self._mw.uiImportExportConfigsAction.setIcon(self._getStyleIcon(":/classic_icons/import_export_configs.svg", ":/classic_icons/import_export_configs-hover.svg")) self._mw.uiImportProjectAction.setIcon(self._getStyleIcon(":/classic_icons/import.svg", ":/classic_icons/import-hover.svg")) self._mw.uiExportProjectAction.setIcon(self._getStyleIcon(":/classic_icons/export.svg", ":/classic_icons/export-hover.svg")) self._mw.uiDeleteProjectAction.setIcon(self._getStyleIcon(":/classic_icons/delete.svg", ":/classic_icons/delete-hover.svg")) self._mw.uiScreenshotAction.setIcon(self._getStyleIcon(":/classic_icons/camera-photo.svg", ":/classic_icons/camera-photo-hover.svg")) self._mw.uiSnapshotAction.setIcon(self._getStyleIcon(":/classic_icons/snapshot.svg", ":/classic_icons/snapshot-hover.svg")) self._mw.uiQuitAction.setIcon(self._getStyleIcon(":/classic_icons/quit.svg", ":/classic_icons/quit-hover.svg")) self._mw.uiPreferencesAction.setIcon(self._getStyleIcon(":/classic_icons/preferences.svg", ":/classic_icons/preferences-hover.svg")) self._mw.uiZoomInAction.setIcon(self._getStyleIcon(":/classic_icons/zoom-in.svg", ":/classic_icons/zoom-in-hover.svg")) self._mw.uiZoomOutAction.setIcon(self._getStyleIcon(":/classic_icons/zoom-out.svg", ":/classic_icons/zoom-out-hover.svg")) self._mw.uiShowPortNamesAction.setIcon(self._getStyleIcon(":/classic_icons/show-interface-names.svg", ":/classic_icons/show-interface-names-hover.svg")) self._mw.uiStartAllAction.setIcon(self._getStyleIcon(":/classic_icons/start.svg", ":/classic_icons/start-hover.svg")) self._mw.uiSuspendAllAction.setIcon(self._getStyleIcon(":/classic_icons/pause.svg", ":/classic_icons/pause-hover.svg")) self._mw.uiStopAllAction.setIcon(self._getStyleIcon(":/classic_icons/stop.svg", ":/classic_icons/stop-hover.svg")) self._mw.uiReloadAllAction.setIcon(self._getStyleIcon(":/classic_icons/reload.svg", ":/classic_icons/reload-hover.svg")) self._mw.uiAuxConsoleAllAction.setIcon(self._getStyleIcon(":/classic_icons/aux-console.svg", ":/classic_icons/aux-console-hover.svg")) self._mw.uiConsoleAllAction.setIcon(self._getStyleIcon(":/classic_icons/console.svg", ":/classic_icons/console-hover.svg")) self._mw.uiAddNoteAction.setIcon(self._getStyleIcon(":/classic_icons/add-note.svg", ":/classic_icons/add-note-hover.svg")) self._mw.uiInsertImageAction.setIcon(self._getStyleIcon(":/classic_icons/image.svg", ":/classic_icons/image-hover.svg")) self._mw.uiDrawRectangleAction.setIcon(self._getStyleIcon(":/classic_icons/rectangle.svg", ":/classic_icons/rectangle-hover.svg")) self._mw.uiDrawEllipseAction.setIcon(self._getStyleIcon(":/classic_icons/ellipse.svg", ":/classic_icons/ellipse-hover.svg")) self._mw.uiDrawLineAction.setIcon(self._getStyleIcon(":/classic_icons/line.svg", ":/classic_icons/line-hover.svg")) self._mw.uiEditReadmeAction.setIcon(self._getStyleIcon(":/classic_icons/edit.svg", ":/classic_icons/edit-hover.svg")) self._mw.uiOnlineHelpAction.setIcon(self._getStyleIcon(":/classic_icons/help.svg", ":/classic_icons/help-hover.svg")) self._mw.uiBrowseRoutersAction.setIcon(self._getStyleIcon(":/classic_icons/router.svg", ":/classic_icons/router-hover.svg")) self._mw.uiBrowseSwitchesAction.setIcon(self._getStyleIcon(":/classic_icons/switch.svg", ":/classic_icons/switch-hover.svg")) self._mw.uiBrowseEndDevicesAction.setIcon(self._getStyleIcon(":/classic_icons/pc.svg", ":/classic_icons/pc-hover.svg")) self._mw.uiBrowseSecurityDevicesAction.setIcon(self._getStyleIcon(":/classic_icons/firewall.svg", ":/classic_icons/firewall-hover.svg")) self._mw.uiBrowseAllDevicesAction.setIcon(self._getStyleIcon(":/classic_icons/browse-all-icons.svg", ":/classic_icons/browse-all-icons-hover.svg")) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/classic_icons/add-link.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(":/classic_icons/add-link-hover.svg"), QtGui.QIcon.Active, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(":/classic_icons/add-link-cancel.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) self._mw.uiAddLinkAction.setIcon(icon) # Lock action has 4 different icons icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/classic_icons/lock.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On) icon.addPixmap(QtGui.QPixmap(":/classic_icons/lock-hover.svg"), QtGui.QIcon.Active, QtGui.QIcon.On) icon.addPixmap(QtGui.QPixmap(":/classic_icons/unlock.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(":/classic_icons/unlock-hover.svg"), QtGui.QIcon.Active, QtGui.QIcon.Off) self._mw.uiLockAllAction.setIcon(icon)
def _dockerImageEditSlot(self): """ Edits a Docker image """ item = self.uiDockerVMsTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) docker_image = self._docker_containers[key] dialog = ConfigurationDialog(docker_image["name"], docker_image, DockerVMConfigurationPage(), parent=self) dialog.show() if dialog.exec_(): # update the icon item.setIcon(0, QtGui.QIcon(docker_image["symbol"])) if docker_image["name"] != item.text(0): new_key = "{server}:{name}".format( server=docker_image["server"], name=docker_image["name"]) if new_key in self._docker_containers: QtWidgets.QMessageBox.critical( self, "Docker image", "Docker container name {} already exists for server {}" .format(docker_image["name"], docker_image["server"])) docker_image["name"] = item.text(0) return self._docker_containers[new_key] = self._docker_containers[ key] del self._docker_containers[key] item.setText(0, docker_image["name"]) item.setData(0, QtCore.Qt.UserRole, new_key) self._refreshInfo(docker_image)
def _iosRouterEditSlot(self): """ Edits an IOS router. """ item = self.uiIOSRoutersTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) ios_router = self._ios_routers[key] dialog = ConfigurationDialog(ios_router["name"], ios_router, IOSRouterConfigurationPage(), parent=self) dialog.show() if dialog.exec_(): # update the icon item.setIcon(0, QtGui.QIcon(ios_router["symbol"])) if ios_router["name"] != item.text(0): # rename the IOS router new_key = "{server}:{name}".format(server=ios_router["server"], name=ios_router["name"]) if new_key in self._ios_routers: QtWidgets.QMessageBox.critical(self, "IOS router", "IOS router name {} already exists for server {}".format(ios_router["name"], ios_router["server"])) ios_router["name"] = item.text(0) return self._ios_routers[new_key] = self._ios_routers[key] del self._ios_routers[key] item.setText(0, ios_router["name"]) item.setData(0, QtCore.Qt.UserRole, new_key) self._refreshInfo(ios_router)
def _qemuVMNewSlot(self): """ Creates a new VM. """ wizard = QemuVMWizard(self._qemu_vms, parent=self) wizard.show() if wizard.exec_(): new_vm_settings = wizard.getSettings() key = "{server}:{name}".format(server=new_vm_settings["server"], name=new_vm_settings["name"]) if key in self._qemu_vms: QtGui.QMessageBox.critical( self, "New QEMU VM", "VM name {} already exists".format( new_vm_settings["name"])) return self._qemu_vms[key] = QEMU_VM_SETTINGS.copy() self._qemu_vms[key].update(new_vm_settings) item = QtGui.QTreeWidgetItem(self.uiQemuVMsTreeWidget) item.setText(0, self._qemu_vms[key]["name"]) item.setIcon(0, QtGui.QIcon(self._qemu_vms[key]["default_symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) self.uiQemuVMsTreeWidget.setCurrentItem(item) if self._qemu_vms[key]["server"] == 'cloud': self._qemu_vms[key]["options"] = "-nographic" self._uploadImages(new_vm_settings)
def _vboxVMEditSlot(self): """ Edits a VirtualBox VM. """ item = self.uiVirtualBoxVMsTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) vbox_vm = self._virtualbox_vms[key] dialog = ConfigurationDialog(vbox_vm["vmname"], vbox_vm, VirtualBoxVMConfigurationPage(), parent=self) dialog.show() if dialog.exec_(): # update the icon item.setIcon(0, QtGui.QIcon(vbox_vm["symbol"])) if vbox_vm["vmname"] != item.text(0): new_key = "{server}:{vmname}".format(server=vbox_vm["server"], name=vbox_vm["vmname"]) if new_key in self._virtualbox_vms: QtWidgets.QMessageBox.critical(self, "VirtualBox VM", "VirtualBox VM name {} already exists for server {}".format(vbox_vm["vmname"], vbox_vm["server"])) vbox_vm["vmname"] = item.text(0) return self._virtualbox_vms[new_key] = self._virtualbox_vms[key] del self._virtualbox_vms[key] item.setText(0, vbox_vm["vmname"]) item.setData(0, QtCore.Qt.UserRole, new_key) self._refreshInfo(vbox_vm)
def _qemuVMEditSlot(self): """ Edits a QEMU VM. """ item = self.uiQemuVMsTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) qemu_vm = self._qemu_vms[key] dialog = ConfigurationDialog(qemu_vm["name"], qemu_vm, QemuVMConfigurationPage(), parent=self) dialog.show() if dialog.exec_(): # update the icon item.setIcon(0, QtGui.QIcon(qemu_vm["symbol"])) if qemu_vm["name"] != item.text(0): new_key = "{server}:{name}".format( server=qemu_vm["server"], name=qemu_vm["name"]) if new_key in self._qemu_vms: QtWidgets.QMessageBox.critical( self, "QEMU VM", "QEMU VM name {} already exists for server {}". format(qemu_vm["name"], qemu_vm["server"])) qemu_vm["name"] = item.text(0) return self._qemu_vms[new_key] = self._qemu_vms[key] del self._qemu_vms[key] item.setText(0, qemu_vm["name"]) item.setData(0, QtCore.Qt.UserRole, new_key) self._refreshInfo(qemu_vm)
def _getStyleIcon(self, normal_file, active_file): icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(normal_file), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(active_file), QtGui.QIcon.Active, QtGui.QIcon.Off) return icon
def _iouDeviceNewSlot(self): """ Creates a new IOU device. """ wizard = IOUDeviceWizard(self._iou_devices, parent=self) wizard.show() if wizard.exec_(): new_device_settings = wizard.getSettings() key = "{server}:{name}".format( server=new_device_settings["server"], name=new_device_settings["name"]) self._iou_devices[key] = IOU_DEVICE_SETTINGS.copy() self._iou_devices[key].update(new_device_settings) item = QtGui.QTreeWidgetItem(self.uiIOUDevicesTreeWidget) item.setText(0, self._iou_devices[key]["name"]) item.setIcon(0, QtGui.QIcon(self._iou_devices[key]["default_symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) self.uiIOUDevicesTreeWidget.setCurrentItem(item) if new_device_settings["server"] == 'cloud': import logging log = logging.getLogger(__name__) # Start uploading the image to cloud files self._upload_image_progress_dialog = QtGui.QProgressDialog( "Uploading image file {}".format( new_device_settings['image']), "Cancel", 0, 0, parent=self) self._upload_image_progress_dialog.setWindowModality( QtCore.Qt.WindowModal) self._upload_image_progress_dialog.setWindowTitle( "IOU image upload") self._upload_image_progress_dialog.show() try: src = self._iou_devices[key]['path'] # Eg: images/IOU/i86.bin dst = 'images/IOU/{}'.format( self._iou_devices[key]['image']) upload_thread = UploadFilesThread( self, MainWindow.instance().cloudSettings(), [(src, dst)]) upload_thread.completed.connect(self._imageUploadComplete) upload_thread.start() except Exception as e: self._upload_image_progress_dialog.reject() log.error(e) QtGui.QMessageBox.critical( self, "IOU image upload", "Error uploading IOU image: {}".format(e))
def _showContextualMenu(self): """ Contextual menu. """ menu = QtGui.QMenu() change_symbol_action = QtGui.QAction("Change symbol", menu) change_symbol_action.setIcon(QtGui.QIcon(":/icons/node_conception.svg")) self.connect(change_symbol_action, QtCore.SIGNAL('triggered()'), self._changeSymbolSlot) menu.addAction(change_symbol_action) menu.exec_(QtGui.QCursor.pos())
def __init__(self): super().__init__() self.setupUi(self) self._node = None self._ports = [] self._interfaces = [] # add the categories for name, category in Node.defaultCategories().items(): self.uiCategoryComboBox.addItem(name, category) # connect Ethernet slots self.uiEthernetListWidget.itemSelectionChanged.connect( self._EthernetChangedSlot) self.uiEthernetWarningPushButton.clicked.connect( self._EthernetWarningSlot) self.uiAddEthernetPushButton.clicked.connect(self._EthernetAddSlot) self.uiAddAllEthernetPushButton.clicked.connect( self._EthernetAddAllSlot) self.uiRefreshEthernetPushButton.clicked.connect( self._EthernetRefreshSlot) self.uiDeleteEthernetPushButton.clicked.connect( self._EthernetDeleteSlot) # connect TAP slots self.uiTAPComboBox.currentIndexChanged.connect(self._TAPSelectedSlot) self.uiTAPListWidget.itemSelectionChanged.connect(self._TAPChangedSlot) self.uiAddTAPPushButton.clicked.connect(self._TAPAddSlot) self.uiAddAllTAPPushButton.clicked.connect(self._TAPAddAllSlot) self.uiRefreshTAPPushButton.clicked.connect(self._TAPRefreshSlot) self.uiDeleteTAPPushButton.clicked.connect(self._TAPDeleteSlot) # connect UDP slots self.uiUDPTreeWidget.itemActivated.connect(self._UDPSelectedSlot) self.uiUDPTreeWidget.itemSelectionChanged.connect(self._UDPChangedSlot) self.uiAddUDPPushButton.clicked.connect(self._UDPAddSlot) self.uiDeleteUDPPushButton.clicked.connect(self._UDPDeleteSlot) # connect other slots self.uiShowSpecialInterfacesCheckBox.stateChanged.connect( self._showSpecialInterfacesSlot) self.uiSymbolToolButton.clicked.connect(self._symbolBrowserSlot) self.uiConsoleTypeComboBox.currentTextChanged.connect( self._consoleTypeChangedSlot) # add an icon to the warning button icon = QtGui.QIcon.fromTheme("dialog-warning") if icon.isNull(): icon = QtGui.QIcon(':/icons/dialog-warning.svg') self.uiEthernetWarningPushButton.setIcon(icon)
def _changeSymbolSlot(self): """Change a symbol for a Docker image.""" item = self.uiDockerVMsTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) docker_image = self._docker_images[key] dialog = SymbolSelectionDialog(self, symbol=docker_image["symbol"], category=docker_image["category"]) dialog.show() if dialog.exec_(): normal_symbol, selected_symbol = dialog.getSymbols() category = dialog.getCategory() item.setIcon(0, QtGui.QIcon(normal_symbol)) docker_image["symbol"] = normal_symbol docker_image["category"] = category
def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) self.setWizardStyle(QtWidgets.QWizard.ModernStyle) if sys.platform.startswith("darwin"): # we want to see the cancel button on OSX self.setOptions(QtWidgets.QWizard.NoDefaultButton) # set the window icon self.setWindowIcon(QtGui.QIcon( ":/images/gns3.ico")) # this info is necessary for QSettings config = self._loadConfig() self.uiPushButtonBrowse.clicked.connect(self._browseTopologiesSlot) self.uiLineEditTopologiesPath.setText( config['Servers']['local_server']['projects_path'])
def _vboxVMEditSlot(self): """ Edits a VirtualBox VM. """ item = self.uiVirtualBoxVMsTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) vbox_vm = self._virtualbox_vms[key] dialog = ConfigurationDialog(vbox_vm["vmname"], vbox_vm, VirtualBoxVMConfigurationPage(), parent=self) dialog.show() if dialog.exec_(): # update the icon item.setIcon(0, QtGui.QIcon(vbox_vm["symbol"])) if vbox_vm["name"] != item.text(0): item.setText(0, vbox_vm["name"]) self._refreshInfo(vbox_vm)
def _showContextualMenu(self): """Contextual menu.""" menu = QtWidgets.QMenu() change_symbol_action = QtWidgets.QAction("Change symbol", menu) change_symbol_action.setIcon( QtGui.QIcon(":/icons/node_conception.svg")) change_symbol_action.setEnabled( len(self.uiDockerVMsTreeWidget.selectedItems()) == 1) change_symbol_action.triggered.connect(self._changeSymbolSlot) menu.addAction(change_symbol_action) delete_action = QtWidgets.QAction("Delete", menu) delete_action.triggered.connect(self._dockerImageDeleteSlot) menu.addAction(delete_action) menu.exec_(QtGui.QCursor.pos())
def _changeSymbolSlot(self): """ Change a symbol for an IOS router. """ item = self.uiIOSRoutersTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) ios_router = self._ios_routers[key] dialog = SymbolSelectionDialog(self, symbol=ios_router["default_symbol"], category=ios_router["category"]) dialog.show() if dialog.exec_(): normal_symbol, selected_symbol = dialog.getSymbols() category = dialog.getCategory() item.setIcon(0, QtGui.QIcon(normal_symbol)) ios_router["default_symbol"] = normal_symbol ios_router["hover_symbol"] = selected_symbol ios_router["category"] = category
def loadPreferences(self): """Loads the Docker VM preferences.""" docker_module = Docker.instance() self._docker_images = copy.deepcopy(docker_module.dockerImages()) self._items.clear() for key, docker_image in self._docker_images.items(): item = QtWidgets.QTreeWidgetItem(self.uiDockerVMsTreeWidget) item.setText(0, docker_image["imagename"]) item.setIcon(0, QtGui.QIcon(docker_image["symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiDockerVMsTreeWidget.setCurrentItem(self._items[0]) self.uiDockerVMsTreeWidget.sortByColumn(0, QtCore.Qt.AscendingOrder)
def _dockerImageNewSlot(self): """Creates a new Docker image.""" wizard = DockerVMWizard(self._docker_images, parent=self) wizard.show() if wizard.exec_(): new_image_settings = wizard.getSettings() key = "{server}:{imagename}".format( server=new_image_settings["server"], imagename=new_image_settings["imagename"]) self._docker_images[key] = DOCKER_CONTAINER_SETTINGS.copy() self._docker_images[key].update(new_image_settings) item = QtWidgets.QTreeWidgetItem(self.uiDockerVMsTreeWidget) item.setText(0, self._docker_images[key]["imagename"]) item.setIcon(0, QtGui.QIcon(self._docker_images[key]["symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) self.uiDockerVMsTreeWidget.setCurrentItem(item)
def loadPreferences(self): """ Loads the VirtualBox VM preferences. """ vbox_module = VirtualBox.instance() self._virtualbox_vms = copy.deepcopy(vbox_module.VMs()) self._items.clear() for key, vbox_vm in self._virtualbox_vms.items(): item = QtWidgets.QTreeWidgetItem(self.uiVirtualBoxVMsTreeWidget) item.setText(0, vbox_vm["name"]) item.setIcon(0, QtGui.QIcon(vbox_vm["symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiVirtualBoxVMsTreeWidget.setCurrentItem(self._items[0]) self.uiVirtualBoxVMsTreeWidget.sortByColumn(0, QtCore.Qt.AscendingOrder)
def loadPreferences(self): """ Loads the IOS router preferences. """ dynamips_module = Dynamips.instance() self._ios_routers = copy.deepcopy(dynamips_module.iosRouters()) self._items.clear() for key, ios_router in self._ios_routers.items(): item = QtGui.QTreeWidgetItem(self.uiIOSRoutersTreeWidget) item.setText(0, ios_router["name"]) item.setIcon(0, QtGui.QIcon(ios_router["default_symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiIOSRoutersTreeWidget.setCurrentItem(self._items[0]) self.uiIOSRoutersTreeWidget.sortByColumn(0, QtCore.Qt.AscendingOrder)
def loadPreferences(self): """ Loads the IOU devices preferences. """ iou_module = IOU.instance() self._iou_devices = copy.deepcopy(iou_module.iouDevices()) self._items.clear() for key, iou_device in self._iou_devices.items(): item = QtGui.QTreeWidgetItem(self.uiIOUDevicesTreeWidget) item.setText(0, iou_device["name"]) item.setIcon(0, QtGui.QIcon(iou_device["default_symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiIOUDevicesTreeWidget.setCurrentItem(self._items[0]) self.uiIOUDevicesTreeWidget.sortByColumn(0, QtCore.Qt.AscendingOrder)
def loadPreferences(self): """ Loads the QEMU VM preferences. """ qemu_module = Qemu.instance() self._qemu_vms = copy.deepcopy(qemu_module.qemuVMs()) self._items.clear() for key, qemu_vm in self._qemu_vms.items(): item = QtGui.QTreeWidgetItem(self.uiQemuVMsTreeWidget) item.setText(0, qemu_vm["name"]) item.setIcon(0, QtGui.QIcon(qemu_vm["default_symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiQemuVMsTreeWidget.setCurrentItem(self._items[0]) self.uiQemuVMsTreeWidget.sortByColumn(0, QtCore.Qt.AscendingOrder)
def _vmwareVMNewSlot(self): """ Creates a new VMware VM. """ wizard = VMwareVMWizard(self._vmware_vms, parent=self) wizard.show() if wizard.exec_(): new_vm_settings = wizard.getSettings() key = "{server}:{name}".format(server=new_vm_settings["server"], name=new_vm_settings["name"]) self._vmware_vms[key] = VMWARE_VM_SETTINGS.copy() self._vmware_vms[key].update(new_vm_settings) item = QtWidgets.QTreeWidgetItem(self.uiVMwareVMsTreeWidget) item.setText(0, self._vmware_vms[key]["name"]) item.setIcon(0, QtGui.QIcon(self._vmware_vms[key]["symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) self.uiVMwareVMsTreeWidget.setCurrentItem(item)
def _changeSymbolSlot(self): """ Change a symbol for a QEMU VM. """ item = self.uiQemuVMsTreeWidget.currentItem() if item: key = item.data(0, QtCore.Qt.UserRole) qemu_vm = self._qemu_vms[key] dialog = SymbolSelectionDialog(self, symbol=qemu_vm["default_symbol"], category=qemu_vm["category"]) dialog.show() if dialog.exec_(): normal_symbol, selected_symbol = dialog.getSymbols() category = dialog.getCategory() item.setIcon(0, QtGui.QIcon(normal_symbol)) qemu_vm["default_symbol"] = normal_symbol qemu_vm["hover_symbol"] = selected_symbol qemu_vm["category"] = category
def loadPreferences(self): """ Loads the IOS router preferences. """ dynamips_module = Dynamips.instance() self._ios_routers = copy.deepcopy(dynamips_module.VMs()) self._items.clear() for key, ios_router in self._ios_routers.items(): item = QtWidgets.QTreeWidgetItem(self.uiIOSRoutersTreeWidget) item.setText(0, ios_router["name"]) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(ios_router["symbol"])) item.setIcon(0, icon) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiIOSRoutersTreeWidget.setCurrentItem(self._items[0]) self.uiIOSRoutersTreeWidget.sortByColumn(0, QtCore.Qt.AscendingOrder) self.uiIOSRoutersTreeWidget.setMaximumWidth(self.uiIOSRoutersTreeWidget.sizeHintForColumn(0) + 10)
def loadPreferences(self): """ Loads the VMware VM preferences. """ vmware_module = VMware.instance() self._vmware_vms = copy.deepcopy(vmware_module.VMs()) self._items.clear() for key, vmware_vm in self._vmware_vms.items(): item = QtWidgets.QTreeWidgetItem(self.uiVMwareVMsTreeWidget) item.setText(0, vmware_vm["name"]) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(vmware_vm["symbol"])) item.setIcon(0, icon) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiVMwareVMsTreeWidget.setCurrentItem(self._items[0]) self.uiVMwareVMsTreeWidget.sortByColumn(0, QtCore.Qt.AscendingOrder) self.uiVMwareVMsTreeWidget.setMaximumWidth(self.uiVMwareVMsTreeWidget.sizeHintForColumn(0) + 10)
def _iosRouterNewSlot(self): """ Creates a new IOS router. """ wizard = IOSRouterWizard(self._ios_routers, parent=self) wizard.show() if wizard.exec_(): ios_settings = wizard.getSettings() key = "{server}:{name}".format(server=ios_settings["server"], name=ios_settings["name"]) self._ios_routers[key] = IOS_ROUTER_SETTINGS.copy() self._ios_routers[key].update(ios_settings) if ios_settings["platform"] == "c7200": self._ios_routers[key]["midplane"] = "vxr" self._ios_routers[key]["npe"] = "npe-400" else: self._ios_routers[key]["iomem"] = 5 for slot_id in range(0, 7): slot = "slot{}".format(slot_id) if slot in ios_settings: self._ios_routers[key][slot] = ios_settings[slot] for wic_id in range(0, 3): wic = "wic{}".format(wic_id) if wic in ios_settings: self._ios_routers[key][wic] = ios_settings[wic] self._ios_routers[key].update(ios_settings) item = QtWidgets.QTreeWidgetItem(self.uiIOSRoutersTreeWidget) item.setText(0, self._ios_routers[key]["name"]) item.setIcon(0, QtGui.QIcon(self._ios_routers[key]["symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) self.uiIOSRoutersTreeWidget.setCurrentItem(item)
def _iouDeviceNewSlot(self): """ Creates a new IOU device. """ wizard = IOUDeviceWizard(self._iou_devices, parent=self) wizard.show() if wizard.exec_(): new_device_settings = wizard.getSettings() key = "{server}:{name}".format( server=new_device_settings["server"], name=new_device_settings["name"]) self._iou_devices[key] = IOU_DEVICE_SETTINGS.copy() self._iou_devices[key].update(new_device_settings) item = QtWidgets.QTreeWidgetItem(self.uiIOUDevicesTreeWidget) item.setText(0, self._iou_devices[key]["name"]) item.setIcon(0, QtGui.QIcon(self._iou_devices[key]["symbol"])) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) self.uiIOUDevicesTreeWidget.setCurrentItem(item)
def loadPreferences(self): """ Loads the Docker VM preferences. """ docker_module = Docker.instance() self._docker_containers = copy.deepcopy(docker_module.VMs()) self._items.clear() for key, docker_image in self._docker_containers.items(): item = QtWidgets.QTreeWidgetItem(self.uiDockerVMsTreeWidget) item.setText(0, docker_image["name"]) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(docker_image["symbol"])) item.setIcon(0, icon) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiDockerVMsTreeWidget.setCurrentItem(self._items[0]) self.uiDockerVMsTreeWidget.sortByColumn(0, QtCore.Qt.AscendingOrder) self.uiDockerVMsTreeWidget.setMaximumWidth( self.uiDockerVMsTreeWidget.sizeHintForColumn(0) + 10)
def __init__(self, parent): super().__init__(parent) self.setupUi(self) self._gns3_vm_settings = { "enable": True, "headless": False, "when_exit": "stop", "engine": "vmware", "vcpus": 1, "ram": 2048, "vmname": "GNS3 VM" } self.setWizardStyle(QtWidgets.QWizard.ModernStyle) if sys.platform.startswith("darwin"): # we want to see the cancel button on OSX self.setOptions(QtWidgets.QWizard.NoDefaultButton) self.uiLocalServerToolButton.clicked.connect( self._localServerBrowserSlot) self.uiGNS3VMDownloadLinkUrlLabel.setText('') self.uiRefreshPushButton.clicked.connect(self._refreshVMListSlot) self.uiVmwareRadioButton.clicked.connect(self._listVMwareVMsSlot) self.uiVirtualBoxRadioButton.clicked.connect( self._listVirtualBoxVMsSlot) self.uiVMwareBannerButton.clicked.connect( self._VMwareBannerButtonClickedSlot) settings = parent.settings() self.uiShowCheckBox.setChecked(settings["hide_setup_wizard"]) # by default all radio buttons are unchecked self.uiVmwareRadioButton.setAutoExclusive(False) self.uiVirtualBoxRadioButton.setAutoExclusive(False) self.uiVmwareRadioButton.setChecked(False) self.uiVirtualBoxRadioButton.setChecked(False) # Mandatory fields self.uiLocalServerWizardPage.registerField( "path*", self.uiLocalServerPathLineEdit) # load all available addresses for address in QtNetwork.QNetworkInterface.allAddresses(): address_string = address.toString() if address.protocol() != QtNetwork.QAbstractSocket.IPv6Protocol: self.uiLocalServerHostComboBox.addItem(address_string, address.toString()) if sys.platform.startswith("darwin"): self.uiVMwareBannerButton.setIcon( QtGui.QIcon(":/images/vmware_fusion_banner.jpg")) else: self.uiVMwareBannerButton.setIcon( QtGui.QIcon(":/images/vmware_workstation_banner.jpg")) if sys.platform.startswith("linux"): self.uiVMRadioButton.setText( "Run the topologies in an isolated and standard VM") self.uiLocalRadioButton.setText( "Run the topologies on my computer") self.uiLocalRadioButton.setChecked(True) self.uiLocalLabel.setVisible(False) Controller.instance().connected_signal.connect( self._refreshLocalServerStatusSlot) Controller.instance().connection_failed_signal.connect( self._refreshLocalServerStatusSlot)