@@ -194,7 +194,9 @@ def list(self, image_id, region_id, zone_id, limit: int, marker: uuid.UUID):
194
194
@cherrypy .tools .resource_object (id_param = "instance_id" , cls = Instance )
195
195
@cherrypy .tools .enforce_policy (policy_name = "instances:delete" )
196
196
def delete (self , instance_id : uuid .UUID ):
197
- cherrypy .response .status = 202
197
+ cherrypy .response .status = 204
198
+ # Fix for https://github.com/cherrypy/cherrypy/issues/1657
199
+ del cherrypy .response .headers ['Content-Type' ]
198
200
with cherrypy .request .db_session () as session :
199
201
instance : Instance = session .merge (cherrypy .request .resource_object , load = False )
200
202
@@ -302,8 +304,13 @@ def action_image(self, instance_id: uuid.UUID):
302
304
raise cherrypy .HTTPError (409 , "Can only image an instance in the following state: %s" %
303
305
InstanceState .STOPPED .value )
304
306
305
- region = session .query (Region ).join (Zone , Region .id == Zone .region_id ).filter (
306
- Zone .id == instance .zone_id ).one ()
307
+ region = session .query (Region ).filter (Region .id == instance .region_id ).one ()
308
+
309
+ image = session .query (Image ).filter (Image .project_id == instance .project_id ).filter (
310
+ Image .name == request .name ).filter (Image .region_id == region .id ).first ()
311
+
312
+ if image is not None :
313
+ raise cherrypy .HTTPError (409 , 'An image with the requested name already exists.' )
307
314
308
315
instance .state = InstanceState .IMAGING
309
316
@@ -317,12 +324,10 @@ def action_image(self, instance_id: uuid.UUID):
317
324
session .add (image )
318
325
session .flush ()
319
326
320
- # Delete vm without actually deleting the backing
321
- create_task (session , instance , delete_instance , instance_id = instance .id , delete_backing = False )
322
-
323
- # Convert the vm to a template
324
- create_task (session , image , convert_vm , image_id = image .id , from_instance = True )
327
+ # Clone the vm to a template
328
+ create_task (session , image , convert_vm , image_id = image .id , instance_id = instance .id )
325
329
330
+ instance .current_task_id = image .current_task_id
326
331
session .commit ()
327
332
328
333
return ResponseImage .from_database (image )
0 commit comments