summaryrefslogtreecommitdiff
path: root/ironic/api/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'ironic/api/controllers')
-rw-r--r--ironic/api/controllers/v1/bios.py41
-rw-r--r--ironic/api/controllers/v1/utils.py26
-rw-r--r--ironic/api/controllers/v1/versions.py4
3 files changed, 59 insertions, 12 deletions
diff --git a/ironic/api/controllers/v1/bios.py b/ironic/api/controllers/v1/bios.py
index 05fc46d8a..8a3adf3b7 100644
--- a/ironic/api/controllers/v1/bios.py
+++ b/ironic/api/controllers/v1/bios.py
@@ -25,23 +25,34 @@ from ironic import objects
METRICS = metrics_utils.get_metrics_logger(__name__)
+_DEFAULT_RETURN_FIELDS = ('name', 'value')
+_DEFAULT_FIELDS_WITH_REGISTRY = ('name', 'value', 'attribute_type',
+ 'allowable_values', 'lower_bound',
+ 'max_length', 'min_length', 'read_only',
+ 'reset_required', 'unique', 'upper_bound')
-def convert_with_links(rpc_bios, node_uuid):
+
+def convert_with_links(rpc_bios, node_uuid, detail=None, fields=None):
"""Build a dict containing a bios setting value."""
+
+ if detail:
+ fields = _DEFAULT_FIELDS_WITH_REGISTRY
+
bios = api_utils.object_to_dict(
rpc_bios,
include_uuid=False,
- fields=('name', 'value'),
+ fields=fields,
link_resource='nodes',
link_resource_args="%s/bios/%s" % (node_uuid, rpc_bios.name),
)
return bios
-def collection_from_list(node_ident, bios_settings):
+def collection_from_list(node_ident, bios_settings, detail=None, fields=None):
bios_list = []
for bios_setting in bios_settings:
- bios_list.append(convert_with_links(bios_setting, node_ident))
+ bios_list.append(convert_with_links(bios_setting, node_ident,
+ detail, fields))
return {'bios': bios_list}
@@ -54,14 +65,23 @@ class NodeBiosController(rest.RestController):
@METRICS.timer('NodeBiosController.get_all')
@method.expose()
- def get_all(self):
+ @args.validate(fields=args.string_list, detail=args.boolean)
+ def get_all(self, detail=None, fields=None):
"""List node bios settings."""
node = api_utils.check_node_policy_and_retrieve(
'baremetal:node:bios:get', self.node_ident)
+ # The BIOS detail and fields query were added in a later
+ # version, check if they are valid based on version
+ allow_query = api_utils.allow_query_bios
+ fields = api_utils.get_request_return_fields(fields, detail,
+ _DEFAULT_RETURN_FIELDS,
+ allow_query, allow_query)
+
settings = objects.BIOSSettingList.get_by_node_id(
api.request.context, node.id)
- return collection_from_list(self.node_ident, settings)
+ return collection_from_list(self.node_ident, settings,
+ detail, fields)
@METRICS.timer('NodeBiosController.get_one')
@method.expose()
@@ -81,4 +101,11 @@ class NodeBiosController(rest.RestController):
raise exception.BIOSSettingNotFound(node=node.uuid,
name=setting_name)
- return {setting_name: convert_with_links(setting, node.uuid)}
+ # Return fields based on version
+ if api_utils.allow_query_bios():
+ fields = _DEFAULT_FIELDS_WITH_REGISTRY
+ else:
+ fields = _DEFAULT_RETURN_FIELDS
+
+ return {setting_name: convert_with_links(setting, node.uuid,
+ fields=fields)}
diff --git a/ironic/api/controllers/v1/utils.py b/ironic/api/controllers/v1/utils.py
index 83c2a1602..4a753c4d1 100644
--- a/ironic/api/controllers/v1/utils.py
+++ b/ironic/api/controllers/v1/utils.py
@@ -1321,18 +1321,27 @@ def allow_detail_query():
return api.request.version.minor >= versions.MINOR_43_ENABLE_DETAIL_QUERY
+def allow_query_bios():
+ """Check if BIOS queries should be allowed based on version"""
+
+ return api.request.version.minor >= versions.MINOR_74_BIOS_REGISTRY
+
+
def allow_reset_interfaces():
"""Check if passing a reset_interfaces query string is allowed."""
return api.request.version.minor >= versions.MINOR_45_RESET_INTERFACES
-def get_request_return_fields(fields, detail, default_fields):
+def get_request_return_fields(fields, detail, default_fields,
+ check_detail_version=allow_detail_query,
+ check_fields_version=None):
"""Calculate fields to return from an API request
The fields query and detail=True query can not be passed into a request at
the same time. To use the detail query we need to be on a version of the
- API greater than 1.43. This function raises an InvalidParameterValue
- exception if either of these conditions are not met.
+ API greater than expected, likewise some APIs require a certain version for
+ the fields query. This function raises an InvalidParameterValue exception
+ if any of these conditions are not met.
If these checks pass then this function will return either the fields
passed in or the default fields provided.
@@ -1341,15 +1350,24 @@ def get_request_return_fields(fields, detail, default_fields):
:param detail: The detail query passed into the API request.
:param default_fields: The default fields to return if fields=None and
detail=None.
+ :param check_detail_version: Function to check if detail query is allowed
+ based on the version.
+ :param check_fields_version: Function to check if fields query is allowed
+ based on the version.
:raises: InvalidParameterValue if there is an invalid combination of query
strings or API version.
:returns: 'fields' passed in value or 'default_fields'
"""
- if detail is not None and not allow_detail_query():
+ if detail is not None and not check_detail_version():
raise exception.InvalidParameterValue(
"Invalid query parameter ?detail=%s received." % detail)
+ if (fields is not None and callable(check_fields_version)
+ and not check_fields_version()):
+ raise exception.InvalidParameterValue(
+ "Invalid query parameter ?fields=%s received." % fields)
+
if fields is not None and detail:
raise exception.InvalidParameterValue(
"Can not specify ?detail=True and fields in the same request.")
diff --git a/ironic/api/controllers/v1/versions.py b/ironic/api/controllers/v1/versions.py
index 97e03485e..677a27475 100644
--- a/ironic/api/controllers/v1/versions.py
+++ b/ironic/api/controllers/v1/versions.py
@@ -111,6 +111,7 @@ BASE_VERSION = 1
# v1.71: Add signifier for Scope based roles.
# v1.72: Add agent_status and agent_status_message to /v1/heartbeat
# v1.73: Add support for deploy and undeploy verbs
+# v1.74: Add bios registry to /v1/nodes/{node}/bios/{setting}
MINOR_0_JUNO = 0
MINOR_1_INITIAL_VERSION = 1
@@ -186,6 +187,7 @@ MINOR_70_CLEAN_DISABLE_RAMDISK = 70
MINOR_71_RBAC_SCOPES = 71
MINOR_72_HEARTBEAT_STATUS = 72
MINOR_73_DEPLOY_UNDEPLOY_VERBS = 73
+MINOR_74_BIOS_REGISTRY = 74
# When adding another version, update:
# - MINOR_MAX_VERSION
@@ -193,7 +195,7 @@ MINOR_73_DEPLOY_UNDEPLOY_VERBS = 73
# explanation of what changed in the new version
# - common/release_mappings.py, RELEASE_MAPPING['master']['api']
-MINOR_MAX_VERSION = MINOR_73_DEPLOY_UNDEPLOY_VERBS
+MINOR_MAX_VERSION = MINOR_74_BIOS_REGISTRY
# String representations of the minor and maximum versions
_MIN_VERSION_STRING = '{}.{}'.format(BASE_VERSION, MINOR_1_INITIAL_VERSION)