Created
October 10, 2021 15:59
-
-
Save RyanKor/472d3369171aee617a240f9cc439ca7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TaskImage(command.Lister): | |
_description = _("Retrieve a listing of Task objects.") | |
def get_parser(self, prog_name): | |
parser = super(TaskImage, self).get_parser(prog_name) | |
parser.add_argument( | |
'--sort-key', | |
metavar="<key>[:<direction>]", | |
default='name:asc', | |
help=_("Sort output by selected keys and directions(asc or desc) " | |
"(default: name:asc), multiple keys and directions can be " | |
"specified separated by comma"), | |
) | |
parser.add_argument( | |
"--page-size", | |
metavar="<size>", | |
help=argparse.SUPPRESS, | |
) | |
parser.add_argument( | |
'--type', | |
metavar='<type>', | |
choices=[ | |
'import', 'export', 'clone' | |
], | |
help=_('Filter tasks by type'), | |
) | |
parser.add_argument( | |
'--status', | |
metavar='<status>', | |
choices=[ | |
"pending", "processing", "success", "failure" | |
], | |
default=None, | |
help=_("Filter tasks based on status.") | |
) | |
return parser | |
def take_action(self, parsed_args): | |
image_client = self.app.client_manager.image | |
columns = ( | |
"id", | |
"type", | |
"status", | |
"owner_id" | |
) | |
column_headers = ( | |
"ID", | |
"Type", | |
"Status", | |
"Owner" | |
) | |
data = image_client.tasks() | |
return ( | |
column_headers, | |
(utils.get_item_properties( | |
s, | |
columns, | |
formatters=_formatters, | |
) for s in data) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment