From f12937ebe1ba1691f5641151552e3bd824ac374d Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Fri, 26 Jun 2015 14:11:45 -0700 Subject: [PATCH] Refactor check_allow_management_verbs Convert check_allow_management_verbs() to use a dictionary mapping of verbs to minimum versions. Change-Id: I56a9df5d0272a21d9e387f5e634c383b1fc8d46b --- ironic/api/controllers/v1/node.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py index 711a8bc2a5..c6ef87f4d5 100644 --- a/ironic/api/controllers/v1/node.py +++ b/ironic/api/controllers/v1/node.py @@ -57,6 +57,16 @@ _VENDOR_METHODS = {} _DEFAULT_RETURN_FIELDS = ('instance_uuid', 'maintenance', 'power_state', 'provision_state', 'uuid', 'name') +# Minimum API version to use for certain verbs +MIN_VERB_VERSIONS = { + # v1.4 added the MANAGEABLE state and two verbs to move nodes into + # and out of that state. Reject requests to do this in older versions + ir_states.VERBS['manage']: 4, + ir_states.VERBS['provide']: 4, + + ir_states.VERBS['inspect']: 6, +} + def hide_fields_in_newer_versions(obj): # if requested version is < 1.3, hide driver_internal_info @@ -83,14 +93,9 @@ def assert_juno_provision_state_name(obj): def check_allow_management_verbs(verb): - # v1.4 added the MANAGEABLE state and two verbs to move nodes into - # and out of that state. Reject requests to do this in older versions - if (pecan.request.version.minor < 4 and - verb in [ir_states.VERBS['manage'], ir_states.VERBS['provide']]): - raise exception.NotAcceptable() - if (pecan.request.version.minor < 6 and - verb == ir_states.VERBS['inspect']): - raise exception.NotAcceptable() + min_version = MIN_VERB_VERSIONS.get(verb) + if min_version is not None and pecan.request.version.minor < min_version: + raise exception.NotAcceptable() class NodePatchType(types.JsonPatchType):