diff --git a/gns3server/controller/topology.py b/gns3server/controller/topology.py index c0457467..3e80c7fc 100644 --- a/gns3server/controller/topology.py +++ b/gns3server/controller/topology.py @@ -307,11 +307,31 @@ def _convert_1_3_later(topo, topo_path): "x": int(note["x"]), "y": int(note["y"]), "z": int(note.get("z", 0)), - "rotation": int(ellipse.get("rotation", 0)), + "rotation": int(note.get("rotation", 0)), "svg": svg } new_topo["topology"]["drawings"].append(new_note) + # Images + for image in topo.get("images", []): + img_path = image["path"] + # Absolute image path are rewrite to project specific image + if os.path.abspath(img_path): + try: + os.makedirs(os.path.join(topo_dir, "images"), exist_ok=True) + shutil.copy(img_path, os.path.join(topo_dir, "images", os.path.basename(img_path))) + except OSError: + pass + new_image = { + "drawing_id": str(uuid.uuid4()), + "x": int(image["x"]), + "y": int(image["y"]), + "z": int(image.get("z", 0)), + "rotation": int(image.get("rotation", 0)), + "svg": os.path.basename(img_path) + } + new_topo["topology"]["drawings"].append(new_image) + # Rectangles for rectangle in topo.get("rectangles", []): svg = ''.format( @@ -325,7 +345,7 @@ def _convert_1_3_later(topo, topo_path): "x": int(rectangle["x"]), "y": int(rectangle["y"]), "z": int(rectangle.get("z", 0)), - "rotation": int(ellipse.get("rotation", 0)), + "rotation": int(rectangle.get("rotation", 0)), "svg": svg } new_topo["topology"]["drawings"].append(new_rectangle) diff --git a/tests/topologies/1_5_images/after/1_5_image.gns3 b/tests/topologies/1_5_images/after/1_5_image.gns3 new file mode 100644 index 00000000..24099682 --- /dev/null +++ b/tests/topologies/1_5_images/after/1_5_image.gns3 @@ -0,0 +1,23 @@ +{ + "auto_start": false, + "name": "1_5_image", + "project_id": "ANYUUID", + "revision": 5, + "topology": { + "computes": [], + "drawings": [ + { + "drawing_id": "ANYUUID", + "rotation": 0, + "svg": "gns3_logo.png", + "x": -64, + "y": -64, + "z": 0 + } + ], + "links": [], + "nodes": [] + }, + "type": "topology", + "version": "ANYSTR" +} diff --git a/tests/topologies/1_5_images/after/project-files/images/gns3_logo.png b/tests/topologies/1_5_images/after/project-files/images/gns3_logo.png new file mode 100644 index 00000000..dd412d33 Binary files /dev/null and b/tests/topologies/1_5_images/after/project-files/images/gns3_logo.png differ diff --git a/tests/topologies/1_5_images/before/1_5_image.gns3 b/tests/topologies/1_5_images/before/1_5_image.gns3 new file mode 100644 index 00000000..1bb6319d --- /dev/null +++ b/tests/topologies/1_5_images/before/1_5_image.gns3 @@ -0,0 +1,17 @@ +{ + "auto_start": false, + "name": "1_5_image", + "project_id": null, + "revision": 4, + "topology": { + "images": [ + { + "path": "images/gns3_logo.png", + "x": -64, + "y": -64 + } + ] + }, + "type": "topology", + "version": "1.5.1dev1" +} diff --git a/tests/topologies/1_5_images/before/project-files/images/gns3_logo.png b/tests/topologies/1_5_images/before/project-files/images/gns3_logo.png new file mode 100644 index 00000000..dd412d33 Binary files /dev/null and b/tests/topologies/1_5_images/before/project-files/images/gns3_logo.png differ