Be able to list only pending or done migrations

This commit is contained in:
Alexandre Aubin 2018-02-03 03:27:13 +01:00
parent c568b04459
commit c266147fd9
3 changed files with 32 additions and 12 deletions

View file

@ -1575,6 +1575,13 @@ tools:
list: list:
action_help: List migrations action_help: List migrations
api: GET /migrations api: GET /migrations
arguments:
--pending:
help: list only pending migrations
action: store_true
--done:
help: list only migrations already performed
action: store_true
### tools_migrations_migrate() ### tools_migrations_migrate()
migrate: migrate:

View file

@ -230,6 +230,7 @@
"migrations_current_target": "Migration target is {}", "migrations_current_target": "Migration target is {}",
"migrations_error_failed_to_load_migration": "ERROR: failed to load migration {migration_id}", "migrations_error_failed_to_load_migration": "ERROR: failed to load migration {migration_id}",
"migrations_forward": "Migrating forward", "migrations_forward": "Migrating forward",
"migrations_list_conflict_pending_done": "You cannot use both --previous and --done at the same time.",
"migrations_loading_migration": "Loading migration {migration_id}...", "migrations_loading_migration": "Loading migration {migration_id}...",
"migrations_migration_has_failed": "Migration {number} {name} has failed with exception {exception}, aborting", "migrations_migration_has_failed": "Migration {number} {name} has failed with exception {exception}, aborting",
"migrations_no_migrations_to_run": "No migrations to run", "migrations_no_migrations_to_run": "No migrations to run",

View file

@ -733,24 +733,36 @@ def tools_reboot(force=False):
subprocess.check_call(['systemctl', 'reboot']) subprocess.check_call(['systemctl', 'reboot'])
def tools_migrations_list(): def tools_migrations_list(pending=False, done=False):
""" """
List existing migrations List existing migrations
""" """
migrations = {"migrations": []} # Check for option conflict
if pending and done:
raise MoulinetteError(errno.EINVAL, m18n.n("migrations_list_conflict_pending_done"))
for migration in _get_migrations_list(): # Get all migrations
migrations["migrations"].append({ migrations = _get_migrations_list()
"id": migration.id,
"number": migration.number,
"name": migration.name,
"mode": migration.mode,
"description": migration.description,
"disclaimer": migration.disclaimer
})
return migrations # If asked, filter pending or done migrations
if pending or done:
last_migration = tools_migrations_state()["last_run_migration"]
last_migration = last_migration["number"] if last_migration else -1
if done:
migrations = [m for m in migrations if m.number <= last_migration]
if pending:
migrations = [m for m in migrations if m.number > last_migration]
# Reduce to dictionnaries
migrations = [{ "id": migration.id,
"number": migration.number,
"name": migration.name,
"mode": migration.mode,
"description": migration.description,
"disclaimer": migration.disclaimer } for migration in migrations ]
return {"migrations": migrations}
def tools_migrations_migrate(target=None, skip=False, auto=False): def tools_migrations_migrate(target=None, skip=False, auto=False):