当前位置: 首页>>代码示例>>Python>>正文


Python local_server.LocalServer类代码示例

本文整理汇总了Python中gns3.local_server.LocalServer的典型用法代码示例。如果您正苦于以下问题:Python LocalServer类的具体用法?Python LocalServer怎么用?Python LocalServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LocalServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_killAlreadyRunningServer

def test_killAlreadyRunningServer(local_server):
    with open(local_server._pid_path(), "w+") as f:
        f.write("42")

    mock_process = MagicMock()
    with patch("psutil.Process", return_value=mock_process) as mock:
        LocalServer.instance()._killAlreadyRunningServer()
        mock.assert_called_with(pid=42)
        assert mock_process.kill.called
开发者ID:maherja,项目名称:gns3-gui,代码行数:9,代码来源:test_local_server.py

示例2: savePreferences

    def savePreferences(self):
        """
        Saves the general preferences.
        """

        additional_images_paths = set()
        for i in range(0, self.uiImageDirectoriesListWidget.count()):
            item = self.uiImageDirectoriesListWidget.item(i)
            additional_images_paths.add(item.text())

        new_local_server_settings = {"images_path": self.uiImagesPathLineEdit.text(),
                                     "projects_path": self.uiProjectsPathLineEdit.text(),
                                     "symbols_path": self.uiSymbolsPathLineEdit.text(),
                                     "configs_path": self.uiConfigsPathLineEdit.text(),
                                     "appliances_path": self.uiAppliancesPathLineEdit.text(),
                                     "report_errors": self.uiCrashReportCheckBox.isChecked(),
                                     "additional_images_paths": ":".join(additional_images_paths)}
        LocalServer.instance().updateLocalServerSettings(new_local_server_settings)

        new_general_settings = {
            "style": self.uiStyleComboBox.currentText(),
            "symbol_theme": self.uiSymbolThemeComboBox.currentText(),
            "experimental_features": self.uiExperimentalFeaturesCheckBox.isChecked(),
            "hdpi": self.uiHdpiCheckBox.isChecked(),
            "check_for_update": self.uiCheckForUpdateCheckBox.isChecked(),
            "overlay_notifications": self.uiOverlayNotificationsCheckBox.isChecked(),
            "telnet_console_command": self.uiTelnetConsoleCommandLineEdit.text(),
            "vnc_console_command": self.uiVNCConsoleCommandLineEdit.text(),
            "spice_console_command": self.uiSPICEConsoleCommandLineEdit.text(),
            "delay_console_all": self.uiDelayConsoleAllSpinBox.value(),
            "send_stats": self.uiStatsCheckBox.isChecked(),
            "multi_profiles": self.uiMultiProfilesCheckBox.isChecked(),
            "direct_file_upload": self.uiDirectFileUpload.isChecked()
        }

        from ..main_window import MainWindow
        MainWindow.instance().setSettings(new_general_settings)

        new_graphics_view_settings = {"scene_width": self.uiSceneWidthSpinBox.value(),
                                      "scene_height": self.uiSceneHeightSpinBox.value(),
                                      "grid_size": self.uiNodeGridSizeSpinBox.value(),
                                      "drawing_grid_size": self.uiDrawingGridSizeSpinBox.value(),
                                      "draw_rectangle_selected_item": self.uiRectangleSelectedItemCheckBox.isChecked(),
                                      "draw_link_status_points": self.uiDrawLinkStatusPointsCheckBox.isChecked(),
                                      "show_interface_labels_on_new_project": self.uiShowInterfaceLabelsOnNewProject.isChecked(),
                                      "limit_size_node_symbols": self.uiLimitSizeNodeSymbolCheckBox.isChecked(),
                                      "show_grid_on_new_project": self.uiShowGridOnNewProject.isChecked(),
                                      "snap_to_grid_on_new_project": self.uiSnapToGridOnNewProject.isChecked(),
                                      "default_label_font": self.uiDefaultLabelStylePlainTextEdit.font().toString(),
                                      "default_label_color": self._default_label_color.name(),
                                      "default_note_font": self.uiDefaultNoteStylePlainTextEdit.font().toString(),
                                      "default_note_color": self._default_note_color.name()}
        MainWindow.instance().uiGraphicsView.setSettings(new_graphics_view_settings)
开发者ID:GNS3,项目名称:gns3-gui,代码行数:53,代码来源:general_preferences_page.py

