1212
1313import logging
1414
15- from cinderclient import api_versions
15+ from openstack import utils as sdk_utils
1616from osc_lib .cli import format_columns
1717from osc_lib .command import command
1818from osc_lib import exceptions
@@ -170,18 +170,18 @@ def get_parser(self, prog_name):
170170 return parser
171171
172172 def take_action (self , parsed_args ):
173- volume_client = self .app .client_manager .volume
174- compute_client = self .app .client_manager .compute
173+ volume_client = self .app .client_manager .sdk_connection . volume
174+ compute_client = self .app .client_manager .sdk_connection . compute
175175
176- if volume_client . api_version < api_versions . APIVersion ( '3.27' ):
176+ if not sdk_utils . supports_microversion ( volume_client , '3.27' ):
177177 msg = _ (
178178 "--os-volume-api-version 3.27 or greater is required to "
179179 "support the 'volume attachment create' command"
180180 )
181181 raise exceptions .CommandError (msg )
182182
183183 if parsed_args .mode :
184- if volume_client . api_version < api_versions . APIVersion ( '3.54' ):
184+ if not sdk_utils . supports_microversion ( volume_client , '3.54' ):
185185 msg = _ (
186186 "--os-volume-api-version 3.54 or greater is required to "
187187 "support the '--mode' option"
@@ -218,17 +218,18 @@ def take_action(self, parsed_args):
218218 )
219219 raise exceptions .CommandError (msg )
220220
221- volume = utils .find_resource (
222- volume_client .volumes ,
223- parsed_args .volume ,
221+ volume = volume_client .find_volume (
222+ parsed_args .volume , ignore_missing = False
224223 )
225- server = utils .find_resource (
226- compute_client .servers ,
227- parsed_args .server ,
224+ server = compute_client .find_server (
225+ parsed_args .server , ignore_missing = False
228226 )
229227
230- attachment = volume_client .attachments .create (
231- volume .id , connector , server .id , parsed_args .mode
228+ attachment = volume_client .create_attachment (
229+ volume .id ,
230+ connector = connector ,
231+ instance = server .id ,
232+ mode = parsed_args .mode ,
232233 )
233234
234235 return _format_attachment (attachment )
@@ -256,16 +257,16 @@ def get_parser(self, prog_name):
256257 return parser
257258
258259 def take_action (self , parsed_args ):
259- volume_client = self .app .client_manager .volume
260+ volume_client = self .app .client_manager .sdk_connection . volume
260261
261- if volume_client . api_version < api_versions . APIVersion ( '3.27' ):
262+ if not sdk_utils . supports_microversion ( volume_client , '3.27' ):
262263 msg = _ (
263264 "--os-volume-api-version 3.27 or greater is required to "
264265 "support the 'volume attachment delete' command"
265266 )
266267 raise exceptions .CommandError (msg )
267268
268- volume_client .attachments . delete (parsed_args .attachment )
269+ volume_client .delete_attachment (parsed_args .attachment )
269270
270271
271272class SetVolumeAttachment (command .ShowOne ):
@@ -330,9 +331,9 @@ def get_parser(self, prog_name):
330331 return parser
331332
332333 def take_action (self , parsed_args ):
333- volume_client = self .app .client_manager .volume
334+ volume_client = self .app .client_manager .sdk_connection . volume
334335
335- if volume_client . api_version < api_versions . APIVersion ( '3.27' ):
336+ if not sdk_utils . supports_microversion ( volume_client , '3.27' ):
336337 msg = _ (
337338 "--os-volume-api-version 3.27 or greater is required to "
338339 "support the 'volume attachment set' command"
@@ -349,8 +350,9 @@ def take_action(self, parsed_args):
349350 'mountpoint' : parsed_args .mountpoint ,
350351 }
351352
352- attachment = volume_client .attachments .update (
353- parsed_args .attachment , connector
353+ attachment = volume_client .update_attachment (
354+ parsed_args .attachment ,
355+ connector = connector ,
354356 )
355357
356358 return _format_attachment (attachment )
@@ -369,16 +371,16 @@ def get_parser(self, prog_name):
369371 return parser
370372
371373 def take_action (self , parsed_args ):
372- volume_client = self .app .client_manager .volume
374+ volume_client = self .app .client_manager .sdk_connection . volume
373375
374- if volume_client . api_version < api_versions . APIVersion ( '3.44' ):
376+ if not sdk_utils . supports_microversion ( volume_client , '3.44' ):
375377 msg = _ (
376378 "--os-volume-api-version 3.44 or greater is required to "
377379 "support the 'volume attachment complete' command"
378380 )
379381 raise exceptions .CommandError (msg )
380382
381- volume_client .attachments . complete (parsed_args .attachment )
383+ volume_client .complete_attachment (parsed_args .attachment )
382384
383385
384386class ListVolumeAttachment (command .Lister ):
@@ -429,10 +431,10 @@ def get_parser(self, prog_name):
429431 return parser
430432
431433 def take_action (self , parsed_args ):
432- volume_client = self .app .client_manager .volume
434+ volume_client = self .app .client_manager .sdk_connection . volume
433435 identity_client = self .app .client_manager .identity
434436
435- if volume_client . api_version < api_versions . APIVersion ( '3.27' ):
437+ if not sdk_utils . supports_microversion ( volume_client , '3.27' ):
436438 msg = _ (
437439 "--os-volume-api-version 3.27 or greater is required to "
438440 "support the 'volume attachment list' command"
@@ -458,7 +460,7 @@ def take_action(self, parsed_args):
458460 # search_opts.update(shell_utils.extract_filters(AppendFilters.filters))
459461
460462 # TODO(stephenfin): Implement sorting
461- attachments = volume_client .attachments . list (
463+ attachments = volume_client .attachments (
462464 search_opts = search_opts ,
463465 marker = parsed_args .marker ,
464466 limit = parsed_args .limit ,
@@ -496,15 +498,15 @@ def get_parser(self, prog_name):
496498 return parser
497499
498500 def take_action (self , parsed_args ):
499- volume_client = self .app .client_manager .volume
501+ volume_client = self .app .client_manager .sdk_connection . volume
500502
501- if volume_client . api_version < api_versions . APIVersion ( '3.27' ):
503+ if not sdk_utils . supports_microversion ( volume_client , '3.27' ):
502504 msg = _ (
503505 "--os-volume-api-version 3.27 or greater is required to "
504506 "support the 'volume attachment show' command"
505507 )
506508 raise exceptions .CommandError (msg )
507509
508- attachment = volume_client .attachments . show (parsed_args .attachment )
510+ attachment = volume_client .get_attachment (parsed_args .attachment )
509511
510512 return _format_attachment (attachment )
0 commit comments