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
)
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):

View File

@ -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

View File

@ -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):

View File

@ -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):