예제 #1
0
    def __init__(self, iou_devices, parent):

        super().__init__(iou_devices, IOU.instance().settings()["use_local_server"], parent)
        self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/multilayer_switch.svg"))

        self.uiTypeComboBox.currentIndexChanged[str].connect(self._typeChangedSlot)

        if sys.platform.startswith("win") or sys.platform.startswith("darwin"):
            # Cannot use IOU locally on Windows and Mac
            self.uiLocalRadioButton.setEnabled(False)

        # Available types
        self.uiTypeComboBox.addItems(["L2 image", "L3 image"])

        # Mandatory fields
        self.uiNameWizardPage.registerField("name*", self.uiNameLineEdit)
        self.uiNameWizardPage.registerField("image*", self.uiIOUImageLineEdit)

        self.uiIOUImageLineEdit.textChanged.connect(self._imageLineEditTextChangedSlot)

        # location of the base config templates
        self._base_iou_l2_config_template = get_resource(os.path.join("configs", "iou_l2_base_startup-config.txt"))
        self._base_iou_l3_config_template = get_resource(os.path.join("configs", "iou_l3_base_startup-config.txt"))

        from ..pages.iou_device_preferences_page import IOUDevicePreferencesPage
        self.addImageSelector(self.uiExistingImageRadioButton, self.uiIOUImageListComboBox, self.uiIOUImageLineEdit, self.uiIOUImageToolButton, IOUDevicePreferencesPage.getIOUImage)
예제 #2
0
    def __init__(self, ios_routers, parent):

        super().__init__(ios_routers,
                         Dynamips.instance().settings()["use_local_server"],
                         parent)
        self.setPixmap(QtWidgets.QWizard.LogoPixmap,
                       QtGui.QPixmap(":/symbols/router.svg"))

        self.uiTestIOSImagePushButton.clicked.connect(self._testIOSImageSlot)
        self.uiIdlePCFinderPushButton.clicked.connect(self._idlePCFinderSlot)
        self.uiEtherSwitchCheckBox.stateChanged.connect(self._etherSwitchSlot)
        self.uiPlatformComboBox.currentIndexChanged[str].connect(
            self._platformChangedSlot)
        self.uiPlatformComboBox.addItems(list(PLATFORMS_DEFAULT_RAM.keys()))

        self._router = None
        # Validate the Idle PC value
        self._idle_valid = False
        idle_pc_rgx = QtCore.QRegExp("^(0x[0-9a-fA-F]{8})?$")
        validator = QtGui.QRegExpValidator(idle_pc_rgx, self)
        self.uiIdlepcLineEdit.setValidator(validator)
        self.uiIdlepcLineEdit.textChanged.connect(self._idlePCValidateSlot)
        self.uiIdlepcLineEdit.textChanged.emit(self.uiIdlepcLineEdit.text())

        # location of the base config templates
        self._base_startup_config_template = get_resource(
            os.path.join("configs", "ios_base_startup-config.txt"))
        self._base_etherswitch_startup_config_template = get_resource(
            os.path.join("configs", "ios_etherswitch_startup-config.txt"))

        # FIXME: hide because of issue on Windows.
        self.uiTestIOSImagePushButton.hide()

        # Mandatory fields
        self.uiNameWizardPage.registerField("name*", self.uiNameLineEdit)
        self.uiIOSImageWizardPage.registerField("image*",
                                                self.uiIOSImageLineEdit)

        self._widget_slots = {
            0: self.uiSlot0comboBox,
            1: self.uiSlot1comboBox,
            2: self.uiSlot2comboBox,
            3: self.uiSlot3comboBox,
            4: self.uiSlot4comboBox,
            5: self.uiSlot5comboBox,
            6: self.uiSlot6comboBox
        }

        self._widget_wics = {
            0: self.uiWic0comboBox,
            1: self.uiWic1comboBox,
            2: self.uiWic2comboBox
        }

        from ..pages.ios_router_preferences_page import IOSRouterPreferencesPage
        self.addImageSelector(self.uiIOSExistingImageRadioButton,
                              self.uiIOSImageListComboBox,
                              self.uiIOSImageLineEdit,
                              self.uiIOSImageToolButton,
                              IOSRouterPreferencesPage.getIOSImage)
    def __init__(self):

        super().__init__()
        self.setupUi(self)

        self.uiSymbolToolButton.clicked.connect(self._symbolBrowserSlot)
        self.uiStartupConfigToolButton.clicked.connect(
            self._startupConfigBrowserSlot)
        self.uiPrivateConfigToolButton.clicked.connect(
            self._privateConfigBrowserSlot)
        self.uiIOUImageToolButton.clicked.connect(self._iouImageBrowserSlot)
        self.uiDefaultValuesCheckBox.stateChanged.connect(
            self._useDefaultValuesSlot)
        self._current_iou_image = ""
        self._compute_id = None

        # location of the base config templates
        self._base_iou_l2_config_template = get_resource(
            os.path.join("configs", "iou_l2_base_startup-config.txt"))
        self._base_iou_l3_config_template = get_resource(
            os.path.join("configs", "iou_l3_base_startup-config.txt"))
        self._default_configs_dir = LocalServer.instance().localServerSettings(
        )["configs_path"]

        # add the categories
        for name, category in Node.defaultCategories().items():
            self.uiCategoryComboBox.addItem(name, category)
