From 8ba61e58b71dc64a87504eead3072e45abc17e78 Mon Sep 17 00:00:00 2001 From: Johan Marcusson Date: Fri, 8 Sep 2023 09:58:03 +0200 Subject: [PATCH] Log error device not reachable after commit --- docs/reporef/index.rst | 1 + src/cnaas_nms/api/device.py | 4 ++++ src/cnaas_nms/db/settings_fields.py | 1 + src/cnaas_nms/devicehandler/sync_devices.py | 15 ++++++++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/reporef/index.rst b/docs/reporef/index.rst index 3ad647be..b295d1d0 100644 --- a/docs/reporef/index.rst +++ b/docs/reporef/index.rst @@ -403,6 +403,7 @@ Keys for interfaces.yml or interfaces_.yml: * 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. + * tags: Optional list of strings, custom user defined tags to apply. * cli_append_str: Optional. Custom configuration to append to this interface. The "downlink" ifclass is used on DIST devices to specify that this interface diff --git a/src/cnaas_nms/api/device.py b/src/cnaas_nms/api/device.py index bbfd2944..407efcb6 100644 --- a/src/cnaas_nms/api/device.py +++ b/src/cnaas_nms/api/device.py @@ -846,8 +846,10 @@ def post(self): class DeviceConfigApi(Resource): @jwt_required + @device_api.param("variables_only") def get(self, hostname: str): """Get device configuration""" + args = request.args result = empty_result() result["data"] = {"config": None} if not Device.valid_hostname(hostname): @@ -861,6 +863,8 @@ def get(self, hostname: str): "generated_config": config, "available_variables": template_vars, } + if "variables_only" in args and args["variables_only"]: + del result["data"]["config"]["generated_config"] except Exception as e: logger.exception(f"Exception while generating config for device {hostname}") return ( diff --git a/src/cnaas_nms/db/settings_fields.py b/src/cnaas_nms/db/settings_fields.py index 51cb0eab..aafa9a8f 100644 --- a/src/cnaas_nms/db/settings_fields.py +++ b/src/cnaas_nms/db/settings_fields.py @@ -138,6 +138,7 @@ class f_interface(BaseModel): untagged_vlan: Optional[int] = vlan_id_schema_optional tagged_vlan_list: Optional[List[int]] = None aggregate_id: Optional[int] = None + tags: Optional[List[str]] = None cli_append_str: str = "" @validator("tagged_vlan_list", each_item=True) diff --git a/src/cnaas_nms/devicehandler/sync_devices.py b/src/cnaas_nms/devicehandler/sync_devices.py index 0da17889..291c0024 100644 --- a/src/cnaas_nms/devicehandler/sync_devices.py +++ b/src/cnaas_nms/devicehandler/sync_devices.py @@ -560,9 +560,22 @@ def push_sync_device( task.run(**task_args) if confirm_mode != 2: task.host.close_connection("napalm") - if confirm_mode == 2: + if confirm_mode == 2 and not dry_run: time.sleep(1) task.run(task=napalm_get, getters=["facts"], name="Verify reachability") + if task.results[2].failed: + logger.error( + "Could not reach device {} after commit, rollback in: {}s".format( + task.host.name, api_settings.COMMIT_CONFIRMED_TIMEOUT + ) + ) + else: + short_facts = {"fqdn": "unknown"} + try: + short_facts["fqdn"] = task.results[2].result["facts"]["fqdn"] + task.results[2].result["facts"] = short_facts + except Exception: + pass if task.results[1].diff: config = task.results[1].host["config"]