driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Failing after 56s
driver / test (3.12) (pull_request) Failing after 46s
driver / lowest (pull_request) Failing after 20s
driver / test (3.13) (pull_request) Failing after 47s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Failing after 1m4s
CI / driver (pull_request) Failing after 2m18s
driver / publish (pull_request) Skipped
napalm-linux now brings napalm-device-types' POSIX scheduled jobs, with Debian's paths. On QTS they are wrong: the crontab that survives a boot is /etc/config/crontab (admin's, no user field), crond runs a copy of it, and a change made only through crontab is gone after the next boot. BusyBox crond reads no /etc/crontab, cron.d, run-parts or anacron, and there is no systemd. QtsScheduledJobsMixin reads /etc/config/crontab as admin's and the other users' crontabs from crond's spool in one round trip, and writes the file first, then loads it and restarts crond. The firmware's own lines are platform by a conservative command list and only run, until a real box shows whether QTS leaves one switched off alone. An application's job is marked lines in admin's crontab; a run is bounded without timeout, which QTS's BusyBox cannot be relied on to have. Requires napalm-device-types 4.26.0 and napalm-linux 0.16.0. Closes #17
204 lines
9.2 KiB
Python
204 lines
9.2 KiB
Python
# Licensed under the Apache License, Version 2.0
|
|
|
|
"""NAPALM driver for QNAP NAS systems running QTS.
|
|
|
|
QTS is a Linux distribution, so this driver inherits the whole OS surface from
|
|
:class:`napalm_linux.linux.LinuxDriver` — packages, services, users, processes,
|
|
Docker — and adds QNAP's own storage, QPKG and virtualisation layers on top:
|
|
|
|
* Physical disk inventory and SMART via ``qcli_storage`` and ``get_hd_smartinfo``
|
|
* Storage pools and volumes via ``qcli_storage`` and ``/proc/mdstat``
|
|
* SMB/NFS/AFP/FTP shares from ``/etc/config/smb.conf`` and ``/etc/exports``
|
|
* QPKG packages instead of a distribution package manager
|
|
* Virtualization Station guests via ``virsh``
|
|
* Container Station via LinuxDriver's Docker support, redirected to the
|
|
QPKG-local ``docker`` binary
|
|
|
|
Connects via SSH. SSH has to be enabled on the NAS first
|
|
(Control Panel → Telnet/SSH). Targets QTS 4.x and QTS 5.x; the parsers are
|
|
written against command output captured from both (see tools/harvest.sh).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from typing import Any
|
|
|
|
from napalm_device_types import (
|
|
FingerprintRule,
|
|
HypervisorDriver,
|
|
PortSpec,
|
|
StorageDriver,
|
|
)
|
|
from napalm_linux.linux import LinuxDriver
|
|
|
|
from napalm_qnap_qts.scheduled_jobs import QtsScheduledJobsMixin
|
|
|
|
#: QNAP Systems' IANA enterprise number. Used by discovery to recognise a NAS
|
|
#: from its SNMP sysObjectID before anyone has supplied credentials.
|
|
QNAP_ENTERPRISE_OID = "1.3.6.1.4.1.24681"
|
|
|
|
#: Where Container Station puts the docker binary. It is not on PATH, and the
|
|
#: volume name varies with which pool the app was installed on, so this is a
|
|
#: glob evaluated on the device rather than a fixed path.
|
|
_DOCKER_GLOBS = (
|
|
"/share/*/.qpkg/container-station/bin/docker",
|
|
"/share/*/.qpkg/container-station/usr/bin/docker",
|
|
)
|
|
|
|
_VERSION_RE = re.compile(r"(\d+)\.")
|
|
|
|
|
|
class QnapQtsDriver(StorageDriver, HypervisorDriver, QtsScheduledJobsMixin, LinuxDriver):
|
|
"""NAPALM driver for QNAP NAS systems running QTS.
|
|
|
|
Scheduled jobs are napalm-device-types' POSIX ones on QTS's paths
|
|
(:class:`~napalm_qnap_qts.scheduled_jobs.QtsScheduledJobsMixin`), ahead of the
|
|
Debian paths ``LinuxDriver`` would give them.
|
|
|
|
Declares all three roles it fills. The role bases carry no implementations,
|
|
so listing them alongside ``LinuxDriver`` costs nothing and shadows nothing;
|
|
what the driver can actually do is whatever it implements below.
|
|
|
|
NAS services are ``get_storage_services()``; the OS service list inherited
|
|
from ``LinuxDriver`` stays ``get_services()``. Two names because they are two
|
|
different things with different return shapes, not because they collided.
|
|
"""
|
|
|
|
# A QNAP is three things at once, and the order says which one leads:
|
|
# storage first, so netOrk shows it as a NAS. Nothing has to restate that
|
|
# -- device_class is read from this line.
|
|
TYPE_LABEL = "Storage"
|
|
VENDOR = "QNAP"
|
|
DRIVER_NAME = "qnap_qts"
|
|
driver_name = "qnap_qts"
|
|
NETMIKO_DEVICE_TYPE = "linux"
|
|
|
|
#: QTS has no systemd, so the systemctl actions LinuxDriver inherits from
|
|
#: napalm-device-types' SystemdServicesMixin would fail on every unit. None
|
|
#: makes every "can it control services?" check -- is ``manage_service``
|
|
#: callable -- answer no, rather than offering buttons that cannot work.
|
|
manage_service = None # type: ignore[assignment]
|
|
#: The same for updates: QTS has no apt, dnf or opkg, and QPKG updates are
|
|
#: not implemented. netOrk leaves a driver without them out of patching.
|
|
get_available_updates = None # type: ignore[assignment]
|
|
refresh_available_updates = None # type: ignore[assignment]
|
|
apply_updates = None # type: ignore[assignment]
|
|
#: The fix templates LinuxDriver carries, and the package proxy it reports,
|
|
#: need a package manager or net-snmp from packages; QTS has neither, and
|
|
#: its SNMP agent is set in its own UI.
|
|
configure_snmp_agent = None # type: ignore[assignment]
|
|
configure_package_proxy = None # type: ignore[assignment]
|
|
get_package_proxy = None # type: ignore[assignment]
|
|
ensure_package = None # type: ignore[assignment]
|
|
#: QTS keeps its name in uLinux.conf and /etc in RAM: LinuxDriver's rename
|
|
#: would report success and be gone after a boot. Off until #13.
|
|
set_hostname = None # type: ignore[assignment]
|
|
#: QTS manages its users in its own UI and ships no shadow-utils (useradd,
|
|
#: usermod, gpasswd) for LinuxDriver's accounts. Off until a QTS variant is
|
|
#: built against a real box (NetOrk/netork#1793), netOrk's own account
|
|
#: included (NetOrk/netork#1817).
|
|
get_local_accounts = None # type: ignore[assignment]
|
|
add_local_account = None # type: ignore[assignment]
|
|
lock_local_account = None # type: ignore[assignment]
|
|
add_service_account = None # type: ignore[assignment]
|
|
|
|
SNMP_OBJECT_ID_PREFIX = QNAP_ENTERPRISE_OID
|
|
SNMP_FINGERPRINT = [
|
|
FingerprintRule("qnap", weight=9.0),
|
|
FingerprintRule("nas", weight=1.0),
|
|
]
|
|
# QTS answers with a stock OpenSSH banner, so SSH alone cannot identify a
|
|
# QNAP — it only confirms the transport this driver needs.
|
|
SSH_FINGERPRINT = [
|
|
FingerprintRule("openssh", weight=1.0),
|
|
]
|
|
# Mandatory: without it every unidentified NAS web UI would score as a QNAP.
|
|
HTTP_FINGERPRINT = [
|
|
FingerprintRule("qnap", weight=9.0, mandatory=True),
|
|
FingerprintRule("qts", weight=4.0),
|
|
]
|
|
PORT_SPECS = [
|
|
PortSpec("https", 443),
|
|
PortSpec("http", 8080),
|
|
]
|
|
|
|
# ── Lifecycle ─────────────────────────────────────────────────────────────
|
|
|
|
def open(self) -> None:
|
|
"""Connect, then resolve the facts that decide which code paths run.
|
|
|
|
QTS 4 and QTS 5 differ in the output of several tools, and the QPKG apps
|
|
that provide docker and virsh live on whichever storage pool they were
|
|
installed on. Resolving all of that once per session keeps every getter
|
|
below free of discovery round trips.
|
|
"""
|
|
super().open()
|
|
self._qts_major = self._detect_qts_major()
|
|
self._docker_path = self._discover_docker_path()
|
|
self._virsh_path = self._discover_virsh_path()
|
|
|
|
def _detect_qts_major(self) -> int | None:
|
|
"""Return the QTS major version, or None when it cannot be read.
|
|
|
|
Deliberately not fatal: a NAS that answers nothing useful here is still
|
|
worth polling, and the newer code path is the better default.
|
|
"""
|
|
try:
|
|
raw = self._send("getcfg System Version").strip()
|
|
except Exception:
|
|
return None
|
|
match = _VERSION_RE.match(raw)
|
|
return int(match.group(1)) if match else None
|
|
|
|
def _discover_docker_path(self) -> str:
|
|
"""Locate Container Station's docker binary, falling back to PATH."""
|
|
try:
|
|
found = self._send(f"ls {' '.join(_DOCKER_GLOBS)} 2>/dev/null | head -1").strip()
|
|
except Exception:
|
|
return "docker"
|
|
return found.splitlines()[0].strip() if found else "docker"
|
|
|
|
def _discover_virsh_path(self) -> str | None:
|
|
"""Locate Virtualization Station's virsh, or None when it is not installed.
|
|
|
|
None is a normal outcome — plenty of QNAP models never run VMs — and it
|
|
is what makes ``get_vms`` return an empty list instead of raising.
|
|
"""
|
|
try:
|
|
found = self._send(
|
|
"ls /share/*/.qpkg/QKVM/usr/bin/virsh /share/*/.qpkg/*/bin/virsh "
|
|
"2>/dev/null | head -1"
|
|
).strip()
|
|
except Exception:
|
|
return None
|
|
return found.splitlines()[0].strip() or None if found else None
|
|
|
|
def _container_engine_binary(self, engine: str) -> str:
|
|
"""Container Station keeps docker off PATH; callers never see the path."""
|
|
if engine == "docker":
|
|
return getattr(self, "_docker_path", None) or "docker"
|
|
return super()._container_engine_binary(engine)
|
|
|
|
# ── QPKG, not apt ─────────────────────────────────────────────────────────
|
|
#
|
|
# QTS is Linux, so LinuxDriver's package methods are in the MRO and would
|
|
# run happily -- against a package manager QTS does not have. They used to
|
|
# be shadowed by StorageDriver's stubs, which made a QNAP refuse them by
|
|
# accident. Now that role bases implement nothing, the refusal has to be
|
|
# deliberate. QPKG parsing lands with the device harvest; until then,
|
|
# refusing is the only honest answer.
|
|
|
|
def get_packages(self) -> Any:
|
|
raise NotImplementedError(
|
|
"QTS uses QPKG, not a Linux package manager; QPKG parsing is not implemented yet"
|
|
)
|
|
|
|
# These two keep napalm-device-types' PackagesMixin signatures; LinuxDriver's
|
|
# own differ from that contract (no version, a purge flag, a dict returned).
|
|
def install_package(self, name: str, version: str = "") -> None: # type: ignore[override]
|
|
raise NotImplementedError("QPKG install is not implemented yet")
|
|
|
|
def uninstall_package(self, name: str) -> None: # type: ignore[override]
|
|
raise NotImplementedError("QPKG removal is not implemented yet")
|