neutron_lib.api.attributes 模块¶
- class neutron_lib.api.attributes.AttributeInfo(resource_attrs)¶
基类:
object提供对资源属性映射的操作。
AttributeInfo 封装 API 资源的属性字典,并提供基于底层属性填充默认值、验证、转换等方法。
- convert_values(res_dict, exc_cls=<function AttributeInfo.<lambda>>)¶
转换和验证请求的属性值。
- 参数:
res_dict – 请求中的资源属性。
exc_cls – 发生错误时要引发的异常,该异常必须接受单个错误消息作为其唯一的构造函数参数。
- 引发:
exc_cls 如果在转换/验证 res_dict 时发生任何错误。
- fill_post_defaults(res_dict, exc_cls=<function AttributeInfo.<lambda>>, check_allow_post=True)¶
填充 POST 请求中属性的默认值。
当发出 POST 请求时,具有默认值的属性不需要由用户指定。此函数填充任何未指定的属性的值(如果它们具有默认值)。
如果未指定属性并且它没有默认值,则会引发异常。
如果指定了属性并且它不允许在 POST 请求中使用,则会引发异常。调用者可以通过设置 check_allow_post=False(由某些内部管理操作使用)来覆盖此行为。
- 参数:
res_dict – 请求中的资源属性。
exc_cls – 发生错误时要引发的异常,该异常必须接受单个错误消息作为其唯一的构造函数参数。
check_allow_post – 如果指定了不允许 POST 的属性,则引发异常。
- 引发:
exc_cls 如果 check_allow_post 为 True 并且此 ResourceAttributes 实例不支持 POST。
- populate_project_id(context, res_dict, is_create)¶
填充请求体中的所有者信息。
确保 project_id 和 tenant_id 属性都存在。验证请求者是否具有所需的权限。对于创建请求,如果需要,将所有者信息从上下文复制到请求体并验证是否指定了所有者。
- 参数:
context – 请求上下文。
res_dict – 请求中的资源属性。
attr_info – 资源的属性映射。
is_create – 这是否是创建请求?
- 引发:
HTTPBadRequest 如果 res_dict 中既未指定 project_id 也未指定 tenant_id。
- verify_attributes(attrs_to_verify)¶
拒绝未知的属性。
使用者应确保在调用此方法之前,将项目信息填充到 attrs_to_verify 中。
- 参数:
attrs_to_verify – 要针对此资源属性进行验证的属性。
- 引发:
HTTPBadRequest:如果 attrs_to_verify 包含此资源属性实例无法识别的任何属性。
- neutron_lib.api.attributes.populate_project_info(attributes)¶
确保 project_id 和 tenant_id 属性都存在。
如果 attributes 中存在 project_id 或 tenant_id,则确保两者都存在。
如果两者都不存在,则不更新 attributes。
- 参数:
attributes – 资源/API 属性的字典或 API 请求/响应字典。
- 返回值:
attributes(如果适用,则使用 project_id 更新)。
- 引发:
HTTPBadRequest 如果 attributes project_id 和 tenant_id 不匹配。
- neutron_lib.api.attributes.retrieve_valid_sort_keys(attr_info)¶
从 attr_info 字典中检索排序键。
迭代 attr_info,过滤并返回定义了 is_sort_key=True 的属性。
- 参数:
attr_info – 通用 Neutron 资源的属性字典。
- 返回值:
排序键集合。