Add discard routine to system log cli and api

This commit is contained in:
Dmitry Shulyak 2015-09-28 10:40:31 +03:00
parent 6e65702d4f
commit 79e57e4c07
3 changed files with 40 additions and 0 deletions

View File

@ -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):

View File

@ -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

View File

@ -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])