Re: [libvirt] [sandbox 06/11] virt-sandbox-image: move DockerSource _format_disk to Source

2015-09-23 Thread Daniel P. Berrange
On Wed, Sep 23, 2015 at 09:53:36AM +0200, Cédric Bosdonnat wrote:
> Formatting a disk is a generic operation that will be needed by other
> sources, at least a virt-builder one.
> ---
>  libvirt-sandbox/image/sources/DockerSource.py | 14 +-
>  libvirt-sandbox/image/sources/Source.py   | 16 
>  2 files changed, 17 insertions(+), 13 deletions(-)

ACK

> diff --git a/libvirt-sandbox/image/sources/Source.py 
> b/libvirt-sandbox/image/sources/Source.py
> index 20f4af0..444baa3 100644
> --- a/libvirt-sandbox/image/sources/Source.py
> +++ b/libvirt-sandbox/image/sources/Source.py
> @@ -21,6 +21,7 @@
>  # Author: Eren Yagdiran 
>  
>  from abc import ABCMeta, abstractmethod
> +import subprocess
>  
>  class Source():
>  '''The Source class defines the base interface for
> @@ -114,3 +115,18 @@ class Source():
>  cleanup.
>  """
>  pass
> +
> +
> +# Utility functions to share between the sources.
> +
> +def format_disk(self,disk,format,connect):
> +cmd = ['virt-sandbox']
> +if connect is not None:
> +cmd.append("-c")
> +cmd.append(connect)
> +cmd.append("-p")
> +params = ['--disk=file:disk_image=%s,format=%s' %(disk,format),
> +  '/sbin/mkfs.ext3',

This reminds me we should switch to mkfs.ext4 to be consistent
with our previous switch to ext4 mount by default.

> +  '/dev/disk/by-tag/disk_image']
> +cmd = cmd + params
> +subprocess.call(cmd)

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 :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [sandbox 06/11] virt-sandbox-image: move DockerSource _format_disk to Source

2015-09-23 Thread Cédric Bosdonnat
Formatting a disk is a generic operation that will be needed by other
sources, at least a virt-builder one.
---
 libvirt-sandbox/image/sources/DockerSource.py | 14 +-
 libvirt-sandbox/image/sources/Source.py   | 16 
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/libvirt-sandbox/image/sources/DockerSource.py 
b/libvirt-sandbox/image/sources/DockerSource.py
index 6c02cc3..41df7a7 100644
--- a/libvirt-sandbox/image/sources/DockerSource.py
+++ b/libvirt-sandbox/image/sources/DockerSource.py
@@ -261,7 +261,7 @@ class DockerSource(Source):
 subprocess.call(cmd)
 
 if parentImage is None:
-self._format_disk(templateImage,format,connect)
+self.format_disk(templateImage,format,connect)
 
 self._extract_tarballs(templatedir + "/" + imagetagid + 
"/template.",format,connect)
 parentImage = templateImage
@@ -299,18 +299,6 @@ class DockerSource(Source):
 imagetagid = parent
 return imagelist
 
-def _format_disk(self,disk,format,connect):
-cmd = ['virt-sandbox']
-if connect is not None:
-cmd.append("-c")
-cmd.append(connect)
-cmd.append("-p")
-params = ['--disk=file:disk_image=%s,format=%s' %(disk,format),
-  '/sbin/mkfs.ext3',
-  '/dev/disk/by-tag/disk_image']
-cmd = cmd + params
-subprocess.call(cmd)
-
 def _extract_tarballs(self,directory,format,connect):
 tarfile = directory + "tar.gz"
 diskfile = directory + "qcow2"
diff --git a/libvirt-sandbox/image/sources/Source.py 
b/libvirt-sandbox/image/sources/Source.py
index 20f4af0..444baa3 100644
--- a/libvirt-sandbox/image/sources/Source.py
+++ b/libvirt-sandbox/image/sources/Source.py
@@ -21,6 +21,7 @@
 # Author: Eren Yagdiran 
 
 from abc import ABCMeta, abstractmethod
+import subprocess
 
 class Source():
 '''The Source class defines the base interface for
@@ -114,3 +115,18 @@ class Source():
 cleanup.
 """
 pass
+
+
+# Utility functions to share between the sources.
+
+def format_disk(self,disk,format,connect):
+cmd = ['virt-sandbox']
+if connect is not None:
+cmd.append("-c")
+cmd.append(connect)
+cmd.append("-p")
+params = ['--disk=file:disk_image=%s,format=%s' %(disk,format),
+  '/sbin/mkfs.ext3',
+  '/dev/disk/by-tag/disk_image']
+cmd = cmd + params
+subprocess.call(cmd)
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list