예제 #4
0
    def __init__(self, ios_routers, parent):

        QtGui.QWizard.__init__(self, parent)
        self.setupUi(self)
        self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/router.normal.svg"))
        self.setWizardStyle(QtGui.QWizard.ModernStyle)
        if sys.platform.startswith("darwin"):
            # we want to see the cancel button on OSX
            self.setOptions(QtGui.QWizard.NoDefaultButton)

        self.uiRemoteRadioButton.toggled.connect(self._remoteServerToggledSlot)
        self.uiLoadBalanceCheckBox.toggled.connect(self._loadBalanceToggledSlot)
        self.uiIOSImageToolButton.clicked.connect(self._iosImageBrowserSlot)
        self.uiTestIOSImagePushButton.clicked.connect(self._testIOSImageSlot)
        self.uiIdlePCFinderPushButton.clicked.connect(self._idlePCFinderSlot)
        self.uiEtherSwitchCheckBox.stateChanged.connect(self._etherSwitchSlot)
        self.uiPlatformComboBox.currentIndexChanged[str].connect(self._platformChangedSlot)
        self.uiPlatformComboBox.addItems(list(PLATFORMS_DEFAULT_RAM.keys()))

        self._router = None
        # Validate the Idle PC value
        self._idle_valid = False
        idle_pc_rgx = QtCore.QRegExp("^(0x[0-9a-fA-F]{8})?$")
        validator = QtGui.QRegExpValidator(idle_pc_rgx, self)
        self.uiIdlepcLineEdit.setValidator(validator)
        self.uiIdlepcLineEdit.textChanged.connect(self._idlePCValidateSlot)
        self.uiIdlepcLineEdit.textChanged.emit(self.uiIdlepcLineEdit.text())

        # location of the base config templates
        self._base_startup_config_template = get_resource(os.path.join("configs", "ios_base_startup-config.txt"))
        self._base_private_config_template = get_resource(os.path.join("configs", "ios_base_private-config.txt"))
        self._base_etherswitch_startup_config_template = get_resource(os.path.join("configs", "ios_etherswitch_startup-config.txt"))

        # FIXME: hide because of issue on Windows.
        self.uiTestIOSImagePushButton.hide()

        # Mandatory fields
        self.uiNamePlatformWizardPage.registerField("name*", self.uiNameLineEdit)
        self.uiIOSImageWizardPage.registerField("image*", self.uiIOSImageLineEdit)

        self._widget_slots = {0: self.uiSlot0comboBox,
                              1: self.uiSlot1comboBox,
                              2: self.uiSlot2comboBox,
                              3: self.uiSlot3comboBox,
                              4: self.uiSlot4comboBox,
                              5: self.uiSlot5comboBox,
                              6: self.uiSlot6comboBox}

        self._widget_wics = {0: self.uiWic0comboBox,
                             1: self.uiWic1comboBox,
                             2: self.uiWic2comboBox}

        self._ios_routers = ios_routers

        if Dynamips.instance().settings()["use_local_server"]:
            # skip the server page if we use the local server
            self.setStartId(1)

        if not ENABLE_CLOUD:
            self.uiCloudRadioButton.hide()
