neutron_lib.api.attributes module¶
- class neutron_lib.api.attributes.AttributeInfo(resource_attrs)¶
Bases:
object
Provides operations on a resource’s attribute map.
AttributeInfo wraps an API resource’s attribute dict and provides methods for filling defaults, validating, converting, etc. based on the underlying attributes.
- convert_values(res_dict, exc_cls=<function AttributeInfo.<lambda>>)¶
Convert and validate attribute values for a request.
- Parameters:
res_dict – The resource attributes from the request.
exc_cls – Exception to be raised on error that must take a single error message as it’s only constructor arg.
- Raises:
exc_cls If any errors occur converting/validating the res_dict.
- fill_post_defaults(res_dict, exc_cls=<function AttributeInfo.<lambda>>, check_allow_post=True)¶
Fill in default values for attributes in a POST request.
When a POST request is made, the attributes with default values do not need to be specified by the user. This function fills in the values of any unspecified attributes if they have a default value.
If an attribute is not specified and it does not have a default value, an exception is raised.
If an attribute is specified and it is not allowed in POST requests, an exception is raised. The caller can override this behavior by setting check_allow_post=False (used by some internal admin operations).
- Parameters:
res_dict – The resource attributes from the request.
exc_cls – Exception to be raised on error that must take a single error message as it’s only constructor arg.
check_allow_post – Raises an exception if a non-POST-able attribute is specified.
- Raises:
exc_cls If check_allow_post is True and this instance of ResourceAttributes doesn’t support POST.
- populate_project_id(context, res_dict, is_create)¶
Populate the owner information in a request body.
Ensure both project_id and tenant_id attributes are present. Validate that the requestor has the required privileges. For a create request, copy owner info from context to request body if needed and verify that owner is specified if required.
- Parameters:
context – The request context.
res_dict – The resource attributes from the request.
attr_info – The attribute map for the resource.
is_create – Is this a create request?
- Raises:
HTTPBadRequest If neither the project_id nor tenant_id are specified in the res_dict.
- verify_attributes(attrs_to_verify)¶
Reject unknown attributes.
Consumers should ensure the project info is populated in the attrs_to_verify before calling this method.
- Parameters:
attrs_to_verify – The attributes to verify against this resource attributes.
- Raises:
HTTPBadRequest: If attrs_to_verify contains any unrecognized for this resource attributes instance.
- neutron_lib.api.attributes.populate_project_info(attributes)¶
Ensure that both project_id and tenant_id attributes are present.
If either project_id or tenant_id is present in attributes then ensure that both are present.
If neither are present then attributes is not updated.
- Parameters:
attributes – A dictionary of resource/API attributes or API request/response dict.
- Returns:
attributes (updated with project_id if applicable).
- Raises:
HTTPBadRequest if the attributes project_id and tenant_id don’t match.
- neutron_lib.api.attributes.retrieve_valid_sort_keys(attr_info)¶
Retrieve sort keys from attr_info dict.
Iterate the attr_info, filter and return the attributes that are defined with is_sort_key=True.
- Parameters:
attr_info – The attribute dict for common neutron resource.
- Returns:
Set of sort keys.