Ejemplo n.º 1
0
    def saveSettings(self, settings, node=None, group=False):
        """
        Saves the TraceNG node settings.

        :param settings: the settings (dictionary)
        :param node: Node instance
        :param group: indicates the settings apply to a group of routers
        """

        # these settings cannot be shared by nodes and updated
        # in the node properties dialog.
        if not group:
            # set the node name
            name = self.uiNameLineEdit.text()
            if not name:
                QtWidgets.QMessageBox.critical(self, "Name", "TraceNG node name cannot be empty!")
            else:
                settings["name"] = name

            ip_address = self.uiIPAddressLineEdit.text().strip()
            if ip_address:
                try:
                    ipaddress.IPv4Address(ip_address)
                    settings["ip_address"] = ip_address
                except ipaddress.AddressValueError:
                    QtWidgets.QMessageBox.critical(self, "IP address", "Invalid IP address format")
                    if node:
                        raise ConfigurationError()

            settings["default_destination"] = self.uiDefaultDestinationLineEdit.text().strip()

        if not node:
            default_name_format = self.uiDefaultNameFormatLineEdit.text().strip()
            if '{0}' not in default_name_format and '{id}' not in default_name_format:
                QtWidgets.QMessageBox.critical(self, "Default name format", "The default name format must contain at least {0} or {id}")
            else:
                settings["default_name_format"] = default_name_format

            symbol_path = self.uiSymbolLineEdit.text()
            settings["symbol"] = symbol_path
            settings["category"] = self.uiCategoryComboBox.itemData(self.uiCategoryComboBox.currentIndex())
        return settings
    def _checkForLinkConnectedToWIC(self, wic_number, settings, node):
        """
        Checks if links are connected to a WIC.

        :param wic_number: WIC slot number
        :param settings: IOS router settings
        :param node: Node instance
        """

        node_ports = node.ports()
        for node_port in node_ports:
            # ports > 15 are WICs ones.
            if node_port.adapterNumber() == wic_number and node_port.portNumber() > 15 and not node_port.isFree():
                wic = settings["wic" + str(wic_number)]
                index = self._widget_wics[wic_number].findText(wic)
                if index != -1:
                    self._widget_wics[wic_number].setCurrentIndex(index)
                QtWidgets.QMessageBox.critical(self, node.name(), "A link is connected to port {} on {}, please remove it first".format(node_port.name(),
                                                                                                                                        wic))
                raise ConfigurationError()
    def _checkForLinkConnectedToAdapter(self, slot_number, settings, node):
        """
        Checks if links are connected to an adapter.

        :param slot_number: adapter slot number
        :param settings: IOS router settings
        :param node: Node instance
        """

        node_ports = node.ports()
        for node_port in node_ports:
            # ports > 15 are WICs ones.
            if node_port.adapterNumber() == slot_number and node_port.portNumber() <= 15 and not node_port.isFree():
                adapter = settings["slot" + str(slot_number)]
                index = self._widget_slots[slot_number].findText(adapter)
                if index != -1:
                    self._widget_slots[slot_number].setCurrentIndex(index)
                QtWidgets.QMessageBox.critical(self, node.name(), "A link is connected to port {} on adapter {}, please remove it first".format(node_port.name(),
                                                                                                                                                adapter))
                raise ConfigurationError()
