Merge "Improve performance of driver's get_available_nodes"

This commit is contained in:
Jenkins
2013年08月17日 01:57:14 +00:00
committed by Gerrit Code Review

View File

@@ -408,10 +408,10 @@ class ComputeManager(manager.SchedulerDependentManager):
def _get_resource_tracker(self, nodename):
rt = self._resource_tracker_dict.get(nodename)
if not rt:
if nodename not in self.driver.get_available_nodes():
if not self.driver.node_is_available(nodename):
raise exception.NovaException(
_("%s is not a valid node managed by this "
"compute host.") % nodename)
_("%s is not a valid node managed by this "
"compute host.") % nodename)
rt = resource_tracker.ResourceTracker(self.host,
self.driver,
@@ -426,8 +426,7 @@ class ComputeManager(manager.SchedulerDependentManager):
instance_uuid,
**kwargs)
if (instance_ref['host'] == self.host and
instance_ref['node'] in self.driver.get_available_nodes()):
self.driver.node_is_available(instance_ref['node'])):
rt = self._get_resource_tracker(instance_ref.get('node'))
rt.update_usage(context, instance_ref)
@@ -792,7 +791,7 @@ class ComputeManager(manager.SchedulerDependentManager):
def pre_start_hook(self, **kwargs):
"""After the service is initialized, but before we fully bring
the service up by listening on RPC queues, make sure to update
our available resources.
our available resources (and indirectly our available nodes).
"""
self.update_available_resource(nova.context.get_admin_context())
@@ -1063,7 +1062,7 @@ class ComputeManager(manager.SchedulerDependentManager):
security_groups = []
if node is None:
node = self.driver.get_available_nodes()[0]
node = self.driver.get_available_nodes(refresh=True)[0]
LOG.debug(_("No node specified, defaulting to %s"), node)
network_info = None
@@ -2705,7 +2704,7 @@ class ComputeManager(manager.SchedulerDependentManager):
"""
if node is None:
node = self.driver.get_available_nodes()[0]
node = self.driver.get_available_nodes(refresh=True)[0]
LOG.debug(_("No node specified, defaulting to %s"), node)
with self._error_out_instance_on_exception(context, instance['uuid'],

View File

@@ -905,7 +905,7 @@ class ComputeDriver(object):
"""
raise NotImplementedError()
def get_available_nodes(self):
def get_available_nodes(self, refresh=False):
"""Returns nodenames of all nodes managed by the compute service.
This method is for multi compute-nodes support. If a driver supports
@@ -913,11 +913,18 @@ class ComputeDriver(object):
by the service. Otherwise, this method should return
[hypervisor_hostname].
"""
stats = self.get_host_stats(refresh=True)
stats = self.get_host_stats(refresh=refresh)
if not isinstance(stats, list):
stats = [stats]
return [s['hypervisor_hostname'] for s in stats]
def node_is_available(self, nodename):
"""Return whether this compute service manages a particular node."""
if nodename in self.get_available_nodes():
return True
# Refresh and check again.
return nodename in self.get_available_nodes(refresh=True)
def get_per_instance_usage(self):
"""Get information about instance resource usage.

View File

@@ -440,7 +440,7 @@ class FakeDriver(driver.ComputeDriver):
def get_volume_connector(self, instance):
return {'ip': '127.0.0.1', 'initiator': 'fake', 'host': 'fakehost'}
def get_available_nodes(self):
def get_available_nodes(self, refresh=False):
return _FAKE_NODES
def instance_on_disk(self, instance):

View File

@@ -4094,7 +4094,7 @@ class HostState(object):
If 'refresh' is True, run update the stats first.
"""
if refresh:
if refresh or not self._stats:
self.update_status()
return self._stats

View File

@@ -140,7 +140,7 @@ class PowerVMOperator(object):
def get_host_stats(self, refresh=False):
"""Return currently known host stats."""
if refresh:
if refresh or not self._host_stats:
self._update_host_stats()
return self._host_stats

View File

@@ -95,7 +95,7 @@ class HostState(object):
"""Return the current state of the host. If 'refresh' is
True, run the update first.
"""
if refresh:
if refresh or not self._stats:
self.update_status()
return self._stats
@@ -158,7 +158,7 @@ class VCState(object):
"""Return the current state of the host. If 'refresh' is
True, run the update first.
"""
if refresh:
if refresh or not self._stats:
self.update_status()
return self._stats

View File

@@ -138,7 +138,7 @@ class HostState(object):
"""Return the current state of the host. If 'refresh' is
True, run the update first.
"""
if refresh:
if refresh or not self._stats:
self.update_status()
return self._stats
Reference in New Issue
openstack/nova
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.