From 119d4a06f3101fed4b562d19729ac4cdbe4341e8 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Tue, 28 Aug 2012 19:25:28 +0100 Subject: [PATCH] heat API : add get_param_value to API utils Add get_param_value helper to common aws API utils Change-Id: I69ab3ed1e34f8691457f3d986b4af06b1d381039 Signed-off-by: Steven Hardy --- heat/api/aws/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/heat/api/aws/utils.py b/heat/api/aws/utils.py index d11dd820c9..39dc01d5a6 100644 --- a/heat/api/aws/utils.py +++ b/heat/api/aws/utils.py @@ -19,6 +19,7 @@ Helper utilities related to the AWS API implementations import re import itertools +from heat.api.aws import exception def format_response(action, response): @@ -89,6 +90,19 @@ def extract_param_list(params, prefix=''): return [dict(kv for di, kv in m) for mi, m in members] +def get_param_value(params, key): + """ + Helper function, looks up an expected parameter in a parsed + params dict and returns the result. If params does not contain + the requested key we raise an exception of the appropriate type + """ + try: + return params[key] + except KeyError: + logger.error("Request does not contain %s parameter!" % key) + raise exception.HeatMissingParameterError(key) + + def reformat_dict_keys(keymap={}, inputdict={}): ''' Utility function for mapping one dict format to another