From 0f33653ca84004c0e72072dd69f46b56111586a6 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Tue, 1 Dec 2026 12:54:55 +0100 Subject: [PATCH] refactor(models): UserDict and ProcessDict in os_models.py, re-exported from models models.py stays within its line baseline; the baseline drops to what is left. --- napalm_device_types/models.py | 37 ++++------------------------ napalm_device_types/os_models.py | 41 ++++++++++++++++++++++++++++++++ tests/quality_baseline.json | 2 +- 3 files changed, 46 insertions(+), 34 deletions(-) create mode 100644 napalm_device_types/os_models.py diff --git a/napalm_device_types/models.py b/napalm_device_types/models.py index ccccc30..b99b691 100644 --- a/napalm_device_types/models.py +++ b/napalm_device_types/models.py @@ -9,7 +9,8 @@ from typing import Literal, NotRequired, get_args from typing_extensions import TypedDict # The SNMP health profile shapes live in snmp_health_profile.py, those of the access -# point getters in access_point_models.py; re-exported here, where they were. +# point getters in access_point_models.py, an OS's accounts and processes in +# os_models.py; re-exported here, where they were. from napalm_device_types.access_point_models import ChannelScanEntryDict as ChannelScanEntryDict from napalm_device_types.access_point_models import ( FastTransitionConfigDict as FastTransitionConfigDict, @@ -22,6 +23,8 @@ from napalm_device_types.access_point_models import SSIDDict as SSIDDict from napalm_device_types.access_point_models import WirelessClientDict as WirelessClientDict from napalm_device_types.access_point_models import WirelessConfigDict as WirelessConfigDict from napalm_device_types.kernel_models import KernelFactsDict as KernelFactsDict +from napalm_device_types.os_models import ProcessDict as ProcessDict +from napalm_device_types.os_models import UserDict as UserDict from napalm_device_types.snmp_health_profile import SnmpHealthProfile as SnmpHealthProfile from napalm_device_types.snmp_health_profile import SnmpInterfacesSpec as SnmpInterfacesSpec from napalm_device_types.snmp_health_profile import SnmpMemorySpec as SnmpMemorySpec @@ -911,38 +914,6 @@ class ReplicationJobDict(TypedDict): # --------------------------------------------------------------------------- -class UserDict(TypedDict): - """A local OS user account.""" - - username: str - #: POSIX's uid; on Windows the relative identifier, the last part of the SID - #: (500 for the built-in Administrator, 1000 and up for accounts created). - uid: int - gid: int - home: str - shell: str - groups: list[str] # all supplementary group names - #: The account's security identifier, where the host names accounts by one - #: (Windows: "S-1-5-21-...-1001"); left out on a POSIX host. - sid: NotRequired[str] - - -class ProcessDict(TypedDict): - """A running OS process.""" - - pid: int - ppid: int - user: str - cpu: float # CPU utilisation 0.0–100.0 - memory: float # RSS percentage of total RAM 0.0–100.0 - vsz: int # virtual memory size in KiB - rss: int # resident set size in KiB - tty: str # controlling terminal; empty string if none - state: str # "R" running, "S" sleeping, "D" uninterruptible, "Z" zombie, etc. - started: str # start time string as reported by ``ps`` (e.g. "12:34" or "May28") - command: str # full command line - - class ApplyUpdatesResultDict(TypedDict): """Result of an ``apply_updates()`` call.""" diff --git a/napalm_device_types/os_models.py b/napalm_device_types/os_models.py new file mode 100644 index 0000000..14ba2f0 --- /dev/null +++ b/napalm_device_types/os_models.py @@ -0,0 +1,41 @@ +"""What an OS driver reports about the host's accounts and processes (``OSDriver``). + +``get_os_users`` gives :class:`UserDict`, ``get_processes`` :class:`ProcessDict`. Both +lived in :mod:`napalm_device_types.models` and are re-exported there. +""" + +from typing import NotRequired + +from typing_extensions import TypedDict + + +class UserDict(TypedDict): + """A local OS user account.""" + + username: str + #: POSIX's uid; on Windows the relative identifier, the last part of the SID + #: (500 for the built-in Administrator, 1000 and up for accounts created). + uid: int + gid: int + home: str + shell: str + groups: list[str] # all supplementary group names + #: The account's security identifier, where the host names accounts by one + #: (Windows: "S-1-5-21-...-1001"); left out on a POSIX host. + sid: NotRequired[str] + + +class ProcessDict(TypedDict): + """A running OS process.""" + + pid: int + ppid: int + user: str + cpu: float # CPU utilisation 0.0–100.0 + memory: float # RSS percentage of total RAM 0.0–100.0 + vsz: int # virtual memory size in KiB + rss: int # resident set size in KiB + tty: str # controlling terminal; empty string if none + state: str # "R" running, "S" sleeping, "D" uninterruptible, "Z" zombie, etc. + started: str # start time string as reported by ``ps`` (e.g. "12:34" or "May28") + command: str # full command line diff --git a/tests/quality_baseline.json b/tests/quality_baseline.json index 1aaf91a..63703d2 100644 --- a/tests/quality_baseline.json +++ b/tests/quality_baseline.json @@ -31,7 +31,7 @@ }, "mypy_relaxed": [], "python_file_lines": { - "napalm_device_types/models.py": 1336 + "napalm_device_types/models.py": 1312 }, "untyped_public": [] }