~cbehrens/nova/search-api

« back to all changes in this revision

Viewing changes to nova/scheduler/api.py

compute_api.get_all should be able to recurse zones (bug 744217).
Also, allow to build more than one instance at once with zone_aware_scheduler types.
Other cleanups with regards to zone aware scheduler...
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
162
162
                    _wrap_method(_process, func), zone_list)]
163
163
 
164
164
 
165
 
def _issue_novaclient_command(nova, zone, collection, method_name, item_id):
 
165
def _issue_novaclient_command(nova, zone, collection,
 
166
        method_name, *args, **kwargs):
166
167
    """Use novaclient to issue command to a single child zone.
167
 
       One of these will be run in parallel for each child zone."""
 
168
       One of these will be run in parallel for each child zone.
 
169
    """
168
170
    manager = getattr(nova, collection)
169
 
    result = None
 
171
 
 
172
    # NOTE(comstud): This is not ideal, but we have to do this based on
 
173
    # how novaclient is implemented right now.
 
174
    # 'find' is special cased as novaclient requires kwargs for it to
 
175
    # filter on a 'get_all'.
 
176
    # Every other method first needs to do a 'get' on the first argument
 
177
    # passed, which should be a UUID.  If it's 'get' itself that we want,
 
178
    # we just return the result.  Otherwise, we next call the real method
 
179
    # that's wanted... passing other arguments that may or may not exist.
 
180
    if method_name in ['find', 'findall']:
 
181
        try:
 
182
            return getattr(manager, method_name)(**kwargs)
 
183
        except novaclient.NotFound:
 
184
            url = zone.api_url
 
185
            LOG.debug(_("%(collection)s.%(method_name)s didn't find "
 
186
                    "anything matching '%(kwargs)s' on '%(url)s'" %
 
187
                    locals()))
 
188
            return None
 
189
 
 
190
    args = list(args)
 
191
    # pop off the UUID to look up
 
192
    item = args.pop(0)
170
193
    try:
171
 
        try:
172
 
            result = manager.get(int(item_id))
173
 
        except ValueError, e:
174
 
            result = manager.find(name=item_id)
 
194
        result = manager.get(item)
175
195
    except novaclient.NotFound:
176
196
        url = zone.api_url
177
 
        LOG.debug(_("%(collection)s '%(item_id)s' not found on '%(url)s'" %
 
197
        LOG.debug(_("%(collection)s '%(item)s' not found on '%(url)s'" %
178
198
                                                locals()))
179
199
        return None
180
200
 
181
 
    if method_name.lower() not in ['get', 'find']:
182
 
        result = getattr(result, method_name)()
 
201
    if method_name.lower() != 'get':
 
202
        # if we're doing something other than 'get', call it passing args.
 
203
        result = getattr(result, method_name)(*args, **kwargs)
183
204
    return result
184
205
 
185
206
 
186
 
def wrap_novaclient_function(f, collection, method_name, item_id):
187
 
    """Appends collection, method_name and item_id to the incoming
 
207
def wrap_novaclient_function(f, collection, method_name, *args, **kwargs):
 
208
    """Appends collection, method_name and arguments to the incoming
188
209
    (nova, zone) call from child_zone_helper."""
189
210
    def inner(nova, zone):
190
 
        return f(nova, zone, collection, method_name, item_id)
 
211
        return f(nova, zone, collection, method_name, *args, **kwargs)
191
212
 
192
213
    return inner
193
214
 
220
241
           the wrapped method. (This ensures that zone-local code can
221
242
           continue to use integer IDs).
222
243
 
223
 
        4. If the item was not found, we delgate the call to a child zone
 
244
        4. If the item was not found, we delegate the call to a child zone
224
245
           using the UUID.
225
246
    """
226
247
    def __init__(self, method_name):