本文整理汇总了Python中gns3.local_server.LocalServer.instance方法的典型用法代码示例。如果您正苦于以下问题:Python LocalServer.instance方法的具体用法?Python LocalServer.instance怎么用?Python LocalServer.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gns3.local_server.LocalServer
的用法示例。
在下文中一共展示了LocalServer.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_killAlreadyRunningServer
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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
示例2: savePreferences
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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)
示例3: _readBaseConfig
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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
示例4: test_startLocalServer
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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)
示例5: _populateGeneralSettingWidgets
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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)
示例6: __init__
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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)
示例7: checkUbridgePermission
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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)
示例8: _configFileValid
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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)
示例9: done
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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)
示例10: _symbolsPathSlot
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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)
示例11: _refreshLocalServerStatusSlot
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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"]))
示例12: local_server
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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
示例13: savePreferences
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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)
示例14: __init__
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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)
示例15: _configFileValid
# 需要导入模块: from gns3.local_server import LocalServer [as 别名]
# 或者: from gns3.local_server.LocalServer import instance [as 别名]
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