mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-06-20 00:03:56 +00:00
Use pyupgrade with --py36-plus param.
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2018 GNS3 Technologies Inc.
|
||||
#
|
||||
@ -105,10 +104,10 @@ class TraceNGVM(BaseNode):
|
||||
self.ubridge_path
|
||||
|
||||
if not os.path.isfile(path):
|
||||
raise TraceNGError("TraceNG program '{}' is not accessible".format(path))
|
||||
raise TraceNGError(f"TraceNG program '{path}' is not accessible")
|
||||
|
||||
if not os.access(path, os.X_OK):
|
||||
raise TraceNGError("TraceNG program '{}' is not executable".format(path))
|
||||
raise TraceNGError(f"TraceNG program '{path}' is not executable")
|
||||
|
||||
def __json__(self):
|
||||
|
||||
@ -159,7 +158,7 @@ class TraceNGVM(BaseNode):
|
||||
if ip_address:
|
||||
ipaddress.IPv4Address(ip_address)
|
||||
except ipaddress.AddressValueError:
|
||||
raise TraceNGError("Invalid IP address: {}\n".format(ip_address))
|
||||
raise TraceNGError(f"Invalid IP address: {ip_address}\n")
|
||||
|
||||
self._ip_address = ip_address
|
||||
log.info("{module}: {name} [{id}] set IP address to {ip_address}".format(module=self.manager.module_name,
|
||||
@ -204,7 +203,7 @@ class TraceNGVM(BaseNode):
|
||||
command = self._build_command(destination)
|
||||
await self._stop_ubridge() # make use we start with a fresh uBridge instance
|
||||
try:
|
||||
log.info("Starting TraceNG: {}".format(command))
|
||||
log.info(f"Starting TraceNG: {command}")
|
||||
flags = 0
|
||||
if hasattr(subprocess, "CREATE_NEW_CONSOLE"):
|
||||
flags = subprocess.CREATE_NEW_CONSOLE
|
||||
@ -216,14 +215,14 @@ class TraceNGVM(BaseNode):
|
||||
|
||||
await self._start_ubridge()
|
||||
if nio:
|
||||
await self.add_ubridge_udp_connection("TraceNG-{}".format(self._id), self._local_udp_tunnel[1], nio)
|
||||
await self.add_ubridge_udp_connection(f"TraceNG-{self._id}", self._local_udp_tunnel[1], nio)
|
||||
|
||||
log.info("TraceNG instance {} started PID={}".format(self.name, self._process.pid))
|
||||
log.info(f"TraceNG instance {self.name} started PID={self._process.pid}")
|
||||
self._started = True
|
||||
self.status = "started"
|
||||
except (OSError, subprocess.SubprocessError) as e:
|
||||
log.error("Could not start TraceNG {}: {}\n".format(self._traceng_path(), e))
|
||||
raise TraceNGError("Could not start TraceNG {}: {}\n".format(self._traceng_path(), e))
|
||||
log.error(f"Could not start TraceNG {self._traceng_path()}: {e}\n")
|
||||
raise TraceNGError(f"Could not start TraceNG {self._traceng_path()}: {e}\n")
|
||||
|
||||
def _termination_callback(self, returncode):
|
||||
"""
|
||||
@ -238,7 +237,7 @@ class TraceNGVM(BaseNode):
|
||||
self.status = "stopped"
|
||||
self._process = None
|
||||
if returncode != 0:
|
||||
self.project.emit("log.error", {"message": "TraceNG process has stopped, return code: {}\n".format(returncode)})
|
||||
self.project.emit("log.error", {"message": f"TraceNG process has stopped, return code: {returncode}\n"})
|
||||
|
||||
async def stop(self):
|
||||
"""
|
||||
@ -256,9 +255,9 @@ class TraceNGVM(BaseNode):
|
||||
try:
|
||||
self._process.kill()
|
||||
except OSError as e:
|
||||
log.error("Cannot stop the TraceNG process: {}".format(e))
|
||||
log.error(f"Cannot stop the TraceNG process: {e}")
|
||||
if self._process.returncode is None:
|
||||
log.warning('TraceNG VM "{}" with PID={} is still running'.format(self._name, self._process.pid))
|
||||
log.warning(f'TraceNG VM "{self._name}" with PID={self._process.pid} is still running')
|
||||
|
||||
self._process = None
|
||||
self._started = False
|
||||
@ -277,7 +276,7 @@ class TraceNGVM(BaseNode):
|
||||
Terminate the process if running
|
||||
"""
|
||||
|
||||
log.info("Stopping TraceNG instance {} PID={}".format(self.name, self._process.pid))
|
||||
log.info(f"Stopping TraceNG instance {self.name} PID={self._process.pid}")
|
||||
#if sys.platform.startswith("win32"):
|
||||
# self._process.send_signal(signal.CTRL_BREAK_EVENT)
|
||||
#else:
|
||||
@ -311,7 +310,7 @@ class TraceNGVM(BaseNode):
|
||||
port_number=port_number))
|
||||
|
||||
if self.is_running():
|
||||
await self.add_ubridge_udp_connection("TraceNG-{}".format(self._id), self._local_udp_tunnel[1], nio)
|
||||
await self.add_ubridge_udp_connection(f"TraceNG-{self._id}", self._local_udp_tunnel[1], nio)
|
||||
|
||||
self._ethernet_adapter.add_nio(port_number, nio)
|
||||
log.info('TraceNG "{name}" [{id}]: {nio} added to port {port_number}'.format(name=self._name,
|
||||
@ -333,7 +332,7 @@ class TraceNGVM(BaseNode):
|
||||
raise TraceNGError("Port {port_number} doesn't exist on adapter {adapter}".format(adapter=self._ethernet_adapter,
|
||||
port_number=port_number))
|
||||
if self.is_running():
|
||||
await self.update_ubridge_udp_connection("TraceNG-{}".format(self._id), self._local_udp_tunnel[1], nio)
|
||||
await self.update_ubridge_udp_connection(f"TraceNG-{self._id}", self._local_udp_tunnel[1], nio)
|
||||
|
||||
async def port_remove_nio_binding(self, port_number):
|
||||
"""
|
||||
@ -350,7 +349,7 @@ class TraceNGVM(BaseNode):
|
||||
|
||||
await self.stop_capture(port_number)
|
||||
if self.is_running():
|
||||
await self._ubridge_send("bridge delete {name}".format(name="TraceNG-{}".format(self._id)))
|
||||
await self._ubridge_send("bridge delete {name}".format(name=f"TraceNG-{self._id}"))
|
||||
|
||||
nio = self._ethernet_adapter.get_nio(port_number)
|
||||
if isinstance(nio, NIOUDP):
|
||||
@ -377,7 +376,7 @@ class TraceNGVM(BaseNode):
|
||||
port_number=port_number))
|
||||
nio = self._ethernet_adapter.get_nio(port_number)
|
||||
if not nio:
|
||||
raise TraceNGError("Port {} is not connected".format(port_number))
|
||||
raise TraceNGError(f"Port {port_number} is not connected")
|
||||
return nio
|
||||
|
||||
async def start_capture(self, port_number, output_file):
|
||||
@ -390,11 +389,11 @@ class TraceNGVM(BaseNode):
|
||||
|
||||
nio = self.get_nio(port_number)
|
||||
if nio.capturing:
|
||||
raise TraceNGError("Packet capture is already activated on port {port_number}".format(port_number=port_number))
|
||||
raise TraceNGError(f"Packet capture is already activated on port {port_number}")
|
||||
|
||||
nio.start_packet_capture(output_file)
|
||||
if self.ubridge:
|
||||
await self._ubridge_send('bridge start_capture {name} "{output_file}"'.format(name="TraceNG-{}".format(self._id),
|
||||
await self._ubridge_send('bridge start_capture {name} "{output_file}"'.format(name=f"TraceNG-{self._id}",
|
||||
output_file=output_file))
|
||||
|
||||
log.info("TraceNG '{name}' [{id}]: starting packet capture on port {port_number}".format(name=self.name,
|
||||
@ -414,7 +413,7 @@ class TraceNGVM(BaseNode):
|
||||
|
||||
nio.stop_packet_capture()
|
||||
if self.ubridge:
|
||||
await self._ubridge_send('bridge stop_capture {name}'.format(name="TraceNG-{}".format(self._id)))
|
||||
await self._ubridge_send('bridge stop_capture {name}'.format(name=f"TraceNG-{self._id}"))
|
||||
|
||||
log.info("TraceNG '{name}' [{id}]: stopping packet capture on port {port_number}".format(name=self.name,
|
||||
id=self.id,
|
||||
@ -450,7 +449,7 @@ class TraceNGVM(BaseNode):
|
||||
try:
|
||||
command.extend(["-b", socket.gethostbyname(nio.rhost)]) # destination host, we need to resolve the hostname because TraceNG doesn't support it
|
||||
except socket.gaierror as e:
|
||||
raise TraceNGError("Can't resolve hostname {}: {}".format(nio.rhost, e))
|
||||
raise TraceNGError(f"Can't resolve hostname {nio.rhost}: {e}")
|
||||
|
||||
command.extend(["-s", "ICMP"]) # Use ICMP probe type by default
|
||||
command.extend(["-f", self._ip_address]) # source IP address to trace from
|
||||
|
Reference in New Issue
Block a user