diff --git a/src/cnaas_nms/app_settings.py b/src/cnaas_nms/app_settings.py index 6bd9f1af..ce64b238 100644 --- a/src/cnaas_nms/app_settings.py +++ b/src/cnaas_nms/app_settings.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import List, Optional +from typing import Optional import yaml from pydantic import field_validator @@ -57,7 +57,6 @@ class ApiSettings(BaseSettings): COMMIT_CONFIRMED_TIMEOUT: int = 300 COMMIT_CONFIRMED_WAIT: int = 1 SETTINGS_OVERRIDE: Optional[dict] = None - DEVICE_TYPES_WITH_INCLUDE_RUNNING_CONFIG: List[str] = [] @field_validator("MGMTDOMAIN_PRIMARY_IP_VERSION") @classmethod @@ -119,7 +118,6 @@ def construct_api_settings() -> ApiSettings: COMMIT_CONFIRMED_TIMEOUT=config.get("commit_confirmed_timeout", 300), COMMIT_CONFIRMED_WAIT=config.get("commit_confirmed_wait", 1), SETTINGS_OVERRIDE=config.get("settings_override", None), - DEVICE_TYPES_WITH_INCLUDE_RUNNING_CONFIG=config.get("device_types_with_include_running_config", []), ) else: return ApiSettings() diff --git a/src/cnaas_nms/devicehandler/sync_devices.py b/src/cnaas_nms/devicehandler/sync_devices.py index 2d4083c1..51603910 100644 --- a/src/cnaas_nms/devicehandler/sync_devices.py +++ b/src/cnaas_nms/devicehandler/sync_devices.py @@ -358,15 +358,23 @@ def populate_device_vars( ) device_variables = {**device_variables, **fabric_device_variables} - # if device type in api_settings.DEVICE_TYPES_WITH_INCLUDE_RUNNING_CONFIG - for dt_str in api_settings.DEVICE_TYPES_WITH_INCLUDE_RUNNING_CONFIG: - if dev.device_type.name.lower() == dt_str.lower(): + # if platform/devtype has unmanaged config sections, get running_config and add to device_variables + local_repo_path = get_template_repo_path(hostname) + mapfile = os.path.join(local_repo_path, dev.platform, "mapping.yml") + if not os.path.isfile(mapfile): + raise RepoStructureException("File {} not found in template repo".format(mapfile)) + with open(mapfile, "r") as f: + mapping = yaml.safe_load(f) + if ( + "unmanaged_config_sections" in mapping[devtype.name] + and type(mapping[devtype.name]["unmanaged_config_sections"]) is list + ): task.host.open_connection("napalm", configuration=task.nornir.config) res = task.run(task=napalm_get, getters=["config"]) task.host.close_connection("napalm") running_config = dict(res.result)["config"]["running"] - # Remove the first task result, which is the napalm_get result, since it's not needed anymore + # Remove the first task result, which is the napalm_get result, since it's not needed for final job result del task.results[0] if running_config is None: raise Exception(f"Failed to get running configuration for {dev.hostname}")