Import images publicly when package is public

When importing a package using package import wizard on the dashboard,
required glance images are imported before having chosen the
visibility of the package (is-public). With this commit, when the
package is set "public" in the final step of the wizard, the glance
images are also set "public".

Closes-Bug: #1507139
Depends−On: I9460360e84cc40d7414aa5cd9f7367f5a80b8466

Change-Id: I64e0572f4986919593b4cf40dac178fcbee9bf6f
This commit is contained in:
Olivier Lemasle 2015-10-19 09:42:05 +02:00
parent cc1b52e5a2
commit 804005da2d
1 changed files with 19 additions and 0 deletions

View File

@ -329,6 +329,9 @@ class ImportPackageWizard(views.ModalFormMixin,
dep_pkgs = self.storage.get_step_data('upload').get(
'dependencies', [])
installed_images = self.storage.get_step_data('upload').get(
'images', [])
redirect = reverse('horizon:murano:packages:index')
dep_data = {'enabled': data['enabled'],
'is_public': data['is_public']}
@ -343,6 +346,20 @@ class ImportPackageWizard(views.ModalFormMixin,
LOG.warning(msg)
messages.warning(self.request, msg)
# Images have been imported as private images during the 'upload' step
# If the package is public, make the required images public
if data['is_public']:
glance_client = glance.glanceclient(self.request, version='1')
for img in installed_images:
try:
glance_client.images.update(img['id'], is_public=True)
LOG.debug('Success update for image {0}'.format(img['id']))
except Exception as e:
msg = _("Error {0} occurred while setting image {1}, {2} "
"public").format(e, img['name'], img['id'])
messages.error(self.request, msg)
LOG.exception(msg)
try:
data['tags'] = [t.strip() for t in data['tags'].split(',')]
murano_client.packages.update(app_id, data)
@ -441,6 +458,7 @@ class ImportPackageWizard(views.ModalFormMixin,
"deployment after successful upload")\
.format(img['name'], img['id'],)
LOG.info(log_msg)
step_data['images'].append(img)
except Exception as e:
msg = _("Error {0} occurred while installing "
"images for {1}").format(e, name)
@ -451,6 +469,7 @@ class ImportPackageWizard(views.ModalFormMixin,
glance_client = glance.glanceclient(self.request, version='1')
original_package = reqs.pop(name)
step_data['dependencies'] = []
step_data['images'] = []
for dep_name, dep_package in reqs.iteritems():
_ensure_images(dep_name, dep_package)
try: