mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-16 08:44:52 +02:00
Rename vpcs_id to id. Must be an integer in the route definition.
This commit is contained in:
parent
2ee49fed57
commit
d142a9a885
@ -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})
|
||||
|
@ -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 = {
|
||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
@ -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__
|
||||
|
||||
|
||||
|
@ -15,9 +15,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# 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 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'
|
||||
|
Loading…
Reference in New Issue
Block a user