def test_update_post(self): image_to_update = self.images.first() image_updated = { 'name': u'new_name', 'container_format': u'new_format', 'is_public': False, 'disk_format': u'new_disk_format', 'properties': {} } self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'image_update') api.image_get_meta(IsA(http.HttpRequest), image_to_update.id).AndReturn(image_to_update) api.image_update(IsA(http.HttpRequest), image_to_update.id, image_updated) self.mox.ReplayAll() form_data = { 'method': 'UpdateImageForm', 'image_id': image_to_update.id, 'name': image_updated['name'], 'container_format': image_updated['container_format'], 'disk_format': image_updated['disk_format'], 'public': image_updated['is_public'] } url = reverse('horizon:nova:images_and_snapshots:images:update', args=[image_to_update.id]) res = self.client.post(url, form_data) self.assertNoFormErrors(res) self.assertRedirectsNoFollow( res, reverse('horizon:nova:images_and_snapshots:index'))
def handle(self, request, data): # TODO add public flag to image meta properties image_id = data['image_id'] error_updating = _('Unable to update image "%s".') meta = { 'is_public': data['public'], 'disk_format': data['disk_format'], 'container_format': 'bare', 'name': data['name'], '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'] try: # Ensure we do not delete properties that have already been # set on an image. meta['features'] = {'X-Glance-Registry-Purge-Props': False} api.image_update(request, image_id, **meta) messages.success(request, _('Image was successfully updated.')) except: exceptions.handle(request, error_updating % image_id) return shortcuts.redirect(self.get_success_url())
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 handle(self, request, data): # TODO add public flag to image meta properties image_id = data['image_id'] error_updating = _('Unable to update image "%s".') meta = { 'is_public': True, 'disk_format': data['disk_format'], 'container_format': data['container_format'], 'name': data['name'], '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'] try: api.image_update(request, image_id, meta) messages.success(request, _('Image was successfully updated.')) except: exceptions.handle(request, error_updating % image_id) return shortcuts.redirect(self.get_success_url())
def handle(self, request, data): # TODO add public flag to image meta properties image_id = data['image_id'] error_updating = _('Unable to update image "%s".') meta = {'is_public': data['public'], 'disk_format': data['disk_format'], 'container_format': 'bare', 'name': data['name'], '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'] try: # Ensure we do not delete properties that have already been # set on an image. meta['features'] = {'X-Glance-Registry-Purge-Props': False} api.image_update(request, image_id, **meta) messages.success(request, _('Image was successfully updated.')) except: exceptions.handle(request, error_updating % image_id) return shortcuts.redirect(self.get_success_url())
def test_update_post(self): image_to_update = self.images.first() image_updated = {'name': u'new_name', 'container_format': u'new_format', 'is_public': False, 'disk_format': u'new_disk_format', 'properties': {}} self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'image_update') api.image_get_meta(IsA(http.HttpRequest), image_to_update.id).AndReturn(image_to_update) api.image_update(IsA(http.HttpRequest), image_to_update.id, image_updated) self.mox.ReplayAll() form_data = {'method': 'UpdateImageForm', 'image_id': image_to_update.id, 'name': image_updated['name'], 'container_format': image_updated['container_format'], 'disk_format': image_updated['disk_format'], 'public': image_updated['is_public']} url = reverse('horizon:nova:images_and_snapshots:images:update', args=[image_to_update.id]) res = self.client.post(url, form_data) self.assertNoFormErrors(res) self.assertRedirectsNoFollow( res, reverse('horizon:nova:images_and_snapshots:index'))
def handle(self, request, data): # TODO add public flag to image meta properties image_id = data["image_id"] error_updating = _('Unable to update image "%s".') meta = { "is_public": True, "disk_format": data["disk_format"], "container_format": data["container_format"], "name": data["name"], "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"] try: api.image_update(request, image_id, meta) messages.success(request, _("Image was successfully updated.")) except: exceptions.handle(request, error_updating % image_id) return shortcuts.redirect(self.get_success_url())
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 handle(self, request, data): image_id = data['image_id'] error_updating = _('Unable to update image "%s".') if data['disk_format'] in ['aki', 'ari', 'ami']: container_format = data['disk_format'] else: container_format = 'bare' meta = {'is_public': data['public'], 'disk_format': data['disk_format'], 'container_format': container_format, 'name': data['name'], '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'] # Ensure we do not delete properties that have already been # set on an image. meta['purge_props'] = False try: image = api.image_update(request, image_id, **meta) messages.success(request, _('Image was successfully updated.')) return image except: exceptions.handle(request, error_updating % image_id)
def handle(self, request, data): image_id = data['image_id'] error_updating = _('Unable to update image "%s".') if data['disk_format'] in ['aki', 'ari', 'ami']: container_format = data['disk_format'] else: container_format = 'bare' meta = { 'is_public': data['public'], 'disk_format': data['disk_format'], 'container_format': container_format, 'name': data['name'], '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'] # Ensure we do not delete properties that have already been # set on an image. meta['purge_props'] = False try: image = api.image_update(request, image_id, **meta) messages.success(request, _('Image was successfully updated.')) return image except: exceptions.handle(request, error_updating % image_id)
def handle(self, request, data): image_id = data['image_id'] instance_choices = dict(self.fields['instance'].choices) instance_name = instance_choices.get(data['instance'], _("Unknown instance (None)")) # The name of the instance in the choices list has the ID appended to # it, so let's slice that off... instance_name = instance_name.rsplit(" (")[0] try: vol = api.volume_attach(request, data['volume_id'], data['instance'], data.get('device', '')) vol_name = api.volume_get(request, data['volume_id']).display_name message = _('Attaching volume %(vol)s to instance ' '%(inst)s on %(dev)s.') % {"vol": vol_name, "inst": instance_name, "dev": vol.device} messages.info(request, message) return True except: redirect = reverse("horizon:nova:volumes:index") exceptions.handle(request, _('Unable to attach volume.'), redirect=redirect) try: image = api.image_update(request, image_id, **meta) messages.success(request, _('Image was successfully updated.')) return image except: exceptions.handle(request, error_updating % image_id)
def handle(self, request, data): # TODO add public flag to image meta properties image_id = data['image_id'] error_updating = _('Unable to update image "%s".') meta = {'is_public': True, 'disk_format': data['disk_format'], 'container_format': data['container_format'], 'name': data['name'], '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'] try: api.image_update(request, image_id, meta) messages.success(request, _('Image was successfully updated.')) except: exceptions.handle(request, error_updating % image_id) return shortcuts.redirect(self.get_success_url())
'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,
'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, _('Unable to delete the requested image ' 'because you are not its owner.'))