Add validation for uids and short how to in hosts_file/README.md
This commit is contained in:
parent
5d677264ff
commit
d6482e83c0
@ -74,7 +74,22 @@ solar changes run-once last
|
|||||||
watch -n 1 solar changes report 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
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -128,17 +128,21 @@ def parameters(res, action, data):
|
|||||||
'target': data.get('ip')}
|
'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):
|
def revert_uids(uids):
|
||||||
"""
|
"""
|
||||||
:param uids: iterable not generator
|
:param uids: iterable not generator
|
||||||
"""
|
"""
|
||||||
history = data.CL()
|
history = data.CL()
|
||||||
not_valid = []
|
check_uids_present(history, uids)
|
||||||
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))
|
|
||||||
|
|
||||||
for uid in uids:
|
for uid in uids:
|
||||||
item = history.get(uid)
|
item = history.get(uid)
|
||||||
@ -222,8 +226,8 @@ def _discard_run(item):
|
|||||||
|
|
||||||
|
|
||||||
def discard_uids(uids):
|
def discard_uids(uids):
|
||||||
|
|
||||||
staged_log = data.SL()
|
staged_log = data.SL()
|
||||||
|
check_uids_present(staged_log, uids)
|
||||||
for uid in uids:
|
for uid in uids:
|
||||||
item = staged_log.get(uid)
|
item = staged_log.get(uid)
|
||||||
if item.action == CHANGES.update.name:
|
if item.action == CHANGES.update.name:
|
||||||
|
Loading…
Reference in New Issue
Block a user