#NEWLINE# @ utils . arg ( '--sort-by' , metavar = '<SORT BY FIELDS>' , help = 'Fields to sort by as a comma separated list. Valid values are id, name, type, address, created_at, updated_at. Fields may be followed by "asc" or "desc", ex "address desc", to set the direction of sorting.' ) #NEWLINE# @ utils . arg ( '--offset' , metavar = '<OFFSET LOCATION>' , help = 'The offset used to paginate the return data.' ) #NEWLINE# @ utils . arg ( '--limit' , metavar = '<RETURN LIMIT>' , help = 'The amount of data to be returned up to the API maximum limit.' ) #NEWLINE# def do_notification_list( mc , args ) : #NEWLINE# #INDENT# 'List notifications for this tenant.' #NEWLINE# fields = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if args . limit : #NEWLINE# #INDENT# fields [ 'limit' ] = args . limit #NEWLINE# #UNINDENT# if args . offset : #NEWLINE# #INDENT# fields [ 'offset' ] = args . offset #NEWLINE# #UNINDENT# if fields . sort_by : #NEWLINE# #INDENT# sort_by = args . sort_by . split ( ',' ) #NEWLINE# for field in sort_by : #NEWLINE# #INDENT# field_values = field . lower ( ) . split ( ) #NEWLINE# if ( len ( field_values ) > 2 ) : #NEWLINE# #INDENT# print ( 'Invalid sort_by value {}' . format ( field ) ) #NEWLINE# #UNINDENT# if ( field_values [ 0 ] not in allowed_notification_sort_by ) : #NEWLINE# #INDENT# print ( 'Sort-by field name {} is not in [{}]' . format ( field_values [ 0 ] , allowed_notification_sort_by ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( ( len ( field_values ) > 1 ) and ( field_values [ 1 ] not in [ 'asc' , 'desc' ] ) ) : #NEWLINE# #INDENT# print ( 'Invalid value {}, must be asc or desc' . format ( field_values [ 1 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# fields [ 'sort_by' ] = args . sort_by #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# notification = mc . notifications . list ( ** fields ) #NEWLINE# #UNINDENT# except exc . HTTPException as he : #NEWLINE# #INDENT# raise exc . CommandError ( ( 'HTTPException code=%s message=%s' % ( he . code , he . message ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if args . json : #NEWLINE# #INDENT# print ( utils . json_formatter ( notification ) ) #NEWLINE# return #NEWLINE# #UNINDENT# cols = [ 'name' , 'id' , 'type' , 'address' ] #NEWLINE# formatters = { #NEWLINE# #INDENT# 'name' : ( lambda x : x [ 'name' ] ) , #NEWLINE# 'id' : ( lambda x : x [ 'id' ] ) , #NEWLINE# 'type' : ( lambda x : x [ 'type' ] ) , #NEWLINE# 'address' : ( lambda x : x [ 'address' ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# if isinstance ( notification , list ) : #NEWLINE# #INDENT# utils . print_list ( notification , cols , formatters = formatters ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# notif_list = list ( ) #NEWLINE# notif_list . append ( notification ) #NEWLINE# utils . print_list ( notif_list , cols , formatters = formatters )