[libvirt] [PATCH sandbox v5 04/20] Image: Add Hooking Mechanism

Cedric Bosdonnat cbosdonnat at suse.com
Wed Sep 9 11:42:27 UTC 2015


On Tue, 2015-09-08 at 17:29 +0100, Daniel P. Berrange wrote:
> From: Eren Yagdiran <erenyagdiran at gmail.com>
> 
> Define a 'Source' class which is an abstract base to use for
> different template repository sources. Initially there will be
> a docker source which can talk to the Docker repository REST
> API, but others may follow.
> 
> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> ---
>  .gitignore                                |  1 +
>  configure.ac                              |  1 +
>  libvirt-sandbox/image/Makefile.am         |  2 ++
>  libvirt-sandbox/image/cli.py              | 15 ++++++++------
>  libvirt-sandbox/image/sources/Makefile.am |  8 ++++++++
>  libvirt-sandbox/image/sources/Source.py   | 33 +++++++++++++++++++++++++++++++
>  libvirt-sandbox/image/sources/__init__.py |  0
>  7 files changed, 54 insertions(+), 6 deletions(-)
>  mode change 100644 => 100755 libvirt-sandbox/image/cli.py
>  create mode 100644 libvirt-sandbox/image/sources/Makefile.am
>  create mode 100644 libvirt-sandbox/image/sources/Source.py
>  create mode 100644 libvirt-sandbox/image/sources/__init__.py
> 
> diff --git a/.gitignore b/.gitignore
> index f77ea12..390d65c 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -42,6 +42,7 @@ libvirt-sandbox/LibvirtSandbox-1.0.typelib
>  *.lo
>  *.la
>  *.o
> +*.pyc
>  *~
>  libvirt-sandbox/libvirt-sandbox-init-lxc
>  libvirt-sandbox/libvirt-sandbox-init-common
> diff --git a/configure.ac b/configure.ac
> index a8376ca..92d65f4 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -130,6 +130,7 @@ AC_OUTPUT(Makefile
>            libvirt-sandbox/Makefile
>            libvirt-sandbox/tests/Makefile
>            libvirt-sandbox/image/Makefile
> +          libvirt-sandbox/image/sources/Makefile
>            bin/Makefile
>            examples/Makefile
>            docs/Makefile
> diff --git a/libvirt-sandbox/image/Makefile.am b/libvirt-sandbox/image/Makefile.am
> index 7c8da51..344a881 100644
> --- a/libvirt-sandbox/image/Makefile.am
> +++ b/libvirt-sandbox/image/Makefile.am
> @@ -1,4 +1,6 @@
>  
> +SUBDIRS = sources
> +
>  pythonsandboxdir = $(pythondir)/libvirt_sandbox
>  pythonsandbox_DATA = __init__.py
>  
> diff --git a/libvirt-sandbox/image/cli.py b/libvirt-sandbox/image/cli.py
> old mode 100644
> new mode 100755
> index ea04820..3bf7d58
> --- a/libvirt-sandbox/image/cli.py
> +++ b/libvirt-sandbox/image/cli.py
> @@ -1,5 +1,5 @@
>  #!/usr/bin/python -Es
> -#
> +# -*- coding: utf-8 -*-
>  # Authors: Daniel P. Berrange <berrange at redhat.com>
>  #          Eren Yagdiran <erenyagdiran at gmail.com>
>  #
> @@ -32,11 +32,14 @@ import sys
>  import urllib2
>  import subprocess
>  
> -default_index_server = "index.docker.io"
> -default_template_dir = "/var/lib/libvirt/templates"
> -
> -debug = True
> -verbose = True
> +import importlib
> +def dynamic_source_loader(name):
> +    name = name[0].upper() + name[1:]
> +    modname = "libvirt_sandbox.image.sources." + name + "Source"
> +    mod = importlib.import_module(modname)
> +    classname = name + "Source"
> +    classimpl = getattr(mod, classname)
> +    return classimpl()
>  
>  gettext.bindtextdomain("libvirt-sandbox", "/usr/share/locale")
>  gettext.textdomain("libvirt-sandbox")
> diff --git a/libvirt-sandbox/image/sources/Makefile.am b/libvirt-sandbox/image/sources/Makefile.am
> new file mode 100644
> index 0000000..48d0f33
> --- /dev/null
> +++ b/libvirt-sandbox/image/sources/Makefile.am
> @@ -0,0 +1,8 @@
> +
> +pythonimagedir = $(pythondir)/libvirt_sandbox/image/sources
> +pythonimage_DATA = \
> +	__init__.py \
> +	Source.py \
> +	$(NULL)
> +
> +EXTRA_DIST = $(pythonimage_DATA)
> diff --git a/libvirt-sandbox/image/sources/Source.py b/libvirt-sandbox/image/sources/Source.py
> new file mode 100644
> index 0000000..f12b0eb
> --- /dev/null
> +++ b/libvirt-sandbox/image/sources/Source.py
> @@ -0,0 +1,33 @@
> +#!/usr/bin/python
> +# -*- coding: utf-8 -*-
> +#
> +# Copyright (C) 2015 Universitat Politècnica de Catalunya.
> +#
> +# This library is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU Lesser General Public
> +# License as published by the Free Software Foundation; either
> +# version 2.1 of the License, or (at your option) any later version.
> +#
> +# This library is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +# Lesser General Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with this library; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
> +#
> +# Author: Eren Yagdiran <erenyagdiran at gmail.com>
> +
> +from abc import ABCMeta, abstractmethod
> +
> +class Source():
> +    '''The Source class defines the base interface for
> +    all image provider source implementations. An image
> +    provide source is able to download templates from
> +    a repository, convert them to a host specific image
> +    format and report commands used to invoke them.'''
> +
> +    __metaclass__ = ABCMeta
> +    def __init__(self):
> +        pass
> diff --git a/libvirt-sandbox/image/sources/__init__.py b/libvirt-sandbox/image/sources/__init__.py
> new file mode 100644
> index 0000000..e69de29

ACK

--
Cedric




More information about the libvir-list mailing list