]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat API : add get_param_value to API utils
authorSteven Hardy <shardy@redhat.com>
Tue, 28 Aug 2012 18:25:28 +0000 (19:25 +0100)
committerSteven Hardy <shardy@redhat.com>
Thu, 30 Aug 2012 12:58:38 +0000 (13:58 +0100)
Add get_param_value helper to common aws API utils

Change-Id: I69ab3ed1e34f8691457f3d986b4af06b1d381039
Signed-off-by: Steven Hardy <shardy@redhat.com>
heat/api/aws/utils.py

index d11dd820c9c630f994f31675e075de3a162b1f31..39dc01d5a679f51386973a214dadeda3b9a940bc 100644 (file)
@@ -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