mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-10-07 03:00:30 +03:00
refactor: use f-strings in dynamips manager
This commit is contained in:
parent
c458459626
commit
bbebf20825
@ -284,9 +284,9 @@ class Dynamips(BaseManager):
|
||||
version = match.group(1)
|
||||
return version
|
||||
else:
|
||||
raise DynamipsError("Could not determine the Dynamips version for {}".format(dynamips_path))
|
||||
raise DynamipsError(f"Could not determine the Dynamips version for {dynamips_path}")
|
||||
except (OSError, subprocess.SubprocessError) as e:
|
||||
raise DynamipsError("Error while looking for the Dynamips version: {}".format(e))
|
||||
raise DynamipsError(f"Error while looking for the Dynamips version: {e}")
|
||||
|
||||
async def start_new_hypervisor(self, working_dir=None):
|
||||
"""
|
||||
@ -308,7 +308,7 @@ class Dynamips(BaseManager):
|
||||
|
||||
dynamips_version = await self.dynamips_version(self.dynamips_path)
|
||||
if parse_version(dynamips_version) < parse_version("0.2.11"):
|
||||
raise DynamipsError("Dynamips version must be >= 0.2.11, detected version is {}".format(dynamips_version))
|
||||
raise DynamipsError(f"Dynamips version must be >= 0.2.11, detected version is {dynamips_version}")
|
||||
|
||||
if not sys.platform.startswith("win"):
|
||||
# Hypervisor should always listen to 127.0.0.1
|
||||
|
||||
@ -96,7 +96,7 @@ class DynamipsHypervisor:
|
||||
try:
|
||||
version = await self.send("hypervisor version")
|
||||
self._version = version[0].split("-", 1)[0]
|
||||
log.debug("Dynamips version {} detected".format(self._version))
|
||||
log.debug(f"Dynamips version {self._version} detected")
|
||||
except IndexError:
|
||||
log.warning("Dynamips version could not be detected")
|
||||
self._version = "Unknown"
|
||||
@ -253,9 +253,7 @@ class DynamipsHypervisor:
|
||||
await self._writer.drain()
|
||||
except OSError as e:
|
||||
raise DynamipsError(
|
||||
"Could not send Dynamips command '{command}' to {host}:{port}: {error}, process running: {run}".format(
|
||||
command=command.strip(), host=self._host, port=self._port, error=e, run=self.is_running()
|
||||
)
|
||||
f"Could not send Dynamips command '{command.strip()}' to {self._host}:{self._port}: {e}, process running: {self.is_running()}"
|
||||
)
|
||||
|
||||
# Now retrieve the result
|
||||
@ -281,9 +279,7 @@ class DynamipsHypervisor:
|
||||
if not chunk:
|
||||
if retries > max_retries:
|
||||
raise DynamipsError(
|
||||
"No data returned from {host}:{port}, Dynamips process running: {run}".format(
|
||||
host=self._host, port=self._port, run=self.is_running()
|
||||
)
|
||||
f"No data returned from {self._host}:{self._port}, Dynamips process running: {self.is_running()}"
|
||||
)
|
||||
else:
|
||||
retries += 1
|
||||
@ -293,9 +289,7 @@ class DynamipsHypervisor:
|
||||
buf += chunk.decode("utf-8", errors="ignore")
|
||||
except OSError as e:
|
||||
raise DynamipsError(
|
||||
"Could not read response for '{command}' from {host}:{port}: {error}, process running: {run}".format(
|
||||
command=command.strip(), host=self._host, port=self._port, error=e, run=self.is_running()
|
||||
)
|
||||
f"Could not read response for '{command.strip()}' from {self._host}:{self._port}: {e}, process running: {self.is_running()}"
|
||||
)
|
||||
|
||||
# If the buffer doesn't end in '\n' then we can't be done
|
||||
@ -304,9 +298,7 @@ class DynamipsHypervisor:
|
||||
continue
|
||||
except IndexError:
|
||||
raise DynamipsError(
|
||||
"Could not communicate with {host}:{port}, Dynamips process running: {run}".format(
|
||||
host=self._host, port=self._port, run=self.is_running()
|
||||
)
|
||||
f"Could not communicate with {self._host}:{self._port}, Dynamips process running: {self.is_running()}"
|
||||
)
|
||||
|
||||
data += buf.split("\r\n")
|
||||
|
||||
@ -195,13 +195,13 @@ class Hypervisor(DynamipsHypervisor):
|
||||
|
||||
command = [self._path]
|
||||
command.extend(["-N1"]) # use instance IDs for filenames
|
||||
command.extend(["-l", "dynamips_i{}_log.txt".format(self._id)]) # log file
|
||||
command.extend(["-l", f"dynamips_i{self._id}_log.txt"]) # log file
|
||||
|
||||
if self._bind_console_host:
|
||||
# support was added in Dynamips version 0.2.23
|
||||
command.extend(["-H", "{}:{}".format(self._host, self._port), "--console-binding-addr", self._console_host])
|
||||
command.extend(["-H", f"{self._host}:{self._port}", "--console-binding-addr", self._console_host])
|
||||
elif self._console_host != "0.0.0.0" and self._console_host != "::":
|
||||
command.extend(["-H", "{}:{}".format(self._host, self._port)])
|
||||
command.extend(["-H", f"{self._host}:{self._port}"])
|
||||
else:
|
||||
command.extend(["-H", str(self._port)])
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user