Esempio n. 1
0
 def handle(self, request, data):
     image_id = data['image_id']
     try:
         api.image_update(request, image_id, image_meta={'is_public': False})
     except glance_exception.ClientConnectionError, e:
         LOG.error("Error connecting to glance", exc_info=True)
         messages.error(request,
                        "Error connecting to glance: %s" % e.message)
Esempio n. 2
0
 def handle(self, request, data):
     image_id = data['image_id']
     try:
         api.image_update(request, image_id,
                 image_meta={'is_public': False})
     except glance_exception.ClientConnectionError, e:
         LOG.exception("Error connecting to glance")
         messages.error(request,
                        _("Error connecting to glance: %s") % e.message)
    def test_image_update(self):
        IMAGE_ID = "1"
        IMAGE_META = {"metadata": "foobar"}

        glance_api = self.stub_glance_api(count=2)
        glance_api.update_image(IMAGE_ID, image_meta={}).AndReturn(TEST_RETURN)
        glance_api.update_image(IMAGE_ID, image_meta=IMAGE_META).AndReturn(TEST_RETURN)

        self.mox.ReplayAll()

        ret_val = api.image_update(self.request, IMAGE_ID)

        self.assertIsInstance(ret_val, api.Image)
        self.assertEqual(ret_val._apidict, TEST_RETURN)

        ret_val = api.image_update(self.request, IMAGE_ID, image_meta=IMAGE_META)

        self.assertIsInstance(ret_val, api.Image)
        self.assertEqual(ret_val._apidict, TEST_RETURN)

        self.mox.VerifyAll()
Esempio n. 4
0
 def handle(self, request, data):
     image_id = data['image_id']
     try:
         api.image_update(request, image_id, image_meta={'is_public': False})
     except GlanceClientConnectionError, e:
         messages.error(request, "Error connecting to glance: %s" % e.message)
Esempio n. 5
0
                'is_public': image_form['is_public'],
                'disk_format': image_form['disk_format'],
                'container_format': image_form['container_format'],
                'name': image_form['name'],
                'location': image_form['location'],
            }
            try:
                # TODO add public flag to properties
                metadata['properties'] = {
                    'kernel_id': int(image_form['kernel_id']),
                    'ramdisk_id': int(image_form['ramdisk_id']),
                    'image_state': image_form['state'],
                    'architecture': image_form['architecture'],
                    'project_id': image_form['project_id'],
                }
                api.image_update(request, image_id, metadata)
                messages.success(request, "Image was successfully updated.")
            except GlanceClientConnectionError, e:
                messages.error(request, "Error connecting to glance: %s" % e.message)
            except glance_exception.Error, e:
                messages.error(request, "Error updating image: %s" % e.message)
            except:
                messages.error(request, "Image could not be updated, please try again.")


        else:
            messages.error(request, "Image could not be uploaded, please try agian.")
            form = UpdateImageForm(request.POST)
            return render_to_response('django_nova_syspanel/images/image_update.html',{
                'image': image,
                'form': form,
Esempio n. 6
0
                    'disk_format': data['disk_format'],
                    'container_format': data['container_format'],
                    'name': data['name'],
                }
                # TODO add public flag to properties
                meta['properties'] = {}
                if data['kernel']:
                    meta['properties']['kernel_id'] = data['kernel']

                if data['ramdisk']:
                    meta['properties']['ramdisk_id'] = data['ramdisk']

                if data['architecture']:
                    meta['properties']['architecture'] = data['architecture']

                api.image_update(request, image_id, meta)
                messages.success(request, _('Image was successfully updated.'))

            except glance_exception.ClientConnectionError, e:
                LOG.exception(_('Error connecting to glance'))
                messages.error(request, error_retrieving)
            except glance_exception.Error, e:
                LOG.exception(error_updating)
                messages.error(request, error_updating)
            except:
                LOG.exception(_('Unspecified Exception in image update'))
                messages.error(request, error_updating)
            return redirect('dash_images_update', tenant_id, image_id)
        else:
            messages.info(
                request,
Esempio n. 7
0
        if image.owner == request.user.username or image.properties.get(
                'user_id') == request.user.username:
            try:
                prop = {}
                for key in [
                        'architecture', 'image_location', 'image_state',
                        'kernel_id', 'project_id', 'ramdisk_id', 'user_id'
                ]:
                    prop[key] = image.properties.get(key)
                meta = {
                    'is_public': True,
                    'name': image_name,
                    'location': "%s://%s@%s%s" % (scheme, auth, loc, path),
                    'properties': prop
                }
                api.image_update(request, image_id, meta)
                messages.success(request, _('Image was successfully updated.'))

            except glance_exception.ClientConnectionError, e:
                LOG.exception(_('Error connecting to glance'))
                messages.error(request, error_retrieving)
            except glance_exception.Error, e:
                LOG.exception(error_updating)
                messages.error(request, error_updating)
            except:
                LOG.exception(_('Unspecified Exception in image update'))
                messages.error(request, error_updating)
            return redirect('dash_metadata_update', tenant_id, image_id)
        else:
            messages.info(
                request,
Esempio n. 8
0
        except glance_exception.Error, e:
            LOG.exception(error_retrieving)
            messages.error(request, error_retrieving)

        if image.owner == request.user.username or image.properties.get('user_id') == request.user.username:
            try:
                prop = {}
                for key in ['architecture', 'image_location', 'image_state', 'kernel_id', 'project_id', 'ramdisk_id', 'user_id']:
                    prop[key] = image.properties.get(key)
                meta = {
                    'is_public': True,
                    'name': image_name,
                    'location' : "%s://%s@%s%s" % (scheme, auth, loc, path),
                    'properties' : prop
                }
                api.image_update(request, image_id, meta)
                messages.success(request, _('Image was successfully updated.'))

            except glance_exception.ClientConnectionError, e:
                LOG.exception(_('Error connecting to glance'))
                messages.error(request, error_retrieving)
            except glance_exception.Error, e:
                LOG.exception(error_updating)
                messages.error(request, error_updating)
            except:
                LOG.exception(_('Unspecified Exception in image update'))
                messages.error(request, error_updating)
            return redirect('dash_metadata_update', tenant_id, image_id)
        else:
            messages.info(request, _('Unable to update image. You are not its \
                                      owner.'))