Code cleanup

This commit is contained in:
Julien Duponchelle committed 2016-02-05 10:07:13 +01:00
1 parent 5bee927481
commit 373113545f
5 files changed
+34 -35

No files matched your search

+6 -6
View File
@@ -403,9 +403,9 @@ class IOUVM(BaseVM):
raise IOUError("Hostname \"{}\" not found in iourc file {}".format(hostname, self.iourc_path))
user_ioukey = config["license"][hostname]
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:
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]
# 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)
log.info('IOU "{name}" [{id}]: starting packet capture on {adapter_number}/{port_number} to {output_file}'.format(name=self._name,
id=self._id,
adapter_number=adapter_number,
port_number=port_number,
output_file=output_file))
id=self._id,
adapter_number=adapter_number,
port_number=port_number,
output_file=output_file))
if self.is_iouyap_running():
self._update_iouyap_config()
+4 -6
View File
@@ -142,16 +142,14 @@ class PortManager:
if end_port < start_port:
raise HTTPConflict(text="Invalid port range {}-{}".format(start_port, end_port))
last_exception = None
for port in range(start_port, end_port + 1):
if port in ignore_ports:
continue
last_exception
try:
PortManager._check_port(host, port, socket_type)
return port
PortManager._check_port(host, port, socket_type)
return port
except OSError as e:
last_exception = e
if port + 1 == end_port:
@@ -163,6 +161,7 @@ class PortManager:
end_port,
host,
last_exception))
@staticmethod
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
return True
def get_free_tcp_port(self, project, port_range_start=None, port_range_end=None):
"""
Get an available TCP port and reserve it
@@ -291,7 +289,7 @@ class PortManager:
"""
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]:
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)
+18 -18
View File
@@ -1084,24 +1084,24 @@ class QemuVM(BaseVM):
raise QemuError("Sorry, adding a link to a started Qemu VM is not supported.")
# FIXME: does the code below work? very undocumented feature...
# dynamically configure an UDP tunnel on the QEMU VM adapter
if nio and isinstance(nio, NIOUDP):
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_add udp vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number,
adapter_number,
nio.lport,
nio.rport,
nio.rhost))
else:
# Apparently there is a bug in Qemu...
# netdev_add [user|tap|socket|hubport|netmap],id=str[,prop=value][,...] -- add 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_add socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number,
nio.rhost,
nio.rport,
self._host,
nio.lport))
# if nio and isinstance(nio, NIOUDP):
# 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_add udp vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number,
# adapter_number,
# nio.lport,
# nio.rport,
# nio.rhost))
# else:
# # Apparently there is a bug in Qemu...
# # netdev_add [user|tap|socket|hubport|netmap],id=str[,prop=value][,...] -- add 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_add socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number,
# nio.rhost,
# nio.rport,
# self._host,
# nio.lport))
adapter.add_nio(0, nio)
log.info('QEMU VM "{name}" [{id}]: {nio} added to adapter {adapter_number}'.format(name=self._name,