Add discard routine to system log cli and api
This commit is contained in:
parent
6e65702d4f
commit
79e57e4c07
@ -102,6 +102,11 @@ def revert(uid):
|
||||
except errors.SolarError as er:
|
||||
raise click.BadParameter(str(er))
|
||||
|
||||
@changes.command()
|
||||
def discard():
|
||||
change.discard_all()
|
||||
|
||||
|
||||
@changes.command()
|
||||
@click.option('--name', default=None)
|
||||
def test(name):
|
||||
|
@ -172,6 +172,10 @@ class Resource(object):
|
||||
self.db_obj.state = RESOURCE_STATE.error.name
|
||||
self.db_obj.save()
|
||||
|
||||
def set_created(self):
|
||||
self.db_obj.state = RESOURCE_STATE.created.name
|
||||
self.db_obj.save()
|
||||
|
||||
def to_be_removed(self):
|
||||
return self.db_obj.state == RESOURCE_STATE.removed.name
|
||||
|
||||
|
@ -195,3 +195,34 @@ def _revert_run(logitem):
|
||||
def revert(uid):
|
||||
return revert_uids([uid])
|
||||
|
||||
|
||||
def _discard_remove(item):
|
||||
resource_obj = resource.load(item.res)
|
||||
resource_obj.set_created()
|
||||
|
||||
_discard_update = _revert_update
|
||||
_discard_run = _revert_run
|
||||
|
||||
|
||||
def discard_uids(uids):
|
||||
staged_log = data.SL()
|
||||
for uid in uids:
|
||||
item = staged_log.get(uid)
|
||||
if item.action == CHANGES.update.name:
|
||||
_discard_update(item)
|
||||
elif item.action == CHANGES.remove.name:
|
||||
_discard_remove(item)
|
||||
elif item.action == CHANGES.run.name:
|
||||
_discard_run(item)
|
||||
else:
|
||||
log.debug('Action %s for resource %s is a side'
|
||||
' effect of another action', item.action, item.res)
|
||||
staged_log.pop(uid)
|
||||
|
||||
|
||||
def discard_uid(uid):
|
||||
return discard_uids([uid])
|
||||
|
||||
def discard_all():
|
||||
staged_log = data.SL()
|
||||
return discard_uids([l.uid for l in staged_log])
|
||||
|
Loading…
Reference in New Issue
Block a user