Skip to content

Commit

Permalink
Set "unknown" bfd_addr to None (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf authored Nov 29, 2023
1 parent 320562b commit 5630054
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/zinolib/event_types.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import logging
from datetime import datetime, timedelta, timezone
from typing import Optional, ClassVar, List, TypeVar, Union, Dict, Generic
from typing_extensions import Annotated

from pydantic import ConfigDict, IPvAnyAddress
from pydantic import BaseModel, computed_field
from pydantic import ConfigDict, IPvAnyAddress, ValidationError, ValidationInfo
from pydantic import BaseModel, computed_field, field_validator
from pydantic.functional_validators import BeforeValidator

from .compat import StrEnum
from .utils import log_exception_with_params


LOG = logging.getLogger(__name__)


def unknown(v: Optional[str]) -> Optional[str]:
if v:
if 'unknown' in v:
return None
return v
return None


# Must be after "unknown"
OptionalIpAnyAddress = Annotated[Optional[IPvAnyAddress], BeforeValidator(unknown)]


def utcnow():
Expand Down Expand Up @@ -138,6 +157,7 @@ def __init_subclass__(cls, **kwargs):
cls.SUBTYPES[cls.type.value] = cls

@classmethod
@log_exception_with_params(LOG)
def create(cls, attrdict):
event_type_string = attrdict["type"]
subtype = Event.SUBTYPES[event_type_string]
Expand Down Expand Up @@ -168,7 +188,7 @@ def description(self) -> Optional[str]:

class BFDEvent(Event):
type: str = Event.Type.BFD
bfd_addr: Optional[IPvAnyAddress] = None
bfd_addr: OptionalIpAnyAddress = None
bfd_discr: Optional[int] = None
bfd_state: BFDState
bfd_ix: int
Expand Down

0 comments on commit 5630054

Please sign in to comment.