Ejemplo n.º 4
0
    def saveSettings(self, settings, node, group=False):
        """
        Saves the Ethernet hub settings.

        :param settings: the settings (dictionary)
        :param node: Node instance
        :param group: indicates the settings apply to a group
        """

        if not group:
            # set the device name
            name = self.uiNameLineEdit.text()
            if not name:
                QtWidgets.QMessageBox.critical(
                    self, "Name", "Ethernet hub name cannot be empty!")
            else:
                settings["name"] = name
        else:
            del settings["name"]

        nbports = self.uiPortsSpinBox.value()

        # check that a link isn't connected to a port
        # before we delete it
        ports = node.ports()
        for port in ports:
            if not port.isFree() and port.portNumber() > nbports:
                self.loadSettings(settings, node)
                QtWidgets.QMessageBox.critical(
                    self, node.name(),
                    "A link is connected to port {}, please remove it first".
                    format(port.name()))
                raise ConfigurationError()

        settings["ports"] = []
        for port in range(1, nbports + 1):
            settings["ports"].append(str(port))
    def saveSettings(self, settings, node=None, group=False):
        """
        Saves the QEMU VM settings.

        :param settings: the settings (dictionary)
        :param node: Node instance
        :param group: indicates the settings apply to a group of VMs
        """

        # these settings cannot be shared by nodes and updated
        # in the node properties dialog.
        if not group:

            name = self.uiNameLineEdit.text()
            if not name:
                QtWidgets.QMessageBox.critical(
                    self, "Name", "The QEMU VM name cannot be empty!")
            else:
                settings["name"] = name

            if "linked_clone" in settings:
                settings["linked_clone"] = self.uiBaseVMCheckBox.isChecked()

            settings["hda_disk_image"] = self.uiHdaDiskImageLineEdit.text(
            ).strip()
            settings["hdb_disk_image"] = self.uiHdbDiskImageLineEdit.text(
            ).strip()
            settings["hdc_disk_image"] = self.uiHdcDiskImageLineEdit.text(
            ).strip()
            settings["hdd_disk_image"] = self.uiHddDiskImageLineEdit.text(
            ).strip()
            settings[
                "hda_disk_interface"] = self.uiHdaDiskInterfaceComboBox.currentText(
                )
            settings[
                "hdb_disk_interface"] = self.uiHdbDiskInterfaceComboBox.currentText(
                )
            settings[
                "hdc_disk_interface"] = self.uiHdcDiskInterfaceComboBox.currentText(
                )
            settings[
                "hdd_disk_interface"] = self.uiHddDiskInterfaceComboBox.currentText(
                )
            settings["cdrom_image"] = self.uiCdromImageLineEdit.text().strip()
            settings["bios_image"] = self.uiBiosImageLineEdit.text().strip()
            settings["initrd"] = self.uiInitrdLineEdit.text().strip()
            settings["kernel_image"] = self.uiKernelImageLineEdit.text().strip(
            )

            # check and save the MAC address
            mac = self.uiMacAddrLineEdit.text()
            if mac != ":::::":
                if not re.search(r"""^([0-9a-fA-F]{2}[:]){5}[0-9a-fA-F]{2}$""",
                                 mac):
                    QtWidgets.QMessageBox.critical(
                        self, "MAC address",
                        "Invalid MAC address (format required: hh:hh:hh:hh:hh:hh)"
                    )
                    if node:
                        raise ConfigurationError()
                else:
                    settings["mac_address"] = mac
            else:
                settings["mac_address"] = None

        if not node:
            # these are template settings

            # save the default name format
            default_name_format = self.uiDefaultNameFormatLineEdit.text(
            ).strip()
            if '{0}' not in default_name_format and '{id}' not in default_name_format:
                QtWidgets.QMessageBox.critical(
                    self, "Default name format",
                    "The default name format must contain at least {0} or {id}"
                )
            else:
                settings["default_name_format"] = default_name_format

            symbol_path = self.uiSymbolLineEdit.text()
            settings["symbol"] = symbol_path

            settings["category"] = self.uiCategoryComboBox.itemData(
                self.uiCategoryComboBox.currentIndex())
            port_name_format = self.uiPortNameFormatLineEdit.text()
            if '{0}' not in port_name_format and '{port0}' not in port_name_format and '{port1}' not in port_name_format:
                QtWidgets.QMessageBox.critical(
                    self, "Port name format",
                    "The format must contain at least {0}, {port0} or {port1}")
            else:
                settings[
                    "port_name_format"] = self.uiPortNameFormatLineEdit.text()

            port_segment_size = self.uiPortSegmentSizeSpinBox.value()
            if port_segment_size and '{1}' not in port_name_format and '{segment0}' not in port_name_format and '{segment1}' not in port_name_format:
                QtWidgets.QMessageBox.critical(
                    self, "Port name format",
                    "If the segment size is not 0, the format must contain {1}, {segment0} or {segment1}"
                )
            else:
                settings["port_segment_size"] = port_segment_size

            settings["first_port_name"] = self.uiFirstPortNameLineEdit.text(
            ).strip()

        if self.uiQemuListComboBox.count():
            qemu_path = self.uiQemuListComboBox.itemData(
                self.uiQemuListComboBox.currentIndex())
            settings["qemu_path"] = qemu_path

        settings["boot_priority"] = self.uiBootPriorityComboBox.itemData(
            self.uiBootPriorityComboBox.currentIndex())
        settings["console_type"] = self.uiConsoleTypeComboBox.currentText(
        ).lower()
        settings["adapter_type"] = self.uiAdapterTypesComboBox.itemData(
            self.uiAdapterTypesComboBox.currentIndex())
        settings["kernel_command_line"] = self.uiKernelCommandLineEdit.text()

        adapters = self.uiAdaptersSpinBox.value()
        if node and node.settings()["adapters"] != adapters:
            # check if the adapters settings have changed
            node_ports = node.ports()
            for node_port in node_ports:
                if not node_port.isFree():
                    QtWidgets.QMessageBox.critical(
                        self, node.name(),
                        "Changing the number of adapters while links are connected isn't supported yet! Please delete all the links first."
                    )
                    raise ConfigurationError()

        settings["adapters"] = adapters
        settings[
            "legacy_networking"] = self.uiLegacyNetworkingCheckBox.isChecked()
        settings["acpi_shutdown"] = self.uiACPIShutdownCheckBox.isChecked()
        settings["cpus"] = self.uiCPUSpinBox.value()
        settings["ram"] = self.uiRamSpinBox.value()
        if self.uiActivateCPUThrottlingCheckBox.isChecked():
            settings["cpu_throttling"] = self.uiCPUThrottlingSpinBox.value()
        else:
            settings["cpu_throttling"] = 0
        settings[
            "process_priority"] = self.uiProcessPriorityComboBox.currentText(
            ).lower()
        settings["options"] = self.uiQemuOptionsLineEdit.text()
        return settings
    def saveSettings(self, settings, node=None, group=False):
        """
        Saves the VMware VM settings.

        :param settings: the settings (dictionary)
        :param node: Node instance
        :param group: indicates the settings apply to a group of VMs
        """

        # these settings cannot be shared by nodes and updated
        # in the node properties dialog.
        if not group:

            if "name" in settings:
                name = self.uiNameLineEdit.text()
                if not name:
                    QtWidgets.QMessageBox.critical(
                        self, "Name", "VMware name cannot be empty!")
                else:
                    settings["name"] = name

            if "linked_base" in settings:
                settings["linked_base"] = self.uiBaseVMCheckBox.isChecked()

        if not node:
            # these are template settings

            # save the default name format
            default_name_format = self.uiDefaultNameFormatLineEdit.text(
            ).strip()
            if '{0}' not in default_name_format and '{id}' not in default_name_format:
                QtWidgets.QMessageBox.critical(
                    self, "Default name format",
                    "The default name format must contain at least {0} or {id}"
                )
            else:
                settings["default_name_format"] = default_name_format

            symbol_path = self.uiSymbolLineEdit.text()
            settings["symbol"] = symbol_path

            settings["category"] = self.uiCategoryComboBox.itemData(
                self.uiCategoryComboBox.currentIndex())
            port_name_format = self.uiPortNameFormatLineEdit.text()
            if '{0}' not in port_name_format and '{port0}' not in port_name_format and '{port1}' not in port_name_format:
                QtWidgets.QMessageBox.critical(
                    self, "Port name format",
                    "The format must contain at least {0}, {port0} or {port1}")
            else:
                settings[
                    "port_name_format"] = self.uiPortNameFormatLineEdit.text()

            port_segment_size = self.uiPortSegmentSizeSpinBox.value()
            if port_segment_size and '{1}' not in port_name_format and '{segment0}' not in port_name_format and '{segment1}' not in port_name_format:
                QtWidgets.QMessageBox.critical(
                    self, "Port name format",
                    "If the segment size is not 0, the format must contain {1}, {segment0} or {segment1}"
                )
            else:
                settings["port_segment_size"] = port_segment_size

            settings["first_port_name"] = self.uiFirstPortNameLineEdit.text(
            ).strip()

        settings["adapter_type"] = self.uiAdapterTypesComboBox.currentText()
        settings["use_any_adapter"] = self.uiUseAnyAdapterCheckBox.isChecked()
        settings["headless"] = self.uiHeadlessModeCheckBox.isChecked()
        settings["acpi_shutdown"] = self.uiACPIShutdownCheckBox.isChecked()

        adapters = self.uiAdaptersSpinBox.value()
        if node and node.settings()["adapters"] != adapters:
            # check if the adapters settings have changed
            for node_port in node.ports():
                if not node_port.isFree():
                    QtWidgets.QMessageBox.critical(
                        self, node.name(),
                        "Changing the number of adapters while links are connected isn't supported yet! Please delete all the links first."
                    )
                    raise ConfigurationError()
        settings["adapters"] = adapters
        return settings