示例3: _readBaseConfig

    def _readBaseConfig(self, config_path):
        """
        Returns a base config content.

        :param config_path: path to the configuration file.

        :returns: config content
        """

        if config_path is None or len(config_path.strip()) == 0:
            return None

        if not os.path.isabs(config_path):
            config_path = os.path.join(LocalServer.instance().localServerSettings()["configs_path"], config_path)

        if not os.path.isfile(config_path):
            return None

        try:
            with open(config_path, "rb") as f:
                log.info("Opening configuration file: {}".format(config_path))
                config = f.read().decode("utf-8")
                config = config.replace('\r', "")
                return config
        except OSError as e:
            self.error_signal.emit(self.id(), "Could not read configuration file {}: {}".format(config_path, e))
            return None
        except UnicodeDecodeError as e:
            self.error_signal.emit(self.id(), "Invalid configuration file {}: {}".format(config_path, e))
            return None
开发者ID:maherja,项目名称:gns3-gui,代码行数:30,代码来源:node.py

示例4: test_startLocalServer

def test_startLocalServer(tmpdir, local_server, local_server_path):
    logging.getLogger().setLevel(logging.DEBUG)  # Make sure we are using debug level in order to get the --debug

    process_mock = MagicMock()
    with patch("subprocess.Popen", return_value=process_mock) as mock:

        # If everything work fine the command is still running and a timeout is raised
        process_mock.communicate.side_effect = subprocess.TimeoutExpired("test", 1)

        LocalServer.instance().startLocalServer()
        mock.assert_called_with([unittest.mock.ANY,
                                 '--local',
                                 '--debug',
                                 '--log=' + str(tmpdir / "gns3_server.log"),
                                 '--pid=' + str(tmpdir / "gns3_server.pid")
                                 ], stderr=unittest.mock.ANY)
开发者ID:maherja,项目名称:gns3-gui,代码行数:16,代码来源:test_local_server.py

示例5: _populateGeneralSettingWidgets

    def _populateGeneralSettingWidgets(self, settings):
        """
        Populates the widgets with the settings.

        :param settings: General settings
        """

        local_server = LocalServer.instance().localServerSettings()
        self.uiProjectsPathLineEdit.setText(local_server["projects_path"])
        self.uiSymbolsPathLineEdit.setText(local_server["symbols_path"])
        self.uiImagesPathLineEdit.setText(local_server["images_path"])
        self.uiConfigsPathLineEdit.setText(local_server["configs_path"])
        self.uiStatsCheckBox.setChecked(settings["send_stats"])
        self.uiCrashReportCheckBox.setChecked(local_server["report_errors"])
        self.uiCheckForUpdateCheckBox.setChecked(settings["check_for_update"])
        self.uiExperimentalFeaturesCheckBox.setChecked(settings["experimental_features"])
        self.uiHdpiCheckBox.setChecked(settings["hdpi"])
        self.uiTelnetConsoleCommandLineEdit.setText(settings["telnet_console_command"])
        self.uiTelnetConsoleCommandLineEdit.setCursorPosition(0)
        index = self.uiStyleComboBox.findText(settings["style"])
        if index != -1:
            self.uiStyleComboBox.setCurrentIndex(index)
        self.uiDelayConsoleAllSpinBox.setValue(settings["delay_console_all"])

        self.uiVNCConsoleCommandLineEdit.setText(settings["vnc_console_command"])
        self.uiVNCConsoleCommandLineEdit.setCursorPosition(0)

        self.uiMultiProfilesCheckBox.setChecked(settings["multi_profiles"])

        self.uiImageDirectoriesListWidget.clear()
        for path in local_server["additional_images_paths"].split(";"):
            if len(path) > 0:
                self.uiImageDirectoriesListWidget.addItem(path)
开发者ID:maherja,项目名称:gns3-gui,代码行数:33,代码来源:general_preferences_page.py

示例6: __init__

    def __init__(self):

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

        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.uiStartupConfigToolButton.clicked.connect(self._startupConfigBrowserSlot)
        self.uiPrivateConfigToolButton.clicked.connect(self._privateConfigBrowserSlot)
        self.uiSymbolToolButton.clicked.connect(self._symbolBrowserSlot)
        self.uiIOSImageToolButton.clicked.connect(self._iosImageBrowserSlot)
        self._compute_id = None
        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())
        self._default_configs_dir = LocalServer.instance().localServerSettings()["configs_path"]

        # add the categories
        for name, category in Node.defaultCategories().items():
            self.uiCategoryComboBox.addItem(name, category)
