Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrajewski committed Jul 11, 2024
1 parent 770ede1 commit 69aefd5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class KeyItem(BaseModel):
id: Global[int] = Field(..., description="Select the Key ID")
name: Global[str] = Field(..., description="Select the chain name")
send_id: Union[Global[int], Variable] = Field(
..., serialization_alias="recvId", validation_alias="srecvId", description="Specify the Send ID"
..., serialization_alias="sendId", validation_alias="sendId", description="Specify the Send ID"
)
recv_id: Union[Global[int], Variable] = Field(
..., serialization_alias="recvId", validation_alias="recvId", description="Specify the Receiver ID"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates
import logging
import re
from copy import deepcopy
from ipaddress import IPv4Interface, IPv6Interface
from typing import Callable, Dict, List, Literal, Optional, Tuple, Type, Union
Expand Down Expand Up @@ -73,6 +74,9 @@

logger = logging.getLogger(__name__)

GRE_INTERFACE_PATTERN = re.compile(pattern="(gre|GRE)(.:){0,1}([0-9]*)$")
IPSEC_INTERFACE_PATTERN = re.compile(pattern="(ipsec|IPSEC)(.:){0,1}([0-9]*)$")

RouteUX2Field = Literal["gre_route", "service_route", "ipsec_route"]
OmpUX2Field = Literal["omp_advertise_ipv4", "omp_advertise_ipv6"]

Expand Down Expand Up @@ -662,7 +666,6 @@ def _parse_omp(
omp_advertise_items = []
for entry in omp_advertises:
prefix_list_items = []
print(entry)
for prefix_entry in entry.get("prefix_list", []):
prefix_list_items.append(self._parse_prefix_entry(prefix_entry, pydantic_field))
if pydantic_model_omp == OmpAdvertiseIPv4:
Expand Down Expand Up @@ -721,11 +724,20 @@ def _parse_route(
subnet_mask=as_global(str(ipv4_interface.netmask)),
)
route_item = pydantic_model(prefix=route_prefix)
if pydantic_field in ["ipsec_route", "gre_route"]:
route_item.interface = route.get("interface")
if pydantic_field == "gre_route" and "interface" in route:
route_item.interface = self.parse_interface(route.get("interface"), GRE_INTERFACE_PATTERN)
elif pydantic_field == "ipsec_route" and "interface" in route:
route_item.interface = self.parse_interface(route.get("interface"), IPSEC_INTERFACE_PATTERN)
items.append(route_item)
values[pydantic_field] = items

def parse_interface(
self, interface: Optional[Union[Global[List[str]], Variable]], pattern: re.Pattern
) -> Optional[Union[Global, Variable]]:
if not interface or isinstance(interface, Variable):
return interface
return Global[List[str]](value=[i for i in interface.value if pattern.match(i)])

def parse_route_leaks(self, values: dict) -> None:
for leak in self.route_leaks_mapping.keys():
if route_leaks := values.get(leak, []):
Expand Down

0 comments on commit 69aefd5

Please sign in to comment.