Coverage for netbox_interface_name_rules / rename_outcomes.py: 100.00%
14 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-16 10:13 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-16 10:13 +0000
1# SPDX-License-Identifier: Apache-2.0
2# Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com>
3"""Outcome facts of a reapply: what happened to each interface that a matching rule acted on.
5An interface that already has its correct name, or that the rule does not claim, has no outcome.
6"""
8from dataclasses import dataclass
9from enum import StrEnum
12class OutcomeKind(StrEnum):
13 """What a reapply did to one interface."""
15 RENAMED = "renamed"
16 BLOCKED = "blocked"
17 UNRESOLVED_VARIABLE = "unresolved variable"
18 UNCLAIMED = "unclaimed"
19 FAILED = "failed"
22@dataclass(frozen=True, slots=True)
23class RenameOutcome:
24 """One outcome fact. *interface_name* is None for a failure that stopped the whole reapply."""
26 kind: OutcomeKind
27 interface_name: str | None
28 reason: str = ""
29 target_name: str | None = None
32def renamed_count(outcomes) -> int:
33 """Return the number of interfaces that *outcomes* renamed or created."""
34 return sum(outcome.kind == OutcomeKind.RENAMED for outcome in outcomes)