예제 #5
0
    def __init__(self, ios_routers, parent):

        QtGui.QWizard.__init__(self, parent)
        self.setupUi(self)
        self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/router.normal.svg"))
        self.setWizardStyle(QtGui.QWizard.ModernStyle)
        if sys.platform.startswith("darwin"):
            # we want to see the cancel button on OSX
            self.setOptions(QtGui.QWizard.NoDefaultButton)

        self.uiRemoteRadioButton.toggled.connect(self._remoteServerToggledSlot)
        self.uiLoadBalanceCheckBox.toggled.connect(self._loadBalanceToggledSlot)
        self.uiIOSImageToolButton.clicked.connect(self._iosImageBrowserSlot)
        self.uiTestIOSImagePushButton.clicked.connect(self._testIOSImageSlot)
        self.uiIdlePCFinderPushButton.clicked.connect(self._idlePCFinderSlot)
        self.uiEtherSwitchCheckBox.stateChanged.connect(self._etherSwitchSlot)
        self.uiPlatformComboBox.currentIndexChanged[str].connect(self._platformChangedSlot)
        self.uiPlatformComboBox.addItems(list(PLATFORMS_DEFAULT_RAM.keys()))

        self._router = None
        # Validate the Idle PC value
        self._idle_valid = False
        idle_pc_rgx = QtCore.QRegExp("^(0x[0-9a-fA-F]{8})?$")
        validator = QtGui.QRegExpValidator(idle_pc_rgx, self)
        self.uiIdlepcLineEdit.setValidator(validator)
        self.uiIdlepcLineEdit.textChanged.connect(self._idlePCValidateSlot)
        self.uiIdlepcLineEdit.textChanged.emit(self.uiIdlepcLineEdit.text())

        # location of the base config templates
        self._base_startup_config_template = get_resource(os.path.join("configs", "ios_base_startup-config.txt"))
        self._base_private_config_template = get_resource(os.path.join("configs", "ios_base_private-config.txt"))
        self._base_etherswitch_startup_config_template = get_resource(os.path.join("configs", "ios_etherswitch_startup-config.txt"))

        # FIXME: hide because of issue on Windows.
        self.uiTestIOSImagePushButton.hide()

        # Mandatory fields
        self.uiNamePlatformWizardPage.registerField("name*", self.uiNameLineEdit)
        self.uiIOSImageWizardPage.registerField("image*", self.uiIOSImageLineEdit)

        self._widget_slots = {0: self.uiSlot0comboBox,
                              1: self.uiSlot1comboBox,
                              2: self.uiSlot2comboBox,
                              3: self.uiSlot3comboBox,
                              4: self.uiSlot4comboBox,
                              5: self.uiSlot5comboBox,
                              6: self.uiSlot6comboBox}

        self._widget_wics = {0: self.uiWic0comboBox,
                             1: self.uiWic1comboBox,
                             2: self.uiWic2comboBox}

        self._ios_routers = ios_routers

        if Dynamips.instance().settings()["use_local_server"]:
            # skip the server page if we use the local server
            self.setStartId(1)

        if not ENABLE_CLOUD:
            self.uiCloudRadioButton.hide()
    def __init__(self):

        QtGui.QWidget.__init__(self)
        self.setupUi(self)
        self.uiInitialConfigToolButton.clicked.connect(self._initialConfigBrowserSlot)
        self.uiIOUImageToolButton.clicked.connect(self._iouImageBrowserSlot)
        self.uiDefaultValuesCheckBox.stateChanged.connect(self._useDefaultValuesSlot)
        self._current_iou_image = ""

        # location of the base config templates
        self._base_iou_l2_config_template = get_resource(os.path.join("configs", "iou_l2_base_initial-config.txt"))
        self._base_iou_l3_config_template = get_resource(os.path.join("configs", "iou_l3_base_initial-config.txt"))
