feat: apt's proxy on a Proxmox VE node (NetOrk/netork#1397)
CI / test (3.10) (push) Failing after 19s
CI / test (3.11) (push) Failing after 17s
CI / test (3.12) (push) Failing after 20s
CI / test (3.10) (pull_request) Failing after 18s
CI / test (3.11) (pull_request) Failing after 20s
CI / test (3.12) (pull_request) Failing after 19s
CI / test (3.10) (push) Failing after 19s
CI / test (3.11) (push) Failing after 17s
CI / test (3.12) (push) Failing after 20s
CI / test (3.10) (pull_request) Failing after 18s
CI / test (3.11) (pull_request) Failing after 20s
CI / test (3.12) (pull_request) Failing after 19s
The node is Debian: AptProxyMixin gives it get_package_proxy(), get_package_proxy_report(), check_package_proxy() and the fix configure_package_proxy(), as on any Debian host. Logged in as root, the transports are the exec path; the file is written without an exit inside _rc's braces, which would end the shell before the status (see #30). Requires napalm-device-types 4.22.0; version 0.7.0.
This commit is contained in:
1 parent
03c7cdfa02
commit
7776bb904a
5 files changed
+99
-2
No files matched your search
@@ -35,6 +35,7 @@ from typing import Any
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from napalm_device_types import (
|
||||
AptProxyMixin,
|
||||
EnsurePackageMixin,
|
||||
FingerprintRule,
|
||||
HostStatusMixin,
|
||||
@@ -99,6 +100,7 @@ class ProxmoxDriver(
|
||||
LicenseMixin,
|
||||
SnmpAgentMixin,
|
||||
EnsurePackageMixin,
|
||||
AptProxyMixin,
|
||||
HypervisorDriver,
|
||||
):
|
||||
"""NAPALM driver for Proxmox VE nodes."""
|
||||
|
||||
@@ -20,6 +20,7 @@ import base64
|
||||
import ipaddress
|
||||
import logging
|
||||
import re
|
||||
import shlex
|
||||
from typing import Any
|
||||
|
||||
from napalm_device_types import APT_UPGRADABLE_COMMAND, parse_apt_upgradable
|
||||
@@ -512,6 +513,25 @@ class ProxmoxSystemMixin:
|
||||
output, status = self._rc(command)
|
||||
return {"ok": status == 0, "output": done if status == 0 else output[-300:]}
|
||||
|
||||
# apt's proxy (napalm-device-types AptProxyMixin): the transports. The node
|
||||
# is logged in as root, so every command runs as root.
|
||||
|
||||
def _run_apt_command(self, command: str) -> str:
|
||||
return str(self._exec_ssh_command(command))
|
||||
|
||||
def _run_apt_root_command(self, command: str, done: str) -> dict:
|
||||
return self._step(command, done)
|
||||
|
||||
def _write_apt_file(self, path: str, content: str) -> dict:
|
||||
encoded = base64.b64encode(content.encode()).decode()
|
||||
# No ``exit`` here: ``_rc`` reads the status after the command's braces.
|
||||
return self._step(
|
||||
f"umask 077 && t=$(mktemp) && echo {encoded} | base64 -d > \"$t\" && "
|
||||
f"install -m 644 -o root -g root \"$t\" {shlex.quote(path)}; "
|
||||
"s=$?; rm -f \"$t\"; [ \"$s\" -eq 0 ]",
|
||||
f"wrote {path}",
|
||||
)
|
||||
|
||||
def install_package(self, name: str, version: str = "") -> None:
|
||||
"""apt-get install *name* (``PackageManagementMixin``); raises when apt fails."""
|
||||
if not _PACKAGE_NAME.match(name) or (version and not _PACKAGE_NAME.match(version)):
|
||||
|
||||
Reference in new issue
Block a user