def update(self, req, type_id, id, body): context = req.environ['cinder.context'] context.authorize(policy.UPDATE_POLICY) self._allow_update(context, type_id) self._check_type(context, type_id) if id not in body: expl = _('Request body and URI mismatch') raise webob.exc.HTTPBadRequest(explanation=expl) if 'image_service:store_id' in body: image_service_store_id = body['image_service:store_id'] image_utils.validate_stores_id(context, image_service_store_id) if 'extra_specs' in body: specs = body['extra_specs'] # Check if multiattach be set with cacheable self._check_cacheable(specs, type_id) db.volume_type_extra_specs_update_or_create(context, type_id, body) # Get created_at and updated_at for notification volume_type = volume_types.get_volume_type(context, type_id) notifier_info = dict(type_id=type_id, id=id, created_at=volume_type['created_at'], updated_at=volume_type['updated_at']) notifier = rpc.get_notifier('volumeTypeExtraSpecs') notifier.info(context, 'volume_type_extra_specs.update', notifier_info) return body
def create(self, req, type_id, body): context = req.environ['cinder.context'] context.authorize(policy.CREATE_POLICY) self._allow_update(context, type_id) self._check_type(context, type_id) specs = body['extra_specs'] if 'image_service:store_id' in specs: image_service_store_id = specs['image_service:store_id'] image_utils.validate_stores_id(context, image_service_store_id) # Check if multiattach be set with cacheable self._check_cacheable(specs, type_id) db.volume_type_extra_specs_update_or_create(context, type_id, specs) # Get created_at and updated_at for notification volume_type = volume_types.get_volume_type(context, type_id) notifier_info = dict(type_id=type_id, specs=specs, created_at=volume_type['created_at'], updated_at=volume_type['updated_at']) notifier = rpc.get_notifier('volumeTypeExtraSpecs') notifier.info(context, 'volume_type_extra_specs.create', notifier_info) return body
def update(self, req, type_id, id, body=None): context = req.environ['cinder.context'] authorize(context) if not body: expl = _('Request body empty') raise webob.exc.HTTPBadRequest(explanation=expl) self._check_type(context, type_id) if id not in body: expl = _('Request body and URI mismatch') 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_key_names(body.keys()) utils.validate_dictionary_string_length(body) db.volume_type_extra_specs_update_or_create(context, type_id, body) notifier_info = dict(type_id=type_id, id=id) notifier = rpc.get_notifier('volumeTypeExtraSpecs') notifier.info(context, 'volume_type_extra_specs.update', notifier_info) return body
def update(self, req, type_id, id, body=None): context = req.environ['cinder.context'] authorize(context, action='update') self._allow_update(context, type_id) if not body: expl = _('Request body empty') raise webob.exc.HTTPBadRequest(explanation=expl) self._check_type(context, type_id) if id not in body: expl = _('Request body and URI mismatch') 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_key_names(body.keys()) utils.validate_dictionary_string_length(body) db.volume_type_extra_specs_update_or_create(context, type_id, body) # Get created_at and updated_at for notification volume_type = volume_types.get_volume_type(context, type_id) notifier_info = dict(type_id=type_id, id=id, created_at=volume_type['created_at'], updated_at=volume_type['updated_at']) notifier = rpc.get_notifier('volumeTypeExtraSpecs') notifier.info(context, 'volume_type_extra_specs.update', notifier_info) return body
def test_volume_type_extra_specs_update(self): expected_specs = self.vol_type1_specs.copy() expected_specs["vol_extra3"] = "4" db.volume_type_extra_specs_update_or_create( context.get_admin_context(), self.volume_type1_id, dict(vol_extra3=4) ) actual_specs = db.volume_type_extra_specs_get(context.get_admin_context(), self.volume_type1_id) self.assertEquals(expected_specs, actual_specs)
def test_volume_type_extra_specs_update(self): expected_specs = self.vol_type1_specs.copy() expected_specs['vol_extra3'] = "4" db.volume_type_extra_specs_update_or_create( context.get_admin_context(), self.volume_type1_id, dict(vol_extra3=4)) actual_specs = db.volume_type_extra_specs_get( context.get_admin_context(), self.volume_type1_id) self.assertEquals(expected_specs, actual_specs)
def test_volume_type_extra_specs_create(self): expected_specs = self.vol_type1_specs.copy() expected_specs['vol_extra4'] = 'value4' expected_specs['vol_extra5'] = 'value5' db.volume_type_extra_specs_update_or_create( context.get_admin_context(), self.volume_type1_id, dict(vol_extra4="value4", vol_extra5="value5")) actual_specs = db.volume_type_extra_specs_get( context.get_admin_context(), self.volume_type1_id) self.assertEquals(expected_specs, actual_specs)
def create(self, req, type_id, body=None): context = req.environ["cinder.context"] authorize(context) self._check_type(context, type_id) self._check_body(body) specs = body.get("extra_specs") if not isinstance(specs, dict): expl = _("Malformed extra specs") raise webob.exc.HTTPBadRequest(explanation=expl) db.volume_type_extra_specs_update_or_create(context, type_id, specs) return body
def create(self, req, type_id, body=None): context = req.environ['cinder.context'] authorize(context) if not self.is_valid_body(body, 'extra_specs'): raise webob.exc.HTTPUnprocessableEntity() self._check_type(context, type_id) specs = body['extra_specs'] db.volume_type_extra_specs_update_or_create(context, type_id, specs) return body
def test_volume_type_extra_specs_create(self): expected_specs = self.vol_type1_specs.copy() expected_specs['vol_extra4'] = 'value4' expected_specs['vol_extra5'] = 'value5' db.volume_type_extra_specs_update_or_create( context.get_admin_context(), self.volume_type1_id, dict(vol_extra4="value4", vol_extra5="value5")) actual_specs = db.volume_type_extra_specs_get( context.get_admin_context(), self.volume_type1_id) self.assertEqual(expected_specs, actual_specs)
def update(self, req, type_id, id, body=None): context = req.environ["cinder.context"] authorize(context) self._check_type(context, type_id) self._check_body(body) if not id in body: expl = _("Request body and URI mismatch") raise webob.exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _("Request body contains too many items") raise webob.exc.HTTPBadRequest(explanation=expl) db.volume_type_extra_specs_update_or_create(context, type_id, body) return body
def update(self, req, type_id, id, body=None): context = req.environ['cinder.context'] authorize(context) if not body: raise webob.exc.HTTPUnprocessableEntity() self._check_type(context, type_id) if not id in body: expl = _('Request body and URI mismatch') raise webob.exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _('Request body contains too many items') raise webob.exc.HTTPBadRequest(explanation=expl) db.volume_type_extra_specs_update_or_create(context, type_id, body) return body
def create(self, req, type_id, body=None): context = req.environ['cinder.context'] authorize(context) self.assert_valid_body(body, 'extra_specs') self._check_type(context, type_id) specs = body['extra_specs'] self._check_key_names(specs.keys()) db.volume_type_extra_specs_update_or_create(context, type_id, specs) notifier_info = dict(type_id=type_id, specs=specs) notifier = rpc.get_notifier('volumeTypeExtraSpecs') notifier.info(context, 'volume_type_extra_specs.create', notifier_info) return body
def create(self, req, type_id, body=None): context = req.environ["cinder.context"] authorize(context) if not self.is_valid_body(body, "extra_specs"): raise webob.exc.HTTPBadRequest() self._check_type(context, type_id) specs = body["extra_specs"] self._check_key_names(specs.keys()) db.volume_type_extra_specs_update_or_create(context, type_id, specs) notifier_info = dict(type_id=type_id, specs=specs) notifier = rpc.get_notifier("volumeTypeExtraSpecs") notifier.info(context, "volume_type_extra_specs.create", notifier_info) return body
def create(self, req, type_id, body=None): context = req.environ['cinder.context'] authorize(context) if not self.is_valid_body(body, 'extra_specs'): raise webob.exc.HTTPBadRequest() self._check_type(context, type_id) specs = body['extra_specs'] db.volume_type_extra_specs_update_or_create(context, type_id, specs) notifier_info = dict(type_id=type_id, specs=specs) notifier_api.notify(context, 'volumeTypeExtraSpecs', 'volume_type_extra_specs.create', notifier_api.INFO, notifier_info) return body
def create(self, req, type_id, body=None): context = req.environ['cinder.context'] authorize(context) if not self.is_valid_body(body, 'extra_specs'): raise webob.exc.HTTPBadRequest() self._check_type(context, type_id) specs = body['extra_specs'] self._check_key_names(specs.keys()) db.volume_type_extra_specs_update_or_create(context, type_id, specs) notifier_info = dict(type_id=type_id, specs=specs) notifier_api.notify(context, 'volumeTypeExtraSpecs', 'volume_type_extra_specs.create', notifier_api.INFO, notifier_info) return body
def update(self, req, type_id, id, body=None): context = req.environ['cinder.context'] authorize(context) if not body: expl = _('Request body empty') raise webob.exc.HTTPBadRequest(explanation=expl) self._check_type(context, type_id) if id not in body: expl = _('Request body and URI mismatch') raise webob.exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _('Request body contains too many items') raise webob.exc.HTTPBadRequest(explanation=expl) db.volume_type_extra_specs_update_or_create(context, type_id, body) notifier_info = dict(type_id=type_id, id=id) notifier = rpc.get_notifier('volumeTypeExtraSpecs') notifier.info(context, 'volume_type_extra_specs.update', notifier_info) return body
def create(self, req, type_id, body): context = req.environ['cinder.context'] context.authorize(policy.CREATE_POLICY) self._allow_update(context, type_id) self._check_type(context, type_id) specs = body['extra_specs'] db.volume_type_extra_specs_update_or_create(context, type_id, specs) # Get created_at and updated_at for notification volume_type = volume_types.get_volume_type(context, type_id) notifier_info = dict(type_id=type_id, specs=specs, created_at=volume_type['created_at'], updated_at=volume_type['updated_at']) notifier = rpc.get_notifier('volumeTypeExtraSpecs') notifier.info(context, 'volume_type_extra_specs.create', notifier_info) return body
def update(self, req, type_id, id, body=None): context = req.environ["cinder.context"] authorize(context) if not body: expl = _("Request body empty") raise webob.exc.HTTPBadRequest(explanation=expl) self._check_type(context, type_id) if id not in body: expl = _("Request body and URI mismatch") raise webob.exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _("Request body contains too many items") raise webob.exc.HTTPBadRequest(explanation=expl) db.volume_type_extra_specs_update_or_create(context, type_id, body) notifier_info = dict(type_id=type_id, id=id) notifier = rpc.get_notifier("volumeTypeExtraSpecs") notifier.info(context, "volume_type_extra_specs.update", notifier_info) return body
def update(self, req, type_id, id, body): context = req.environ['cinder.context'] context.authorize(policy.UPDATE_POLICY) self._allow_update(context, type_id) self._check_type(context, type_id) if id not in body: expl = _('Request body and URI mismatch') raise webob.exc.HTTPBadRequest(explanation=expl) db.volume_type_extra_specs_update_or_create(context, type_id, body) # Get created_at and updated_at for notification volume_type = volume_types.get_volume_type(context, type_id) notifier_info = dict(type_id=type_id, id=id, created_at=volume_type['created_at'], updated_at=volume_type['updated_at']) notifier = rpc.get_notifier('volumeTypeExtraSpecs') notifier.info(context, 'volume_type_extra_specs.update', notifier_info) return body
def update(self, req, type_id, id, body=None): context = req.environ['cinder.context'] authorize(context) if not body: expl = _('Request body empty') raise webob.exc.HTTPBadRequest(explanation=expl) self._check_type(context, type_id) if id not in body: expl = _('Request body and URI mismatch') raise webob.exc.HTTPBadRequest(explanation=expl) if len(body) > 1: expl = _('Request body contains too many items') raise webob.exc.HTTPBadRequest(explanation=expl) db.volume_type_extra_specs_update_or_create(context, type_id, body) notifier_info = dict(type_id=type_id, id=id) notifier_api.notify(context, 'volumeTypeExtraSpecs', 'volume_type_extra_specs.update', notifier_api.INFO, notifier_info) return body
def create(self, req, type_id, body=None): context = req.environ['cinder.context'] authorize(context, action='create') self._allow_update(context, type_id) self.assert_valid_body(body, 'extra_specs') self._check_type(context, type_id) specs = body['extra_specs'] self._check_key_names(specs.keys()) utils.validate_dictionary_string_length(specs) db.volume_type_extra_specs_update_or_create(context, type_id, specs) # Get created_at and updated_at for notification volume_type = volume_types.get_volume_type(context, type_id) notifier_info = dict(type_id=type_id, specs=specs, created_at=volume_type['created_at'], updated_at=volume_type['updated_at']) notifier = rpc.get_notifier('volumeTypeExtraSpecs') notifier.info(context, 'volume_type_extra_specs.create', notifier_info) return body