Ejemplo n.º 7
0
    def saveSettings(self, settings, node=None, group=False):
        """
        Saves the VirtualBox VM settings.

        :param settings: the settings (dictionary)
        :param node: Node instance
        :param group: indicates the settings apply to a group of VMs
        """

        # these settings cannot be shared by nodes and updated
        # in the node properties dialog.
        if not group:

            if "name" in settings:
                name = self.uiNameLineEdit.text()
                if not name:
                    QtWidgets.QMessageBox.critical(
                        self, "Name", "VirtualBox name cannot be empty!")
                else:
                    settings["name"] = name

            if "linked_clone" in settings:
                settings["linked_clone"] = self.uiBaseVMCheckBox.isChecked()

        if not node:
            # these are template settings

            # save the default name format
            default_name_format = self.uiDefaultNameFormatLineEdit.text(
            ).strip()
            if '{0}' not in default_name_format and '{id}' not in default_name_format:
                QtWidgets.QMessageBox.critical(
                    self, "Default name format",
                    "The default name format must contain at least {0} or {id}"
                )
            else:
                settings["default_name_format"] = default_name_format

            symbol_path = self.uiSymbolLineEdit.text()
            settings["symbol"] = symbol_path
            settings["category"] = self.uiCategoryComboBox.itemData(
                self.uiCategoryComboBox.currentIndex())

            port_name_format = self.uiPortNameFormatLineEdit.text()
            port_segment_size = self.uiPortSegmentSizeSpinBox.value()
            first_port_name = self.uiFirstPortNameLineEdit.text().strip()

            try:
                StandardPortNameFactory(self.uiAdaptersSpinBox.value(),
                                        first_port_name, port_name_format,
                                        port_segment_size)
            except (IndexError, ValueError, KeyError):
                QtWidgets.QMessageBox.critical(self, "Invalid format",
                                               "Invalid port name format")
                raise ConfigurationError()

            settings["port_name_format"] = self.uiPortNameFormatLineEdit.text()
            settings["port_segment_size"] = port_segment_size
            settings["first_port_name"] = first_port_name

        settings["console_type"] = self.uiConsoleTypeComboBox.currentText(
        ).lower()
        settings[
            "console_auto_start"] = self.uiConsoleAutoStartCheckBox.isChecked(
            )
        settings["ram"] = self.uiVMRamSpinBox.value()
        settings["adapter_type"] = self.uiAdapterTypesComboBox.currentText()
        settings["headless"] = self.uiHeadlessModeCheckBox.isChecked()
        settings["on_close"] = self.uiOnCloseComboBox.itemData(
            self.uiOnCloseComboBox.currentIndex())
        settings["use_any_adapter"] = self.uiUseAnyAdapterCheckBox.isChecked()

        adapters = self.uiAdaptersSpinBox.value()
        if node:
            if node.settings()["adapters"] != adapters:
                # check if the adapters settings have changed
                node_ports = node.ports()
                for node_port in node_ports:
                    if not node_port.isFree():
                        QtWidgets.QMessageBox.critical(
                            self, node.name(),
                            "Changing the number of adapters while links are connected isn't supported yet! Please delete all the links first."
                        )
                        raise ConfigurationError()
        settings["adapters"] = adapters
        settings["custom_adapters"] = self._custom_adapters.copy()
        settings["usage"] = self.uiUsageTextEdit.toPlainText()
        return settings
