[libvirt] [sandbox PATCH 04/11] Image: Add download function

Daniel P. Berrange berrange at redhat.com
Thu Jul 30 10:42:33 UTC 2015


On Thu, Jul 23, 2015 at 03:57:30PM +0000, Eren Yagdiran wrote:
> Refactor download function from virt-sandbox-image to use
> the newly introduced Source abstract class. The docker-specific
> download code is moved to a new DockerSource class.
> ---
>  virt-sandbox-image/sources/DockerSource.py | 193 +++++++++++++++++++++++++++
>  virt-sandbox-image/sources/Source.py       |   5 +
>  virt-sandbox-image/virt-sandbox-image.py   | 202 ++++-------------------------
>  3 files changed, 225 insertions(+), 175 deletions(-)
>  create mode 100644 virt-sandbox-image/sources/DockerSource.py
> 
> diff --git a/virt-sandbox-image/sources/DockerSource.py b/virt-sandbox-image/sources/DockerSource.py
> new file mode 100644
> index 0000000..5bcd613
> --- /dev/null
> +++ b/virt-sandbox-image/sources/DockerSource.py
> @@ -0,0 +1,193 @@
> +#!/usr/bin/python
> +
> +from Source import Source
> +import urllib2
> +import sys
> +import json
> +import traceback
> +import os
> +import subprocess
> +import shutil
> +
> +class DockerSource(Source):
> +    default_index_server = "index.docker.io"
> +    default_template_dir = "/var/lib/libvirt/templates"
> +    default_image_path = "/var/lib/libvirt/templates"
> +    default_disk_format = "qcow2"
> +
> +    www_auth_username = None
> +    www_auth_password = None
> +
> +    def __init__(self,server="index.docker.io",destdir="/var/lib/libvirt/templates"):
> +        self.default_index_server = server
> +        self.default_template_dir = destdir
> +
> +    def download_template(self,**args):
> +        name = args['name']
> +        registry = args['registry'] if args['registry'] is not None else self.default_index_server
> +        username = args['username']
> +        password = args['password']
> +        templatedir = args['templatedir'] if args['templatedir'] is not None else self.default_template_dir
> +        self.__download_template(name,registry,username,password,templatedir)
> +
> +    def __download_template(self,name, server,username,password,destdir):

Double underscores are used by python built-in methods, so you should
avoid them. Convention is to have a single leading _ for private
methods.


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list