Create link using UDP work

This commit is contained in:
Julien Duponchelle committed 2016-03-14 16:51:47 +01:00
1 parent 8cb5a6ec75
commit 9771b33b68
6 files changed
+42 -24

No files matched your search

+20 -5
View File
@@ -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))
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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