mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-13 20:08:55 +00:00
Revert compute.py
This commit is contained in:
parent
97a91f1899
commit
a08ddce033
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user