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

Commit

Permalink
Merge pull request #529 from CiscoDevNet/dev/snmp
Browse files Browse the repository at this point in the history
SNMP converter
  • Loading branch information
jpkrajewski authored Mar 18, 2024
2 parents 968a2f8 + bd1a24d commit ce903dc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class TargetItem(BaseModel):
validation_alias="vpnId",
description="Set VPN in which SNMP server is located",
)
ip: Union[Global[Union[IPv4Address, IPv6Address]], Variable] = Field(
ip: Union[Global[IPv4Address], Global[IPv6Address], Variable] = Field(
..., description="Set IPv4/IPv6 address of SNMP server"
)
port: Union[Global[int], Variable] = Field(..., description="Set UDP port number to connect to SNMP server")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from catalystwan.exceptions import CatalystwanException
from catalystwan.models.configuration.feature_profile.sdwan.system import AnySystemParcel
from catalystwan.utils.config_migration.converters.feature_template.dhcp import DhcpTemplateConverter
from catalystwan.utils.config_migration.converters.feature_template.snmp import SNMPTemplateConverter
from catalystwan.utils.feature_template.find_template_values import find_template_values

from .aaa import AAATemplateConverter
Expand Down Expand Up @@ -39,6 +40,7 @@
ThousandEyesTemplateConverter,
UcseTemplateConverter,
DhcpTemplateConverter,
SNMPTemplateConverter,
]


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import logging
from copy import deepcopy

from catalystwan.api.configuration_groups.parcel import Variable, as_global, as_variable
from catalystwan.models.configuration.feature_profile.sdwan.system.snmp import Authorization, SNMPParcel

logger = logging.getLogger(__name__)


class SNMPTemplateConverter:
"""
A class for converting template values into a SecurityParcel object.
Attributes:
supported_template_types (tuple): A tuple of supported template types.
"""

supported_template_types = ("cisco_snmp",)

@staticmethod
def create_parcel(name: str, description: str, template_values: dict) -> SNMPParcel:
"""
Creates a SecurityParcel object based on the provided template values.
Args:
name (str): The name of the SecurityParcel.
description (str): The description of the SecurityParcel.
template_values (dict): A dictionary containing the template values.
Returns:
SecurityParcel: A SecurityParcel object with the provided template values.
"""
values = deepcopy(template_values)
for community_item in values.get("community", []):
if authorization := community_item.get("authorization"):
community_item["authorization"] = as_global(authorization.value, Authorization)

values["target"] = values.pop("trap", {}).get("target", [])
default_view_oid_id = "{{{{l_snmpView_1_snmpOid_{}_id}}}}"
for view in values.get("view", []):
for i, oid in enumerate(view.get("oid", [])):
id_ = oid.get("id", as_variable(default_view_oid_id.format(i + 1)))
if isinstance(id_, Variable):
logger.info(
f"OID ID is not set, using device specific variable {default_view_oid_id.format(i + 1)}"
)
oid["id"] = id_

parcel_values = {"parcel_name": name, "parcel_description": description, **values}
return SNMPParcel(**parcel_values) # type: ignore
5 changes: 3 additions & 2 deletions catalystwan/workflows/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@
"omp-vsmart",
"cisco_ntp",
"ntp",
# "bgp",
# "cisco_bgp",
"bgp",
"cisco_bgp",
"cisco_snmp",
]

FEATURE_PROFILE_TRANSPORT = ["dhcp", "cisco_dhcp_server", "dhcp-server"]
Expand Down

0 comments on commit ce903dc

Please sign in to comment.