예제 #7
0
    def __init__(self, ios_routers, parent):

        super().__init__(ios_routers, parent)
        self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/router.svg"))

        self.uiTestIOSImagePushButton.clicked.connect(self._testIOSImageSlot)
        self.uiIdlePCFinderPushButton.clicked.connect(self._idlePCFinderSlot)
        self.uiEtherSwitchCheckBox.stateChanged.connect(self._etherSwitchSlot)
        self.uiPlatformComboBox.currentIndexChanged[str].connect(self._platformChangedSlot)
        self.uiPlatformComboBox.addItems(list(PLATFORMS_DEFAULT_RAM.keys()))

        self._router = None
        # Validate the Idle PC value
        self._idle_valid = False

        # True if we have create a temporary project for computing IDLE PC
        self._project_created = False

        idle_pc_rgx = QtCore.QRegExp("^(0x[0-9a-fA-F]{8})?$")
        validator = QtGui.QRegExpValidator(idle_pc_rgx, self)
        self.uiIdlepcLineEdit.setValidator(validator)
        self.uiIdlepcLineEdit.textChanged.connect(self._idlePCValidateSlot)
        self.uiIdlepcLineEdit.textChanged.emit(self.uiIdlepcLineEdit.text())

        # location of the base config templates
        self._base_startup_config_template = get_resource(os.path.join("configs", "ios_base_startup-config.txt"))
        self._base_etherswitch_startup_config_template = get_resource(os.path.join("configs", "ios_etherswitch_startup-config.txt"))

        # FIXME: hide because of issue on Windows.
        self.uiTestIOSImagePushButton.hide()

        # Mandatory fields
        self.uiNameWizardPage.registerField("name*", self.uiNameLineEdit)
        self.uiIOSImageWizardPage.registerField("image*", self.uiIOSImageLineEdit)

        self._widget_slots = {0: self.uiSlot0comboBox,
                              1: self.uiSlot1comboBox,
                              2: self.uiSlot2comboBox,
                              3: self.uiSlot3comboBox,
                              4: self.uiSlot4comboBox,
                              5: self.uiSlot5comboBox,
                              6: self.uiSlot6comboBox}

        self._widget_wics = {0: self.uiWic0comboBox,
                             1: self.uiWic1comboBox,
                             2: self.uiWic2comboBox}

        from ..pages.ios_router_preferences_page import IOSRouterPreferencesPage
        self.addImageSelector(self.uiIOSExistingImageRadioButton,
                              self.uiIOSImageListComboBox,
                              self.uiIOSImageLineEdit,
                              self.uiIOSImageToolButton,
                              IOSRouterPreferencesPage.getIOSImage)
    def getSettings(self):
        """
        Returns the settings set in this Wizard.

        :return: settings dict
        """

        path = self.uiIOUImageLineEdit.text()

        initial_config = ""
        if self.uiTypeComboBox.currentText() == "L2 image":
            # set the default L2 base initial-config
            resource_name = get_resource(os.path.join("configs", "iou_l2_base_initial-config.txt"))
            if resource_name:
                initial_config = resource_name
            default_symbol = ":/symbols/multilayer_switch.normal.svg"
            hover_symbol = ":/symbols/multilayer_switch.selected.svg"
            category = Node.switches
        else:
            # set the default L3 base initial-config
            resource_name = get_resource(os.path.join("configs", "iou_l3_base_initial-config.txt"))
            if resource_name:
                initial_config = resource_name
            default_symbol = ":/symbols/router.normal.svg"
            hover_symbol = ":/symbols/router.selected.svg"
            category = Node.routers

        if IOU.instance().settings()["use_local_server"] or self.uiLocalRadioButton.isChecked():
            server = "local"
        elif self.uiRemoteRadioButton.isChecked():
            if self.uiLoadBalanceCheckBox.isChecked():
                server = next(iter(Servers.instance()))
                server = "{}:{}".format(server.host, server.port)
            else:
                server = self.uiRemoteServersComboBox.currentText()
        else: # Cloud is selected
            server = "cloud"

        settings = {
            "name": self.uiNameLineEdit.text(),
            "path": path,
            "image": os.path.basename(path),
            "initial_config": initial_config,
            "default_symbol": default_symbol,
            "category": category,
            "hover_symbol": hover_symbol,
            "server": server,
        }

        return settings
예제 #9
0
    def createNode(self, node, node_name):
        """
        Creates a node.

        :param node: Node instance
        :param node_name: Node name
        """

        log.info("creating node {}".format(node))

        if node_name:
            for node_key, info in self._vpcs_nodes.items():
                if node_name == info["name"]:
                    vm_settings = {}
                    for setting_name, value in self._vpcs_nodes[
                            node_key].items():

                        if setting_name in node.settings(
                        ) and setting_name != "name" and value != "" and value is not None:
                            vm_settings[setting_name] = value

                    node.create(
                        default_name_format=info["default_name_format"],
                        additional_settings=vm_settings)
                    return

        vm_settings = {
            "base_script_file":
            self._settings.get(
                "base_script_file",
                get_default_base_config(
                    get_resource(
                        os.path.join("configs", "vpcs_base_config.txt"))))
        }
        node.create(additional_settings=vm_settings)