Ejemplo n.º 8
0
    def saveSettings(self, settings, node=None, group=False):
        """
        Saves the router settings.

        :param settings: the settings (dictionary)
        :param node: Node instance
        :param group: indicates the settings apply to a group of routers
        """

        if not group:

            # Check if the Idle-PC value has been validated okay
            if not self._idle_valid:
                idle_pc = self.uiIdlepcLineEdit.text()
                QtWidgets.QMessageBox.critical(
                    self, "Idle-PC",
                    "{} is not a valid Idle-PC value ".format(idle_pc))
                raise ConfigurationError()

            # set the device name
            name = self.uiNameLineEdit.text()
            if not name:
                QtWidgets.QMessageBox.critical(
                    self, "Name", "IOS router name cannot be empty!")
            elif node and not node.validateHostname(name):
                QtWidgets.QMessageBox.critical(
                    self, "Name",
                    "Invalid name detected for IOS router: {}".format(name))
            else:
                settings["name"] = name

            # check and save the base MAC address
            mac = self.uiBaseMACLineEdit.text()
            if mac != "..":
                if not re.search(r"""^([0-9a-fA-F]{4}\.){2}[0-9a-fA-F]{4}$""",
                                 mac):
                    QtWidgets.QMessageBox.critical(
                        self, "MAC address",
                        "Invalid MAC address (format required: hhhh.hhhh.hhhh)"
                    )
                else:
                    settings["mac_addr"] = mac
            elif not node:
                settings["mac_addr"] = ""

            # save the IOS image path
            settings["image"] = self.uiIOSImageLineEdit.text()

        if not node:
            # these are template settings

            # save the default name format
            default_name_format = self.uiDefaultNameFormatLineEdit.text(
            ).strip()
            if '{0}' not in default_name_format and '{id}' not in default_name_format:
                QtWidgets.QMessageBox.critical(
                    self, "Default name format",
                    "The default name format must contain at least {0} or {id}"
                )
            else:
                settings["default_name_format"] = default_name_format

            startup_config = self.uiStartupConfigLineEdit.text().strip()
            if not startup_config:
                settings["startup_config"] = ""
            elif startup_config != settings["startup_config"]:
                if self._configFileValid(startup_config):
                    settings["startup_config"] = startup_config
                else:
                    QtWidgets.QMessageBox.critical(
                        self, "Startup-config",
                        "Cannot read the startup-config file")

            private_config = self.uiPrivateConfigLineEdit.text().strip()
            if not private_config:
                settings["private_config"] = ""
            elif private_config != settings["private_config"]:
                if self._configFileValid(private_config):
                    settings["private_config"] = private_config
                else:
                    QtWidgets.QMessageBox.critical(
                        self, "Private-config",
                        "Cannot read the private-config file")

            symbol_path = self.uiSymbolLineEdit.text()
            settings["symbol"] = symbol_path

            settings["category"] = self.uiCategoryComboBox.itemData(
                self.uiCategoryComboBox.currentIndex())

        # get the platform and chassis if applicable
        if node:
            platform = node.settings().get("platform")
        else:
            platform = settings.get("platform")
        if "chassis" in settings or (node and node.settings().get("chassis")):
            settings["chassis"] = self.uiChassisTextLabel.text()

        if platform == "c7200":
            # save the midplane and NPE settings
            settings["midplane"] = self.uiMidplaneComboBox.currentText()
            settings["npe"] = self.uiNPEComboBox.currentText()

            if node:
                sensors = []
                sensors.append(self.uiSensor1SpinBox.value())
                sensors.append(self.uiSensor2SpinBox.value())
                sensors.append(self.uiSensor3SpinBox.value())
                sensors.append(self.uiSensor4SpinBox.value())
                settings["sensors"] = sensors

                power_supplies = []
                if self.uiPowerSupply1ComboBox.currentIndex() == 0:
                    power_supplies.append(1)
                else:
                    power_supplies.append(0)

                if self.uiPowerSupply2ComboBox.currentIndex() == 0:
                    power_supplies.append(1)
                else:
                    power_supplies.append(0)
                settings["power_supplies"] = power_supplies
        else:
            # save the I/O memory setting
            settings["iomem"] = self.uiIomemSpinBox.value()

        # save the memories and disks settings
        settings["ram"] = self.uiRamSpinBox.value()
        settings["nvram"] = self.uiNvramSpinBox.value()
        settings["disk0"] = self.uiDisk0SpinBox.value()
        settings["disk1"] = self.uiDisk1SpinBox.value()
        settings["auto_delete_disks"] = self.uiAutoDeleteCheckBox.isChecked()

        # save the system ID (processor board ID in IOS) setting
        settings["system_id"] = self.uiSystemIdLineEdit.text()

        # save the exec area setting
        settings["exec_area"] = self.uiExecAreaSpinBox.value()

        # save the Idle-PC setting
        settings["idlepc"] = self.uiIdlepcLineEdit.text()

        # save the idlemax setting
        settings["idlemax"] = self.uiIdlemaxSpinBox.value()

        # save the idlesleep setting
        settings["idlesleep"] = self.uiIdlesleepSpinBox.value()

        # save the mmap setting
        settings["mmap"] = self.uiMmapCheckBox.isChecked()

        # load the sparsemem setting
        settings["sparsemem"] = self.uiSparseMemoryCheckBox.isChecked()

        # save the adapters and WICs configuration and
        # check if a module port is connected before removing or replacing.
        for slot_number, widget in self._widget_slots.items():
            if not widget.isEnabled():
                break
            module = widget.currentText()
            if module:
                if node:
                    settings["slot" + str(slot_number)] = node.settings().get(
                        "slot" + str(slot_number))

                if settings.get("slot" + str(slot_number)) and settings.get(
                        "slot" + str(slot_number)) != module:
                    if node:
                        self._checkForLinkConnectedToAdapter(
                            slot_number, settings, node)
                settings["slot" + str(slot_number)] = module
            elif "slot" + str(slot_number) in settings and settings[
                    "slot" + str(slot_number)]:
                if node:
                    self._checkForLinkConnectedToAdapter(
                        slot_number, settings, node)
                settings["slot" + str(slot_number)] = ""

        for wic_number, widget in self._widget_wics.items():
            if not widget.isEnabled():
                break
            wic_name = str(widget.currentText())
            if wic_name:
                if node:
                    settings["wic" + str(wic_number)] = node.settings().get(
                        "wic" + str(wic_number))

                if settings["wic" + str(wic_number)] and settings[
                        "wic" + str(wic_number)] != wic_name:
                    if node:
                        self._checkForLinkConnectedToWIC(
                            wic_number, settings, node)
                settings["wic" + str(wic_number)] = wic_name
            elif "wic" + str(wic_number) in settings and settings[
                    "wic" + str(wic_number)]:
                if node:
                    self._checkForLinkConnectedToWIC(wic_number, settings,
                                                     node)
                settings["wic" + str(wic_number)] = ""
        return settings
    def saveSettings(self, settings, node=None, group=False):
        """
        Saves the IOU device settings.

        :param settings: the settings (dictionary)
        :param node: Node instance
        :param group: indicates the settings apply to a group of routers
        """

        # these settings cannot be shared by nodes and updated
        # in the node properties dialog.
        if not group:
            # set the device name
            name = self.uiNameLineEdit.text()
            if not name:
                QtWidgets.QMessageBox.critical(
                    self, "Name", "IOU device name cannot be empty!")
            elif node and not node.validateHostname(name):
                QtWidgets.QMessageBox.critical(
                    self, "Name",
                    "Invalid name detected for IOU device: {}".format(name))
            else:
                settings["name"] = name

            # save the IOU image path
            ios_path = self.uiIOUImageLineEdit.text().strip()
            if ios_path:
                settings["path"] = ios_path

        if not node:
            # these are template settings

            # save the default name format
            default_name_format = self.uiDefaultNameFormatLineEdit.text(
            ).strip()
            if '{0}' not in default_name_format and '{id}' not in default_name_format:
                QtWidgets.QMessageBox.critical(
                    self, "Default name format",
                    "The default name format must contain at least {0} or {id}"
                )
            else:
                settings["default_name_format"] = default_name_format

            # save the startup-config
            startup_config = self.uiStartupConfigLineEdit.text().strip()
            if not startup_config:
                settings["startup_config"] = ""
            elif startup_config != settings["startup_config"]:
                if self._configFileValid(startup_config):
                    settings["startup_config"] = startup_config
                else:
                    QtWidgets.QMessageBox.critical(
                        self, "Startup-config",
                        "Cannot read the startup-config file")

            # save the private-config
            private_config = self.uiPrivateConfigLineEdit.text().strip()
            if not private_config:
                settings["private_config"] = ""
            elif private_config != settings["private_config"]:
                if self._configFileValid(private_config):
                    settings["private_config"] = private_config
                else:
                    QtWidgets.QMessageBox.critical(
                        self, "Private-config",
                        "Cannot read the private-config file")

            settings["symbol"] = self.uiSymbolLineEdit.text()
            settings["category"] = self.uiCategoryComboBox.itemData(
                self.uiCategoryComboBox.currentIndex())

        # save advanced settings
        settings["l1_keepalives"] = self.uiL1KeepalivesCheckBox.isChecked()
        settings[
            "use_default_iou_values"] = self.uiDefaultValuesCheckBox.isChecked(
            )
        settings["ram"] = self.uiRamSpinBox.value()
        settings["nvram"] = self.uiNvramSpinBox.value()

        ethernet_adapters = self.uiEthernetAdaptersSpinBox.value()
        serial_adapters = self.uiSerialAdaptersSpinBox.value()
        if ethernet_adapters + serial_adapters > 16:
            QtWidgets.QMessageBox.warning(
                self, settings["name"],
                "The total number of adapters cannot exceed 16")
            raise ConfigurationError()

        if node:
            if node.settings(
            )["ethernet_adapters"] != ethernet_adapters or node.settings(
            )["serial_adapters"] != serial_adapters:
                # check if the adapters settings have changed
                node_ports = node.ports()
                for node_port in node_ports:
                    if not node_port.isFree():
                        QtWidgets.QMessageBox.critical(
                            self, node.name(),
                            "Changing the number of adapters while links are connected isn't supported yet! Please delete all the links first."
                        )
                        raise ConfigurationError()

        settings["ethernet_adapters"] = ethernet_adapters
        settings["serial_adapters"] = serial_adapters
        return settings
