Merge "use attribute functions/operations from neutron-lib"

This commit is contained in:
Jenkins 2017-05-30 08:02:54 +00:00 committed by Gerrit Code Review
commit 4f8bef7356

View File

@ -15,6 +15,7 @@
from neutron.api.v2 import attributes
from neutron_lib.api import attributes as lib_attrs
from oslo_config import cfg
from oslo_utils import uuidutils
import webob.exc
@ -27,15 +28,16 @@ def _fixup_res_dict(context, attr_name, res_dict, check_allow_post=True):
if cfg.CONF.api_replay_mode and 'id' not in res_dict:
res_dict['id'] = uuidutils.generate_uuid()
attr_info = attributes.RESOURCE_ATTRIBUTE_MAP[attr_name]
attr_ops = lib_attrs.AttributeInfo(attr_info)
try:
attributes.populate_tenant_id(context, res_dict, attr_info, True)
attributes.verify_attributes(res_dict, attr_info)
attr_ops.populate_project_id(context, res_dict, True)
attributes.populate_project_info(attr_info)
attr_ops.verify_attributes(res_dict)
except webob.exc.HTTPBadRequest as e:
# convert webob exception into ValueError as these functions are
# for internal use. webob exception doesn't make sense.
raise ValueError(e.detail)
attributes.fill_default_value(attr_info, res_dict,
check_allow_post=check_allow_post)
attributes.convert_value(attr_info, res_dict)
attr_ops.fill_post_defaults(res_dict, check_allow_post=check_allow_post)
attr_ops.convert_values(res_dict)
return res_dict