From e622b26d42b368915e688b5c1e0afa46a6801f8b Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Thu, 5 Nov 2026 00:34:20 +0100 Subject: [PATCH] refactor: keep the log source shapes in log_sources, not in models models.py is over the file size limit and may not grow (quality ratchet); the shapes sit with their mixin, as ScheduledJobDict does. Refs NetOrk/netork#2049 --- napalm_device_types/__init__.py | 4 ++++ napalm_device_types/log_sources.py | 35 ++++++++++++++++++++++++++++-- napalm_device_types/models.py | 31 -------------------------- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/napalm_device_types/__init__.py b/napalm_device_types/__init__.py index 6ec5dea..107d41e 100644 --- a/napalm_device_types/__init__.py +++ b/napalm_device_types/__init__.py @@ -169,6 +169,8 @@ from napalm_device_types.local_accounts import ( ) from napalm_device_types.log_sources import ( LOG_SOURCES_COMMAND, + LogSourceDict, + LogSourcesDict, LogSourcesMixin, LogSourcesUnavailable, parse_log_sources, @@ -406,6 +408,8 @@ __all__ = [ "ListeningSocketsMixin", "ListeningSocketsUnavailable", "LOG_SOURCES_COMMAND", + "LogSourceDict", + "LogSourcesDict", "LogSourcesMixin", "LogSourcesUnavailable", "parse_log_sources", diff --git a/napalm_device_types/log_sources.py b/napalm_device_types/log_sources.py index 99a60cf..90f2fbf 100644 --- a/napalm_device_types/log_sources.py +++ b/napalm_device_types/log_sources.py @@ -33,12 +33,43 @@ from __future__ import annotations import re from datetime import UTC, datetime from shlex import quote -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, TypedDict from napalm_device_types.listening import _cgroup_paths, _container, _sections, _unit -from napalm_device_types.models import LogSourceDict, LogSourcesDict from napalm_device_types.terminal import strip_terminal_codes + +class LogSourceDict(TypedDict): + """A log the host writes: a unit's journal, a file a process holds open, or a + container's stream as the engine keeps it. + + ``path`` is as its writer sees it: a file a container writes is named inside + that container. Whether anything reads the log is the consumer's question. + """ + + kind: str # "journald", "file" or "container" + path: str | None # the file; None for a journal + unit: str | None # the journal's unit, or the file writer's service; without ".service" + container_id: str | None # the full container ID: the writer's, or the stream's + process: str | None # the first process holding the file + size: int | None # bytes; None for a journal, or when the file could not be read + modified: str | None # the last write, ISO 8601 UTC; None as for size + + +class LogSourcesDict(TypedDict): + """What ``LogSourcesMixin.get_log_sources`` read. + + ``attributed`` is False when the reading ran without root: only the login + user's own processes show their files then, so a missing log means "not + told", not "not there". ``journald`` is False on a host without systemd's + journal, where no unit has one. + """ + + attributed: bool + journald: bool + sources: list[LogSourceDict] + + _BEGIN = "LOGS_BEGIN" _END = "LOGS_END" diff --git a/napalm_device_types/models.py b/napalm_device_types/models.py index 32b27e2..b2d4302 100644 --- a/napalm_device_types/models.py +++ b/napalm_device_types/models.py @@ -406,37 +406,6 @@ class ListeningSocketsDict(TypedDict): sockets: list[ListeningSocketDict] -class LogSourceDict(TypedDict): - """A log the host writes: a unit's journal, a file a process holds open, or a - container's stream as the engine keeps it. - - ``path`` is as its writer sees it: a file a container writes is named inside - that container. Whether anything reads the log is the consumer's question. - """ - - kind: str # "journald", "file" or "container" - path: str | None # the file; None for a journal - unit: str | None # the journal's unit, or the file writer's service; without ".service" - container_id: str | None # the full container ID: the writer's, or the stream's - process: str | None # the first process holding the file - size: int | None # bytes; None for a journal, or when the file could not be read - modified: str | None # the last write, ISO 8601 UTC; None as for size - - -class LogSourcesDict(TypedDict): - """What ``LogSourcesMixin.get_log_sources`` read. - - ``attributed`` is False when the reading ran without root: only the login - user's own processes show their files then, so a missing log means "not - told", not "not there". ``journald`` is False on a host without systemd's - journal, where no unit has one. - """ - - attributed: bool - journald: bool - sources: list[LogSourceDict] - - class NetfilterMatchDict(TypedDict): """One condition of a netfilter rule.