mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Code cleanup
This commit is contained in:
parent
5bee927481
commit
373113545f
@ -403,9 +403,9 @@ class IOUVM(BaseVM):
|
|||||||
raise IOUError("Hostname \"{}\" not found in iourc file {}".format(hostname, self.iourc_path))
|
raise IOUError("Hostname \"{}\" not found in iourc file {}".format(hostname, self.iourc_path))
|
||||||
user_ioukey = config["license"][hostname]
|
user_ioukey = config["license"][hostname]
|
||||||
if user_ioukey[-1:] != ';':
|
if user_ioukey[-1:] != ';':
|
||||||
raise IOUError("IOU key not ending with ; in iourc file".format(self.iourc_path))
|
raise IOUError("IOU key not ending with ; in iourc file {}".format(self.iourc_path))
|
||||||
if len(user_ioukey) != 17:
|
if len(user_ioukey) != 17:
|
||||||
raise IOUError("IOU key length is not 16 characters in iourc file".format(self.iourc_path))
|
raise IOUError("IOU key length is not 16 characters in iourc file {}".format(self.iourc_path))
|
||||||
user_ioukey = user_ioukey[:16]
|
user_ioukey = user_ioukey[:16]
|
||||||
|
|
||||||
# We can't test this because it's mean distributing a valid licence key
|
# We can't test this because it's mean distributing a valid licence key
|
||||||
@ -1255,10 +1255,10 @@ class IOUVM(BaseVM):
|
|||||||
|
|
||||||
nio.startPacketCapture(output_file, data_link_type)
|
nio.startPacketCapture(output_file, data_link_type)
|
||||||
log.info('IOU "{name}" [{id}]: starting packet capture on {adapter_number}/{port_number} to {output_file}'.format(name=self._name,
|
log.info('IOU "{name}" [{id}]: starting packet capture on {adapter_number}/{port_number} to {output_file}'.format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
adapter_number=adapter_number,
|
adapter_number=adapter_number,
|
||||||
port_number=port_number,
|
port_number=port_number,
|
||||||
output_file=output_file))
|
output_file=output_file))
|
||||||
|
|
||||||
if self.is_iouyap_running():
|
if self.is_iouyap_running():
|
||||||
self._update_iouyap_config()
|
self._update_iouyap_config()
|
||||||
|
@ -142,16 +142,14 @@ class PortManager:
|
|||||||
if end_port < start_port:
|
if end_port < start_port:
|
||||||
raise HTTPConflict(text="Invalid port range {}-{}".format(start_port, end_port))
|
raise HTTPConflict(text="Invalid port range {}-{}".format(start_port, end_port))
|
||||||
|
|
||||||
|
|
||||||
last_exception = None
|
last_exception = None
|
||||||
for port in range(start_port, end_port + 1):
|
for port in range(start_port, end_port + 1):
|
||||||
if port in ignore_ports:
|
if port in ignore_ports:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
last_exception
|
|
||||||
try:
|
try:
|
||||||
PortManager._check_port(host, port, socket_type)
|
PortManager._check_port(host, port, socket_type)
|
||||||
return port
|
return port
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
last_exception = e
|
last_exception = e
|
||||||
if port + 1 == end_port:
|
if port + 1 == end_port:
|
||||||
@ -163,6 +161,7 @@ class PortManager:
|
|||||||
end_port,
|
end_port,
|
||||||
host,
|
host,
|
||||||
last_exception))
|
last_exception))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _check_port(host, port, socket_type):
|
def _check_port(host, port, socket_type):
|
||||||
"""
|
"""
|
||||||
@ -182,7 +181,6 @@ class PortManager:
|
|||||||
s.bind(sa) # the port is available if bind is a success
|
s.bind(sa) # the port is available if bind is a success
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_free_tcp_port(self, project, port_range_start=None, port_range_end=None):
|
def get_free_tcp_port(self, project, port_range_start=None, port_range_end=None):
|
||||||
"""
|
"""
|
||||||
Get an available TCP port and reserve it
|
Get an available TCP port and reserve it
|
||||||
@ -291,7 +289,7 @@ class PortManager:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if port in self._used_udp_ports:
|
if port in self._used_udp_ports:
|
||||||
raise HTTPConflict(text="UDP port {} already in use on host".format(port, self._console_host))
|
raise HTTPConflict(text="UDP port {} already in use on host {}".format(port, self._console_host))
|
||||||
if port < self._udp_port_range[0] or port > self._udp_port_range[1]:
|
if port < self._udp_port_range[0] or port > self._udp_port_range[1]:
|
||||||
raise HTTPConflict(text="UDP port {} is outside the range {}-{}".format(port, self._udp_port_range[0], self._udp_port_range[1]))
|
raise HTTPConflict(text="UDP port {} is outside the range {}-{}".format(port, self._udp_port_range[0], self._udp_port_range[1]))
|
||||||
self._used_udp_ports.add(port)
|
self._used_udp_ports.add(port)
|
||||||
|
@ -1084,24 +1084,24 @@ class QemuVM(BaseVM):
|
|||||||
raise QemuError("Sorry, adding a link to a started Qemu VM is not supported.")
|
raise QemuError("Sorry, adding a link to a started Qemu VM is not supported.")
|
||||||
# FIXME: does the code below work? very undocumented feature...
|
# FIXME: does the code below work? very undocumented feature...
|
||||||
# dynamically configure an UDP tunnel on the QEMU VM adapter
|
# dynamically configure an UDP tunnel on the QEMU VM adapter
|
||||||
if nio and isinstance(nio, NIOUDP):
|
# if nio and isinstance(nio, NIOUDP):
|
||||||
if self._legacy_networking:
|
# if self._legacy_networking:
|
||||||
yield from self._control_vm("host_net_remove {} gns3-{}".format(adapter_number, adapter_number))
|
# yield from self._control_vm("host_net_remove {} gns3-{}".format(adapter_number, adapter_number))
|
||||||
yield from self._control_vm("host_net_add udp vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number,
|
# yield from self._control_vm("host_net_add udp vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number,
|
||||||
adapter_number,
|
# adapter_number,
|
||||||
nio.lport,
|
# nio.lport,
|
||||||
nio.rport,
|
# nio.rport,
|
||||||
nio.rhost))
|
# nio.rhost))
|
||||||
else:
|
# else:
|
||||||
# Apparently there is a bug in Qemu...
|
# # Apparently there is a bug in Qemu...
|
||||||
# netdev_add [user|tap|socket|hubport|netmap],id=str[,prop=value][,...] -- add host network device
|
# # netdev_add [user|tap|socket|hubport|netmap],id=str[,prop=value][,...] -- add host network device
|
||||||
# netdev_del id -- remove host network device
|
# # netdev_del id -- remove host network device
|
||||||
yield from self._control_vm("netdev_del gns3-{}".format(adapter_number))
|
# yield from self._control_vm("netdev_del gns3-{}".format(adapter_number))
|
||||||
yield from self._control_vm("netdev_add socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number,
|
# yield from self._control_vm("netdev_add socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number,
|
||||||
nio.rhost,
|
# nio.rhost,
|
||||||
nio.rport,
|
# nio.rport,
|
||||||
self._host,
|
# self._host,
|
||||||
nio.lport))
|
# nio.lport))
|
||||||
|
|
||||||
adapter.add_nio(0, nio)
|
adapter.add_nio(0, nio)
|
||||||
log.info('QEMU VM "{name}" [{id}]: {nio} added to adapter {adapter_number}'.format(name=self._name,
|
log.info('QEMU VM "{name}" [{id}]: {nio} added to adapter {adapter_number}'.format(name=self._name,
|
||||||
|
@ -61,20 +61,20 @@ class Query:
|
|||||||
body = json.dumps(body)
|
body = json.dumps(body)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def go(future):
|
def go_request(future):
|
||||||
response = yield from aiohttp.request(method, self.get_url(path, api_version), data=body)
|
response = yield from aiohttp.request(method, self.get_url(path, api_version), data=body)
|
||||||
future.set_result(response)
|
future.set_result(response)
|
||||||
future = asyncio.Future()
|
future = asyncio.Future()
|
||||||
asyncio.async(go(future))
|
asyncio.async(go_request(future))
|
||||||
self._loop.run_until_complete(future)
|
self._loop.run_until_complete(future)
|
||||||
response = future.result()
|
response = future.result()
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def go(future, response):
|
def go_read(future, response):
|
||||||
response = yield from response.read()
|
response = yield from response.read()
|
||||||
future.set_result(response)
|
future.set_result(response)
|
||||||
future = asyncio.Future()
|
future = asyncio.Future()
|
||||||
asyncio.async(go(future, response))
|
asyncio.async(go_read(future, response))
|
||||||
self._loop.run_until_complete(future)
|
self._loop.run_until_complete(future)
|
||||||
response.body = future.result()
|
response.body = future.result()
|
||||||
x_route = response.headers.get('X-Route', None)
|
x_route = response.headers.get('X-Route', None)
|
||||||
|
@ -42,7 +42,7 @@ def test_reserve_tcp_port_outside_range():
|
|||||||
assert mock_emit.call_args[0][0] == "log.warning"
|
assert mock_emit.call_args[0][0] == "log.warning"
|
||||||
|
|
||||||
|
|
||||||
def test_reserve_tcp_port_already_used():
|
def test_reserve_tcp_port_already_used_by_another_program():
|
||||||
"""
|
"""
|
||||||
This test simulate a scenario where the port is already taken
|
This test simulate a scenario where the port is already taken
|
||||||
by another programm on the server
|
by another programm on the server
|
||||||
@ -65,6 +65,7 @@ def test_reserve_tcp_port_already_used():
|
|||||||
assert port != 2001
|
assert port != 2001
|
||||||
assert mock_emit.call_args[0][0] == "log.warning"
|
assert mock_emit.call_args[0][0] == "log.warning"
|
||||||
|
|
||||||
|
|
||||||
def test_reserve_tcp_port_already_used():
|
def test_reserve_tcp_port_already_used():
|
||||||
"""
|
"""
|
||||||
This test simulate a scenario where the port is already taken
|
This test simulate a scenario where the port is already taken
|
||||||
|
Loading…
Reference in New Issue
Block a user