From a08ddce0333b688c2fa3eea4e00aa51167a06944 Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 22 Oct 2020 20:05:37 +1030 Subject: [PATCH] Revert compute.py --- gns3server/controller/compute.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/gns3server/controller/compute.py b/gns3server/controller/compute.py index 8d540298..770acce0 100644 --- a/gns3server/controller/compute.py +++ b/gns3server/controller/compute.py @@ -63,9 +63,7 @@ class Compute: A GNS3 compute. """ - def __init__(self, compute_id, controller=None, protocol="http", host="localhost", port=3080, user=None, - password=None, name=None, console_host=None): - + def __init__(self, compute_id, controller=None, protocol="http", host="localhost", port=3080, user=None, password=None, name=None, console_host=None): self._http_session = None assert controller is not None log.info("Create compute %s", compute_id) @@ -105,10 +103,14 @@ class Compute: def _session(self): if self._http_session is None or self._http_session.closed is True: - connector = aiohttp.TCPConnector(limit=None, force_close=True) - self._http_session = aiohttp.ClientSession(connector=connector) + self._http_session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(limit=None, force_close=True)) return self._http_session + #def __del__(self): + # + # if self._http_session: + # self._http_session.close() + def _set_auth(self, user, password): """ Set authentication parameters @@ -577,7 +579,7 @@ class Compute: return response async def get(self, path, **kwargs): - return await self.http_query("GET", path, **kwargs) + return (await self.http_query("GET", path, **kwargs)) async def post(self, path, data={}, **kwargs): response = await self.http_query("POST", path, data, **kwargs) @@ -594,17 +596,19 @@ class Compute: """ Forward a call to the emulator on compute """ - action = "/{}/{}".format(type, path) try: + action = "/{}/{}".format(type, path) res = await self.http_query(method, action, data=data, timeout=None) except aiohttp.ServerDisconnectedError: - raise ControllerError(f"Connection lost to {self._id} during {method} {action}") + log.error("Connection lost to %s during %s %s", self._id, method, action) + raise aiohttp.web.HTTPGatewayTimeout() return res.json async def images(self, type): """ Return the list of images available for this type on the compute node. """ + images = [] res = await self.http_query("GET", "/{}/images".format(type), timeout=None) images = res.json @@ -637,11 +641,11 @@ class Compute: :returns: Tuple (ip_for_this_compute, ip_for_other_compute) """ if other_compute == self: - return self.host_ip, self.host_ip + return (self.host_ip, self.host_ip) # Perhaps the user has correct network gateway, we trust him - if self.host_ip not in ('0.0.0.0', '127.0.0.1') and other_compute.host_ip not in ('0.0.0.0', '127.0.0.1'): - return self.host_ip, other_compute.host_ip + if (self.host_ip not in ('0.0.0.0', '127.0.0.1') and other_compute.host_ip not in ('0.0.0.0', '127.0.0.1')): + return (self.host_ip, other_compute.host_ip) this_compute_interfaces = await self.interfaces() other_compute_interfaces = await other_compute.interfaces() @@ -671,6 +675,6 @@ class Compute: other_network = ipaddress.ip_network("{}/{}".format(other_interface["ip_address"], other_interface["netmask"]), strict=False) if this_network.overlaps(other_network): - return this_interface["ip_address"], other_interface["ip_address"] + return (this_interface["ip_address"], other_interface["ip_address"]) raise ValueError("No common subnet for compute {} and {}".format(self.name, other_compute.name))