From d142a9a88528d757b2b0943f9b9adb39ede128bc Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 18 Jan 2015 12:12:11 -0700 Subject: [PATCH] Rename vpcs_id to id. Must be an integer in the route definition. --- gns3server/handlers/vpcs_handler.py | 60 ++++++++++++++++------------- gns3server/schemas/vpcs.py | 6 +-- tests/__init__.py | 0 tests/api/test_version.py | 1 - tests/api/test_vpcs.py | 6 +-- 5 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 tests/__init__.py diff --git a/gns3server/handlers/vpcs_handler.py b/gns3server/handlers/vpcs_handler.py index 5213c27e..86d97144 100644 --- a/gns3server/handlers/vpcs_handler.py +++ b/gns3server/handlers/vpcs_handler.py @@ -23,90 +23,98 @@ from ..modules.vpcs import VPCS class VPCSHandler(object): + """ + API entry points for VPCS. + """ + @classmethod @Route.post( r"/vpcs", status_codes={ - 201: "Success of creation of VPCS", + 201: "VPCS instance created", 409: "Conflict" }, - description="Create a new VPCS and return it", + description="Create a new VPCS instance", input=VPCS_CREATE_SCHEMA, output=VPCS_OBJECT_SCHEMA) def create(request, response): + vpcs = VPCS.instance() - vm = yield from vpcs.create_vm(request.json['name']) - response.json({'name': vm.name, - "vpcs_id": vm.id, + vm = yield from vpcs.create_vm(request.json["name"]) + response.json({"name": vm.name, + "id": vm.id, "console": vm.console}) @classmethod @Route.post( - r"/vpcs/{vpcs_id}/start", + r"/vpcs/{id:\d+}/start", parameters={ - "vpcs_id": "Id of VPCS instance" + "id": "VPCS instance ID" }, status_codes={ - 201: "Success of creation of VPCS", + 204: "VPCS instance started", }, - description="Start VPCS", - ) + description="Start a VPCS instance") def create(request, response): + vpcs_manager = VPCS.instance() - vm = yield from vpcs_manager.start_vm(int(request.match_info['vpcs_id'])) + yield from vpcs_manager.start_vm(int(request.match_info["id"])) response.json({}) @classmethod @Route.post( - r"/vpcs/{vpcs_id}/stop", + r"/vpcs/{id:\d+}/stop", parameters={ - "vpcs_id": "Id of VPCS instance" + "id": "VPCS instance ID" }, status_codes={ 201: "Success of stopping VPCS", }, - description="Stop VPCS", - ) + description="Stop a VPCS instance") def create(request, response): + vpcs_manager = VPCS.instance() - vm = yield from vpcs_manager.stop_vm(int(request.match_info['vpcs_id'])) + yield from vpcs_manager.stop_vm(int(request.match_info["id"])) response.json({}) @classmethod @Route.get( - r"/vpcs/{vpcs_id}", + r"/vpcs/{id:\d+}", parameters={ - "vpcs_id": "Id of VPCS instance" + "id": "VPCS instance ID" }, description="Get information about a VPCS", output=VPCS_OBJECT_SCHEMA) def show(request, response): - response.json({'name': "PC 1", "vpcs_id": 42, "console": 4242}) + + response.json({'name': "PC 1", "id": 42, "console": 4242}) @classmethod @Route.put( - r"/vpcs/{vpcs_id}", + r"/vpcs/{id:\d+}", parameters={ - "vpcs_id": "Id of VPCS instance" + "id": "VPCS instance ID" }, description="Update VPCS information", input=VPCS_OBJECT_SCHEMA, output=VPCS_OBJECT_SCHEMA) def update(request, response): - response.json({'name': "PC 1", "vpcs_id": 42, "console": 4242}) + + response.json({'name': "PC 1", "id": 42, "console": 4242}) @classmethod @Route.post( - r"/vpcs/{vpcs_id}/nio", + r"/vpcs/{id:\d+}/nio", parameters={ - "vpcs_id": "Id of VPCS instance" + "id": "VPCS instance ID" }, status_codes={ - 201: "Success of creation of NIO", + 201: "NIO created", 409: "Conflict" }, description="ADD NIO to a VPCS", input=VPCS_ADD_NIO_SCHEMA) def create_nio(request, response): + # TODO: raise 404 if VPCS not found - response.json({'name': "PC 2", "vpcs_id": 42, "console": 4242}) + response.json({'name': "PC 2", "id": 42, "console": 4242}) diff --git a/gns3server/schemas/vpcs.py b/gns3server/schemas/vpcs.py index 7d205391..2947efba 100644 --- a/gns3server/schemas/vpcs.py +++ b/gns3server/schemas/vpcs.py @@ -26,7 +26,7 @@ VPCS_CREATE_SCHEMA = { "type": "string", "minLength": 1, }, - "vpcs_id": { + "id": { "description": "VPCS device instance ID", "type": "integer" }, @@ -215,7 +215,7 @@ VPCS_OBJECT_SCHEMA = { "type": "string", "minLength": 1, }, - "vpcs_id": { + "id": { "description": "VPCS device instance ID", "type": "integer" }, @@ -227,7 +227,7 @@ VPCS_OBJECT_SCHEMA = { }, }, "additionalProperties": False, - "required": ["name", "vpcs_id", "console"] + "required": ["name", "id", "console"] } VBOX_CREATE_SCHEMA = { diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/api/test_version.py b/tests/api/test_version.py index a052bb43..35d0f5b8 100644 --- a/tests/api/test_version.py +++ b/tests/api/test_version.py @@ -21,7 +21,6 @@ It's also used for unittest the HTTP implementation. """ from tests.utils import asyncio_patch -from tests.api.base import server, loop from gns3server.version import __version__ diff --git a/tests/api/test_vpcs.py b/tests/api/test_vpcs.py index ccecd96f..6abb5c3c 100644 --- a/tests/api/test_vpcs.py +++ b/tests/api/test_vpcs.py @@ -15,9 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from tests.api.base import server, loop from tests.utils import asyncio_patch -from gns3server import modules @asyncio_patch('gns3server.modules.VPCS.create_vm', return_value=84) @@ -26,7 +24,7 @@ def test_vpcs_create(server): assert response.status == 200 assert response.route == '/vpcs' assert response.json['name'] == 'PC TEST 1' - assert response.json['vpcs_id'] == 84 + assert response.json['id'] == 84 def test_vpcs_nio_create(server): @@ -41,5 +39,5 @@ def test_vpcs_nio_create(server): 'port_id': 0}, example=True) assert response.status == 200 - assert response.route == '/vpcs/{vpcs_id}/nio' + assert response.route == '/vpcs/{id}/nio' assert response.json['name'] == 'PC 2'