Ejemplo n.º 10
0
    def saveSettings(self, settings, node=None, group=False):
        """
        Saves the Ethernet hub settings.

        :param settings: the settings (dictionary)
        :param node: Node instance
        :param group: indicates the settings apply to a group
        """

        if not group:
            # set the device name
            name = self.uiNameLineEdit.text()
            if not name:
                QtWidgets.QMessageBox.critical(
                    self, "Name", "Ethernet hub name cannot be empty!")
            else:
                settings["name"] = name

        nb_ports = self.uiPortsSpinBox.value()

        if node:
            # check that a link isn't connected to a port before we delete it
            ports = node.ports()
            for port in ports:
                if not port.isFree() and port.portNumber() > nb_ports:
                    self.loadSettings(settings, node)
                    QtWidgets.QMessageBox.critical(
                        self, node.name(),
                        "A link is connected to port {}, please remove it first"
                        .format(port.name()))
                    raise ConfigurationError()

        else:
            # these are template settings

            # save the default name format
            default_name_format = self.uiDefaultNameFormatLineEdit.text(
            ).strip()
            if '{0}' not in default_name_format and '{id}' not in default_name_format:
                QtWidgets.QMessageBox.critical(
                    self, "Default name format",
                    "The default name format must contain at least {0} or {id}"
                )
            else:
                settings["default_name_format"] = default_name_format

            symbol_path = self.uiSymbolLineEdit.text()
            settings["symbol"] = symbol_path

            settings["category"] = self.uiCategoryComboBox.itemData(
                self.uiCategoryComboBox.currentIndex())

        settings["ports_mapping"] = []
        for port_number in range(0, nb_ports):
            settings["ports_mapping"].append({
                "port_number":
                int(port_number),
                "name":
                "Ethernet{}".format(port_number)
            })
        return settings