Merge "Fix freezer backup support"
This commit is contained in:
@@ -50,6 +50,7 @@ class FreezerCommandManager(commandmanager.CommandManager):
|
|||||||
'client-delete': clients.ClientDelete,
|
'client-delete': clients.ClientDelete,
|
||||||
'backup-list': backups.BackupList,
|
'backup-list': backups.BackupList,
|
||||||
'backup-show': backups.BackupShow,
|
'backup-show': backups.BackupShow,
|
||||||
|
'backup-delete': backups.BackupDelete,
|
||||||
'session-list': sessions.SessionList,
|
'session-list': sessions.SessionList,
|
||||||
'session-show': sessions.SessionShow,
|
'session-show': sessions.SessionShow,
|
||||||
'session-create': sessions.SessionCreate,
|
'session-create': sessions.SessionCreate,
|
||||||
|
@@ -16,6 +16,7 @@ import datetime
|
|||||||
import logging
|
import logging
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
from cliff import show
|
||||||
|
|
||||||
@@ -30,33 +31,21 @@ class BackupShow(show.ShowOne):
|
|||||||
"""Show the metadata of a single backup"""
|
"""Show the metadata of a single backup"""
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(BackupShow, self).get_parser(prog_name)
|
parser = super(BackupShow, self).get_parser(prog_name)
|
||||||
parser.add_argument(dest='backup_uuid',
|
parser.add_argument(dest='backup_id',
|
||||||
help='UUID of the backup')
|
help='ID of the backup')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
# due to the fact that a backup_id is composed of several strings
|
backup = self.app.client.backups.get(parsed_args.backup_id)
|
||||||
# some of them may include a slash "/" so it will never find the
|
|
||||||
# correct backup, so the workaround for this version is to use the
|
|
||||||
# backup_uuid as a filter for the search. this won't work when the
|
|
||||||
# user wants to delete a backup, but that functionality is yet to be
|
|
||||||
# provided by the api.
|
|
||||||
search = {"match": [{"backup_uuid": parsed_args.backup_uuid}, ], }
|
|
||||||
backup = self.app.client.backups.list(search=search)
|
|
||||||
|
|
||||||
if not backup:
|
if not backup:
|
||||||
raise exceptions.ApiClientException('Backup not found')
|
raise exceptions.ApiClientException('Backup not found')
|
||||||
|
|
||||||
backup = backup[0]
|
|
||||||
|
|
||||||
column = (
|
column = (
|
||||||
'Backup ID',
|
'Backup ID',
|
||||||
'Backup UUID',
|
|
||||||
'Metadata'
|
'Metadata'
|
||||||
)
|
)
|
||||||
data = (
|
data = (
|
||||||
backup.get('backup_id'),
|
backup.get('backup_id'),
|
||||||
backup.get('backup_uuid'),
|
|
||||||
pprint.pformat(backup.get('backup_metadata'))
|
pprint.pformat(backup.get('backup_metadata'))
|
||||||
)
|
)
|
||||||
return column, data
|
return column, data
|
||||||
@@ -96,24 +85,39 @@ class BackupList(lister.Lister):
|
|||||||
offset=parsed_args.offset,
|
offset=parsed_args.offset,
|
||||||
search=search)
|
search=search)
|
||||||
|
|
||||||
columns = ('Backup UUID', 'Hostname', 'Path', 'Created at', 'Level')
|
columns = ('Backup ID', 'Hostname', 'Path', 'Created at', 'Level')
|
||||||
|
|
||||||
# Print empty table if no backups found
|
# Print empty table if no backups found
|
||||||
if not backups:
|
if not backups:
|
||||||
backups = [{}]
|
backups = [{}]
|
||||||
data = ((b.get('backup_uuid', ''),
|
|
||||||
b.get('backup_metadata', {}).get('hostname', ''),
|
data = ((b.get('backup_id', ''),
|
||||||
b.get('backup_metadata', {}).get('path_to_backup', ''),
|
b.get('backup_metadata', {}).get('hostname', ''),
|
||||||
b.get('backup_metadata', {}).get('time_stamp', ''),
|
b.get('backup_metadata', {}).get('path_to_backup', ''),
|
||||||
b.get('backup_metadata', {}).get('curr_backup_level', '')
|
datetime.datetime.fromtimestamp(
|
||||||
) for b in backups)
|
int(b.get('backup_metadata', {}).get(
|
||||||
else:
|
'time_stamp', ''))) if b.get(
|
||||||
data = ((b.get('backup_uuid'),
|
'backup_metadata') else '',
|
||||||
b.get('backup_metadata', {}).get('hostname'),
|
b.get('backup_metadata', {}).get('curr_backup_level', '')
|
||||||
b.get('backup_metadata', {}).get('path_to_backup'),
|
) for b in backups)
|
||||||
datetime.datetime.fromtimestamp(
|
|
||||||
int(b.get('backup_metadata', {}).get('time_stamp'))),
|
|
||||||
b.get('backup_metadata', {}).get('curr_backup_level')
|
|
||||||
) for b in backups)
|
|
||||||
|
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
|
|
||||||
|
class BackupDelete(command.Command):
|
||||||
|
"""Delete a backup from the api"""
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(BackupDelete, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(dest='backup_id',
|
||||||
|
help='ID of the backup')
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
# Need to check that backup exists
|
||||||
|
backup = self.app.client.backups.get(parsed_args.backup_id)
|
||||||
|
if not backup:
|
||||||
|
logging.info("Unable to delete specified backup.")
|
||||||
|
raise exceptions.ApiClientException('Backup not found')
|
||||||
|
|
||||||
|
self.app.client.backups.delete(parsed_args.backup_id)
|
||||||
|
logging.info('Backup {0} deleted'.format(parsed_args.backup_id))
|
||||||
|
Reference in New Issue
Block a user