diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py index c28110898a..97796183fb 100644 --- a/ironic/api/controllers/v1/node.py +++ b/ironic/api/controllers/v1/node.py @@ -96,6 +96,16 @@ PROVISION_ACTION_STATES = (ir_states.VERBS['manage'], ir_states.VERBS['provide'], ir_states.VERBS['abort']) +_NODES_CONTROLLER_RESERVED_WORDS = None + + +def get_nodes_controller_reserved_names(): + global _NODES_CONTROLLER_RESERVED_WORDS + if _NODES_CONTROLLER_RESERVED_WORDS is None: + _NODES_CONTROLLER_RESERVED_WORDS = ( + api_utils.get_controller_reserved_names(NodesController)) + return _NODES_CONTROLLER_RESERVED_WORDS + def hide_fields_in_newer_versions(obj): # if requested version is < 1.3, hide driver_internal_info @@ -924,6 +934,12 @@ class NodeMaintenanceController(rest.RestController): class NodesController(rest.RestController): """REST controller for Nodes.""" + # NOTE(lucasagomes): For future reference. If we happen + # to need to add another sub-controller in this class let's + # try to make it a parameter instead of an endpoint due + # https://bugs.launchpad.net/ironic/+bug/1572651, e.g, instead of + # v1/nodes/(ident)/detail we could have v1/nodes/(ident)?detail=True + states = NodeStatesController() """Expose the state controller action as a sub-element of nodes""" @@ -1033,8 +1049,7 @@ class NodesController(rest.RestController): if not api_utils.allow_node_logical_names(): raise exception.NotAcceptable() - reserved_names = api_utils.get_controller_reserved_names( - NodesController) + reserved_names = get_nodes_controller_reserved_names() for name in names: if not api_utils.is_valid_node_name(name): raise wsme.exc.ClientSideError( @@ -1043,7 +1058,7 @@ class NodesController(rest.RestController): if name in reserved_names: raise wsme.exc.ClientSideError( 'The word "%(name)s" is reserved and can not be used as a ' - 'node name. Other reserved words are: %(reserved)s' % + 'node name. Reserved words are: %(reserved)s.' % {'name': name, 'reserved': ', '.join(reserved_names)}, status_code=http_client.BAD_REQUEST) diff --git a/releasenotes/notes/reserved-node-names-67a08012ed1131ae.yaml b/releasenotes/notes/reserved-node-names-67a08012ed1131ae.yaml index c490b74f88..cc3748c491 100644 --- a/releasenotes/notes/reserved-node-names-67a08012ed1131ae.yaml +++ b/releasenotes/notes/reserved-node-names-67a08012ed1131ae.yaml @@ -2,4 +2,5 @@ fixes: - Fixes a problem which allowed nodes to be named with some reserved words that are implicitly not allowed due the way the Ironic API - works. + works. The reserved words are "maintenance", "management", "ports", + "states", "vendor_passthru", "validate" and "detail".