Achieve a consistent style output

When the list is empty, the different style output is being used for
the freezer action-list, backup-list, job-list, session-list and
client-list.

Achieve a consistent style output for these commands in this patch.

Change-Id: I17f65fc3a836357f2c4857b4e5f7de7c8e8fb116
Closes-Bug: #1642101
This commit is contained in:
Shangzhong Zhu 2016-11-16 09:18:24 +08:00
parent e9c591fe0f
commit 0968fdf606
4 changed files with 87 additions and 35 deletions

View File

@ -98,16 +98,31 @@ class ActionList(lister.Lister):
search=search search=search
) )
return (('Action ID', 'Name', 'Action', columns = ('Action ID', 'Name', 'Action',
'Path to Backup or Restore', 'Mode', 'Storage', 'snapshot'), 'Path to Backup or Restore', 'Mode', 'Storage', 'snapshot')
((action.get('action_id'),
action.get('freezer_action', {}).get('backup_name', ''), # Print empty table if no actions found
action.get('freezer_action', {}).get('action', 'backup'), if not actions:
action.get('freezer_action', {}).get('path_to_backup', ''), actions = [{}]
action.get('freezer_action', {}).get('mode', 'fs'), data = ((action.get('action-id', ''),
action.get('freezer_action', {}).get('storage', 'swift'), action.get('freezer_action', {}).get('backup_name', ''),
action.get('freezer_action', {}).get('snapshot', 'False') action.get('freezer_action', {}).get('action', ''),
) for action in actions)) 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): class ActionDelete(command.Command):

View File

@ -95,12 +95,26 @@ class BackupList(lister.Lister):
backups = self.app.client.backups.list(limit=parsed_args.limit, backups = self.app.client.backups.list(limit=parsed_args.limit,
offset=parsed_args.offset, offset=parsed_args.offset,
search=search) search=search)
return (('Backup UUID', 'Hostname', 'Path', 'Created at', 'Level'),
((b.get('backup_uuid'), columns = ('Backup UUID', 'Hostname', 'Path', 'Created at', 'Level')
b.get('backup_metadata', {}).get('hostname'),
b.get('backup_metadata', {}).get('path_to_backup'), # Print empty table if no backups found
datetime.datetime.fromtimestamp( if not backups:
int(b.get('backup_metadata', {}).get('time_stamp'))), backups = [{}]
b.get('backup_metadata', {}).get('curr_backup_level') data = ((b.get('backup_uuid', ''),
) for b in backups)) 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

View File

@ -117,18 +117,29 @@ class JobList(lister.Lister):
search=search search=search
) )
if not jobs: columns = ('Job ID', 'Description', '# Actions', 'Result', 'Event',
print('No jobs') 'Session ID')
return (('Job ID', 'Description', '# Actions', 'Result', 'Event', # Print empty table if no jobs found
'Session ID'), if not jobs:
((job.get('job_id'), jobs = [{}]
job.get('description'), data = ((job.get('job_id', ''),
len(job.get('job_actions', [])), job.get('description', ''),
job.get('job_schedule', {}).get('result', ''), job.get('job_actions', ''),
job.get('job_schedule', {}).get('event', ''), job.get('job_schedule', {}).get('result', ''),
job.get('session_id', '') job.get('job_schedule', {}).get('event', ''),
) for job in jobs)) 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): class JobGet(command.Command):

View File

@ -90,12 +90,24 @@ class SessionList(lister.Lister):
search=parsed_args.search search=parsed_args.search
) )
return (('Session ID', 'Description', 'Status', '# Jobs'), columns = ('Session ID', 'Description', 'Status', '# Jobs')
((session.get('session_id'),
session.get('description'), # Print empty table if no sessions found
session.get('status'), if not sessions:
len(session.get('jobs', [])), sessions = [{}]
) for session in 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): class SessionCreate(command.Command):