开发者ID:maherja,项目名称:gns3-gui,代码行数:33,代码来源:ios_router_configuration_page.py

示例7: checkUbridgePermission

    def checkUbridgePermission(self):
        """Check if ubridge has the correct permission"""
        if not sys.platform.startswith("win") and os.geteuid() == 0:
            # we are root, so we should have privileged access.
            return (0, None)

        path = LocalServer.instance().localServerSettings().get("ubridge_path")
        if path is None:
            return (0, None)
        if not os.path.exists(path):
            return (2, "Ubridge path {path} doesn't exists".format(path=path))

        request_setuid = False
        if sys.platform.startswith("linux"):
            try:
                if "security.capability" in os.listxattr(path):
                    caps = os.getxattr(path, "security.capability")
                    # test the 2nd byte and check if the 13th bit (CAP_NET_RAW) is set
                    if not struct.unpack("<IIIII", caps)[1] & 1 << 13:
                        return (2, "Ubridge requires CAP_NET_RAW. Run sudo setcap cap_net_admin,cap_net_raw=ep {path}".format(path=path))
                else:
                    # capabilities not supported
                    request_setuid = True
            except AttributeError:
                # Due to a Python bug, os.listxattr could be missing: https://github.com/GNS3/gns3-gui/issues/2010
                return (1, "Could not determine if CAP_NET_RAW capability is set for uBridge (Python bug)".format(path=path))

        if sys.platform.startswith("darwin") or request_setuid:
            if os.stat(path).st_uid != 0 or not os.stat(path).st_mode & stat.S_ISUID:
                return (2, "Ubridge should be setuid. Run sudo chown root:admin {path} and sudo chmod 4750 {path}".format(path=path))
        return (0, None)
开发者ID:maherja,项目名称:gns3-gui,代码行数:31,代码来源:doctor_dialog.py

示例8: _configFileValid

 def _configFileValid(self, path):
     """
     Return true if it's a valid configuration file
     """
     if not os.path.isabs(path):
         path = os.path.join(LocalServer.instance().localServerSettings()["configs_path"], path)
     return os.access(path, os.R_OK)
开发者ID:GNS3,项目名称:gns3-gui,代码行数:7,代码来源:vpcs_node_configuration_page.py

示例9: done

    def done(self, result):
        """
        This dialog is closed.

        :param result: ignored
        """

        Controller.instance().setDisplayError(True)
        settings = self.parentWidget().settings()
        if result:
            settings["hide_setup_wizard"] = True
        else:
            local_server_settings = LocalServer.instance().localServerSettings()
            if local_server_settings["host"] is None:
                local_server_settings["host"] = DEFAULT_LOCAL_SERVER_HOST
                LocalServer.instance().updateLocalServerSettings(local_server_settings)
            settings["hide_setup_wizard"] = self.uiShowCheckBox.isChecked()

        self.parentWidget().setSettings(settings)
        super().done(result)
开发者ID:athmane,项目名称:gns3-gui,代码行数:20,代码来源:setup_wizard.py

示例10: _symbolsPathSlot

    def _symbolsPathSlot(self):
        """
        Slot to select the symbols directory path.
        """

        local_server = LocalServer.instance().localServerSettings()
        directory = local_server["symbols_path"]
        path = QtWidgets.QFileDialog.getExistingDirectory(self, "My symbols directory", directory, QtWidgets.QFileDialog.ShowDirsOnly)
        if path:
            self.uiSymbolsPathLineEdit.setText(path)
            self.uiSymbolsPathLineEdit.setCursorPosition(0)
开发者ID:maherja,项目名称:gns3-gui,代码行数:11,代码来源:general_preferences_page.py

示例11: _refreshLocalServerStatusSlot

 def _refreshLocalServerStatusSlot(self):
     """
     Refresh the local server status page
     """
     if Controller.instance().connected():
         self.uiLocalServerStatusLabel.setText("Connection to local server successful")
         Controller.instance().get("/gns3vm", self._getSettingsCallback)
     elif Controller.instance().connecting():
         self.uiLocalServerStatusLabel.setText("Please wait connection to the GNS3 server")
     else:
         local_server_settings = LocalServer.instance().localServerSettings()
         self.uiLocalServerStatusLabel.setText("Connection to local server failed.\n* Make sure GNS3 is allowed in your firewall.\n* Go back and try to change the server port\n* Please check with a browser if you can connect to {protocol}://{host}:{port}.\n* Try to run {path} in a terminal to see if you have an error if the above does not work.".format(protocol=local_server_settings["protocol"], host=local_server_settings["host"], port=local_server_settings["port"], path=local_server_settings["path"]))