예제 #10
0
def getTopologyValidationErrors(topology):
    """
    Apply a JSON schema to a topology

    :param topology: A dict of the topology
    :returns: Return None if ok otherwise an error message
    """

    with open(get_resource(os.path.join("schemas", "topology.json"))) as f:
        schema = json.load(f)

    v = jsonschema.Draft4Validator(schema)
    errors = sorted(v.iter_errors(topology), key=lambda e: e.path)
    if len(errors) == 0:
        return None

    error_message = ""
    for error in errors:
        # Uncomment for more details
        # for suberror in sorted(error.context, key=lambda e: e.schema_path):
        #    print(list(suberror.schema_path), suberror.message, sep=", ")
        error_message += "{}\n".format(str(error))

    error_message += "Best error message: {}\n".format(jsonschema.exceptions.best_match(v.iter_errors(topology)).message)
    return error_message
    def __init__(self):

        QtGui.QWidget.__init__(self)
        self.setupUi(self)
        self.uiInitialConfigToolButton.clicked.connect(
            self._initialConfigBrowserSlot)
        self.uiIOUImageToolButton.clicked.connect(self._iouImageBrowserSlot)
        self.uiDefaultValuesCheckBox.stateChanged.connect(
            self._useDefaultValuesSlot)
        self._current_iou_image = ""

        # location of the base config templates
        self._base_iou_l2_config_template = get_resource(
            os.path.join("configs", "iou_l2_base_initial-config.txt"))
        self._base_iou_l3_config_template = get_resource(
            os.path.join("configs", "iou_l3_base_initial-config.txt"))
예제 #12
0
    def _loadSettings(self):
        """
        Loads the settings from the persistent settings file.
        """

        local_config = LocalConfig.instance()

        # restore the VPCS settings from QSettings (for backward compatibility)
        legacy_settings = {}
        settings = QtCore.QSettings()
        settings.beginGroup(self.__class__.__name__)
        for name in VPCS_SETTINGS.keys():
            if settings.contains(name):
                legacy_settings[name] = settings.value(
                    name, type=VPCS_SETTING_TYPES[name])
        settings.remove("")
        settings.endGroup()

        if legacy_settings:
            local_config.saveSectionSettings(self.__class__.__name__,
                                             legacy_settings)
        self._settings = local_config.loadSectionSettings(
            self.__class__.__name__, VPCS_SETTINGS)

        if not self._settings["base_script_file"]:
            self._settings["base_script_file"] = get_default_base_config(
                get_resource(os.path.join("configs", "vpcs_base_config.txt")))

        if not os.path.exists(self._settings["vpcs_path"]):
            self._settings["vpcs_path"] = self._findVPCS(self)

        # keep the config file sync
        self._saveSettings()
예제 #13
0
def getTopologyValidationErrors(topology):
    """
    Apply a JSON schema to a topology

    :param topology: A dict of the topology
    :returns: Return None if ok otherwise an error message
    """

    with open(get_resource(os.path.join("schemas", "topology.json"))) as f:
        schema = json.load(f)

    v = jsonschema.Draft4Validator(schema)
    errors = sorted(v.iter_errors(topology), key=lambda e: e.path)
    if len(errors) == 0:
        return None

    error_message = ""
    for error in errors:
        # Uncomment for more details
        # for suberror in sorted(error.context, key=lambda e: e.schema_path):
        #    print(list(suberror.schema_path), suberror.message, sep=", ")
        error_message += "{}\n".format(str(error))

    error_message += "Best error message: {}\n".format(
        jsonschema.exceptions.best_match(v.iter_errors(topology)).message)
    return error_message
