# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """UCI writes run step by step, each step's exit status checked (#35). A write stages its changes with one ``uci`` command each, commits the config, then restarts what reads it. Every step runs on an SSH exec channel of its own, so its exit status is the command's own -- nothing is hidden behind ``|| true`` or a shell prompt. A refused step raises :class:`CommandErrorException` naming the step and what the device said. A refusal before the commit reverts what was staged, so the next commit of the config -- by any write -- does not apply half a change; nothing is restarted. A refused restart comes after the commit: the change is saved, and the error says so. """ from __future__ import annotations import logging import re import shlex from collections.abc import Sequence from dataclasses import dataclass, field from typing import TYPE_CHECKING from napalm.base.exceptions import CommandErrorException if TYPE_CHECKING: # pragma: no cover - typing only from napalm_device_types import CommandResult logger = logging.getLogger(__name__) #: Seconds one step may take; ``wifi`` brings every radio down and up again. UCI_STEP_TIMEOUT = 60 #: ``config.section=type`` or ``config.section.option=value`` of ``uci show``. _SHOW_LINE = re.compile( r"^(?P[^.=\s]+)\.(?P
[^.=\s]+)(?:\.(?P