162
162
_wrap_method(_process, func), zone_list)]
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.
168
170
manager = getattr(nova, collection)
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']:
182
return getattr(manager, method_name)(**kwargs)
183
except novaclient.NotFound:
185
LOG.debug(_("%(collection)s.%(method_name)s didn't find "
186
"anything matching '%(kwargs)s' on '%(url)s'" %
191
# pop off the UUID to look up
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'" %
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)
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)