@@ -2157,32 +2157,35 @@ async def destroy_unit(self, unit_id, destroy_storage=False, dry_run=False, forc
21572157 """Destroy units by name.
21582158
21592159 """
2160- connection = self .connection ()
2161- app_facade = client .ApplicationFacade .from_connection (connection )
2162-
2163- # Get the corresponding unit tag
2164- unit_tag = tag .unit (unit_id )
2165- if unit_tag is None :
2166- log .error ("Error converting %s to a valid unit tag" , unit_id )
2167- return JujuUnitError ("Error converting %s to a valid unit tag" , unit_id )
2168-
2169- log .debug (
2170- 'Destroying unit %s' , unit_id )
2171-
2172- return await app_facade .DestroyUnit (units = [{
2173- 'unit-tag' : unit_tag ,
2174- 'destroy-storage' : destroy_storage ,
2175- 'force' : force ,
2176- 'max-wait' : max_wait ,
2177- 'dry-run' : dry_run ,
2178- }])
2160+ return await self .destroy_units (unit_id ,
2161+ destroy_storage = destroy_storage ,
2162+ dry_run = dry_run ,
2163+ force = force ,
2164+ max_wait = max_wait
2165+ )
21792166
21802167 async def destroy_units (self , * unit_names , destroy_storage = False , dry_run = False , force = False , max_wait = None ):
21812168 """Destroy several units at once.
21822169
21832170 """
2184- for u in unit_names :
2185- await self .destroy_unit (u , destroy_storage , dry_run , force , max_wait )
2171+ connection = self .connection ()
2172+ app_facade = client .ApplicationFacade .from_connection (connection )
2173+
2174+ units_to_destroy = []
2175+ for unit_id in unit_names :
2176+ unit_tag = tag .unit (unit_id )
2177+ if unit_tag is None :
2178+ log .error ("Error converting %s to a valid unit tag" , unit_id )
2179+ raise JujuUnitError ("Error converting %s to a valid unit tag" , unit_id )
2180+ units_to_destroy .append ({
2181+ 'unit-tag' : unit_tag ,
2182+ 'destroy-storage' : destroy_storage ,
2183+ 'force' : force ,
2184+ 'max-wait' : max_wait ,
2185+ 'dry-run' : dry_run ,
2186+ })
2187+ log .debug ('Destroying units %s' , unit_names )
2188+ return await app_facade .DestroyUnit (units = units_to_destroy )
21862189
21872190 def download_backup (self , archive_id , target_filename = None ):
21882191 """Download a backup archive file.
0 commit comments