本文整理汇总了Python中gns3.local_server_config.LocalServerConfig.instance方法的典型用法代码示例。如果您正苦于以下问题:Python LocalServerConfig.instance方法的具体用法?Python LocalServerConfig.instance怎么用?Python LocalServerConfig.instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gns3.local_server_config.LocalServerConfig
的用法示例。
在下文中一共展示了LocalServerConfig.instance方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateLocalServerSettings
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def updateLocalServerSettings(self, new_settings):
"""
Update the local server settings. Keep the key not in new_settings
"""
old_settings = copy.copy(self._settings)
if not self._settings:
self._settings = new_settings
else:
self._settings.update(new_settings)
self._port = self._settings["port"]
LocalServerConfig.instance().saveSettings("Server", self._settings)
# Settings have changed we need to restart the server
if old_settings != self._settings:
if self._settings["auto_start"]:
# We restart the local server only if we really need. Auth can be hot change
settings_require_restart = ('host', 'port', 'path')
need_restart = False
for s in settings_require_restart:
if old_settings.get(s) != self._settings.get(s):
need_restart = True
if need_restart:
self.stopLocalServer(wait=True)
self.localServerAutoStartIfRequire()
# If the controller is remote:
else:
self.stopLocalServer(wait=True)
if self._settings.get("host") is None:
self._http_client = None
else:
self._http_client = HTTPClient(self._settings)
Controller.instance().setHttpClient(self._http_client)
示例2: image_manager
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def image_manager(tmpdir, images_dir):
ImageManager._instance = None
settings = LOCAL_SERVER_SETTINGS
settings['images_path'] = str(images_dir)
LocalServerConfig.instance().setConfigFile(str(tmpdir / "test.cfg"))
with patch('gns3.local_server_config.LocalServerConfig.loadSettings', return_value=LOCAL_SERVER_SETTINGS):
yield ImageManager.instance()
ImageManager._instance = None
示例3: test_loadSettings_EmptySettings
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def test_loadSettings_EmptySettings(tmpdir, local_server):
with open(str(tmpdir / "test.cfg"), "w+") as f:
f.write("")
LocalServerConfig.instance().setConfigFile(str(tmpdir / "test.cfg"))
assert local_server.localServerSettings()["port"] == 3080
assert len(local_server.localServerSettings()["password"]) == 64
assert local_server.localServerSettings()["user"] == "admin"
示例4: test_loadSettings
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def test_loadSettings(tmpdir, local_server):
with open(str(tmpdir / "test.cfg"), "w+") as f:
f.write("""
[Server]
auth=True
user=world
password=hello""")
LocalServerConfig.instance().setConfigFile(str(tmpdir / "test.cfg"))
assert local_server.localServerSettings()["password"] == "hello"
示例5: _saveSettings
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def _saveSettings(self):
"""
Saves the settings to the persistent settings file.
"""
# save the settings
LocalConfig.instance().saveSectionSettings(self.__class__.__name__, self._settings)
server_settings = {"enable_hardware_acceleration": self._settings["enable_hardware_acceleration"],
"require_hardware_acceleration": self._settings["require_hardware_acceleration"]}
LocalServerConfig.instance().saveSettings(self.__class__.__name__, server_settings)
示例6: local_server
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig 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
示例7: _saveSettings
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def _saveSettings(self):
"""
Saves the settings to the persistent settings file.
"""
# save the settings
LocalConfig.instance().saveSectionSettings(self.__class__.__name__, self._settings)
# save some settings to the local server config file
if sys.platform.startswith("linux"):
server_settings = {
"enable_kvm": self._settings["enable_kvm"],
}
LocalServerConfig.instance().saveSettings(self.__class__.__name__, server_settings)
示例8: getDirectory
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def getDirectory(self):
"""
Returns the images directory path.
:returns: path to the default images directory
"""
return copy.copy(LocalServerConfig.instance().loadSettings("Server", LOCAL_SERVER_SETTINGS)['images_path'])
示例9: local_server_config
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def local_server_config():
from gns3.local_server_config import LocalServerConfig
(fd, config_path) = tempfile.mkstemp()
os.close(fd)
LocalServerConfig._instance = LocalServerConfig(config_file=config_path)
return LocalServerConfig.instance()
示例10: _saveSettings
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def _saveSettings(self):
"""
Saves the settings to the persistent settings file.
"""
# save the settings
LocalConfig.instance().saveSectionSettings(self.__class__.__name__, self._settings)
if self._settings["vpcs_path"]:
# save some settings to the server config file
server_settings = {"vpcs_path": os.path.normpath(self._settings["vpcs_path"])}
config = LocalServerConfig.instance()
config.saveSettings(self.__class__.__name__, server_settings)
示例11: _saveSettings
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def _saveSettings(self):
"""
Saves the settings to the persistent settings file.
"""
# save the settings
LocalConfig.instance().saveSectionSettings(self.__class__.__name__, self._settings)
# save some settings to the local server config file
server_settings = {
"allocate_aux_console_ports": self._settings["allocate_aux_console_ports"],
"ghost_ios_support": self._settings["ghost_ios_support"],
"sparse_memory_support": self._settings["sparse_memory_support"],
"mmap_support": self._settings["mmap_support"],
}
if self._settings["dynamips_path"]:
server_settings["dynamips_path"] = os.path.normpath(self._settings["dynamips_path"])
config = LocalServerConfig.instance()
config.saveSettings(self.__class__.__name__, server_settings)
示例12: localServerSettings
# 需要导入模块: from gns3.local_server_config import LocalServerConfig [as 别名]
# 或者: from gns3.local_server_config.LocalServerConfig import instance [as 别名]
def localServerSettings(self):
"""
Returns the local server settings.
:returns: local server settings (dict)
"""
settings = LocalServerConfig.instance().loadSettings("Server", LOCAL_SERVER_SETTINGS)
self._settings = copy.copy(settings)
# user & password
if settings["auth"] is True and not settings["user"].strip():
settings["user"] = "admin"
settings["password"] = self._passwordGenerate()
# local GNS3 server path
local_server_path = shutil.which(settings["path"].strip())
if local_server_path is None:
default_server_path = shutil.which("gns3server")
if default_server_path is not None:
settings["path"] = os.path.abspath(default_server_path)
else:
settings["path"] = os.path.abspath(local_server_path)
# uBridge path
ubridge_path = shutil.which(settings["ubridge_path"].strip())
if ubridge_path is None:
default_ubridge_path = shutil.which("ubridge")
if default_ubridge_path is not None:
settings["ubridge_path"] = os.path.abspath(default_ubridge_path)
else:
settings["ubridge_path"] = os.path.abspath(ubridge_path)
if self._settings != settings:
self.updateLocalServerSettings(settings)
return settings