Add the notion of adapters and slot in the api

This commit is contained in:
Julien Duponchelle 2015-02-13 18:09:50 +01:00
parent 821eb5e92b
commit 2cab5293c7
7 changed files with 39 additions and 31 deletions

View File

@ -194,10 +194,11 @@ class IOUHandler:
response.set_status(204)
@Route.post(
r"/projects/{project_id}/iou/vms/{vm_id}/ports/{port_number:\d+}/nio",
r"/projects/{project_id}/iou/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio",
parameters={
"project_id": "UUID for the project",
"vm_id": "UUID for the instance",
"adapter_number": "Network adapter where the nio is located",
"port_number": "Port where the nio should be added"
},
status_codes={
@ -213,16 +214,17 @@ class IOUHandler:
iou_manager = IOU.instance()
vm = iou_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
nio = iou_manager.create_nio(vm.iouyap_path, request.json)
vm.slot_add_nio_binding(0, int(request.match_info["port_number"]), nio)
vm.slot_add_nio_binding(int(request.match_info["adapter_number"]), int(request.match_info["port_number"]), nio)
response.set_status(201)
response.json(nio)
@classmethod
@Route.delete(
r"/projects/{project_id}/iou/vms/{vm_id}/ports/{port_number:\d+}/nio",
r"/projects/{project_id}/iou/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio",
parameters={
"project_id": "UUID for the project",
"vm_id": "UUID for the instance",
"adapter_number": "Network adapter where the nio is located",
"port_number": "Port from where the nio should be removed"
},
status_codes={
@ -235,5 +237,5 @@ class IOUHandler:
iou_manager = IOU.instance()
vm = iou_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
vm.slot_remove_nio_binding(0, int(request.match_info["port_number"]))
vm.slot_remove_nio_binding(int(request.match_info["adapter_number"]), int(request.match_info["port_number"]))
response.set_status(204)

View File

@ -252,11 +252,12 @@ class VirtualBoxHandler:
response.set_status(204)
@Route.post(
r"/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio",
r"/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/ports/{port_id:\d+}/nio",
parameters={
"project_id": "UUID for the project",
"vm_id": "UUID for the instance",
"adapter_id": "Adapter where the nio should be added"
"adapter_id": "Adapter where the nio should be added",
"port_id": "Port in the adapter (always 0 for virtualbox)"
},
status_codes={
201: "NIO created",
@ -277,11 +278,12 @@ class VirtualBoxHandler:
@classmethod
@Route.delete(
r"/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio",
r"/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/ports/{port_id:\d+}/nio",
parameters={
"project_id": "UUID for the project",
"vm_id": "UUID for the instance",
"adapter_id": "Adapter from where the nio should be removed"
"adapter_id": "Adapter from where the nio should be removed",
"port_id": "Port in the adapter (always 0 for virtualbox)"
},
status_codes={
204: "NIO deleted",

View File

@ -178,10 +178,11 @@ class VPCSHandler:
response.set_status(204)
@Route.post(
r"/projects/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio",
r"/projects/{project_id}/vpcs/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio",
parameters={
"project_id": "UUID for the project",
"vm_id": "UUID for the instance",
"adapter_number": "Network adapter where the nio is located",
"port_number": "Port where the nio should be added"
},
status_codes={
@ -203,10 +204,11 @@ class VPCSHandler:
@classmethod
@Route.delete(
r"/projects/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio",
r"/projects/{project_id}/vpcs/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio",
parameters={
"project_id": "UUID for the project",
"vm_id": "UUID for the instance",
"adapter_number": "Network adapter where the nio is located",
"port_number": "Port from where the nio should be removed"
},
status_codes={

View File

@ -74,7 +74,9 @@ class Query:
asyncio.async(go(future, response))
self._loop.run_until_complete(future)
response.body = future.result()
response.route = response.headers.get('X-Route', None).replace("/v1", "")
x_route = response.headers.get('X-Route', None)
if x_route is not None:
response.route = x_route.replace("/v1", "")
if response.body is not None:
try:

View File

@ -142,41 +142,41 @@ def test_iou_update(server, vm, tmpdir, free_console_port):
def test_iou_nio_create_udp(server, vm):
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
"lport": 4242,
"rport": 4343,
"rhost": "127.0.0.1"},
example=True)
assert response.status == 201
assert response.route == "/projects/{project_id}/iou/vms/{vm_id}/ports/{port_number:\d+}/nio"
assert response.route == "/projects/{project_id}/iou/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
assert response.json["type"] == "nio_udp"
def test_iou_nio_create_ethernet(server, vm):
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_generic_ethernet",
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_generic_ethernet",
"ethernet_device": "eth0",
},
example=True)
assert response.status == 201
assert response.route == "/projects/{project_id}/iou/vms/{vm_id}/ports/{port_number:\d+}/nio"
assert response.route == "/projects/{project_id}/iou/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
assert response.json["type"] == "nio_generic_ethernet"
assert response.json["ethernet_device"] == "eth0"
def test_iou_nio_create_tap(server, vm):
with patch("gns3server.modules.base_manager.BaseManager._has_privileged_access", return_value=True):
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_tap",
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_tap",
"tap_device": "test"})
assert response.status == 201
assert response.route == "/projects/{project_id}/iou/vms/{vm_id}/ports/{port_number:\d+}/nio"
assert response.route == "/projects/{project_id}/iou/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
assert response.json["type"] == "nio_tap"
def test_iou_delete_nio(server, vm):
server.post("/projects/{project_id}/iou/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
"lport": 4242,
"rport": 4343,
"rhost": "127.0.0.1"})
response = server.delete("/projects/{project_id}/iou/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
response = server.delete("/projects/{project_id}/iou/vms/{vm_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert response.status == 204
assert response.route == "/projects/{project_id}/iou/vms/{vm_id}/ports/{port_number:\d+}/nio"
assert response.route == "/projects/{project_id}/iou/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"

View File

@ -93,7 +93,7 @@ def test_vbox_reload(server, vm):
def test_vbox_nio_create_udp(server, vm):
with asyncio_patch('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_add_nio_binding') as mock:
response = server.post("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"],
response = server.post("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"],
vm_id=vm["vm_id"]), {"type": "nio_udp",
"lport": 4242,
"rport": 4343,
@ -105,21 +105,21 @@ def test_vbox_nio_create_udp(server, vm):
assert args[0] == 0
assert response.status == 201
assert response.route == "/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio"
assert response.route == "/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/ports/{port_id:\d+}/nio"
assert response.json["type"] == "nio_udp"
def test_vbox_delete_nio(server, vm):
with asyncio_patch('gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.adapter_remove_nio_binding') as mock:
response = server.delete("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
response = server.delete("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert mock.called
args, kwgars = mock.call_args
assert args[0] == 0
assert response.status == 204
assert response.route == "/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio"
assert response.route == "/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/ports/{port_id:\d+}/nio"
def test_vbox_update(server, vm, free_console_port):

View File

@ -63,33 +63,33 @@ def test_vpcs_create_port(server, project, free_console_port):
def test_vpcs_nio_create_udp(server, vm):
response = server.post("/projects/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
response = server.post("/projects/{project_id}/vpcs/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
"lport": 4242,
"rport": 4343,
"rhost": "127.0.0.1"},
example=True)
assert response.status == 201
assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio"
assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
assert response.json["type"] == "nio_udp"
def test_vpcs_nio_create_tap(server, vm):
with patch("gns3server.modules.base_manager.BaseManager._has_privileged_access", return_value=True):
response = server.post("/projects/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_tap",
response = server.post("/projects/{project_id}/vpcs/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_tap",
"tap_device": "test"})
assert response.status == 201
assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio"
assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
assert response.json["type"] == "nio_tap"
def test_vpcs_delete_nio(server, vm):
server.post("/projects/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
server.post("/projects/{project_id}/vpcs/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
"lport": 4242,
"rport": 4343,
"rhost": "127.0.0.1"})
response = server.delete("/projects/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
response = server.delete("/projects/{project_id}/vpcs/vms/{vm_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert response.status == 204
assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio"
assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
def test_vpcs_start(server, vm):