提交 1d7e92d1 编写于 作者: A Amador Pahim

vmimage: make the list of providers expandable

Public interface to append custom providers to the list iof providers
so users can add their private/internal image repositories.
Signed-off-by: NAmador Pahim <apahim@redhat.com>
上级 49f4352c
......@@ -322,7 +322,6 @@ def get(name=None, version=None, build=None, arch=None, checksum=None,
if cache_dir is None:
cache_dir = tempfile.gettempdir()
providers_list = list_providers()
provider_args = {}
if version is not None:
provider_args['version'] = version
......@@ -331,7 +330,7 @@ def get(name=None, version=None, build=None, arch=None, checksum=None,
if arch is not None:
provider_args['arch'] = arch
for provider in providers_list:
for provider in IMAGE_PROVIDERS:
if name is None or name == provider.name.lower():
cls = provider(**provider_args)
try:
......@@ -356,3 +355,7 @@ def list_providers():
if (_ != ImageProviderBase and
isinstance(_, type) and
issubclass(_, ImageProviderBase))]
#: List of available providers classes
IMAGE_PROVIDERS = list_providers()
......@@ -57,3 +57,49 @@ external snapshot created out of the base image::
>>> i2 = vmimage.get()
>>> i1.path == i2.path
False
Custom Image Provider
=====================
If you need your own Image Provider, you can extend the
``vmimage.IMAGE_PROVIDERS`` list, including your provider class. For instance,
using the ``vmimage`` utility in an Avocado test, we could add our own provider
with::
from avocado import Test
from avocado.utils import vmimage
class MyProvider(vmimage.ImageProviderBase):
name = 'MyDistro'
def __init__(self, version='[0-9]+', build='[0-9]+.[0-9]+',
arch=os.uname()[4]):
"""
:params version: The regular expression that represents
your distro version numbering.
:params build: The regular expression that represents
your build version numbering.
:params arch: The default architecture to look images for.
"""
super(MyProvider, self).__init__(version, build, arch)
# The URL which contains a list of the distro versions
self.url_versions = 'https://dl.fedoraproject.org/pub/fedora/linux/releases/'
# The URL which contains a list of distro images
self.url_images = self.url_versions + '{version}/CloudImages/{arch}/images/'
# The images naming pattern
self.image_pattern = 'Fedora-Cloud-Base-{version}-{build}.{arch}.qcow2$'
class MyTest(Test):
def setUp(self):
vmimage.IMAGE_PROVIDERS.append(MyProvider)
image = vmimage.get('MyDistro')
...
def test(self):
...
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册