Use black with -l 120 param.

This commit is contained in:
grossmj committed 2021-04-13 18:46:50 +09:30
1 parent f928738bd5
commit c021e21309
194 files changed
+6034 -4564

No files matched your search

+84 -87
View File
@@ -26,6 +26,7 @@ import gns3server.utils.interfaces
import gns3server.utils.asyncio
import logging
log = logging.getLogger(__name__)
@@ -54,12 +55,14 @@ class Cloud(BaseNode):
self._ports_mapping = []
for interface in self._interfaces():
if not interface["special"]:
self._ports_mapping.append({
"interface": interface["name"],
"type": interface["type"],
"port_number": len(self._ports_mapping),
"name": interface["name"]
})
self._ports_mapping.append(
{
"interface": interface["name"],
"type": interface["type"],
"port_number": len(self._ports_mapping),
"name": interface["name"],
}
)
else:
port_number = 0
for port in ports:
@@ -79,23 +82,24 @@ class Cloud(BaseNode):
host_interfaces = []
network_interfaces = gns3server.utils.interfaces.interfaces()
for interface in network_interfaces:
host_interfaces.append({"name": interface["name"],
"type": interface["type"],
"special": interface["special"]})
host_interfaces.append(
{"name": interface["name"], "type": interface["type"], "special": interface["special"]}
)
return {"name": self.name,
"usage": self.usage,
"node_id": self.id,
"project_id": self.project.id,
"remote_console_host": self.remote_console_host,
"remote_console_port": self.remote_console_port,
"remote_console_type": self.remote_console_type,
"remote_console_http_path": self.remote_console_http_path,
"ports_mapping": self._ports_mapping,
"interfaces": host_interfaces,
"status": self.status,
"node_directory": self.working_path
}
return {
"name": self.name,
"usage": self.usage,
"node_id": self.id,
"project_id": self.project.id,
"remote_console_host": self.remote_console_host,
"remote_console_port": self.remote_console_port,
"remote_console_type": self.remote_console_type,
"remote_console_http_path": self.remote_console_http_path,
"ports_mapping": self._ports_mapping,
"interfaces": host_interfaces,
"status": self.status,
"node_directory": self.working_path,
}
@property
def remote_console_host(self):
@@ -265,7 +269,7 @@ class Cloud(BaseNode):
return True
is_wifi = False
else:
if 'Wi-Fi' in line:
if "Wi-Fi" in line:
is_wifi = True
return False
@@ -284,27 +288,27 @@ class Cloud(BaseNode):
break
if not port_info:
raise NodeError("Port {port_number} doesn't exist on cloud '{name}'".format(
name=self.name,
port_number=port_number)
raise NodeError(
"Port {port_number} doesn't exist on cloud '{name}'".format(name=self.name, port_number=port_number)
)
bridge_name = f"{self._id}-{port_number}"
await self._ubridge_send(f"bridge create {bridge_name}")
if not isinstance(nio, NIOUDP):
raise NodeError("Source NIO is not UDP")
await self._ubridge_send('bridge add_nio_udp {name} {lport} {rhost} {rport}'.format(
name=bridge_name,
lport=nio.lport,
rhost=nio.rhost,
rport=nio.rport)
await self._ubridge_send(
"bridge add_nio_udp {name} {lport} {rhost} {rport}".format(
name=bridge_name, lport=nio.lport, rhost=nio.rhost, rport=nio.rport
)
)
await self._ubridge_apply_filters(bridge_name, nio.filters)
if port_info["type"] in ("ethernet", "tap"):
if not self.manager.has_privileged_access(self.ubridge_path):
raise NodeError("uBridge requires root access or the capability to interact with Ethernet and TAP adapters")
raise NodeError(
"uBridge requires root access or the capability to interact with Ethernet and TAP adapters"
)
if sys.platform.startswith("win"):
await self._add_ubridge_ethernet_connection(bridge_name, port_info["interface"])
@@ -313,7 +317,9 @@ class Cloud(BaseNode):
if port_info["type"] == "ethernet":
network_interfaces = [interface["name"] for interface in self._interfaces()]
if not port_info["interface"] in network_interfaces:
raise NodeError(f"Interface '{port_info['interface']}' could not be found on this system, please update '{self.name}'")
raise NodeError(
f"Interface '{port_info['interface']}' could not be found on this system, please update '{self.name}'"
)
if sys.platform.startswith("linux"):
await self._add_linux_ethernet(port_info, bridge_name)
@@ -323,23 +329,22 @@ class Cloud(BaseNode):
await self._add_windows_ethernet(port_info, bridge_name)
elif port_info["type"] == "tap":
await self._ubridge_send('bridge add_nio_tap {name} "{interface}"'.format(
name=bridge_name,
interface=port_info["interface"])
await self._ubridge_send(
'bridge add_nio_tap {name} "{interface}"'.format(
name=bridge_name, interface=port_info["interface"]
)
)
elif port_info["type"] == "udp":
await self._ubridge_send('bridge add_nio_udp {name} {lport} {rhost} {rport}'.format(
name=bridge_name,
lport=port_info["lport"],
rhost=port_info["rhost"],
rport=port_info["rport"])
await self._ubridge_send(
"bridge add_nio_udp {name} {lport} {rhost} {rport}".format(
name=bridge_name, lport=port_info["lport"], rhost=port_info["rhost"], rport=port_info["rport"]
)
)
if nio.capturing:
await self._ubridge_send('bridge start_capture {name} "{pcap_file}"'.format(
name=bridge_name,
pcap_file=nio.pcap_output_file)
await self._ubridge_send(
'bridge start_capture {name} "{pcap_file}"'.format(name=bridge_name, pcap_file=nio.pcap_output_file)
)
await self._ubridge_send(f"bridge start {bridge_name}")
@@ -362,18 +367,13 @@ class Cloud(BaseNode):
break
i += 1
await self._ubridge_send('bridge add_nio_tap "{name}" "{interface}"'.format(
name=bridge_name,
interface=tap)
)
await self._ubridge_send('brctl addif "{interface}" "{tap}"'.format(
tap=tap,
interface=interface)
await self._ubridge_send(
'bridge add_nio_tap "{name}" "{interface}"'.format(name=bridge_name, interface=tap)
)
await self._ubridge_send('brctl addif "{interface}" "{tap}"'.format(tap=tap, interface=interface))
else:
await self._ubridge_send('bridge add_nio_linux_raw {name} "{interface}"'.format(
name=bridge_name,
interface=interface)
await self._ubridge_send(
'bridge add_nio_linux_raw {name} "{interface}"'.format(name=bridge_name, interface=interface)
)
async def _add_osx_ethernet(self, port_info, bridge_name):
@@ -382,20 +382,20 @@ class Cloud(BaseNode):
"""
# Wireless adapters are not well supported by the libpcap on OSX
if (await self._is_wifi_adapter_osx(port_info["interface"])):
if await self._is_wifi_adapter_osx(port_info["interface"]):
raise NodeError("Connecting to a Wireless adapter is not supported on Mac OS")
if port_info["interface"].startswith("vmnet"):
# Use a special NIO to connect to VMware vmnet interfaces on OSX (libpcap doesn't support them)
await self._ubridge_send('bridge add_nio_fusion_vmnet {name} "{interface}"'.format(
name=bridge_name,
interface=port_info["interface"])
await self._ubridge_send(
'bridge add_nio_fusion_vmnet {name} "{interface}"'.format(
name=bridge_name, interface=port_info["interface"]
)
)
return
if not gns3server.utils.interfaces.has_netmask(port_info["interface"]):
raise NodeError(f"Interface {port_info['interface']} has no netmask, interface down?")
await self._ubridge_send('bridge add_nio_ethernet {name} "{interface}"'.format(
name=bridge_name,
interface=port_info["interface"])
await self._ubridge_send(
'bridge add_nio_ethernet {name} "{interface}"'.format(name=bridge_name, interface=port_info["interface"])
)
async def _add_windows_ethernet(self, port_info, bridge_name):
@@ -405,9 +405,8 @@ class Cloud(BaseNode):
if not gns3server.utils.interfaces.has_netmask(port_info["interface"]):
raise NodeError(f"Interface {port_info['interface']} has no netmask, interface down?")
await self._ubridge_send('bridge add_nio_ethernet {name} "{interface}"'.format(
name=bridge_name,
interface=port_info["interface"])
await self._ubridge_send(
'bridge add_nio_ethernet {name} "{interface}"'.format(name=bridge_name, interface=port_info["interface"])
)
async def add_nio(self, nio, port_number):
@@ -421,10 +420,11 @@ class Cloud(BaseNode):
if port_number in self._nios:
raise NodeError(f"Port {port_number} isn't free")
log.info('Cloud "{name}" [{id}]: NIO {nio} bound to port {port}'.format(name=self._name,
id=self._id,
nio=nio,
port=port_number))
log.info(
'Cloud "{name}" [{id}]: NIO {nio} bound to port {port}'.format(
name=self._name, id=self._id, nio=nio, port=port_number
)
)
try:
await self.start()
await self._add_ubridge_connection(nio, port_number)
@@ -474,11 +474,10 @@ class Cloud(BaseNode):
if isinstance(nio, NIOUDP):
self.manager.port_manager.release_udp_port(nio.lport, self._project)
log.info('Cloud "{name}" [{id}]: NIO {nio} removed from port {port}'.format(
name=self._name,
id=self._id,
nio=nio,
port=port_number)
log.info(
'Cloud "{name}" [{id}]: NIO {nio} removed from port {port}'.format(
name=self._name, id=self._id, nio=nio, port=port_number
)
)
del self._nios[port_number]
@@ -497,9 +496,8 @@ class Cloud(BaseNode):
"""
if not [port["port_number"] for port in self._ports_mapping if port_number == port["port_number"]]:
raise NodeError("Port {port_number} doesn't exist on cloud '{name}'".format(
name=self.name,
port_number=port_number)
raise NodeError(
"Port {port_number} doesn't exist on cloud '{name}'".format(name=self.name, port_number=port_number)
)
if port_number not in self._nios:
@@ -523,14 +521,13 @@ class Cloud(BaseNode):
raise NodeError(f"Packet capture is already activated on port {port_number}")
nio.start_packet_capture(output_file)
bridge_name = f"{self._id}-{port_number}"
await self._ubridge_send('bridge start_capture {name} "{output_file}"'.format(
name=bridge_name,
output_file=output_file)
await self._ubridge_send(
'bridge start_capture {name} "{output_file}"'.format(name=bridge_name, output_file=output_file)
)
log.info("Cloud '{name}' [{id}]: starting packet capture on port {port_number}".format(
name=self.name,
id=self.id,
port_number=port_number)
log.info(
"Cloud '{name}' [{id}]: starting packet capture on port {port_number}".format(
name=self.name, id=self.id, port_number=port_number
)
)
async def stop_capture(self, port_number):
@@ -547,8 +544,8 @@ class Cloud(BaseNode):
bridge_name = f"{self._id}-{port_number}"
await self._ubridge_send(f"bridge stop_capture {bridge_name}")
log.info("Cloud'{name}' [{id}]: stopping packet capture on port {port_number}".format(
name=self.name,
id=self.id,
port_number=port_number)
log.info(
"Cloud'{name}' [{id}]: stopping packet capture on port {port_number}".format(
name=self.name, id=self.id, port_number=port_number
)
)