mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 00:08:11 +00:00
Create link using UDP work
This commit is contained in:
parent
8cb5a6ec75
commit
9771b33b68
@ -91,11 +91,26 @@ class Hypervisor:
|
||||
data = json.dumps(data)
|
||||
response = yield from session.request(method, url, headers=headers, data=data)
|
||||
body = yield from response.read()
|
||||
if response.status >= 300:
|
||||
raise aiohttp.errors.HttpProcessingError(code=response.status, message=body)
|
||||
yield from response.release()
|
||||
return body
|
||||
if body:
|
||||
body = body.decode()
|
||||
if response.status == 400:
|
||||
raise aiohttp.web.HTTPBadRequest(text=body)
|
||||
elif response.status == 401:
|
||||
raise aiohttp.web.HTTPUnauthorized(text=body)
|
||||
elif response.status == 403:
|
||||
raise aiohttp.web.HTTPForbidden(text=body)
|
||||
elif response.status == 404:
|
||||
raise aiohttp.web.HTTPNotFound(text="{} not found on hypervisor".format(url))
|
||||
elif response.status == 409:
|
||||
raise aiohttp.web.HTTPConflict(text=body)
|
||||
elif response.status >= 300:
|
||||
raise NotImplemented("{} status code is not supported".format(e.status))
|
||||
if body and len(body):
|
||||
response.json = json.loads(body)
|
||||
else:
|
||||
response.json = {}
|
||||
return response
|
||||
|
||||
@asyncio.coroutine
|
||||
def post(self, path, data={}):
|
||||
yield from self.httpQuery("POST", path, data)
|
||||
return (yield from self.httpQuery("POST", path, data))
|
||||
|
@ -20,7 +20,7 @@ import aiohttp
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from .vm import VM
|
||||
from .link import Link
|
||||
from .udp_link import UDPLink
|
||||
|
||||
|
||||
class Project:
|
||||
@ -98,7 +98,7 @@ class Project:
|
||||
"""
|
||||
Create a link. By default the link is empty
|
||||
"""
|
||||
link = Link(self)
|
||||
link = UDPLink(self)
|
||||
self._links[link.id] = link
|
||||
return link
|
||||
|
||||
|
@ -35,9 +35,9 @@ class UDPLink(Link):
|
||||
port_number2 = self._vms[1]["port_number"]
|
||||
|
||||
# Reserve a UDP port on both side
|
||||
response = yield from vm1.post("/ports/udp".format(self._project.id))
|
||||
response = yield from vm1.hypervisor.post("/projects/{}/ports/udp".format(self._project.id))
|
||||
vm1_port = response.json["udp_port"]
|
||||
response = yield from vm2.post("/ports/udp".format(self._project.id))
|
||||
response = yield from vm2.hypervisor.post("/projects/{}/ports/udp".format(self._project.id))
|
||||
vm2_port = response.json["udp_port"]
|
||||
|
||||
# Create the tunnel on both side
|
||||
|
@ -48,5 +48,6 @@ class LinkHandler:
|
||||
yield from link.addVM(project.getVM(vm["vm_id"]),
|
||||
vm["adapter_number"],
|
||||
vm["port_number"])
|
||||
yield from link.create()
|
||||
response.set_status(201)
|
||||
response.json(link)
|
||||
|
@ -64,7 +64,7 @@ def test_hypervisor_httpQueryError(hypervisor, async_run):
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
response.status = 409
|
||||
|
||||
with pytest.raises(aiohttp.errors.HttpProcessingError):
|
||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||
async_run(hypervisor.post("/projects", {"a": "b"}))
|
||||
|
||||
|
||||
|
@ -51,20 +51,22 @@ def test_create_link(http_controller, tmpdir, project, hypervisor, async_run):
|
||||
vm1 = async_run(project.addVM(hypervisor, None))
|
||||
vm2 = async_run(project.addVM(hypervisor, None))
|
||||
|
||||
response = http_controller.post("/projects/{}/links".format(project.id), {
|
||||
"vms": [
|
||||
{
|
||||
"vm_id": vm1.id,
|
||||
"adapter_number": 0,
|
||||
"port_number": 3
|
||||
},
|
||||
{
|
||||
"vm_id": vm2.id,
|
||||
"adapter_number": 2,
|
||||
"port_number": 4
|
||||
}
|
||||
]
|
||||
}, example=True)
|
||||
|
||||
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create"):
|
||||
response = http_controller.post("/projects/{}/links".format(project.id), {
|
||||
"vms": [
|
||||
{
|
||||
"vm_id": vm1.id,
|
||||
"adapter_number": 0,
|
||||
"port_number": 3
|
||||
},
|
||||
{
|
||||
"vm_id": vm2.id,
|
||||
"adapter_number": 2,
|
||||
"port_number": 4
|
||||
}
|
||||
]
|
||||
}, example=True)
|
||||
assert response.status == 201
|
||||
assert response.json["link_id"] is not None
|
||||
assert len(response.json["vms"]) == 2
|
||||
|
Loading…
Reference in New Issue
Block a user