1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-03 21:58:13 +00:00

Revert compute.py

This commit is contained in:
grossmj 2020-10-22 20:05:37 +10:30
parent 97a91f1899
commit a08ddce033

View File

@ -63,9 +63,7 @@ class Compute:
A GNS3 compute. A GNS3 compute.
""" """
def __init__(self, compute_id, controller=None, protocol="http", host="localhost", port=3080, user=None, def __init__(self, compute_id, controller=None, protocol="http", host="localhost", port=3080, user=None, password=None, name=None, console_host=None):
password=None, name=None, console_host=None):
self._http_session = None self._http_session = None
assert controller is not None assert controller is not None
log.info("Create compute %s", compute_id) log.info("Create compute %s", compute_id)
@ -105,10 +103,14 @@ class Compute:
def _session(self): def _session(self):
if self._http_session is None or self._http_session.closed is True: 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=aiohttp.TCPConnector(limit=None, force_close=True))
self._http_session = aiohttp.ClientSession(connector=connector)
return self._http_session return self._http_session
#def __del__(self):
#
# if self._http_session:
# self._http_session.close()
def _set_auth(self, user, password): def _set_auth(self, user, password):
""" """
Set authentication parameters Set authentication parameters
@ -577,7 +579,7 @@ class Compute:
return response return response
async def get(self, path, **kwargs): 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): async def post(self, path, data={}, **kwargs):
response = await self.http_query("POST", 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 Forward a call to the emulator on compute
""" """
action = "/{}/{}".format(type, path)
try: try:
action = "/{}/{}".format(type, path)
res = await self.http_query(method, action, data=data, timeout=None) res = await self.http_query(method, action, data=data, timeout=None)
except aiohttp.ServerDisconnectedError: 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 return res.json
async def images(self, type): async def images(self, type):
""" """
Return the list of images available for this type on the compute node. 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) res = await self.http_query("GET", "/{}/images".format(type), timeout=None)
images = res.json images = res.json
@ -637,11 +641,11 @@ class Compute:
:returns: Tuple (ip_for_this_compute, ip_for_other_compute) :returns: Tuple (ip_for_this_compute, ip_for_other_compute)
""" """
if other_compute == self: 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 # 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'): 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 return (self.host_ip, other_compute.host_ip)
this_compute_interfaces = await self.interfaces() this_compute_interfaces = await self.interfaces()
other_compute_interfaces = await other_compute.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) other_network = ipaddress.ip_network("{}/{}".format(other_interface["ip_address"], other_interface["netmask"]), strict=False)
if this_network.overlaps(other_network): 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)) raise ValueError("No common subnet for compute {} and {}".format(self.name, other_compute.name))