2525LOG = logging .getLogger (__name__ )
2626
2727
28+ def _format_limit (limit ):
29+ columns = (
30+ "description" ,
31+ "id" ,
32+ "project_id" ,
33+ "region_id" ,
34+ "resource_limit" ,
35+ "resource_name" ,
36+ "service_id" ,
37+ )
38+ column_headers = (
39+ "description" ,
40+ "id" ,
41+ "project_id" ,
42+ "region_id" ,
43+ "resource_limit" ,
44+ "resource_name" ,
45+ "service_id" ,
46+ )
47+ return (column_headers , utils .get_item_properties (limit , columns ))
48+
49+
2850class CreateLimit (command .ShowOne ):
2951 _description = _ ("Create a limit" )
3052
@@ -67,47 +89,33 @@ def get_parser(self, prog_name):
6789 return parser
6890
6991 def take_action (self , parsed_args ):
70- identity_client = self .app .client_manager .identity
71-
72- project = common_utils .find_project (
73- identity_client , parsed_args .project
92+ identity_client = self .app .client_manager .sdk_connection .identity
93+
94+ kwargs = {
95+ "resource_name" : parsed_args .resource_name ,
96+ "resource_limit" : parsed_args .resource_limit ,
97+ }
98+ if parsed_args .description :
99+ kwargs ["description" ] = parsed_args .description
100+
101+ # TODO(0weng): Add --project-domain option
102+ # to support filtering project domain
103+ kwargs ["project_id" ] = common_utils ._find_sdk_id (
104+ identity_client .find_project ,
105+ name_or_id = parsed_args .project ,
74106 )
75- service = common_utils .find_service (
107+ kwargs [ "service_id" ] = common_utils .find_service_sdk (
76108 identity_client , parsed_args .service
77- )
78- region = None
109+ ). id
110+
79111 if parsed_args .region :
80- if 'None' not in parsed_args .region :
81- # NOTE (vishakha): Due to bug #1799153 and for any another
82- # related case where GET resource API does not support the
83- # filter by name, osc_lib.utils.find_resource() method cannot
84- # be used because that method try to fall back to list all the
85- # resource if requested resource cannot be get via name. Which
86- # ends up with NoUniqueMatch error.
87- # So osc_lib.utils.find_resource() function cannot be used for
88- # 'regions', using common_utils.get_resource() instead.
89- region = common_utils .get_resource (
90- identity_client .regions , parsed_args .region
91- )
92- else :
93- self .log .warning (
94- _ (
95- "Passing 'None' to indicate no region is deprecated. "
96- "Instead, don't pass --region."
97- )
98- )
112+ kwargs ["region_id" ] = identity_client .get_region (
113+ parsed_args .region
114+ ).id
99115
100- limit = identity_client .limits .create (
101- project ,
102- service ,
103- parsed_args .resource_name ,
104- parsed_args .resource_limit ,
105- description = parsed_args .description ,
106- region = region ,
107- )
116+ limit = identity_client .create_limit (** kwargs )
108117
109- limit ._info .pop ('links' , None )
110- return zip (* sorted (limit ._info .items ()))
118+ return _format_limit (limit )
111119
112120
113121class ListLimit (command .Lister ):
@@ -139,47 +147,31 @@ def get_parser(self, prog_name):
139147 return parser
140148
141149 def take_action (self , parsed_args ):
142- identity_client = self .app .client_manager .identity
150+ identity_client = self .app .client_manager .sdk_connection . identity
143151
144- service = None
152+ kwargs = {}
145153 if parsed_args .service :
146- service = common_utils .find_service (
154+ kwargs [ "service_id" ] = common_utils .find_service_sdk (
147155 identity_client , parsed_args .service
148156 )
149- region = None
157+
150158 if parsed_args .region :
151- if 'None' not in parsed_args .region :
152- # NOTE (vishakha): Due to bug #1799153 and for any another
153- # related case where GET resource API does not support the
154- # filter by name, osc_lib.utils.find_resource() method cannot
155- # be used because that method try to fall back to list all the
156- # resource if requested resource cannot be get via name. Which
157- # ends up with NoUniqueMatch error.
158- # So osc_lib.utils.find_resource() function cannot be used for
159- # 'regions', using common_utils.get_resource() instead.
160- region = common_utils .get_resource (
161- identity_client .regions , parsed_args .region
162- )
163- else :
164- self .log .warning (
165- _ (
166- "Passing 'None' to indicate no region is deprecated. "
167- "Instead, don't pass --region."
168- )
169- )
159+ kwargs ["region_id" ] = identity_client .get_region (
160+ parsed_args .region
161+ ).id
170162
171- project = None
163+ # TODO(0weng): Add --project-domain option
164+ # to support filtering project domain
172165 if parsed_args .project :
173- project = utils .find_resource (
174- identity_client .projects , parsed_args .project
166+ kwargs ["project_id" ] = common_utils ._find_sdk_id (
167+ identity_client .find_project ,
168+ name_or_id = parsed_args .project ,
175169 )
176170
177- limits = identity_client .limits .list (
178- service = service ,
179- resource_name = parsed_args .resource_name ,
180- region = region ,
181- project = project ,
182- )
171+ if parsed_args .resource_name :
172+ kwargs ["resource_name" ] = parsed_args .resource_name
173+
174+ limits = identity_client .limits (** kwargs )
183175
184176 columns = (
185177 'ID' ,
@@ -209,10 +201,9 @@ def get_parser(self, prog_name):
209201 return parser
210202
211203 def take_action (self , parsed_args ):
212- identity_client = self .app .client_manager .identity
213- limit = identity_client .limits .get (parsed_args .limit_id )
214- limit ._info .pop ('links' , None )
215- return zip (* sorted (limit ._info .items ()))
204+ identity_client = self .app .client_manager .sdk_connection .identity
205+ limit = identity_client .get_limit (parsed_args .limit_id )
206+ return _format_limit (limit )
216207
217208
218209class SetLimit (command .ShowOne ):
@@ -240,17 +231,16 @@ def get_parser(self, prog_name):
240231 return parser
241232
242233 def take_action (self , parsed_args ):
243- identity_client = self .app .client_manager .identity
244-
245- limit = identity_client .limits .update (
246- parsed_args .limit_id ,
247- description = parsed_args .description ,
248- resource_limit = parsed_args .resource_limit ,
249- )
234+ identity_client = self .app .client_manager .sdk_connection .identity
250235
251- limit ._info .pop ('links' , None )
236+ kwargs = {}
237+ if parsed_args .description :
238+ kwargs ["description" ] = parsed_args .description
239+ if parsed_args .resource_limit :
240+ kwargs ["resource_limit" ] = parsed_args .resource_limit
241+ limit = identity_client .update_limit (parsed_args .limit_id , ** kwargs )
252242
253- return zip ( * sorted ( limit . _info . items ()) )
243+ return _format_limit ( limit )
254244
255245
256246class DeleteLimit (command .Command ):
@@ -262,17 +252,20 @@ def get_parser(self, prog_name):
262252 'limit_id' ,
263253 metavar = '<limit-id>' ,
264254 nargs = "+" ,
265- help = _ ('Limit to delete (ID)' ),
255+ help = _ (
256+ 'Limit to delete (ID) '
257+ '(repeat option to remove multiple limits)'
258+ ),
266259 )
267260 return parser
268261
269262 def take_action (self , parsed_args ):
270- identity_client = self .app .client_manager .identity
263+ identity_client = self .app .client_manager .sdk_connection . identity
271264
272265 errors = 0
273266 for limit_id in parsed_args .limit_id :
274267 try :
275- identity_client .limits . delete (limit_id )
268+ identity_client .delete_limit (limit_id )
276269 except Exception as e :
277270 errors += 1
278271 LOG .error (
0 commit comments