Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow specifying ranges of vlans in tagged_vlan_list #373

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 @@
try:
obj = data
for item in loc:
if type(obj) is str:
return obj

Check warning on line 196 in src/cnaas_nms/db/settings.py

View check run for this annotation

Codecov / codecov/patch

src/cnaas_nms/db/settings.py#L196

Added line #L196 was not covered by tests
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 @@
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"

Check warning on line 138 in src/cnaas_nms/db/settings_fields.py

View check run for this annotation

Codecov / codecov/patch

src/cnaas_nms/db/settings_fields.py#L135-L138

Added lines #L135 - L138 were not covered by tests
else:
assert 1 <= int(v) <= 4095, "VLAN IDs in range must be between 1-4095"

Check warning on line 140 in src/cnaas_nms/db/settings_fields.py

View check run for this annotation

Codecov / codecov/patch

src/cnaas_nms/db/settings_fields.py#L140

Added line #L140 was not covered by tests


class f_interface(BaseModel):
name: str = ifname_range_schema
ifclass: str = ifclass_schema
Expand All @@ -139,7 +148,10 @@
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
Loading