def update(self, req, type_id, id, body=None): """Update encryption specs for a given volume type.""" context = req.environ['cinder.context'] authorize(context) if not body: expl = _('Request body empty.') raise webob.exc.HTTPBadRequest(explanation=expl) if not self.is_valid_body(body, 'encryption'): expl = _('Update body is not valid. It must contain "encryption."') raise webob.exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _('Request body contains too many items.') raise webob.exc.HTTPBadRequest(explanation=expl) self._check_type(context, type_id) if self._encrypted_type_in_use(context, type_id): expl = _('Cannot update encryption specs. Volume type in use.') raise webob.exc.HTTPBadRequest(explanation=expl) encryption_specs = body['encryption'] self._check_encryption_input(encryption_specs, create=False) db.volume_type_encryption_update(context, type_id, encryption_specs) notifier_info = dict(type_id=type_id, id=id) notifier = rpc.get_notifier('volumeTypeEncryption') notifier.info(context, 'volume_type_encryption.update', notifier_info) return body
def update(self, req, type_id, id, body=None): """Update encryption specs for a given volume type.""" context = req.environ['cinder.context'] authorize(context) self.assert_valid_body(body, 'encryption') if len(body) > 1: expl = _('Request body contains too many items.') raise webob.exc.HTTPBadRequest(explanation=expl) self._check_type(context, type_id) if self._encrypted_type_in_use(context, type_id): expl = _('Cannot update encryption specs. Volume type in use.') raise webob.exc.HTTPBadRequest(explanation=expl) encryption_specs = body['encryption'] self._check_encryption_input(encryption_specs, create=False) db.volume_type_encryption_update(context, type_id, encryption_specs) notifier_info = dict(type_id=type_id, id=id) notifier = rpc.get_notifier('volumeTypeEncryption') notifier.info(context, 'volume_type_encryption.update', notifier_info) return body
def test_volume_type_encryption_update(self): update_values = self._get_values(updated=True) self.updated = [ db.volume_type_encryption_update(self.ctxt, values["volume_type_id"], values) for values in update_values ] for i, encryption in enumerate(self.updated): self._assertEqualObjects(update_values[i], encryption, self._ignored_keys)
def test_volume_type_encryption_update(self): update_values = self._get_values(updated=True) self.updated = \ [db.volume_type_encryption_update(self.ctxt, values['volume_type_id'], values) for values in update_values] for i, encryption in enumerate(self.updated): self._assertEqualObjects(update_values[i], encryption, self._ignored_keys)
def update(self, req, type_id, id, body): """Update encryption specs for a given volume type.""" context = req.environ['cinder.context'] self._authorize_policy(context, policy.UPDATE_ENCRYPTION_POLICY) key_size = body['encryption'].get('key_size') if key_size is not None: body['encryption']['key_size'] = int(key_size) self._check_type(context, type_id) if self._encrypted_type_in_use(context, type_id): expl = _('Cannot update encryption specs. Volume type in use.') raise webob.exc.HTTPBadRequest(explanation=expl) encryption_specs = body['encryption'] db.volume_type_encryption_update(context, type_id, encryption_specs) notifier_info = dict(type_id=type_id, id=id) notifier = rpc.get_notifier('volumeTypeEncryption') notifier.info(context, 'volume_type_encryption.update', notifier_info) return body