Rename imagebackend arguments.

Rename function arguments to something which more clearly indicates
their purpose. No functional changes.

Change-Id: Iedbc5477ac54527b60c520fd7c774e608adb07c0
This commit is contained in:
Michael Still 2012-09-03 20:49:45 +10:00
parent ca6505ef66
commit 23987c19c4
5 changed files with 37 additions and 38 deletions

View File

@ -34,11 +34,11 @@ class Backend(object):
size, *args, **kwargs):
pass
def cache(self, fn, fname, size=None, *args, **kwargs):
def cache(self, fetch_func, filename, size=None, *args, **kwargs):
pass
def libvirt_info(self, disk_bus, disk_dev,
device_type, cache_mode):
def libvirt_info(self, disk_bus, disk_dev, device_type,
cache_mode):
info = config.LibvirtConfigGuestDisk()
info.source_type = 'file'
info.source_device = device_type

View File

@ -1882,8 +1882,8 @@ class LibvirtConnTestCase(test.TestCase):
# large disk space.
self.mox.StubOutWithMock(imagebackend.Image, 'cache')
imagebackend.Image.cache(context=mox.IgnoreArg(),
fn=mox.IgnoreArg(),
fname='otherdisk',
fetch_func=mox.IgnoreArg(),
filename='otherdisk',
image_id=123456,
project_id='fake',
size=10737418240L,

View File

@ -286,7 +286,7 @@ class BareMetalDriver(driver.ComputeDriver):
raise NotImplementedError()
@staticmethod
def _cache_image(fn, target, fname, cow=False, *args, **kwargs):
def _cache_image(fetch_func, target, fname, cow=False, *args, **kwargs):
"""Wrapper for a method that creates an image that caches the image.
This wrapper will save the image into a common store and create a
@ -307,11 +307,11 @@ class BareMetalDriver(driver.ComputeDriver):
base = os.path.join(base_dir, fname)
@utils.synchronized(fname)
def call_if_not_exists(base, fn, *args, **kwargs):
def call_if_not_exists(base, fetch_func, *args, **kwargs):
if not os.path.exists(base):
fn(target=base, *args, **kwargs)
fetch_func(target=base, *args, **kwargs)
call_if_not_exists(base, fn, *args, **kwargs)
call_if_not_exists(base, fetch_func, *args, **kwargs)
if cow:
libvirt_utils.create_cow_image(base, target)
@ -351,7 +351,7 @@ class BareMetalDriver(driver.ComputeDriver):
if disk_images['kernel_id']:
fname = disk_images['kernel_id']
self._cache_image(fn=libvirt_utils.fetch_image,
self._cache_image(fetch_func=libvirt_utils.fetch_image,
context=context,
target=basepath('kernel'),
fname=fname,
@ -361,7 +361,7 @@ class BareMetalDriver(driver.ComputeDriver):
project_id=inst['project_id'])
if disk_images['ramdisk_id']:
fname = disk_images['ramdisk_id']
self._cache_image(fn=libvirt_utils.fetch_image,
self._cache_image(fetch_func=libvirt_utils.fetch_image,
context=context,
target=basepath('ramdisk'),
fname=fname,
@ -381,7 +381,7 @@ class BareMetalDriver(driver.ComputeDriver):
else:
root_fname += "_%d" % inst['root_gb']
self._cache_image(fn=libvirt_utils.fetch_image,
self._cache_image(fetch_func=libvirt_utils.fetch_image,
context=context,
target=basepath('root'),
fname=root_fname,

View File

@ -1261,17 +1261,17 @@ class LibvirtDriver(driver.ComputeDriver):
if disk_images['kernel_id']:
fname = disk_images['kernel_id']
raw('kernel').cache(fn=libvirt_utils.fetch_image,
raw('kernel').cache(fetch_func=libvirt_utils.fetch_image,
context=context,
fname=fname,
filename=fname,
image_id=disk_images['kernel_id'],
user_id=instance['user_id'],
project_id=instance['project_id'])
if disk_images['ramdisk_id']:
fname = disk_images['ramdisk_id']
raw('ramdisk').cache(fn=libvirt_utils.fetch_image,
raw('ramdisk').cache(fetch_func=libvirt_utils.fetch_image,
context=context,
fname=fname,
filename=fname,
image_id=disk_images['ramdisk_id'],
user_id=instance['user_id'],
project_id=instance['project_id'])
@ -1286,9 +1286,9 @@ class LibvirtDriver(driver.ComputeDriver):
if not self._volume_in_mapping(self.default_root_device,
block_device_info):
image('disk').cache(fn=libvirt_utils.fetch_image,
image('disk').cache(fetch_func=libvirt_utils.fetch_image,
context=context,
fname=root_fname,
filename=root_fname,
size=size,
image_id=disk_images['image_id'],
user_id=instance['user_id'],
@ -1305,8 +1305,8 @@ class LibvirtDriver(driver.ComputeDriver):
ephemeral_gb,
instance["os_type"])
size = ephemeral_gb * 1024 * 1024 * 1024
image('disk.local').cache(fn=fn,
fname=fname,
image('disk.local').cache(fetch_func=fn,
filename=fname,
size=size,
ephemeral_size=ephemeral_gb)
else:
@ -1320,8 +1320,8 @@ class LibvirtDriver(driver.ComputeDriver):
fname = "ephemeral_%s_%s_%s" % (eph['num'],
eph['size'],
instance["os_type"])
image(_get_eph_disk(eph)).cache(fn=fn,
fname=fname,
image(_get_eph_disk(eph)).cache(fetch_func=fn,
fileman=fname,
size=size,
ephemeral_size=eph['size'])
@ -1336,8 +1336,8 @@ class LibvirtDriver(driver.ComputeDriver):
if swap_mb > 0:
size = swap_mb * 1024 * 1024
image('disk.swap').cache(fn=self._create_swap,
fname="swap_%s" % swap_mb,
image('disk.swap').cache(fetch_func=self._create_swap,
filename="swap_%s" % swap_mb,
size=size,
swap_mb=swap_mb)
@ -2548,9 +2548,9 @@ class LibvirtDriver(driver.ComputeDriver):
image = self.image_backend.image(instance['name'],
instance_disk,
FLAGS.libvirt_images_type)
image.cache(fn=libvirt_utils.fetch_image,
image.cache(fetch_func=libvirt_utils.fetch_image,
context=ctxt,
fname=cache_name,
filename=cache_name,
image_id=instance['image_ref'],
user_id=instance['user_id'],
project_id=instance['project_id'],

View File

@ -99,31 +99,31 @@ class Image(object):
info.source_path = self.path
return info
def cache(self, fn, fname, size=None, *args, **kwargs):
def cache(self, fetch_func, filename, size=None, *args, **kwargs):
"""Creates image from template.
Ensures that template and image not already exists.
Ensures that base directory exists.
Synchronizes on template fetching.
:fn: function, that creates template.
Should accept `target` argument.
:fname: Template name
:fetch_func: Function that creates the base image
Should accept `target` argument.
:filename: Name of the file in the image directory
:size: Size of created image in bytes (optional)
"""
@utils.synchronized(fname, external=True, lock_path=self.lock_path)
@utils.synchronized(filename, external=True, lock_path=self.lock_path)
def call_if_not_exists(target, *args, **kwargs):
if not os.path.exists(target):
fn(target=target, *args, **kwargs)
fetch_func(target=target, *args, **kwargs)
if not os.path.exists(self.path):
base_dir = os.path.join(FLAGS.instances_path, '_base')
if not os.path.exists(base_dir):
utils.ensure_tree(base_dir)
base = os.path.join(base_dir, fname)
base = os.path.join(base_dir, filename)
self.create_image(call_if_not_exists, base, size,
*args, **kwargs)
*args, **kwargs)
class Raw(Image):
@ -177,8 +177,8 @@ class Qcow2(Image):
class Lvm(Image):
@staticmethod
def escape(fname):
return fname.replace('_', '__')
def escape(filename):
return filename.replace('_', '__')
def __init__(self, instance, name):
super(Lvm, self).__init__("block", "raw", is_block_dev=True)
@ -237,8 +237,7 @@ class Backend(object):
'default': Qcow2 if use_cow else Raw
}
def image(self, instance, name,
image_type=None):
def image(self, instance, name, image_type=None):
"""Constructs image for selected backend
:instance: Instance name.