File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- __version__ = "2.0 "
1+ __version__ = "2.1 "
Original file line number Diff line number Diff line change @@ -97,11 +97,20 @@ def get_parser(self, prog_name):
9797 default = False ,
9898 action = 'store_true' ,
9999 )
100+ optional .add_argument ('-u' ,
101+ '--user' ,
102+ metavar = 'USER_ID' ,
103+ dest = 'user_id' ,
104+ required = False ,
105+ default = None ,
106+ )
100107 return parser
101108
102109 @handle_http_error
103110 def take_action (self , parsed_args ):
104- result = self .app .context ["client" ].keypairs .list ()
111+ result = self .app .context ["client" ].keypairs .list (
112+ user_id = parsed_args .user_id
113+ )
105114 if parsed_args .show_key or parsed_args .show_short_key :
106115 self .columns .append ("public_key" )
107116 if parsed_args .show_short_key and not parsed_args .show_key :
Original file line number Diff line number Diff line change @@ -19,14 +19,18 @@ class KeyPairManager(base.Manager):
1919 """Manager class for manipulating keypairs."""
2020 resource_class = KeyPair
2121
22- def list (self , return_raw = False ):
22+ def list (self , return_raw = False , user_id = None ):
2323 """Get list of all keypairs for domain.
2424
2525 :param return_raw: flag to force returning raw JSON instead of
2626 Python object of self.resource_class
27+ :param string user_id: optional filter of keypairs by User id.
2728 :rtype: list of :class:`Keypair`
2829 """
29- return self ._list ('/keypairs' , 'keypairs' , return_raw = return_raw )
30+ url = '/keypairs'
31+ if user_id :
32+ url = url + '?user_id={}' .format (user_id )
33+ return self ._list (url , 'keypairs' , return_raw = return_raw )
3034
3135 @process_pair_params
3236 def add (self , keypair , return_raw = False ):
Original file line number Diff line number Diff line change @@ -14,6 +14,17 @@ def test_keypair_list():
1414 assert len (output ) == 2
1515
1616
17+ def test_keypair_list_filter ():
18+ client = make_client (return_value = answers .KEYPAIR_LIST )
19+
20+ args = ["keypair list" ,
21+ "--user" , "88ad5569d8c64f828ac3d2efa4e552dd" ]
22+
23+ output = run_cmd (args , client , json_output = True )
24+
25+ assert len (output ) == 2
26+
27+
1728def test_keypair_add ():
1829 client = make_client (return_value = answers .KEYPAIR_ADD )
1930
You can’t perform that action at this time.
0 commit comments