From 6d4529f4457c63fc901c627b57491e1452c0cc88 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 25 Jul 2017 11:39:46 +0200 Subject: [PATCH] Duplicate IOU Ref https://github.com/GNS3/gns3-gui/issues/1065 --- .../handlers/api/compute/iou_handler.py | 20 +++++++++++++++++++ tests/handlers/api/compute/test_iou.py | 14 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/gns3server/handlers/api/compute/iou_handler.py b/gns3server/handlers/api/compute/iou_handler.py index 18761c25..1dc4057a 100644 --- a/gns3server/handlers/api/compute/iou_handler.py +++ b/gns3server/handlers/api/compute/iou_handler.py @@ -133,6 +133,26 @@ class IOUHandler: yield from IOU.instance().delete_node(request.match_info["node_id"]) response.set_status(204) + @Route.post( + r"/projects/{project_id}/iou/nodes/{node_id}/duplicate", + parameters={ + "project_id": "Project UUID", + "node_id": "Node UUID" + }, + status_codes={ + 201: "Instance duplicated", + 404: "Instance doesn't exist" + }, + description="Duplicate a IOU instance") + def duplicate(request, response): + + new_node = yield from IOU.instance().duplicate_node( + request.match_info["node_id"], + request.json["destination_node_id"] + ) + response.set_status(201) + response.json(new_node) + @Route.post( r"/projects/{project_id}/iou/nodes/{node_id}/start", parameters={ diff --git a/tests/handlers/api/compute/test_iou.py b/tests/handlers/api/compute/test_iou.py index 3f6f120d..7ce96512 100644 --- a/tests/handlers/api/compute/test_iou.py +++ b/tests/handlers/api/compute/test_iou.py @@ -308,3 +308,17 @@ def test_image_vm(http_compute, tmpdir): with open(str(tmpdir / "test2.md5sum")) as f: checksum = f.read() assert checksum == "033bd94b1168d7e4f0d644c3c95e35bf" + + +def test_iou_duplicate(http_compute, vm): + with asyncio_patch("gns3server.compute.iou.IOU.duplicate_node", return_value=True) as mock: + response = http_compute.post( + "/projects/{project_id}/iou/nodes/{node_id}/duplicate".format( + project_id=vm["project_id"], + node_id=vm["node_id"]), + body={ + "destination_node_id": str(uuid.uuid4()) + }, + example=True) + assert mock.called + assert response.status == 201