~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/api/ec2/apirequest.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-01-21 11:48:06 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110121114806-v8fvnnl6az4m4ohv
Tags: upstream-2011.1~bzr597
ImportĀ upstreamĀ versionĀ 2011.1~bzr597

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
APIRequest class
21
21
"""
22
22
 
23
 
import logging
24
23
import re
25
24
# TODO(termie): replace minidom with etree
26
25
from xml.dom import minidom
27
26
 
28
 
_log = logging.getLogger("api")
29
 
_log.setLevel(logging.DEBUG)
 
27
from nova import log as logging
 
28
 
 
29
LOG = logging.getLogger("nova.api.request")
30
30
 
31
31
 
32
32
_c2u = re.compile('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))')
83
83
 
84
84
 
85
85
class APIRequest(object):
86
 
    def __init__(self, controller, action):
 
86
    def __init__(self, controller, action, args):
87
87
        self.controller = controller
88
88
        self.action = action
 
89
        self.args = args
89
90
 
90
 
    def send(self, context, **kwargs):
 
91
    def invoke(self, context):
91
92
        try:
92
93
            method = getattr(self.controller,
93
94
                             _camelcase_to_underscore(self.action))
94
95
        except AttributeError:
95
 
            _error = ('Unsupported API request: controller = %s,'
96
 
                      'action = %s') % (self.controller, self.action)
97
 
            _log.warning(_error)
 
96
            _error = _('Unsupported API request: controller = %s,'
 
97
                       'action = %s') % (self.controller, self.action)
 
98
            LOG.exception(_error)
98
99
            # TODO: Raise custom exception, trap in apiserver,
99
100
            #       and reraise as 400 error.
100
101
            raise Exception(_error)
101
102
 
102
103
        args = {}
103
 
        for key, value in kwargs.items():
 
104
        for key, value in self.args.items():
104
105
            parts = key.split(".")
105
106
            key = _camelcase_to_underscore(parts[0])
106
107
            if isinstance(value, str) or isinstance(value, unicode):
142
143
 
143
144
        response = xml.toxml()
144
145
        xml.unlink()
145
 
        _log.debug(response)
 
146
        LOG.debug(response)
146
147
        return response
147
148
 
148
149
    def _render_dict(self, xml, el, data):
151
152
                val = data[key]
152
153
                el.appendChild(self._render_data(xml, key, val))
153
154
        except:
154
 
            _log.debug(data)
 
155
            LOG.debug(data)
155
156
            raise
156
157
 
157
158
    def _render_data(self, xml, el_name, data):