From 804005da2d6f4ae44147ebafb8197f09bea41fab Mon Sep 17 00:00:00 2001 From: Olivier Lemasle Date: Mon, 19 Oct 2015 09:42:05 +0200 Subject: [PATCH] Import images publicly when package is public MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- muranodashboard/packages/views.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/muranodashboard/packages/views.py b/muranodashboard/packages/views.py index 18a77cfaf..29a429191 100644 --- a/muranodashboard/packages/views.py +++ b/muranodashboard/packages/views.py @@ -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: