def invoke(self, context): try: method = getattr(self.controller, ec2utils.camelcase_to_underscore(self.action)) except AttributeError: LOG.exception('Unsupported API request: action = %(action)s', {'action': self.action}) raise exception.InvalidRequest() args = ec2utils.dict_from_dotted_str(self.args.items()) def convert_dicts_to_lists(args): if not isinstance(args, dict): return args for key in args.keys(): # NOTE(vish): Turn numeric dict keys into lists # NOTE(Alex): Turn "value"-only dict keys into values if isinstance(args[key], dict): if args[key] == {}: continue first_subkey = next(six.iterkeys(args[key])) if first_subkey.isdigit(): s = args[key] args[key] = [convert_dicts_to_lists(s[k]) for k in sorted(s)] elif (first_subkey == 'value' and len(args[key]) == 1): args[key] = args[key]['value'] return args args = convert_dicts_to_lists(args) result = method(context, **args) return self._render_response(result, context.request_id)
def invoke(self, context): try: method = getattr(self.controller, ec2utils.camelcase_to_underscore(self.action)) except AttributeError: LOG.exception(_('Unsupported API request: action = %(action)s'), {'action': self.action}) raise exception.InvalidRequest() args = ec2utils.dict_from_dotted_str(self.args.items()) def convert_dicts_to_lists(args): if not isinstance(args, dict): return args for key in args.keys(): # NOTE(vish): Turn numeric dict keys into lists # NOTE(Alex): Turn "value"-only dict keys into values if isinstance(args[key], dict): if args[key] == {}: continue first_subkey = next(six.iterkeys(args[key])) if first_subkey.isdigit(): s = args[key] args[key] = [ convert_dicts_to_lists(s[k]) for k in sorted(s) ] elif (first_subkey == 'value' and len(args[key]) == 1): args[key] = args[key]['value'] return args args = convert_dicts_to_lists(args) result = method(context, **args) return self._render_response(result, context.request_id)