diff --git a/freezerclient/v1/actions.py b/freezerclient/v1/actions.py index 3573d16..5b149b0 100644 --- a/freezerclient/v1/actions.py +++ b/freezerclient/v1/actions.py @@ -98,16 +98,31 @@ class ActionList(lister.Lister): search=search ) - return (('Action ID', 'Name', 'Action', - 'Path to Backup or Restore', 'Mode', 'Storage', 'snapshot'), - ((action.get('action_id'), - action.get('freezer_action', {}).get('backup_name', ''), - action.get('freezer_action', {}).get('action', 'backup'), - action.get('freezer_action', {}).get('path_to_backup', ''), - action.get('freezer_action', {}).get('mode', 'fs'), - action.get('freezer_action', {}).get('storage', 'swift'), - action.get('freezer_action', {}).get('snapshot', 'False') - ) for action in actions)) + columns = ('Action ID', 'Name', 'Action', + 'Path to Backup or Restore', 'Mode', 'Storage', 'snapshot') + + # Print empty table if no actions found + if not actions: + actions = [{}] + data = ((action.get('action-id', ''), + action.get('freezer_action', {}).get('backup_name', ''), + action.get('freezer_action', {}).get('action', ''), + action.get('freezer_action', {}).get('path_to_backup', ''), + action.get('freezer_action', {}).get('mode', ''), + action.get('freezer_action', {}).get('storage', ''), + action.get('freezer_action', {}).get('snapshot', '') + ) for action in actions) + else: + data = ((action.get('action_id'), + action.get('freezer_action', {}).get('backup_name', ''), + action.get('freezer_action', {}).get('action', 'backup'), + action.get('freezer_action', {}).get('path_to_backup', ''), + action.get('freezer_action', {}).get('mode', 'fs'), + action.get('freezer_action', {}).get('storage', 'swift'), + action.get('freezer_action', {}).get('snapshot', 'False') + ) for action in actions) + + return columns, data class ActionDelete(command.Command): diff --git a/freezerclient/v1/backups.py b/freezerclient/v1/backups.py index 7109780..3c82b62 100644 --- a/freezerclient/v1/backups.py +++ b/freezerclient/v1/backups.py @@ -95,12 +95,26 @@ class BackupList(lister.Lister): backups = self.app.client.backups.list(limit=parsed_args.limit, offset=parsed_args.offset, search=search) - return (('Backup UUID', 'Hostname', 'Path', 'Created at', 'Level'), - ((b.get('backup_uuid'), - b.get('backup_metadata', {}).get('hostname'), - b.get('backup_metadata', {}).get('path_to_backup'), - datetime.datetime.fromtimestamp( - int(b.get('backup_metadata', {}).get('time_stamp'))), - b.get('backup_metadata', {}).get('curr_backup_level') - ) for b in backups)) + + columns = ('Backup UUID', 'Hostname', 'Path', 'Created at', 'Level') + + # Print empty table if no backups found + if not backups: + backups = [{}] + data = ((b.get('backup_uuid', ''), + b.get('backup_metadata', {}).get('hostname', ''), + b.get('backup_metadata', {}).get('path_to_backup', ''), + b.get('backup_metadata', {}).get('time_stamp', ''), + b.get('backup_metadata', {}).get('curr_backup_level', '') + ) for b in backups) + else: + data = ((b.get('backup_uuid'), + b.get('backup_metadata', {}).get('hostname'), + b.get('backup_metadata', {}).get('path_to_backup'), + 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 diff --git a/freezerclient/v1/jobs.py b/freezerclient/v1/jobs.py index 4547ac5..0737d7f 100644 --- a/freezerclient/v1/jobs.py +++ b/freezerclient/v1/jobs.py @@ -117,18 +117,29 @@ class JobList(lister.Lister): search=search ) - if not jobs: - print('No jobs') + columns = ('Job ID', 'Description', '# Actions', 'Result', 'Event', + 'Session ID') - return (('Job ID', 'Description', '# Actions', 'Result', 'Event', - 'Session ID'), - ((job.get('job_id'), - job.get('description'), - len(job.get('job_actions', [])), - job.get('job_schedule', {}).get('result', ''), - job.get('job_schedule', {}).get('event', ''), - job.get('session_id', '') - ) for job in jobs)) + # Print empty table if no jobs found + if not jobs: + jobs = [{}] + data = ((job.get('job_id', ''), + job.get('description', ''), + job.get('job_actions', ''), + job.get('job_schedule', {}).get('result', ''), + job.get('job_schedule', {}).get('event', ''), + job.get('session_id', '') + ) for job in jobs) + else: + data = ((job.get('job_id'), + job.get('description'), + len(job.get('job_actions', [])), + job.get('job_schedule', {}).get('result', ''), + job.get('job_schedule', {}).get('event', ''), + job.get('session_id', '') + ) for job in jobs) + + return columns, data class JobGet(command.Command): diff --git a/freezerclient/v1/sessions.py b/freezerclient/v1/sessions.py index 0ab6efe..a4634b8 100644 --- a/freezerclient/v1/sessions.py +++ b/freezerclient/v1/sessions.py @@ -90,12 +90,24 @@ class SessionList(lister.Lister): search=parsed_args.search ) - return (('Session ID', 'Description', 'Status', '# Jobs'), - ((session.get('session_id'), - session.get('description'), - session.get('status'), - len(session.get('jobs', [])), - ) for session in sessions)) + columns = ('Session ID', 'Description', 'Status', '# Jobs') + + # Print empty table if no sessions found + if not sessions: + sessions = [{}] + data = ((session.get('session_id', ''), + session.get('description', ''), + session.get('status', ''), + session.get('jobs', ''), + ) for session in sessions) + else: + data = ((session.get('session_id'), + session.get('description'), + session.get('status'), + len(session.get('jobs', [])), + ) for session in sessions) + + return columns, data class SessionCreate(command.Command):