diff --git a/catalystwan/utils/config_migration/reverters/config_reverter.py b/catalystwan/utils/config_migration/reverters/config_reverter.py index 808b6c07..00e6bc72 100644 --- a/catalystwan/utils/config_migration/reverters/config_reverter.py +++ b/catalystwan/utils/config_migration/reverters/config_reverter.py @@ -1,3 +1,4 @@ +from typing import Callable from venv import logger from catalystwan.exceptions import CatalystwanException @@ -9,15 +10,18 @@ class UX2ConfigReverter: def __init__(self, session) -> None: self._session = session - def rollback(self, rollback_config: UX2ConfigRollback) -> bool: + def rollback(self, rollback_config: UX2ConfigRollback, progress: Callable[[str, int, int], None]) -> bool: try: - for cg_id in rollback_config.config_group_ids: + for i, cg_id in enumerate(rollback_config.config_group_ids): self._session.endpoints.configuration_group.delete_config_group(cg_id) - for feature_profile_id, type_ in rollback_config.feature_profile_ids: + progress("Removing Configuration Groups", i + 1, len(rollback_config.config_group_ids)) + for i, feature_profile_entry in enumerate(rollback_config.feature_profile_ids): + feature_profile_id, type_ = feature_profile_entry api = FeatureProfileAPIFactory.get_api(type_, self._session) if type_ == "policy-object": continue api.delete_profile(feature_profile_id) # type: ignore + progress("Removing Feature Profiles", i + 1, len(rollback_config.feature_profile_ids)) except CatalystwanException as e: logger.error(f"Error occured during config revert: {e}") return False diff --git a/catalystwan/workflows/config_migration.py b/catalystwan/workflows/config_migration.py index 57c91537..c839b6fd 100644 --- a/catalystwan/workflows/config_migration.py +++ b/catalystwan/workflows/config_migration.py @@ -226,7 +226,11 @@ def push_ux2_config( return rollback -def rollback_ux2_config(session: ManagerSession, rollback_config: UX2ConfigRollback) -> bool: +def rollback_ux2_config( + session: ManagerSession, + rollback_config: UX2ConfigRollback, + progress: Callable[[str, int, int], None] = log_progress, +) -> bool: config_reverter = UX2ConfigReverter(session) - status = config_reverter.rollback(rollback_config) + status = config_reverter.rollback(rollback_config, progress) return status