Rename vpcs_id to id. Must be an integer in the route definition.

This commit is contained in:
Jeremy 2015-01-18 12:12:11 -07:00
parent 2ee49fed57
commit d142a9a885
5 changed files with 39 additions and 34 deletions

View File

@ -23,90 +23,98 @@ from ..modules.vpcs import VPCS
class VPCSHandler(object): class VPCSHandler(object):
"""
API entry points for VPCS.
"""
@classmethod @classmethod
@Route.post( @Route.post(
r"/vpcs", r"/vpcs",
status_codes={ status_codes={
201: "Success of creation of VPCS", 201: "VPCS instance created",
409: "Conflict" 409: "Conflict"
}, },
description="Create a new VPCS and return it", description="Create a new VPCS instance",
input=VPCS_CREATE_SCHEMA, input=VPCS_CREATE_SCHEMA,
output=VPCS_OBJECT_SCHEMA) output=VPCS_OBJECT_SCHEMA)
def create(request, response): def create(request, response):
vpcs = VPCS.instance() vpcs = VPCS.instance()
vm = yield from vpcs.create_vm(request.json['name']) vm = yield from vpcs.create_vm(request.json["name"])
response.json({'name': vm.name, response.json({"name": vm.name,
"vpcs_id": vm.id, "id": vm.id,
"console": vm.console}) "console": vm.console})
@classmethod @classmethod
@Route.post( @Route.post(
r"/vpcs/{vpcs_id}/start", r"/vpcs/{id:\d+}/start",
parameters={ parameters={
"vpcs_id": "Id of VPCS instance" "id": "VPCS instance ID"
}, },
status_codes={ status_codes={
201: "Success of creation of VPCS", 204: "VPCS instance started",
}, },
description="Start VPCS", description="Start a VPCS instance")
)
def create(request, response): def create(request, response):
vpcs_manager = VPCS.instance() 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({}) response.json({})
@classmethod @classmethod
@Route.post( @Route.post(
r"/vpcs/{vpcs_id}/stop", r"/vpcs/{id:\d+}/stop",
parameters={ parameters={
"vpcs_id": "Id of VPCS instance" "id": "VPCS instance ID"
}, },
status_codes={ status_codes={
201: "Success of stopping VPCS", 201: "Success of stopping VPCS",
}, },
description="Stop VPCS", description="Stop a VPCS instance")
)
def create(request, response): def create(request, response):
vpcs_manager = VPCS.instance() 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({}) response.json({})
@classmethod @classmethod
@Route.get( @Route.get(
r"/vpcs/{vpcs_id}", r"/vpcs/{id:\d+}",
parameters={ parameters={
"vpcs_id": "Id of VPCS instance" "id": "VPCS instance ID"
}, },
description="Get information about a VPCS", description="Get information about a VPCS",
output=VPCS_OBJECT_SCHEMA) output=VPCS_OBJECT_SCHEMA)
def show(request, response): def show(request, response):
response.json({'name': "PC 1", "vpcs_id": 42, "console": 4242})
response.json({'name': "PC 1", "id": 42, "console": 4242})
@classmethod @classmethod
@Route.put( @Route.put(
r"/vpcs/{vpcs_id}", r"/vpcs/{id:\d+}",
parameters={ parameters={
"vpcs_id": "Id of VPCS instance" "id": "VPCS instance ID"
}, },
description="Update VPCS information", description="Update VPCS information",
input=VPCS_OBJECT_SCHEMA, input=VPCS_OBJECT_SCHEMA,
output=VPCS_OBJECT_SCHEMA) output=VPCS_OBJECT_SCHEMA)
def update(request, response): def update(request, response):
response.json({'name': "PC 1", "vpcs_id": 42, "console": 4242})
response.json({'name': "PC 1", "id": 42, "console": 4242})
@classmethod @classmethod
@Route.post( @Route.post(
r"/vpcs/{vpcs_id}/nio", r"/vpcs/{id:\d+}/nio",
parameters={ parameters={
"vpcs_id": "Id of VPCS instance" "id": "VPCS instance ID"
}, },
status_codes={ status_codes={
201: "Success of creation of NIO", 201: "NIO created",
409: "Conflict" 409: "Conflict"
}, },
description="ADD NIO to a VPCS", description="ADD NIO to a VPCS",
input=VPCS_ADD_NIO_SCHEMA) input=VPCS_ADD_NIO_SCHEMA)
def create_nio(request, response): def create_nio(request, response):
# TODO: raise 404 if VPCS not found # 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})

View File

@ -26,7 +26,7 @@ VPCS_CREATE_SCHEMA = {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
}, },
"vpcs_id": { "id": {
"description": "VPCS device instance ID", "description": "VPCS device instance ID",
"type": "integer" "type": "integer"
}, },
@ -215,7 +215,7 @@ VPCS_OBJECT_SCHEMA = {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
}, },
"vpcs_id": { "id": {
"description": "VPCS device instance ID", "description": "VPCS device instance ID",
"type": "integer" "type": "integer"
}, },
@ -227,7 +227,7 @@ VPCS_OBJECT_SCHEMA = {
}, },
}, },
"additionalProperties": False, "additionalProperties": False,
"required": ["name", "vpcs_id", "console"] "required": ["name", "id", "console"]
} }
VBOX_CREATE_SCHEMA = { VBOX_CREATE_SCHEMA = {

0
tests/__init__.py Normal file
View File

View File

@ -21,7 +21,6 @@ It's also used for unittest the HTTP implementation.
""" """
from tests.utils import asyncio_patch from tests.utils import asyncio_patch
from tests.api.base import server, loop
from gns3server.version import __version__ from gns3server.version import __version__

View File

@ -15,9 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from tests.api.base import server, loop
from tests.utils import asyncio_patch from tests.utils import asyncio_patch
from gns3server import modules
@asyncio_patch('gns3server.modules.VPCS.create_vm', return_value=84) @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.status == 200
assert response.route == '/vpcs' assert response.route == '/vpcs'
assert response.json['name'] == 'PC TEST 1' assert response.json['name'] == 'PC TEST 1'
assert response.json['vpcs_id'] == 84 assert response.json['id'] == 84
def test_vpcs_nio_create(server): def test_vpcs_nio_create(server):
@ -41,5 +39,5 @@ def test_vpcs_nio_create(server):
'port_id': 0}, 'port_id': 0},
example=True) example=True)
assert response.status == 200 assert response.status == 200
assert response.route == '/vpcs/{vpcs_id}/nio' assert response.route == '/vpcs/{id}/nio'
assert response.json['name'] == 'PC 2' assert response.json['name'] == 'PC 2'