diff --git a/cyborg/api/controllers/v2/attributes.py b/cyborg/api/controllers/v2/attributes.py index bfc3b59b..cb188d71 100644 --- a/cyborg/api/controllers/v2/attributes.py +++ b/cyborg/api/controllers/v2/attributes.py @@ -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": , + "key": , + "value": + } + :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): diff --git a/cyborg/common/policy.py b/cyborg/common/policy.py index 6e02fe19..d0798cfb 100644 --- a/cyborg/common/policy.py +++ b/cyborg/common/policy.py @@ -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.'), diff --git a/cyborg/objects/attribute.py b/cyborg/objects/attribute.py index 6ddaa722..f0816cdf 100644 --- a/cyborg/objects/attribute.py +++ b/cyborg/objects/attribute.py @@ -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):