mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Create link using UDP work
This commit is contained in:
6 files changed
+42
-24
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user