From 996dad2f5c447da1c964942cc5b9de46d9331a52 Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 26 Sep 2024 18:41:23 +0700 Subject: [PATCH] Support to reset MAC addresses for Docker nodes and some adjustments for fast duplication. --- gns3server/controller/export_project.py | 2 +- gns3server/controller/project.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gns3server/controller/export_project.py b/gns3server/controller/export_project.py index 9db43381..ae6126ad 100644 --- a/gns3server/controller/export_project.py +++ b/gns3server/controller/export_project.py @@ -200,7 +200,7 @@ async def _patch_project_file(project, path, zstream, include_images, keep_compu if not keep_compute_ids: node["compute_id"] = "local" # To make project portable all node by default run on local - if "properties" in node and node["node_type"] != "docker": + if "properties" in node: for prop, value in node["properties"].items(): # reset the MAC address diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 43c3b130..44099d9e 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -1057,11 +1057,13 @@ class Project: assert self._status != "closed" try: - proj = await self._duplicate_fast(name, location, reset_mac_addresses) + proj = await self._fast_duplication(name, location, reset_mac_addresses) if proj: if previous_status == "closed": await self.close() return proj + else: + log.info("Fast duplication failed, fallback to normal duplication") except Exception as e: raise aiohttp.web.HTTPConflict(text="Cannot duplicate project: {}".format(str(e))) @@ -1251,13 +1253,11 @@ class Project: def __repr__(self): return "".format(self._name, self._id) - async def _duplicate_fast(self, name=None, location=None, reset_mac_addresses=True): - # remote replication is not supported - if not sys.platform.startswith("linux") and not sys.platform.startswith("win"): - return None + async def _fast_duplication(self, name=None, location=None, reset_mac_addresses=True): + # remote replication is not supported with remote computes for compute in self.computes: if compute.id != "local": - log.warning("Duplicate fast not support remote compute: '{}'".format(compute.id)) + log.warning("Fast duplication is not support with remote compute: '{}'".format(compute.id)) return None # work dir p_work = pathlib.Path(location or self.path).parent.absolute() @@ -1266,7 +1266,7 @@ class Project: new_project_path = p_work.joinpath(new_project_id) # copy dir await wait_run_in_executor(shutil.copytree, self.path, new_project_path.as_posix()) - log.info("[FAST] Copy project: {} to: '{}', cost={}s".format(self.path, new_project_path, time.time() - t0)) + log.info("Project content copied from '{}' to '{}' in {}s".format(self.path, new_project_path, time.time() - t0)) topology = json.loads(new_project_path.joinpath('{}.gns3'.format(self.name)).read_bytes()) project_name = name or topology["name"] # If the project name is already used we generate a new one @@ -1285,7 +1285,7 @@ class Project: _move_node_file(new_project_path, node["node_id"], new_node_id) node["node_id"] = new_node_id if reset_mac_addresses: - if "properties" in node and node["node_type"] != "docker": + if "properties" in node: for prop, value in node["properties"].items(): # reset the MAC address if prop in ("mac_addr", "mac_address"): @@ -1307,5 +1307,5 @@ class Project: os.remove(new_project_path.joinpath('{}.gns3'.format(self.name))) project = await self.controller.load_project(dot_gns3_path, load=False) - log.info("[FAST] Project '{}' duplicated in {:.4f} seconds".format(project.name, time.time() - t0)) + log.info("Project '{}' fast duplicated in {:.4f} seconds".format(project.name, time.time() - t0)) return project \ No newline at end of file