开发者ID:athmane,项目名称:gns3-gui,代码行数:12,代码来源:setup_wizard.py

示例12: local_server

def local_server(local_server_path, tmpdir):
    with open(str(tmpdir / "test.cfg"), "w+") as f:
        f.write("""
[Server]
path={}""".format(local_server_path))

    LocalServerConfig.instance().setConfigFile(str(tmpdir / "test.cfg"))
    LocalServer._instance = None
    with patch("gns3.local_server.LocalServer.localServerAutoStartIfRequire"):
        local_server = LocalServer.instance()
        local_server._config_directory = str(tmpdir)
        yield local_server
开发者ID:maherja,项目名称:gns3-gui,代码行数:12,代码来源:test_local_server.py

示例13: savePreferences

    def savePreferences(self):
        """
        Saves the general preferences.
        """

        additional_images_paths = set()
        for i in range(0, self.uiImageDirectoriesListWidget.count()):
            item = self.uiImageDirectoriesListWidget.item(i)
            additional_images_paths.add(item.text())

        new_local_server_settings = {"images_path": self.uiImagesPathLineEdit.text(),
                                     "projects_path": self.uiProjectsPathLineEdit.text(),
                                     "symbols_path": self.uiSymbolsPathLineEdit.text(),
                                     "configs_path": self.uiConfigsPathLineEdit.text(),
                                     "report_errors": self.uiCrashReportCheckBox.isChecked(),
                                     "additional_images_paths": ":".join(additional_images_paths)}
        LocalServer.instance().updateLocalServerSettings(new_local_server_settings)

        new_general_settings = {
            "style": self.uiStyleComboBox.currentText(),
            "experimental_features": self.uiExperimentalFeaturesCheckBox.isChecked(),
            "hdpi": self.uiHdpiCheckBox.isChecked(),
            "check_for_update": self.uiCheckForUpdateCheckBox.isChecked(),
            "telnet_console_command": self.uiTelnetConsoleCommandLineEdit.text(),
            "vnc_console_command": self.uiVNCConsoleCommandLineEdit.text(),
            "delay_console_all": self.uiDelayConsoleAllSpinBox.value(),
            "send_stats": self.uiStatsCheckBox.isChecked(),
            "multi_profiles": self.uiMultiProfilesCheckBox.isChecked()
        }

        from ..main_window import MainWindow
        MainWindow.instance().setSettings(new_general_settings)

        new_graphics_view_settings = {"scene_width": self.uiSceneWidthSpinBox.value(),
                                      "scene_height": self.uiSceneHeightSpinBox.value(),
                                      "draw_rectangle_selected_item": self.uiRectangleSelectedItemCheckBox.isChecked(),
                                      "draw_link_status_points": self.uiDrawLinkStatusPointsCheckBox.isChecked(),
                                      "default_label_font": self.uiDefaultLabelStylePlainTextEdit.font().toString(),
                                      "default_label_color": self._default_label_color.name()}
        MainWindow.instance().uiGraphicsView.setSettings(new_graphics_view_settings)
开发者ID:maherja,项目名称:gns3-gui,代码行数:40,代码来源:general_preferences_page.py

示例14: __init__

    def __init__(self):

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

        self.uiSymbolToolButton.clicked.connect(self._symbolBrowserSlot)
        self._default_configs_dir = LocalServer.instance().localServerSettings()["configs_path"]
        if Controller.instance().isRemote():
            self.uiScriptFileToolButton.hide()

        # add the categories
        for name, category in Node.defaultCategories().items():
            self.uiCategoryComboBox.addItem(name, category)
开发者ID:GNS3,项目名称:gns3-gui,代码行数:13,代码来源:traceng_node_configuration_page.py

示例15: _configFileValid

    def _configFileValid(self, path):
        """
        Return true if it's a valid configuration file
        """

        if not os.path.isabs(path):
            path = os.path.join(LocalServer.instance().localServerSettings()["configs_path"], path)
        result = os.access(path, os.R_OK)
        if not result:
            if not os.path.exists(path):
                log.error("Cannot access config file '{}'".format(path))
            else:
                log.error("Cannot read config file '{}'".format(path))
        return result
开发者ID:GNS3,项目名称:gns3-gui,代码行数:14,代码来源:ios_router_configuration_page.py


注:本文中的gns3.local_server.LocalServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。