From b1eccc0ace928776a139dbe687e98ebd0bf755d8 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 8 Mar 2015 14:13:19 -0600 Subject: [PATCH] Properly restore configs for Dynamips routers. --- gns3server/modules/dynamips/__init__.py | 25 ++++++++++++--------- gns3server/modules/dynamips/nodes/router.py | 22 +----------------- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index 21db9cbd..ed538f23 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -458,10 +458,8 @@ class Dynamips(BaseManager): if hasattr(vm, name) and getattr(vm, name) != value: if hasattr(vm, "set_{}".format(name)): setter = getattr(vm, "set_{}".format(name)) - if asyncio.iscoroutinefunction(vm.close): - yield from setter(value) - else: - setter(value) + yield from setter(value) + elif name.startswith("slot") and value in ADAPTER_MATRIX: slot_id = int(name[-1]) adapter_name = value @@ -496,29 +494,36 @@ class Dynamips(BaseManager): yield from vm.set_sparsemem(False) # update the configs if needed - yield from self.create_vm_configs(vm, settings.get("startup_config_content"), settings.get("private_config_content")) + yield from self.create_vm_configs(vm, settings) @asyncio.coroutine - def create_vm_configs(self, vm, startup_config_content, private_config_content): + def create_vm_configs(self, vm, settings): """ Creates VM configs from pushed content. :param vm: VM instance - :param startup_config_content: content of the startup-config - :param private_config_content: content of the private-config + :param settings: VM settings """ module_workdir = vm.project.module_working_directory(self.module_name.lower()) default_startup_config_path = os.path.join(module_workdir, "configs", "i{}_startup-config.cfg".format(vm.dynamips_id)) default_private_config_path = os.path.join(module_workdir, "configs", "i{}_private-config.cfg".format(vm.dynamips_id)) + startup_config_content = settings.get("startup_config_content") if startup_config_content: startup_config_path = self._create_config(vm, startup_config_content, default_startup_config_path) - yield from vm.set_config(startup_config_path) + yield from vm.set_configs(startup_config_path) + else: + startup_config_path = settings.get("startup_config", "") + yield from vm.set_configs(startup_config_path) + private_config_content = settings.get("private_config_content") if private_config_content: private_config_path = self._create_config(vm, private_config_content, default_private_config_path) - yield from vm.set_config(vm.startup_config, private_config_path) + yield from vm.set_configs(vm.startup_config, private_config_path) + else: + private_config_path = settings.get("private_config", "") + yield from vm.set_configs(vm.startup_config, private_config_path) def _create_config(self, vm, content, path): """ diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/modules/dynamips/nodes/router.py index 706fc319..92079aad 100644 --- a/gns3server/modules/dynamips/nodes/router.py +++ b/gns3server/modules/dynamips/nodes/router.py @@ -1396,16 +1396,6 @@ class Router(BaseVM): return self._startup_config - @startup_config.setter - def startup_config(self, startup_config): - """ - Sets the startup-config for this router. - - :param startup_config: path to startup-config file - """ - - self._startup_config = startup_config - @property def private_config(self): """ @@ -1416,16 +1406,6 @@ class Router(BaseVM): return self._private_config - @private_config.setter - def private_config(self, private_config): - """ - Sets the private-config for this router. - - :param private_config: path to private-config file - """ - - self._private_config = private_config - @asyncio.coroutine def set_name(self, new_name): """ @@ -1466,7 +1446,7 @@ class Router(BaseVM): self._name = new_name @asyncio.coroutine - def set_config(self, startup_config, private_config=''): + def set_configs(self, startup_config, private_config=''): """ Sets the config files that are pushed to startup-config and private-config in NVRAM when the instance is started.