Skip to content

Commit

Permalink
Merge pull request #6 from Pansanel/master
Browse files Browse the repository at this point in the history
Fix the issue where the retrieved image is not deleted by cloudkeeper-os
  • Loading branch information
Pansanel authored Jul 19, 2017
2 parents adf3fc5 + d0ffa18 commit e313f91
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cloudkeeper_os/imagemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""

import json
import os

from oslo_config import cfg
from oslo_log import log
Expand Down Expand Up @@ -60,9 +61,11 @@ def add_appliance(self, appliance):
LOG.debug("Image access mode: "
"%s" % appliance.image.Mode.Name(appliance.image.mode))
if appliance.image.Mode.Name(appliance.image.mode) == 'REMOTE':
remote_image = True
filename = utils.retrieve_image(appliance)
else:
filename = appliance.image.location
remote_image = False
if not filename:
LOG.error("Image filename is not set.")
return None
Expand All @@ -89,6 +92,13 @@ def add_appliance(self, appliance):
)
glance.images.upload(glance_image.id, image_data)
glance.images.update(glance_image.id, **properties)

image_data.close()

if remote_image:
LOG.debug("Delete retrieved image: %s" % (filename))
os.unlink(filename)

return glance_image.id

def update_appliance(self, appliance):
Expand All @@ -113,8 +123,10 @@ def update_appliance(self, appliance):
LOG.debug("Image access mode: "
"%s" % appliance.image.Mode.Name(appliance.image.mode))
if appliance.image.Mode.Name(appliance.image.mode) == 'REMOTE':
remote_image = True
filename = utils.retrieve_image(appliance)
else:
remote_image = False
filename = appliance.image.location
if not filename:
LOG.error("Image filename is not set.")
Expand All @@ -136,6 +148,13 @@ def update_appliance(self, appliance):
"values: %s" % (properties))
glance.images.upload(glance_image.id, image_data)
glance.images.update(glance_image.id, **properties)

image_data.close()

if remote_image:
LOG.debug("Delete retrieved image: %s" % (filename))
os.unlink(filename)

return glance_image.id


Expand Down

0 comments on commit e313f91

Please sign in to comment.