예제 #14
0
    def _loadSettings(self):
        """
        Loads the settings from the persistent settings file.
        """

        local_config = LocalConfig.instance()

        # restore the VPCS settings from QSettings (for backward compatibility)
        legacy_settings = {}
        settings = QtCore.QSettings()
        settings.beginGroup(self.__class__.__name__)
        for name in VPCS_SETTINGS.keys():
            if settings.contains(name):
                legacy_settings[name] = settings.value(name, type=VPCS_SETTING_TYPES[name])
        settings.remove("")
        settings.endGroup()

        if legacy_settings:
            local_config.saveSectionSettings(self.__class__.__name__, legacy_settings)
        self._settings = local_config.loadSectionSettings(self.__class__.__name__, VPCS_SETTINGS)

        if not self._settings["base_script_file"]:
            self._settings["base_script_file"] = get_default_base_config(get_resource(os.path.join("configs", "vpcs_base_config.txt")))

        if not os.path.exists(self._settings["vpcs_path"]):
            self._settings["vpcs_path"] = self._findVPCS(self)

        # keep the config file sync
        self._saveSettings()
예제 #15
0
    def __init__(self, iou_devices, parent):

        QtGui.QWizard.__init__(self, parent)
        self.setupUi(self)
        self.setPixmap(QtGui.QWizard.LogoPixmap,
                       QtGui.QPixmap(":/symbols/multilayer_switch.normal.svg"))
        self.setWizardStyle(QtGui.QWizard.ModernStyle)
        if sys.platform.startswith("darwin"):
            # we want to see the cancel button on OSX
            self.setOptions(QtGui.QWizard.NoDefaultButton)

        self.uiRemoteRadioButton.toggled.connect(self._remoteServerToggledSlot)
        self.uiLoadBalanceCheckBox.toggled.connect(
            self._loadBalanceToggledSlot)
        self.uiIOUImageToolButton.clicked.connect(self._iouImageBrowserSlot)
        self.uiTypeComboBox.currentIndexChanged[str].connect(
            self._typeChangedSlot)

        if sys.platform.startswith("win") or sys.platform.startswith("darwin"):
            # Cannot use IOU locally on Windows
            self.uiLocalRadioButton.setEnabled(False)

        # Available types
        self.uiTypeComboBox.addItems(["L2 image", "L3 image"])

        # Mandatory fields
        self.uiNameImageWizardPage.registerField("name*", self.uiNameLineEdit)
        self.uiNameImageWizardPage.registerField("image*",
                                                 self.uiIOUImageLineEdit)

        self._iou_devices = iou_devices

        if IOU.instance().settings()["use_local_server"]:
            # skip the server page if we use the local server
            self.setStartId(1)
        else:
            self.uiIOUImageToolButton.setEnabled(False)

        if not ENABLE_CLOUD:
            self.uiCloudRadioButton.hide()

        # location of the base config templates
        self._base_iou_l2_config_template = get_resource(
            os.path.join("configs", "iou_l2_base_initial-config.txt"))
        self._base_iou_l3_config_template = get_resource(
            os.path.join("configs", "iou_l3_base_initial-config.txt"))
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.setupUi(self)

        self._main_window = MainWindow.instance()
        self._ios_routers = {}
        self._items = []

        self.uiNewIOSRouterPushButton.clicked.connect(self._iosRouterNewSlot)
        self.uiEditIOSRouterPushButton.clicked.connect(self._iosRouterEditSlot)
        self.uiDeleteIOSRouterPushButton.clicked.connect(self._iosRouterDeleteSlot)
        self.uiIOSRoutersTreeWidget.currentItemChanged.connect(self._iosRouterChangedSlot)
        self.uiIOSRoutersTreeWidget.itemPressed.connect(self._iosRouterPressedSlot)
        self.uiDecompressIOSPushButton.clicked.connect(self._decompressIOSSlot)

        self._base_startup_config_template = get_resource(os.path.join("configs", "ios_base_startup-config.txt"))
        self._base_private_config_template = get_resource(os.path.join("configs", "ios_base_private-config.txt"))
        self._base_configs_to_delete = []
    def _iouImageBrowserSlot(self):
        """
        Slot to open a file browser and select an IOU image.
        """

        path = self.getIOUImage(self)
        if not path:
            return
        self.uiIOUPathLineEdit.clear()
        self.uiIOUPathLineEdit.setText(path)

        if "l2" in path:
            # set the default L2 base initial-config
            resource_name = get_resource(os.path.join("configs", "iou_l2_base_initial-config.txt"))
            if resource_name:
                self.uiInitialConfigLineEdit.setText(resource_name)
        else:
            # set the default L3 base initial-config
            resource_name = get_resource(os.path.join("configs", "iou_l3_base_initial-config.txt"))
            if resource_name:
                self.uiInitialConfigLineEdit.setText(resource_name)
    def __init__(self):

        super().__init__()
        self.setupUi(self)

        self.uiSymbolToolButton.clicked.connect(self._symbolBrowserSlot)
        self.uiStartupConfigToolButton.clicked.connect(self._startupConfigBrowserSlot)
        self.uiPrivateConfigToolButton.clicked.connect(self._privateConfigBrowserSlot)
        self.uiIOUImageToolButton.clicked.connect(self._iouImageBrowserSlot)
        self.uiDefaultValuesCheckBox.stateChanged.connect(self._useDefaultValuesSlot)
        self._current_iou_image = ""
        self._server = None

        # location of the base config templates
        self._base_iou_l2_config_template = get_resource(os.path.join("configs", "iou_l2_base_startup-config.txt"))
        self._base_iou_l3_config_template = get_resource(os.path.join("configs", "iou_l3_base_startup-config.txt"))
        self._default_configs_dir = Servers.instance().localServerSettings()["configs_path"]

        # add the categories
        for name, category in Node.defaultCategories().items():
            self.uiCategoryComboBox.addItem(name, category)
