fix: what bandit and the remaining lint rules found
- driver.py: the logger is defined after the imports (E402). The lazy paramiko client is annotated Any, as _node_ssh already is; the quoted paramiko.SSHClient named a module that is never imported there (F821). - Unused locals are gone: get_facts' hostname, get_users' groups (both read a value nobody used), the ARP flags column is _flags; the output is unchanged. - Long lines are wrapped: the apt-get and snmpd.conf commands are split into adjacent string literals, the power-action error message and the system mixin's docstring are wrapped; the text is unchanged. - get_vm_status re-raises with raise ... from e (B904). - The two except Exception: pass (closing the SSH session, the is_alive probe) now log at debug level (B110), so a swallowed failure leaves a trace. - nosec for the empty "password" field of NAPALM's get_users shape and the ssh_password_auth flag (B105); all three are false positives. - tests: unused loop variables.
This commit is contained in:
1 parent
3b873d91fe
commit
3365207c98
6 files changed
+28
-19
No files matched your search
@@ -32,8 +32,6 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from napalm.base.exceptions import ConnectionException
|
||||
from napalm_device_types import (
|
||||
AptProxyMixin,
|
||||
@@ -68,6 +66,8 @@ from napalm_proxmox.vm_mixin import ProxmoxVMMixin
|
||||
from napalm_proxmox.vm_provision_mixin import ProxmoxVMProvisionMixin
|
||||
from napalm_proxmox.vm_snapshot_mixin import ProxmoxVMSnapshotMixin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Type aliases
|
||||
# --------------------------------------------------------------------------- #
|
||||
@@ -156,7 +156,8 @@ class ProxmoxDriver(
|
||||
|
||||
self._api: ProxmoxAPI | None = None
|
||||
self._node_name: str = ""
|
||||
self._ssh_client: paramiko.SSHClient | None = None
|
||||
# paramiko.SSHClient; paramiko is imported lazily (see _node_ssh).
|
||||
self._ssh_client: Any = None
|
||||
|
||||
# Candidate config (merge/replace)
|
||||
self._candidate_config: str = ""
|
||||
@@ -257,7 +258,7 @@ class ProxmoxDriver(
|
||||
try:
|
||||
self._ssh_client.close()
|
||||
except Exception:
|
||||
pass
|
||||
logger.debug("%s: closing the SSH session: ignored", self.hostname, exc_info=True)
|
||||
self._ssh_client = None
|
||||
|
||||
def is_alive(self) -> _JsonDict:
|
||||
@@ -274,7 +275,7 @@ class ProxmoxDriver(
|
||||
self._api.version.get()
|
||||
alive = True
|
||||
except Exception:
|
||||
pass
|
||||
logger.debug("%s: liveness probe failed", self.hostname, exc_info=True)
|
||||
return {"is_alive": alive}
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
@@ -432,7 +433,6 @@ class ProxmoxDriver(
|
||||
|
||||
uptime = float(status.get("uptime", 0))
|
||||
dns_search = dns.get("search", "")
|
||||
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"))
|
||||
|
||||
Reference in new issue
Block a user