Skip to content

Commit

Permalink
Merge pull request #373 from SUNET/feature.tagged_vlan_list_range
Browse files Browse the repository at this point in the history
allow specifying ranges of vlans in tagged_vlan_list
  • Loading branch information
indy-independence authored Oct 21, 2024
2 parents 7c4df23 + f2b9436 commit 1824065
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/reporef/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Keys for interfaces.yml or interfaces_<model>.yml:
* Additional interface options for port_template type:

* untagged_vlan: Optional. Numeric VLAN ID for untagged frames.
* tagged_vlan_list: Optional. List of allowed numeric VLAN IDs for tagged frames.
* tagged_vlan_list: Optional. List of allowed VLAN IDs, can be single values or ranges, ex: [1, 5, "10-15"]
* description: Optional. Description for the interface, this should be a string 0-64 characters.
* enabled: Optional. Set the administrative state of the interface. Defaults to true if not set.
* aggregate_id: Optional. Identifier for configuring LACP etc. Integer value.
Expand Down
3 changes: 2 additions & 1 deletion src/cnaas_nms/db/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def get_settings_root():

f_root = get_settings_root()


redis_client = StrictRedis(
host=app_settings.REDIS_HOSTNAME, port=app_settings.REDIS_PORT, retry_on_timeout=True, socket_keepalive=True
)
Expand Down Expand Up @@ -193,6 +192,8 @@ def get_pydantic_error_value(data: dict, loc: tuple):
try:
obj = data
for item in loc:
if type(obj) is str:
return obj
obj = obj[item]
except KeyError:
return None
Expand Down
16 changes: 14 additions & 2 deletions src/cnaas_nms/db/settings_fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ipaddress import AddressValueError, IPv4Interface
from typing import Annotated, Dict, List, Optional
from typing import Annotated, Dict, List, Optional, Union

from pydantic import BaseModel, Field, FieldValidationInfo, conint, field_validator
from pydantic.functional_validators import AfterValidator
Expand Down Expand Up @@ -131,6 +131,15 @@ class f_evpn_peer(BaseModel):
hostname: str = hostname_schema


def vlan_range_check(v: str):
if "-" in v:
start, end = v.split("-")
assert int(start) < int(end), "Start of range must be less than end of range"
assert int(start) >= 1 and int(end) <= 4095, "VLAN IDs in range must be between 1-4095"
else:
assert 1 <= int(v) <= 4095, "VLAN IDs in range must be between 1-4095"


class f_interface(BaseModel):
name: str = ifname_range_schema
ifclass: str = ifclass_schema
Expand All @@ -139,7 +148,10 @@ class f_interface(BaseModel):
description: Optional[str] = ifdescr_schema
enabled: Optional[bool] = None
untagged_vlan: Optional[int] = vlan_id_schema_optional
tagged_vlan_list: Optional[List[Annotated[int, Field(ge=1, le=4094)]]] = None
# tagged vlan list can be list of vlans IDs or ranges of VLAN IDs ("1-10")
tagged_vlan_list: Optional[
List[Union[Annotated[int, Field(ge=1, le=4095)], Annotated[str, AfterValidator(vlan_range_check)]]]
] = None
aggregate_id: Optional[int] = None
tags: Optional[List[str]] = None
vrf: Optional[str] = vlan_name_schema
Expand Down

0 comments on commit 1824065

Please sign in to comment.