style: ruff format and the lint rules of the driver standard
Mechanical: ruff format, and ruff check --fix with the rule set every NAPALM driver uses (E, F, I, UP, B at line length 100, Python 3.10). What ruff cannot fix comes in the next commit.
This commit is contained in:
1 parent
1f6859de08
commit
3b873d91fe
27 files changed
+195
-225
No files matched your search
+20
-28
@@ -34,6 +34,7 @@ from typing import Any
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from napalm.base.exceptions import ConnectionException
|
||||
from napalm_device_types import (
|
||||
AptProxyMixin,
|
||||
EnsurePackageMixin,
|
||||
@@ -46,29 +47,26 @@ from napalm_device_types import (
|
||||
PortSpec,
|
||||
ServicePackagesMixin,
|
||||
SnmpAgentMixin,
|
||||
SystemIdentityMixin,
|
||||
SystemdServicesMixin,
|
||||
SystemIdentityMixin,
|
||||
)
|
||||
from napalm.base.exceptions import ConnectionException
|
||||
from napalm_device_types.ssh_host_keys import HostKeyCheck, SshHostKeyMismatch
|
||||
|
||||
try:
|
||||
from proxmoxer import ProxmoxAPI
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"proxmoxer is required: pip install proxmoxer"
|
||||
) from exc
|
||||
raise ImportError("proxmoxer is required: pip install proxmoxer") from exc
|
||||
|
||||
from napalm_proxmox.interfaces_mixin import ProxmoxInterfaceMixin
|
||||
from napalm_proxmox.sdn_mixin import ProxmoxSDNMixin
|
||||
from napalm_proxmox.lldp_mixin import ProxmoxLLDPMixin
|
||||
from napalm_proxmox.config_mixin import ProxmoxConfigMixin
|
||||
from napalm_proxmox.vm_mixin import ProxmoxVMMixin
|
||||
from napalm_proxmox.vm_contract_mixin import ProxmoxVMContractMixin
|
||||
from napalm_proxmox.vm_snapshot_mixin import ProxmoxVMSnapshotMixin
|
||||
from napalm_proxmox.vm_provision_mixin import ProxmoxVMProvisionMixin
|
||||
from napalm_proxmox.interfaces_mixin import ProxmoxInterfaceMixin
|
||||
from napalm_proxmox.lldp_mixin import ProxmoxLLDPMixin
|
||||
from napalm_proxmox.routing_mixin import ProxmoxRoutingMixin
|
||||
from napalm_proxmox.sdn_mixin import ProxmoxSDNMixin
|
||||
from napalm_proxmox.system_mixin import ProxmoxSystemMixin
|
||||
from napalm_proxmox.vm_contract_mixin import ProxmoxVMContractMixin
|
||||
from napalm_proxmox.vm_mixin import ProxmoxVMMixin
|
||||
from napalm_proxmox.vm_provision_mixin import ProxmoxVMProvisionMixin
|
||||
from napalm_proxmox.vm_snapshot_mixin import ProxmoxVMSnapshotMixin
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Type aliases
|
||||
@@ -144,7 +142,8 @@ class ProxmoxDriver(
|
||||
|
||||
self._port: int = self.optional_args.get("port", 8006)
|
||||
self._verify_ssl: bool = self.optional_args.get(
|
||||
"verify_ssl", self.optional_args.get("ssl_verify", self.optional_args.get("verify", True))
|
||||
"verify_ssl",
|
||||
self.optional_args.get("ssl_verify", self.optional_args.get("verify", True)),
|
||||
)
|
||||
self._realm: str = self.optional_args.get("realm", "pam")
|
||||
self._token_name: str | None = self.optional_args.get("token_name")
|
||||
@@ -157,7 +156,7 @@ class ProxmoxDriver(
|
||||
|
||||
self._api: ProxmoxAPI | None = None
|
||||
self._node_name: str = ""
|
||||
self._ssh_client: "paramiko.SSHClient | None" = None
|
||||
self._ssh_client: paramiko.SSHClient | None = None
|
||||
|
||||
# Candidate config (merge/replace)
|
||||
self._candidate_config: str = ""
|
||||
@@ -211,9 +210,7 @@ class ProxmoxDriver(
|
||||
self._resolve_node()
|
||||
|
||||
except Exception as exc:
|
||||
raise ConnectionException(
|
||||
f"Cannot connect to {self.hostname}: {exc}"
|
||||
) from exc
|
||||
raise ConnectionException(f"Cannot connect to {self.hostname}: {exc}") from exc
|
||||
|
||||
def _resolve_node(self) -> str:
|
||||
"""Resolve the PVE node this connection talks to.
|
||||
@@ -231,9 +228,7 @@ class ProxmoxDriver(
|
||||
self._node_name = self._node
|
||||
return self._node_name
|
||||
|
||||
members = [
|
||||
s for s in (self._api.cluster.status.get() or []) if s.get("type") == "node"
|
||||
]
|
||||
members = [s for s in (self._api.cluster.status.get() or []) if s.get("type") == "node"]
|
||||
short_host = self.hostname.split(".")[0]
|
||||
for pick in (
|
||||
lambda s: s.get("local"),
|
||||
@@ -305,7 +300,6 @@ class ProxmoxDriver(
|
||||
falls back to a direct paramiko SSH connection.
|
||||
"""
|
||||
import base64 as _b64
|
||||
import time as _time
|
||||
|
||||
# Try API exec endpoint
|
||||
try:
|
||||
@@ -359,7 +353,9 @@ class ProxmoxDriver(
|
||||
connect_kwargs["password"] = ssh_pass
|
||||
client = paramiko.SSHClient()
|
||||
try:
|
||||
HostKeyCheck(self.optional_args, self.hostname, 22).connect(client, **connect_kwargs)
|
||||
HostKeyCheck(self.optional_args, self.hostname, 22).connect(
|
||||
client, **connect_kwargs
|
||||
)
|
||||
except Exception:
|
||||
client.close()
|
||||
raise
|
||||
@@ -439,9 +435,7 @@ class ProxmoxDriver(
|
||||
hostname = self._node_name
|
||||
fqdn = f"{self._node_name}.{dns_search}" if dns_search else self.hostname
|
||||
|
||||
iface_list = sorted(
|
||||
iface["iface"] for iface in network if iface.get("iface")
|
||||
)
|
||||
iface_list = sorted(iface["iface"] for iface in network if iface.get("iface"))
|
||||
|
||||
pve_version = version.get("version", "")
|
||||
release = version.get("release", "")
|
||||
@@ -465,7 +459,7 @@ class ProxmoxDriver(
|
||||
"n=$(cat /sys/class/dmi/id/product_name 2>/dev/null); "
|
||||
"r=$(cat /sys/class/dmi/id/product_version 2>/dev/null); "
|
||||
"s=$(cat /sys/class/dmi/id/product_serial 2>/dev/null); "
|
||||
"printf '%s\\n%s\\n%s\\n%s\\n' \"$v\" \"$n\" \"$r\" \"$s\""
|
||||
'printf \'%s\\n%s\\n%s\\n%s\\n\' "$v" "$n" "$r" "$s"'
|
||||
)
|
||||
lines = self._exec_ssh_command(dmi_cmd).splitlines()
|
||||
if len(lines) >= 4:
|
||||
@@ -515,5 +509,3 @@ class ProxmoxDriver(
|
||||
def cli(self, commands: list[str], encoding: str = "text") -> dict[str, str]:
|
||||
"""Execute a list of shell commands and return their outputs."""
|
||||
return {cmd: self._exec_ssh_command(cmd) for cmd in commands}
|
||||
|
||||
|
||||
Reference in new issue
Block a user