From 01be1b32c4e48817bf58efc1c48f1697404e45e2 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 25 Jul 2017 10:01:03 +0200 Subject: [PATCH] Duplicate support for qemu Ref https://github.com/GNS3/gns3-gui/issues/1065 --- .../handlers/api/compute/qemu_handler.py | 20 +++++++++++++++++++ tests/handlers/api/compute/test_qemu.py | 15 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/gns3server/handlers/api/compute/qemu_handler.py b/gns3server/handlers/api/compute/qemu_handler.py index 69c7032a..1f5a9566 100644 --- a/gns3server/handlers/api/compute/qemu_handler.py +++ b/gns3server/handlers/api/compute/qemu_handler.py @@ -143,6 +143,26 @@ class QEMUHandler: yield from Qemu.instance().delete_node(request.match_info["node_id"]) response.set_status(204) + @Route.post( + r"/projects/{project_id}/qemu/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 Qemu instance") + def duplicate(request, response): + + new_node = yield from Qemu.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}/qemu/nodes/{node_id}/start", parameters={ diff --git a/tests/handlers/api/compute/test_qemu.py b/tests/handlers/api/compute/test_qemu.py index 229284a2..a1a9ab88 100644 --- a/tests/handlers/api/compute/test_qemu.py +++ b/tests/handlers/api/compute/test_qemu.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import pytest +import uuid import os import sys import stat @@ -346,3 +347,17 @@ def test_capabilities(http_compute): with asyncio_patch("gns3server.compute.Qemu.get_kvm_archs", return_value=["x86_64"]): response = http_compute.get("/qemu/capabilities", example=True) assert response.json["kvm"] == ["x86_64"] + + +def test_qemu_duplicate(http_compute, vm): + with asyncio_patch("gns3server.compute.qemu.Qemu.duplicate_node", return_value=True) as mock: + response = http_compute.post( + "/projects/{project_id}/qemu/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