@@ -833,6 +833,8 @@ def take_action(self, parsed_args):
833833 'OS-EXT-STS:task_state' ,
834834 'OS-EXT-STS:power_state' ,
835835 'Networks' ,
836+ 'Image Name' ,
837+ 'Image ID' ,
836838 'OS-EXT-AZ:availability_zone' ,
837839 'OS-EXT-SRV-ATTR:host' ,
838840 'Metadata' ,
@@ -844,6 +846,8 @@ def take_action(self, parsed_args):
844846 'Task State' ,
845847 'Power State' ,
846848 'Networks' ,
849+ 'Image Name' ,
850+ 'Image ID' ,
847851 'Availability Zone' ,
848852 'Host' ,
849853 'Properties' ,
@@ -860,12 +864,14 @@ def take_action(self, parsed_args):
860864 'Name' ,
861865 'Status' ,
862866 'Networks' ,
867+ 'Image Name' ,
863868 )
864869 column_headers = (
865870 'ID' ,
866871 'Name' ,
867872 'Status' ,
868873 'Networks' ,
874+ 'Image Name' ,
869875 )
870876 mixed_case_fields = []
871877
@@ -877,17 +883,42 @@ def take_action(self, parsed_args):
877883 data = compute_client .servers .list (search_opts = search_opts ,
878884 marker = marker_id ,
879885 limit = parsed_args .limit )
880- return (column_headers ,
881- (utils .get_item_properties (
882- s , columns ,
883- mixed_case_fields = mixed_case_fields ,
884- formatters = {
885- 'OS-EXT-STS:power_state' :
886- _format_servers_list_power_state ,
887- 'Networks' : _format_servers_list_networks ,
888- 'Metadata' : utils .format_dict ,
889- },
890- ) for s in data ))
886+
887+ images = {}
888+ # Create a dict that maps image_id to image object.
889+ # Needed so that we can display the "Image Name" column.
890+ # "Image Name" is not crucial, so we swallow any exceptions.
891+ try :
892+ images_list = self .app .client_manager .image .images .list ()
893+ for i in images_list :
894+ images [i .id ] = i
895+ except Exception :
896+ pass
897+
898+ # Populate image_name and image_id attributes of server objects
899+ # so that we can display "Image Name" and "Image ID" columns.
900+ for s in data :
901+ if 'id' in s .image :
902+ image = images .get (s .image ['id' ])
903+ if image :
904+ s .image_name = image .name
905+ s .image_id = s .image ['id' ]
906+ else :
907+ s .image_name = ''
908+ s .image_id = ''
909+
910+ table = (column_headers ,
911+ (utils .get_item_properties (
912+ s , columns ,
913+ mixed_case_fields = mixed_case_fields ,
914+ formatters = {
915+ 'OS-EXT-STS:power_state' :
916+ _format_servers_list_power_state ,
917+ 'Networks' : _format_servers_list_networks ,
918+ 'Metadata' : utils .format_dict ,
919+ },
920+ ) for s in data ))
921+ return table
891922
892923
893924class LockServer (command .Command ):
0 commit comments