Added purge script for soft deleted objects
This patchset implements the purge script as specified in its related blueprint: - The '--age-in-days' option allows to specify the number of days before expiry - The '--max-number' option allows us to specify a limit on the number of objects to delete - The '--audit-template' option allows you to only delete objects related to the specified audit template UUID or name - The '--dry-run' option to go through the purge procedure without actually deleting anything - The '--exclude-orphans' option which allows you to exclude from the purge any object that does not have a parent (i.e. and audit without a related audit template) A prompt has been added to also propose to narrow down the number of deletions to be below the specified limit. Change-Id: I3ce83ab95277c109df67a6b5b920a878f6e59d3f Implements: blueprint db-purge-engine
This commit is contained in:
@@ -25,7 +25,7 @@ from oslo_config import cfg
|
||||
|
||||
from watcher.common import service
|
||||
from watcher.db import migration
|
||||
|
||||
from watcher.db import purge
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
@@ -56,6 +56,12 @@ class DBCommand(object):
|
||||
def create_schema():
|
||||
migration.create_schema()
|
||||
|
||||
@staticmethod
|
||||
def purge():
|
||||
purge.purge(CONF.command.age_in_days, CONF.command.max_number,
|
||||
CONF.command.audit_template, CONF.command.exclude_orphans,
|
||||
CONF.command.dry_run)
|
||||
|
||||
|
||||
def add_command_parsers(subparsers):
|
||||
parser = subparsers.add_parser(
|
||||
@@ -96,6 +102,33 @@ def add_command_parsers(subparsers):
|
||||
help="Create the database schema.")
|
||||
parser.set_defaults(func=DBCommand.create_schema)
|
||||
|
||||
parser = subparsers.add_parser(
|
||||
'purge',
|
||||
help="Purge the database.")
|
||||
parser.add_argument('-d', '--age-in-days',
|
||||
help="Number of days since deletion (from today) "
|
||||
"to exclude from the purge. If None, everything "
|
||||
"will be purged.",
|
||||
type=int, default=None, nargs='?')
|
||||
parser.add_argument('-n', '--max-number',
|
||||
help="Max number of objects expected to be deleted. "
|
||||
"Prevents the deletion if exceeded. No limit if "
|
||||
"set to None.",
|
||||
type=int, default=None, nargs='?')
|
||||
parser.add_argument('-t', '--audit-template',
|
||||
help="UUID or name of the audit template to purge.",
|
||||
type=str, default=None, nargs='?')
|
||||
parser.add_argument('-e', '--exclude-orphans', action='store_true',
|
||||
help="Flag to indicate whether or not you want to "
|
||||
"exclude orphans from deletion (default: False).",
|
||||
default=False)
|
||||
parser.add_argument('--dry-run', action='store_true',
|
||||
help="Flag to indicate whether or not you want to "
|
||||
"perform a dry run (no deletion).",
|
||||
default=False)
|
||||
|
||||
parser.set_defaults(func=DBCommand.purge)
|
||||
|
||||
|
||||
command_opt = cfg.SubCommandOpt('command',
|
||||
title='Command',
|
||||
@@ -114,6 +147,7 @@ def main():
|
||||
valid_commands = set([
|
||||
'upgrade', 'downgrade', 'revision',
|
||||
'version', 'stamp', 'create_schema',
|
||||
'purge',
|
||||
])
|
||||
if not set(sys.argv).intersection(valid_commands):
|
||||
sys.argv.append('upgrade')
|
||||
|
||||
Reference in New Issue
Block a user