File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -917,6 +917,8 @@ def take_action(self, parsed_args):
917917 'Networks' ,
918918 'Image Name' ,
919919 'Image ID' ,
920+ 'Flavor Name' ,
921+ 'Flavor ID' ,
920922 'OS-EXT-AZ:availability_zone' ,
921923 'OS-EXT-SRV-ATTR:host' ,
922924 'Metadata' ,
@@ -930,6 +932,8 @@ def take_action(self, parsed_args):
930932 'Networks' ,
931933 'Image Name' ,
932934 'Image ID' ,
935+ 'Flavor Name' ,
936+ 'Flavor ID' ,
933937 'Availability Zone' ,
934938 'Host' ,
935939 'Properties' ,
@@ -977,8 +981,19 @@ def take_action(self, parsed_args):
977981 except Exception :
978982 pass
979983
980- # Populate image_name and image_id attributes of server objects
981- # so that we can display "Image Name" and "Image ID" columns.
984+ flavors = {}
985+ # Create a dict that maps flavor_id to flavor object.
986+ # Needed so that we can display the "Flavor Name" column.
987+ # "Flavor Name" is not crucial, so we swallow any exceptions.
988+ try :
989+ flavors_list = compute_client .flavors .list ()
990+ for i in flavors_list :
991+ flavors [i .id ] = i
992+ except Exception :
993+ pass
994+
995+ # Populate image_name, image_id, flavor_name and flavor_id attributes
996+ # of server objects so that we can display those columns.
982997 for s in data :
983998 if 'id' in s .image :
984999 image = images .get (s .image ['id' ])
@@ -988,6 +1003,14 @@ def take_action(self, parsed_args):
9881003 else :
9891004 s .image_name = ''
9901005 s .image_id = ''
1006+ if 'id' in s .flavor :
1007+ flavor = flavors .get (s .flavor ['id' ])
1008+ if flavor :
1009+ s .flavor_name = flavor .name
1010+ s .flavor_id = s .flavor ['id' ]
1011+ else :
1012+ s .flavor_name = ''
1013+ s .flavor_id = ''
9911014
9921015 table = (column_headers ,
9931016 (utils .get_item_properties (
Original file line number Diff line number Diff line change @@ -957,6 +957,8 @@ class TestServerList(TestServer):
957957 'Networks' ,
958958 'Image Name' ,
959959 'Image ID' ,
960+ 'Flavor Name' ,
961+ 'Flavor ID' ,
960962 'Availability Zone' ,
961963 'Host' ,
962964 'Properties' ,
@@ -1027,6 +1029,12 @@ def setUp(self):
10271029 for s in self .servers
10281030 ]
10291031
1032+ Flavor = collections .namedtuple ('Flavor' , 'id name' )
1033+ self .flavors_mock .list .return_value = [
1034+ Flavor (id = s .flavor ['id' ], name = self .flavor .name )
1035+ for s in self .servers
1036+ ]
1037+
10301038 for s in self .servers :
10311039 self .data .append ((
10321040 s .id ,
@@ -1046,6 +1054,8 @@ def setUp(self):
10461054 server ._format_servers_list_networks (s .networks ),
10471055 self .image .name ,
10481056 s .image ['id' ],
1057+ self .flavor .name ,
1058+ s .flavor ['id' ],
10491059 getattr (s , 'OS-EXT-AZ:availability_zone' ),
10501060 getattr (s , 'OS-EXT-SRV-ATTR:host' ),
10511061 s .Metadata ,
You can’t perform that action at this time.
0 commit comments