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

Commit

Permalink
bulk refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan committed Feb 19, 2024
1 parent 3b42f5a commit 110e95c
Show file tree
Hide file tree
Showing 55 changed files with 2,775 additions and 3,026 deletions.
121 changes: 69 additions & 52 deletions catalystwan/models/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from enum import Enum
from typing import Dict, List, Set, Tuple
from typing import Dict, List, Literal, Set, Tuple


def check_fields_exclusive(values: Dict, field_names: Set[str], at_least_one: bool = False) -> bool:
Expand Down Expand Up @@ -47,53 +46,71 @@ def check_any_of_exclusive_field_sets(values: Dict, field_sets: List[Tuple[Set[s
raise ValueError(f"One of {all_sets_field_names} must be assigned")


class InterfaceTypeEnum(str, Enum):
ETHERNET = "Ethernet"
FAST_ETHERNET = "FastEthernet"
FIVE_GIGABIT_ETHERNET = "FiveGigabitEthernet"
FORTY_GIGABIT_ETHERNET = "FortyGigabitEthernet"
GIGABIT_ETHERNET = "GigabitEthernet"
HUNDRED_GIG_ETHERNET = "HundredGigE"
LOOPBACK = "Loopback"
TEN_GIGABIT_ETHERNET = "TenGigabitEthernet"
TUNNEL = "Tunnel"
TWENTY_FIVEGIGABIT_ETHERNET = "TwentyFiveGigabitEthernet"
TWENTY_FIVE_GIG_ETHERNET = "TwentyFiveGigE"
TWO_GIGABIT_ETHERNET = "TwoGigabitEthernet"
VIRTUAL_PORT_GROUP = "VirtualPortGroup"
VLAN = "Vlan"


class TLOCColorEnum(str, Enum):
DEFAULT = "default"
MPLS = "mpls"
METRO_ETHERNET = "metro-ethernet"
BIZ_INTERNET = "biz-internet"
PUBLIC_INTERNET = "public-internet"
LTE = "lte"
THREEG = "3g"
RED = "red"
GREEN = "green"
BLUE = "blue"
GOLD = "gold"
SILVER = "silver"
BRONZE = "bronze"
CUSTOM1 = "custom1"
CUSTOM2 = "custom2"
CUSTOM3 = "custom3"
PRIVATE1 = "private1"
PRIVATE2 = "private2"
PRIVATE3 = "private3"
PRIVATE4 = "private4"
PRIVATE5 = "private5"
PRIVATE6 = "private6"


class WellKnownBGPCommunitiesEnum(str, Enum):
INTERNET = "internet"
LOCAL_AS = "local-AS"
NO_ADVERTISE = "no-advertise"
NO_EXPORT = "no-export"


UUID = str
InterfaceType = Literal[
"Ethernet",
"FastEthernet",
"FiveGigabitEthernet",
"FortyGigabitEthernet",
"GigabitEthernet",
"HundredGigE",
"Loopback",
"TenGigabitEthernet",
"Tunnel",
"TwentyFiveGigabitEthernet",
"TwentyFiveGigE",
"TwoGigabitEthernet",
"VirtualPortGroup",
"Vlan",
]

TLOCColor = Literal[
"default",
"mpls",
"metro-ethernet",
"biz-internet",
"public-internet",
"lte",
"3g",
"red",
"green",
"blue",
"gold",
"silver",
"bronze",
"custom1",
"custom2",
"custom3",
"private1",
"private2",
"private3",
"private4",
"private5",
"private6",
]


WellKnownBGPCommunities = Literal[
"internet",
"local-AS",
"no-advertise",
"no-export",
]

ServiceChainNumber = Literal[
"SC1",
"SC2",
"SC3",
"SC4",
"SC5",
"SC6",
"SC7",
"SC8",
"SC9",
"SC10",
"SC11",
"SC12",
"SC13",
"SC14",
"SC15",
"SC16",
]
28 changes: 8 additions & 20 deletions catalystwan/models/configuration/common.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
from enum import Enum

from pydantic import BaseModel, Extra, Field

from catalystwan.models.profileparcel.traffic_policy import GlobalOptionTypeDef, UuidDef


class Solution(str, Enum):
MOBILITY = "mobility"
SDWAN = "sdwan"
NFVIRTUAL = "nfvirtual"
SDROUTING = "sd-routing"


class RefId(BaseModel):
class Config:
extra = Extra.forbid

option_type: GlobalOptionTypeDef = Field(..., alias="optionType")
value: UuidDef
from typing import Literal

Solution = Literal[
"mobility",
"sdwan",
"nfvirtual",
"sd-routing",
]
8 changes: 4 additions & 4 deletions catalystwan/models/configuration/feature_profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ auto_sim: Union[Variable, Global[bool], Default[None]]

### 3. Literals vs Enums

Use `Enums` over the `Literals`. Justification:
- `Enum` provides IntelliSense.
- Both provides static typing safety.
- `Enum` can be treated as a `str`.
Use `Literal` over the `Enums`. Justification:
- Both provides static typing safety ant intellisense (type-hints).
- `(str, Enum)` can be problematic as `__str__` != `__format__` for Enum
- When instantiating pydantic Field defined as `Literal` no explicit import of specific `Enum` is needed

### 4. Naming Conventions

Expand Down
119 changes: 59 additions & 60 deletions catalystwan/models/configuration/feature_profile/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import datetime
from enum import Enum
from typing import Generic, List, Literal, Optional, TypeVar, Union
from uuid import UUID

Expand All @@ -14,15 +13,65 @@
IPV4Address = str
IPv6Address = str


class ProfileType(str, Enum):
TRANSPORT = "transport"
SYSTEM = "system"
CLI = "cli"
SERVICE = "service"
APPLICATION_PRIORITY = "application-priority"
POLICY_OBJECT = "policy-object"
EMBEDDED_SECURITY = "embedded-security"
ParcelType = Literal[
"appqoe",
"lan/vpn",
"lan/vpn/interface/ethernet",
"lan/vpn/interface/gre",
"lan/vpn/interface/ipsec",
"lan/vpn/interface/svi",
"dhcp-server",
"tracker",
"trackergroup",
"routing/bgp",
"routing/eigrp",
"routing/multicast",
"routing/ospf",
"routing/ospfv3/ipv4",
"routing/ospfv3/ipv6",
"wirelesslan",
"switchport",
"app-probe",
"app-list",
"color",
"data-prefix",
"expanded-community",
"class",
"data-ipv6-prefix",
"ipv6-prefix",
"prefix",
"policer",
"preferred-color-group",
"sla-class",
"tloc",
"standard-community",
"security-localdomain",
"security-fqdn",
"security-ipssignature",
"security-urllist",
"security-urllist",
"security-port",
"security-protocolname",
"security-geolocation",
"security-zone",
"security-localapp",
"security-data-ip-prefix",
]

ProfileType = Literal[
"transport",
"system",
"cli",
"service",
"application-priority",
"policy-object",
"embedded-security",
]

SchemaType = Literal[
"post",
"put",
]


class FeatureProfileInfo(BaseModel):
Expand Down Expand Up @@ -78,51 +127,6 @@ class ParcelCreationResponse(BaseModel):
id: UUID = Field(serialization_alias="parcelId", validation_alias="parcelId")


class ParcelType(str, Enum):
APPQOE = "appqoe"
LAN_VPN = "lan/vpn"
LAN_VPN_INTERFACE_ETHERNET = "lan/vpn/interface/ethernet"
LAN_VPN_INTERFACE_GRE = "lan/vpn/interface/gre"
LAN_VPN_INTERFACE_IPSEC = "lan/vpn/interface/ipsec"
LAN_VPN_INTERFACE_SVI = "lan/vpn/interface/svi"
DHCP_SERVER = "dhcp-server"
TRACKER = "tracker"
TRACKER_GROUP = "trackergroup"
ROUTING_BGP = "routing/bgp"
ROUTING_EIGRP = "routing/eigrp"
ROUTING_MULTICAST = "routing/multicast"
ROUTING_OSPF = "routing/ospf"
ROUTING_OSPFV3_IPV4 = "routing/ospfv3/ipv4"
ROUTING_OSPFV3_IPV6 = "routing/ospfv3/ipv6"
WIRELESSLAN = "wirelesslan"
SWITCHPORT = "switchport"
APP_PROBE = "app-probe"
APPLICATION_LIST = "app-list"
COLOR = "color"
DATA_PREFIX = "data-prefix"
EXPANDED_COMMUNITY = "expanded-community"
FOWARDING_CLASS = "class"
IPV6_DATA_PREFIX = "data-ipv6-prefix"
IPV6_PREFIX_LIST = "ipv6-prefix"
PREFIX_LIST = "prefix"
POLICIER = "policer"
PREFERRED_COLOR_GROUP = "preferred-color-group"
SLA_CLASS = "sla-class"
TLOC = "tloc"
STANDARD_COMMUNITY = "standard-community"
LOCAL_DOMAIN = "security-localdomain"
FQDN_DOMAIN = "security-fqdn"
IPS_SIGNATURE = "security-ipssignature"
URL_ALLOW = "security-urllist"
URL_BLOCK = "security-urllist"
SECURITY_PORT = "security-port"
PROTOCOL_LIST = "security-protocolname"
GEO_LOCATION_LIST = "security-geolocation"
SECURITY_ZONE_LIST = "security-zone"
SECURITY_APPLICATION_LIST = "security-localapp"
SECURITY_DATA_PREFIX = "security-data-ip-prefix"


class Parcel(BaseModel, Generic[T]):
parcel_id: str = Field(alias="parcelId")
parcel_type: ParcelType = Field(alias="parcelType")
Expand Down Expand Up @@ -157,11 +161,6 @@ class Prefix(BaseModel):
mask: Union[Variable, Global[str]]


class SchemaType(str, Enum):
POST = "post"
PUT = "put"


class SchemaTypeQuery(BaseModel):
model_config = ConfigDict(populate_by_name=True)

Expand Down
Loading

0 comments on commit 110e95c

Please sign in to comment.