Optimized describing of instance.
Change-Id: I4685621ce72ef4004fc05b2628493b8c5b8f0fd5
This commit is contained in:
parent
f946fd8b1e
commit
8a0963aa71
|
@ -332,14 +332,11 @@ class UniversalDescriber(object):
|
|||
|
||||
def describe(self, context, ids=None, names=None, filter=None):
|
||||
self.context = context
|
||||
selective_describe = ids is not None or names is not None
|
||||
self.selective_describe = ids is not None or names is not None
|
||||
self.ids = set(ids or [])
|
||||
self.names = set(names or [])
|
||||
# NOTE(Alex): OS items are retrieved here first to let specific
|
||||
# describer a chance to recreate some default object and refresh
|
||||
# the db items before their retrieval.
|
||||
self.os_items = self.get_os_items()
|
||||
self.items = self.get_db_items()
|
||||
self.os_items = self.get_os_items()
|
||||
formatted_items = []
|
||||
|
||||
self.items_dict = {i['os_id']: i for i in (self.items or [])}
|
||||
|
@ -349,7 +346,7 @@ class UniversalDescriber(object):
|
|||
os_item_id = self.get_id(os_item)
|
||||
item = self.items_dict.get(os_item_id, None)
|
||||
# NOTE(Alex): Filter out items not requested in names or ids
|
||||
if (selective_describe and
|
||||
if (self.selective_describe and
|
||||
not (os_item_name in self.names or
|
||||
(item and item['id'] in self.ids))):
|
||||
continue
|
||||
|
|
|
@ -43,7 +43,7 @@ ec2_opts = [
|
|||
'describe instances'),
|
||||
cfg.StrOpt('default_flavor',
|
||||
default='m1.small',
|
||||
help='A flavor to use as a default instance type'),
|
||||
help='A flavor to use as a default instance type')
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
@ -323,7 +323,13 @@ class InstanceDescriber(common.TaggableItemsDescriber):
|
|||
self.os_volumes = _get_os_volumes(self.context)
|
||||
self.os_flavors = _get_os_flavors(self.context)
|
||||
nova = clients.nova(ec2_context.get_os_admin_context())
|
||||
return nova.servers.list(
|
||||
if self.ids == 1 and len(self.items) == 1:
|
||||
try:
|
||||
return [nova.servers.get(self.items[0]['os_id'])]
|
||||
except nova_exception.NotFound:
|
||||
return []
|
||||
else:
|
||||
return nova.servers.list(
|
||||
search_opts={'all_tenants': True,
|
||||
'project_id': self.context.project_id})
|
||||
|
||||
|
|
|
@ -140,6 +140,7 @@ class SecurityGroupDescriber(common.TaggableItemsDescriber):
|
|||
os_groups = security_group_engine.get_os_groups(self.context)
|
||||
if self.check_and_repair_default_groups(os_groups, self.all_db_items):
|
||||
self.all_db_items = db_api.get_items(self.context, 'sg')
|
||||
self.items = self.get_db_items()
|
||||
os_groups = security_group_engine.get_os_groups(self.context)
|
||||
for os_group in os_groups:
|
||||
os_group['name'] = _translate_group_name(self.context,
|
||||
|
|
|
@ -703,6 +703,8 @@ class InstanceTestCase(base.ApiTestCase):
|
|||
self.nova_admin.servers.list.return_value = [
|
||||
fakes.OSInstance_full(fakes.OS_INSTANCE_1),
|
||||
fakes.OSInstance_full(fakes.OS_INSTANCE_2)]
|
||||
self.nova_admin.servers.get.return_value = (
|
||||
fakes.OSInstance_full(fakes.OS_INSTANCE_1))
|
||||
self.cinder.volumes.list.return_value = [
|
||||
fakes.OSVolume(fakes.OS_VOLUME_1),
|
||||
fakes.OSVolume(fakes.OS_VOLUME_2),
|
||||
|
|
Loading…
Reference in New Issue