diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-03-03 20:06:21 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-03-03 20:06:21 +0000 |
| commit | 587e03962f99300c089a1fe99aef567931a4c8ea (patch) | |
| tree | 080224e53765197edb3370e977f0927efd42f3fd /nova/compute | |
| parent | a9be29baefafd3d7f80a098cce7226c1db2c1834 (diff) | |
| parent | e03a3df8869ad5303aaba0f006c17d0927fa6dab (diff) | |
Merge "Refactor compute manager _get_instances_by_driver"
Diffstat (limited to 'nova/compute')
| -rwxr-xr-x | nova/compute/manager.py | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 619316e9e..9979187f9 100755 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -388,21 +388,14 @@ class ComputeManager(manager.SchedulerDependentManager): """Return a list of instance records that match the instances found on the hypervisor. """ - local_instances = [] try: - # Try to find all local instances by uuid. - # FIXME(comstud): Would be nice to consolidate this into - # a single query to nova-conductor. - for uuid in self.driver.list_instance_uuids(): - try: - instance = self.conductor_api.instance_get_by_uuid( - context, uuid) - local_instances.append(instance) - except exception.InstanceNotFound as e: - LOG.error(_('Instance %(uuid)s found in the ' - 'hypervisor, but not in the database'), - locals()) - continue + driver_uuids = self.driver.list_instance_uuids() + local_instances = self.conductor_api.instance_get_all_by_filters( + context, {'uuid': driver_uuids}) + local_instance_uuids = [inst['uuid'] for inst in local_instances] + for uuid in set(driver_uuids) - set(local_instance_uuids): + LOG.error(_('Instance %(uuid)s found in the hypervisor, but ' + 'not in the database'), locals()) return local_instances except NotImplementedError: pass @@ -410,9 +403,9 @@ class ComputeManager(manager.SchedulerDependentManager): # The driver doesn't support uuids listing, so we'll have # to brute force. driver_instances = self.driver.list_instances() - all_instances = self.conductor_api.instance_get_all(context) - name_map = dict([(instance['name'], instance) - for instance in all_instances]) + instances = self.conductor_api.instance_get_all_by_host(context, + self.host) + name_map = dict((instance['name'], instance) for instance in instances) local_instances = [] for driver_instance in driver_instances: instance = name_map.get(driver_instance) |
