From e613c4f5a515e2c50600c6b4504afe71f136068a Mon Sep 17 00:00:00 2001 From: Johan Marcusson Date: Mon, 13 Sep 2021 11:36:30 +0200 Subject: [PATCH 1/3] Same options as access ports for dist ports, description, vlans etc. --- docs/reporef/index.rst | 9 +++++++++ src/cnaas_nms/db/settings_fields.py | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/docs/reporef/index.rst b/docs/reporef/index.rst index 7b228f69..48b8e47b 100644 --- a/docs/reporef/index.rst +++ b/docs/reporef/index.rst @@ -288,6 +288,15 @@ Keys for interfaces.yml or interfaces_.yml: * ifclass: Interface class, one of: downlink, fabric, custom, port_template_* * config: Optional. Raw CLI config used in case "custom" ifclass was selected +* 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. + * 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. + Special value -1 means configure MLAG and use ID based on indexnum. + The "downlink" ifclass is used on DIST devices to specify that this interface is used to connect access devices. The "fabric" ifclass is used to specify that this interface is used to connect DIST or CORE devices with each other to form diff --git a/src/cnaas_nms/db/settings_fields.py b/src/cnaas_nms/db/settings_fields.py index 5c8096d2..8787563d 100644 --- a/src/cnaas_nms/db/settings_fields.py +++ b/src/cnaas_nms/db/settings_fields.py @@ -56,6 +56,7 @@ IFCLASS_REGEX = r'(custom|downlink|fabric|port_template_[a-zA-Z0-9_]+)' ifclass_schema = Field(None, regex=f"^{IFCLASS_REGEX}$", description="Interface class: custom, downlink or uplink") +ifdescr_schema = Field(None, max_length=64, description="Interface description, 0-64 characters") tcpudp_port_schema = Field(None, ge=0, lt=65536, description="TCP or UDP port number, 0-65535") ebgp_multihop_schema = Field(None, ge=1, le=255, description="Numeric IP TTL, 1-255") maximum_routes_schema = Field(None, ge=0, le=4294967294, description="Maximum number of routes to receive from peer") @@ -111,6 +112,11 @@ class f_interface(BaseModel): name: str = ifname_schema ifclass: str = ifclass_schema config: Optional[str] = None + description: Optional[str] = ifdescr_schema + enabled: Optional[bool] = None + untagged_vlan: Optional[int] = vlan_id_schema_optional + tagged_vlan_list: List[vlan_id_schema] = [] + aggregate_id: Optional[int] = None class f_vrf(BaseModel): From f54c9a9fc31835aa9b94be26a4659132cec530cb Mon Sep 17 00:00:00 2001 From: Johan Marcusson Date: Mon, 13 Sep 2021 14:23:22 +0200 Subject: [PATCH 2/3] Check items in vlan list with validator instead, don't think it's possible with just pydantic model --- src/cnaas_nms/db/settings_fields.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cnaas_nms/db/settings_fields.py b/src/cnaas_nms/db/settings_fields.py index 8787563d..2c827732 100644 --- a/src/cnaas_nms/db/settings_fields.py +++ b/src/cnaas_nms/db/settings_fields.py @@ -115,9 +115,14 @@ class f_interface(BaseModel): description: Optional[str] = ifdescr_schema enabled: Optional[bool] = None untagged_vlan: Optional[int] = vlan_id_schema_optional - tagged_vlan_list: List[vlan_id_schema] = [] + tagged_vlan_list: Optional[List[int]] = None aggregate_id: Optional[int] = None + @validator("tagged_vlan_list", each_item=True) + def check_valid_vlan_ids(cls, v): + assert 0 < v < 4096 + return v + class f_vrf(BaseModel): name: str = None From 3227944ff707820084f72e3c68062ec731cbae13 Mon Sep 17 00:00:00 2001 From: Johan Marcusson Date: Tue, 14 Sep 2021 10:26:04 +0200 Subject: [PATCH 3/3] Populate template_vars with any items that passed through pydantic for port_template_* and others ifclass --- src/cnaas_nms/confpush/sync_devices.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cnaas_nms/confpush/sync_devices.py b/src/cnaas_nms/confpush/sync_devices.py index 763c1e3d..dd3b9e3c 100644 --- a/src/cnaas_nms/confpush/sync_devices.py +++ b/src/cnaas_nms/confpush/sync_devices.py @@ -281,6 +281,12 @@ def populate_device_vars(session, dev: Device, 'peer_ip': None, 'peer_asn': None }) + else: + if_dict = {'indexnum': ifindexnum} + for key, value in intf.items(): + if_dict[key] = value + fabric_device_variables['interfaces'].append(if_dict) + for local_if, data in fabric_interfaces.items(): logger.warn(f"Interface {local_if} on device {hostname} not " "configured as linknet because of wrong ifclass")