예제 #19
0
    def __init__(self, iou_devices, parent):

        QtGui.QWizard.__init__(self, parent)
        self.setupUi(self)
        self.setPixmap(QtGui.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/multilayer_switch.normal.svg"))
        self.setWizardStyle(QtGui.QWizard.ModernStyle)
        if sys.platform.startswith("darwin"):
            # we want to see the cancel button on OSX
            self.setOptions(QtGui.QWizard.NoDefaultButton)

        self.uiRemoteRadioButton.toggled.connect(self._remoteServerToggledSlot)
        self.uiLoadBalanceCheckBox.toggled.connect(self._loadBalanceToggledSlot)
        self.uiIOUImageToolButton.clicked.connect(self._iouImageBrowserSlot)
        self.uiTypeComboBox.currentIndexChanged[str].connect(self._typeChangedSlot)

        if sys.platform.startswith("win") or sys.platform.startswith("darwin"):
            # Cannot use IOU locally on Windows
            self.uiLocalRadioButton.setEnabled(False)

        # Available types
        self.uiTypeComboBox.addItems(["L2 image", "L3 image"])

        # Mandatory fields
        self.uiNameImageWizardPage.registerField("name*", self.uiNameLineEdit)
        self.uiNameImageWizardPage.registerField("image*", self.uiIOUImageLineEdit)

        self._iou_devices = iou_devices

        if IOU.instance().settings()["use_local_server"]:
            # skip the server page if we use the local server
            self.setStartId(1)
        else:
            self.uiIOUImageToolButton.setEnabled(False)

        if not ENABLE_CLOUD:
            self.uiCloudRadioButton.hide()

        # location of the base config templates
        self._base_iou_l2_config_template = get_resource(os.path.join("configs", "iou_l2_base_initial-config.txt"))
        self._base_iou_l3_config_template = get_resource(os.path.join("configs", "iou_l3_base_initial-config.txt"))
예제 #20
0
    def getSettings(self):
        """
        Returns the settings set in this Wizard.

        :return: settings dict
        """

        settings = {"name": self.uiNameLineEdit.text(),
                    "base_script_file": get_default_base_config(get_resource(os.path.join("configs", "vpcs_base_config.txt"))),
                    "symbol": ":/symbols/vpcs_guest.svg",
                    "category": Node.end_devices,
                    "server": self._compute_id}

        return settings
예제 #21
0
    def _loadSettings(self):
        """
        Loads the settings from the persistent settings file.
        """

        self._settings = LocalConfig.instance().loadSectionSettings(self.__class__.__name__, VPCS_SETTINGS)

        if not self._settings["base_script_file"]:
            self._settings["base_script_file"] = get_default_base_config(get_resource(os.path.join("configs", "vpcs_base_config.txt")))

        if not os.path.exists(self._settings["vpcs_path"]):
            vpcs_path = shutil.which("vpcs")
            if vpcs_path:
                self._settings["vpcs_path"] = os.path.abspath(vpcs_path)
            else:
                self._settings["vpcs_path"] = ""
    def _scriptFileBrowserSlot(self):
        """
        Slot to open a file browser and select a script-file file.
        """

        config_dir = get_resource("configs")
        path = QtGui.QFileDialog.getOpenFileName(self, "Select a startup configuration", config_dir)
        if not path:
            return

        if not os.access(path, os.R_OK):
            QtGui.QMessageBox.critical(self, "Startup configuration", "Cannot read {}".format(path))
            return

        self.uiScriptFileLineEdit.clear()
        self.uiScriptFileLineEdit.setText(path)
예제 #23
0
    def _check_config(self):
        """
        :param appliance: Sanity check on the appliance configuration
        """
        if "registry_version" not in self._appliance:
            raise ApplianceError("Invalid appliance configuration please report the issue on https://github.com/GNS3/gns3-registry")
        if self._appliance["registry_version"] > 4:
            raise ApplianceError("Please update GNS3 in order to install this appliance")

        with open(get_resource(os.path.join("schemas", "appliance.json"))) as f:
            schema = json.load(f)
        v = jsonschema.Draft4Validator(schema)
        try:
            v.validate(self._appliance)
        except jsonschema.ValidationError as e:
            error = jsonschema.exceptions.best_match(v.iter_errors(self._appliance)).message
            raise ApplianceError("Invalid appliance file: {}".format(error))
예제 #24
0
    def _check_config(self):
        """
        :param appliance: Sanity check on the appliance configuration
        """
        if "registry_version" not in self._appliance:
            raise ApplianceError("Invalid appliance configuration please report the issue on https://github.com/GNS3/gns3-registry")
        if self._appliance["registry_version"] > 3:
            raise ApplianceError("Please update GNS3 in order to install this appliance")

        with open(get_resource(os.path.join("schemas", "appliance.json"))) as f:
            schema = json.load(f)
        v = jsonschema.Draft4Validator(schema)
        try:
            v.validate(self._appliance)
        except jsonschema.ValidationError as e:
            error = jsonschema.exceptions.best_match(v.iter_errors(self._appliance)).message
            raise ApplianceError("Invalid appliance file: {}".format(error))
    def _populateWidgets(self, settings):
        """
        Populates the widgets with the settings.

        :param settings: VPCS settings
        """

        self.uiVPCSPathLineEdit.setText(settings["path"])
        self.uiScriptFileEdit.setText(settings["base_script_file"])
        self.uiUseLocalServercheckBox.setChecked(settings["use_local_server"])
        self.uiConsoleStartPortSpinBox.setValue(settings["console_start_port_range"])
        self.uiConsoleEndPortSpinBox.setValue(settings["console_end_port_range"])
        self.uiUDPStartPortSpinBox.setValue(settings["udp_start_port_range"])
        self.uiUDPEndPortSpinBox.setValue(settings["udp_end_port_range"])

        if not self.uiScriptFileEdit.text():
            resource_name = get_resource(os.path.join("configs", "vpcs_base_config.txt"))
            if resource_name:
                self.uiScriptFileEdit.setText(resource_name)
예제 #26
0
    def getSettings(self):
        """
        Returns the settings set in this Wizard.

        :return: settings dict
        """

        settings = {
            "name":
            self.uiNameLineEdit.text(),
            "base_script_file":
            get_default_base_config(
                get_resource(os.path.join("configs", "vpcs_base_config.txt"))),
            "symbol":
            ":/symbols/vpcs_guest.svg",
            "category":
            Node.end_devices,
            "server":
            self._compute_id
        }

        return settings
예제 #27
0
    def createNode(self, node, node_name):
        """
        Creates a node.

        :param node: Node instance
        :param node_name: Node name
        """

        log.info("creating node {}".format(node))

        if node_name:
            for node_key, info in self._vpcs_nodes.items():
                if node_name == info["name"]:
                    vm_settings = {}
                    for setting_name, value in self._vpcs_nodes[node_key].items():

                        if setting_name in node.settings() and setting_name != "name" and value != "" and value is not None:
                            vm_settings[setting_name] = value

                    node.create(default_name_format=info["default_name_format"], additional_settings=vm_settings)
                    return

        vm_settings = {
            "base_script_file": self._settings.get("base_script_file", get_default_base_config(get_resource(os.path.join("configs", "vpcs_base_config.txt"))))
        }
        node.create(additional_settings=vm_settings)