From cc4d766a0476211288d5b67f3647a721159185d3 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 22 Oct 2012 10:25:21 -0700 Subject: Remove database usage from libvirt imagecache module This removes the database instance list operation from the libvirt imagecache module and pushes it up into compute/manager.py. This is a step in the proposed strategy to move db usage out of the virt drivers up into compute/manager.py in support of bp:no-db-compute. Change-Id: I2ea39f14304ed4b44c7ac9650703a5f780411c18 --- nova/virt/driver.py | 2 +- nova/virt/fake.py | 4 ++++ nova/virt/libvirt/driver.py | 4 ++-- nova/virt/libvirt/imagecache.py | 10 ++++------ nova/virt/powervm/driver.py | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/driver.py b/nova/virt/driver.py index 8a7c39fa8..941d46e5e 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -641,7 +641,7 @@ class ComputeDriver(object): # TODO(tr3buchet): update all subclasses and remove this return True - def manage_image_cache(self, context): + def manage_image_cache(self, context, all_instances): """ Manage the driver's local image cache. diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 0996988cd..3527ac19b 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -46,6 +46,10 @@ class FakeInstance(object): class FakeDriver(driver.ComputeDriver): + capabilities = { + "has_imagecache": True, + } + """Fake hypervisor driver""" def __init__(self, read_only=False): diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index fcbc8f688..d9218f629 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -2767,9 +2767,9 @@ class LibvirtDriver(driver.ComputeDriver): out, err = utils.execute('env', 'LANG=C', 'uptime') return out - def manage_image_cache(self, context): + def manage_image_cache(self, context, all_instances): """Manage the local cache of images.""" - self.image_cache_manager.verify_base_images(context) + self.image_cache_manager.verify_base_images(context, all_instances) def _cleanup_remote_migration(self, dest, inst_base, inst_base_resize): """Used only for cleanup in case migrate_disk_and_power_off fails""" diff --git a/nova/virt/libvirt/imagecache.py b/nova/virt/libvirt/imagecache.py index ba350749a..dd4635123 100644 --- a/nova/virt/libvirt/imagecache.py +++ b/nova/virt/libvirt/imagecache.py @@ -29,7 +29,6 @@ import time from nova.compute import task_states from nova.compute import vm_states -from nova import db from nova import flags from nova.openstack.common import cfg from nova.openstack.common import log as logging @@ -127,14 +126,13 @@ class ImageCacheManager(object): ent))): self._store_image(base_dir, ent, original=False) - def _list_running_instances(self, context): + def _list_running_instances(self, context, all_instances): """List running instances (on all compute nodes).""" self.used_images = {} self.image_popularity = {} self.instance_names = set() - instances = db.instance_get_all(context) - for instance in instances: + for instance in all_instances: self.instance_names.add(instance['name']) resize_states = [task_states.RESIZE_PREP, @@ -357,7 +355,7 @@ class ImageCacheManager(object): virtutils.chown(base_file, os.getuid()) os.utime(base_file, None) - def verify_base_images(self, context): + def verify_base_images(self, context, all_instances): """Verify that base images are in a reasonable state.""" # NOTE(mikal): The new scheme for base images is as follows -- an @@ -379,7 +377,7 @@ class ImageCacheManager(object): LOG.debug(_('Verify base images')) self._list_base_images(base_dir) - self._list_running_instances(context) + self._list_running_instances(context, all_instances) # Determine what images are on disk because they're in use for img in self.used_images: diff --git a/nova/virt/powervm/driver.py b/nova/virt/powervm/driver.py index 3b65b5c45..5fc73b4a9 100644 --- a/nova/virt/powervm/driver.py +++ b/nova/virt/powervm/driver.py @@ -169,7 +169,7 @@ class PowerVMDriver(driver.ComputeDriver): """ return False - def manage_image_cache(self, context): + def manage_image_cache(self, context, all_instances): """ Manage the driver's local image cache. -- cgit