From 7abb426d0476573d4aabe67c9b14878afc3ac943 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 21 Jan 2015 17:21:17 +0100 Subject: [PATCH] Get informations about a VPCS instance --- docs/api/examples/get_vpcsuuid.txt | 22 +++++++++++++++++++ .../api/examples/post_virtualboxuuidstart.txt | 15 +++++++++++++ docs/api/examples/post_virtualboxuuidstop.txt | 15 +++++++++++++ docs/api/examples/post_vpcs.txt | 2 +- gns3server/handlers/vpcs_handler.py | 17 ++++++++++++++ tests/api/test_vpcs.py | 8 +++++++ 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 docs/api/examples/get_vpcsuuid.txt create mode 100644 docs/api/examples/post_virtualboxuuidstart.txt create mode 100644 docs/api/examples/post_virtualboxuuidstop.txt diff --git a/docs/api/examples/get_vpcsuuid.txt b/docs/api/examples/get_vpcsuuid.txt new file mode 100644 index 00000000..797f00bd --- /dev/null +++ b/docs/api/examples/get_vpcsuuid.txt @@ -0,0 +1,22 @@ +curl -i -X GET 'http://localhost:8000/vpcs/{uuid}' + +GET /vpcs/{uuid} HTTP/1.1 + + + +HTTP/1.1 200 +CONNECTION: close +CONTENT-LENGTH: 213 +CONTENT-TYPE: application/json +DATE: Thu, 08 Jan 2015 16:09:15 GMT +SERVER: Python/3.4 aiohttp/0.13.1 +X-ROUTE: /vpcs/{uuid} + +{ + "console": 2001, + "name": "PC TEST 1", + "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80", + "script_file": null, + "startup_script": null, + "uuid": "40f76457-de2b-4399-8853-a35393a72a2d" +} diff --git a/docs/api/examples/post_virtualboxuuidstart.txt b/docs/api/examples/post_virtualboxuuidstart.txt new file mode 100644 index 00000000..dee153b5 --- /dev/null +++ b/docs/api/examples/post_virtualboxuuidstart.txt @@ -0,0 +1,15 @@ +curl -i -X POST 'http://localhost:8000/virtualbox/{uuid}/start' -d '{}' + +POST /virtualbox/{uuid}/start HTTP/1.1 +{} + + +HTTP/1.1 200 +CONNECTION: close +CONTENT-LENGTH: 2 +CONTENT-TYPE: application/json +DATE: Thu, 08 Jan 2015 16:09:15 GMT +SERVER: Python/3.4 aiohttp/0.13.1 +X-ROUTE: /virtualbox/{uuid}/start + +{} diff --git a/docs/api/examples/post_virtualboxuuidstop.txt b/docs/api/examples/post_virtualboxuuidstop.txt new file mode 100644 index 00000000..5bcfc6af --- /dev/null +++ b/docs/api/examples/post_virtualboxuuidstop.txt @@ -0,0 +1,15 @@ +curl -i -X POST 'http://localhost:8000/virtualbox/{uuid}/stop' -d '{}' + +POST /virtualbox/{uuid}/stop HTTP/1.1 +{} + + +HTTP/1.1 200 +CONNECTION: close +CONTENT-LENGTH: 2 +CONTENT-TYPE: application/json +DATE: Thu, 08 Jan 2015 16:09:15 GMT +SERVER: Python/3.4 aiohttp/0.13.1 +X-ROUTE: /virtualbox/{uuid}/stop + +{} diff --git a/docs/api/examples/post_vpcs.txt b/docs/api/examples/post_vpcs.txt index 395b109e..1977fc1d 100644 --- a/docs/api/examples/post_vpcs.txt +++ b/docs/api/examples/post_vpcs.txt @@ -21,5 +21,5 @@ X-ROUTE: /vpcs "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80", "script_file": null, "startup_script": null, - "uuid": "6370f75e-0a48-4e2b-95a8-0140da6ef1fb" + "uuid": "a022aa0d-acab-4554-b2a6-6e6f51c9d65e" } diff --git a/gns3server/handlers/vpcs_handler.py b/gns3server/handlers/vpcs_handler.py index 007b95dd..df6788f7 100644 --- a/gns3server/handlers/vpcs_handler.py +++ b/gns3server/handlers/vpcs_handler.py @@ -50,6 +50,23 @@ class VPCSHandler: startup_script=request.json.get("startup_script")) response.json(vm) + @classmethod + @Route.get( + r"/vpcs/{uuid}", + parameters={ + "uuid": "VPCS instance UUID" + }, + status_codes={ + 200: "VPCS instance started", + 404: "VPCS instance doesn't exist" + }, + description="Get a VPCS instance") + def show(request, response): + + vpcs_manager = VPCS.instance() + vm = vpcs_manager.get_vm(request.match_info["uuid"]) + response.json(vm) + @classmethod @Route.post( r"/vpcs/{uuid}/start", diff --git a/tests/api/test_vpcs.py b/tests/api/test_vpcs.py index 00ce14f4..0b24753f 100644 --- a/tests/api/test_vpcs.py +++ b/tests/api/test_vpcs.py @@ -39,6 +39,14 @@ def test_vpcs_create(server, project): assert response.json["script_file"] is None +def test_vpcs_get(server, project, vm): + response = server.get("/vpcs/{}".format(vm["uuid"]), example=True) + assert response.status == 200 + assert response.route == "/vpcs/{uuid}" + assert response.json["name"] == "PC TEST 1" + assert response.json["project_uuid"] == project.uuid + + def test_vpcs_create_script_file(server, project, tmpdir): path = os.path.join(str(tmpdir), "test") with open(path, 'w+') as f: