Merge "Import images publicly when package is public"

This commit is contained in:
Jenkins 2015-11-10 14:22:59 +00:00 committed by Gerrit Code Review
commit f05dda723e
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: