diff --git a/examples/hosts_file/README.md b/examples/hosts_file/README.md index 61086897..7760f9a4 100644 --- a/examples/hosts_file/README.md +++ b/examples/hosts_file/README.md @@ -74,7 +74,22 @@ solar changes run-once last watch -n 1 solar changes report last ``` +How to discard pending changes ? +After database was populated by some example, lets say +``` +python examples/hosts_file/hosts.py deploy +``` +User is able to discard all changes with +``` +solar ch discard +``` +Or any particular change with +``` +solar ch stage +log task=hosts_file1.run uid=a5990538-c9c6-49e4-8d58-29fae9c7aaed +solar ch discard a5990538-c9c6-49e4-8d58-29fae9c7aaed +``` diff --git a/solar/solar/system_log/change.py b/solar/solar/system_log/change.py index f1ad5c5c..cc38722b 100644 --- a/solar/solar/system_log/change.py +++ b/solar/solar/system_log/change.py @@ -128,17 +128,21 @@ def parameters(res, action, data): 'target': data.get('ip')} +def check_uids_present(log, uids): + not_valid = [] + for uid in uids: + if log.get(uid) is None: + not_valid.append(uid) + if not_valid: + raise CannotFindID('UIDS: {} not in history.'.format(not_valid)) + + def revert_uids(uids): """ :param uids: iterable not generator """ history = data.CL() - not_valid = [] - for uid in uids: - if history.get(uid) is None: - not_valid.append(uid) - if not_valid: - raise CannotFindID('UIDS: {} not in history.'.format(not_valid)) + check_uids_present(history, uids) for uid in uids: item = history.get(uid) @@ -222,8 +226,8 @@ def _discard_run(item): def discard_uids(uids): - staged_log = data.SL() + check_uids_present(staged_log, uids) for uid in uids: item = staged_log.get(uid) if item.action == CHANGES.update.name: