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

Commit

Permalink
add rollback progress
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan committed Mar 22, 2024
1 parent a5dae78 commit 1c32e68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions catalystwan/utils/config_migration/reverters/config_reverter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Callable
from venv import logger

from catalystwan.exceptions import CatalystwanException
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions catalystwan/workflows/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1c32e68

Please sign in to comment.