Support create attribute api

Change-Id: If55c722166bbaa3f0203ce5c0c9002ceb3bde859
This commit is contained in:
songwenping 2023-01-04 16:45:25 +08:00 committed by Wenping Song
parent 08f63a8426
commit 58e46e9e44
3 changed files with 23 additions and 1 deletions

View File

@ -136,6 +136,25 @@ class AttributesController(base.CyborgController,
LOG.info('[attributes] get_one returned: %s', ret)
return ret
@authorize_wsgi.authorize_wsgi("cyborg:attribute", "create", False)
@expose.expose(Attribute, body=types.jsontype,
status_code=HTTPStatus.CREATED)
def post(self, req_attr):
"""Create one attribute.
:param req_attr: attribute value.
{ "deployable_id": <integer>,
"key": <string>,
"value": <string>
}
:returns: The object of created attribute
"""
LOG.info("[attributes] POST request = (%s)", req_attr)
context = pecan.request.context
attribute = objects.Attribute(context, **req_attr).create(context)
ret = Attribute.convert_with_links(attribute)
LOG.info('[attributes] post returned: %s', ret)
return ret
@authorize_wsgi.authorize_wsgi("cyborg:attribute", "delete")
@expose.expose(None, wtypes.text, status_code=HTTPStatus.NO_CONTENT)
def delete(self, uuid):

View File

@ -69,6 +69,9 @@ attribute_policies = [
policy.RuleDefault('cyborg:attribute:get_all',
'rule:allow',
description='Retrieve all attribute records'),
policy.RuleDefault('cyborg:attribute:create',
'rule:allow',
description='Create an attribute record'),
policy.RuleDefault('cyborg:attribute:delete',
'rule:allow',
description='Delete attribute records.'),

View File

@ -48,7 +48,7 @@ class Attribute(base.CyborgObject, object_base.VersionedObjectDictCompat):
values = self.obj_get_changes()
db_attr = self.dbapi.attribute_create(context,
values)
self._from_db_object(self, db_attr)
return self._from_db_object(self, db_attr)
@classmethod
def get(cls, context, uuid):