driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 15s
driver / lowest (pull_request) Successful in 27s
driver / types (pull_request) Successful in 54s
driver / test (3.12) (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 53s
driver / build (pull_request) Successful in 24s
driver / security (pull_request) Successful in 58s
CI / driver (pull_request) Successful in 1m41s
driver / publish (pull_request) Skipped
The standard's ratchet holds linux.py at its recorded size: the two exec-channel transports move to _shares.LinuxSharesMixin, which the host readings bring in.
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""The file shares the host serves and the ones it has mounted (NetOrk/netork#3104).
|
|
|
|
Both readings are napalm-device-types': the NFS exports and Samba shares the host
|
|
serves (``PosixSharesMixin``) and the NFS exports and SMB shares it has mounted
|
|
(``NetworkMountsMixin``). Both commands are read-only and read files every user may
|
|
read, so they run on an exec channel under ``sh`` as the login user, never through sudo.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from shlex import quote
|
|
from typing import TYPE_CHECKING
|
|
|
|
from napalm_device_types import NetworkMountsMixin, PosixSharesMixin
|
|
|
|
if TYPE_CHECKING: # pragma: no cover - for type checkers only
|
|
from napalm_device_types import CommandResult
|
|
|
|
|
|
class LinuxSharesMixin(PosixSharesMixin, NetworkMountsMixin):
|
|
"""The transports for ``get_shares`` and ``get_network_mounts``."""
|
|
|
|
if TYPE_CHECKING: # pragma: no cover - declared for type checkers only
|
|
|
|
def run_command(
|
|
self,
|
|
command: str,
|
|
*,
|
|
privileged: bool = False,
|
|
timeout: float = 60,
|
|
stdin: bytes | None = None,
|
|
) -> CommandResult: ...
|
|
|
|
def _run_shares_command(self, command: str) -> str:
|
|
return self.run_command(f"sh -c {quote(command)}", timeout=60).stdout
|
|
|
|
def _run_network_mounts_command(self, command: str) -> str:
|
|
return self.run_command(f"sh -c {quote(command)}", timeout=30).stdout
|