[libvirt] [sandbox PATCH v4 03/21] Image: Add Hooking Mechanism

2015-08-28 Thread Eren Yagdiran
-1301  
USA
+#
+# Author: Eren Yagdiran erenyagdi...@gmail.com
+
+from abc import ABCMeta, abstractmethod
+
+class Source():
+__metaclass__ = ABCMeta
+def __init__(self):
+pass
diff --git a/virt-sandbox-image/sources/__init__.py 
b/virt-sandbox-image/sources/__init__.py
new file mode 100644
index 000..df8603b
--- /dev/null
+++ b/virt-sandbox-image/sources/__init__.py
@@ -0,0 +1,26 @@
+#!/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 erenyagdi...@gmail.com
+#
+
+import os
+import glob
+modules = glob.glob(os.path.dirname(__file__)+/*.py)
+__all__ = [ os.path.basename(f)[:-3] for f in modules]
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
old mode 100644
new mode 100755
index a9cb0ff..fa9e1c8
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -1,5 +1,5 @@
 #!/usr/bin/python -Es
-#
+# -*- coding: utf-8 -*-
 # Authors: Daniel P. Berrange berra...@redhat.com
 #  Eren Yagdiran erenyagdi...@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 = 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)
-- 
2.1.0

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

[libvirt] [sandbox PATCH v4 10/21] Image: Add get_command function to Source

2015-08-28 Thread Eren Yagdiran
Provide a way to know how a template can be started depending on the used source
DockerSource will need to parse the topmost config file in order to find the 
igniter command
---
 virt-sandbox-image/sources/DockerSource.py | 14 ++
 virt-sandbox-image/sources/Source.py   |  4 
 2 files changed, 18 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 760ba6c..3e0362b 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -29,6 +29,15 @@ import os
 import subprocess
 import shutil
 
+class DockerConfParser():
+
+def __init__(self,jsonfile):
+with open(jsonfile) as json_file:
+self.json_data = json.load(json_file)
+def getRunCommand(self):
+cmd = self.json_data['container_config']['Cmd'][2]
+return cmd[cmd.index('') + 1:cmd.rindex('')]
+
 class DockerSource(Source):
 
 www_auth_username = None
@@ -363,5 +372,10 @@ class DockerSource(Source):
 parent = None
 imagetagid = parent
 
+def get_command(self,configfile):
+configParser = DockerConfParser(configfile)
+commandToRun = configParser.getRunCommand()
+return commandToRun
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index d66e61e..9daf62d 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -37,3 +37,7 @@ class Source():
 @abstractmethod
 def delete_template(self,**args):
   pass
+
+@abstractmethod
+def get_command(self,**args):
+  pass
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 07/21] Image: Add download function

2015-08-28 Thread Eren Yagdiran
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/Makefile.am |   1 +
 virt-sandbox-image/sources/DockerSource.py | 214 +
 virt-sandbox-image/sources/Source.py   |   4 +
 virt-sandbox-image/virt-sandbox-image.py   | 204 +--
 4 files changed, 251 insertions(+), 172 deletions(-)
 create mode 100644 virt-sandbox-image/sources/DockerSource.py

diff --git a/virt-sandbox-image/Makefile.am b/virt-sandbox-image/Makefile.am
index 5ab4d2e..8188c80 100644
--- a/virt-sandbox-image/Makefile.am
+++ b/virt-sandbox-image/Makefile.am
@@ -8,6 +8,7 @@ install-data-local:
$(INSTALL) -m 0755 $(srcdir)/virt-sandbox-image.py 
$(DESTDIR)$(pkgpythondir)
$(INSTALL) -m 0644 $(srcdir)/sources/__init__.py 
$(DESTDIR)$(pkgpythondir)/sources
$(INSTALL) -m 0644 $(srcdir)/sources/Source.py 
$(DESTDIR)$(pkgpythondir)/sources
+   $(INSTALL) -m 0644 $(srcdir)/sources/DockerSource.py 
$(DESTDIR)$(pkgpythondir)/sources
 
 uninstall-local:
rm -f $(DESTDIR)$(pkgpythondir)
diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
new file mode 100644
index 000..f3cf5f3
--- /dev/null
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -0,0 +1,214 @@
+#!/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 erenyagdi...@gmail.com
+#
+
+from Source import Source
+import urllib2
+import sys
+import json
+import traceback
+import os
+import subprocess
+import shutil
+
+class DockerSource(Source):
+
+www_auth_username = None
+www_auth_password = None
+
+def __init__(self):
+self.default_index_server = index.docker.io
+
+def _check_cert_validate(self):
+major = sys.version_info.major
+SSL_WARNING = SSL certificates couldn't be validated by default. You 
need to have 2.7.9/3.4.3 or higher
+SSL_WARNING +=\nSee https://bugs.python.org/issue22417\n;
+py2_7_9_hexversion = 34015728
+py3_4_3_hexversion = 50594800
+if  (major == 2 and sys.hexversion  py2_7_9_hexversion) or (major == 
3 and sys.hexversion  py3_4_3_hexversion):
+sys.stderr.write(SSL_WARNING)
+
+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']
+self._download_template(name,registry,username,password,templatedir)
+
+def _download_template(self,name, server,username,password,destdir):
+
+if username is not None:
+self.www_auth_username = username
+self.www_auth_password = password
+
+self._check_cert_validate()
+tag = latest
+offset = name.find(':')
+if offset != -1:
+tag = name[offset + 1:]
+name = name[0:offset]
+try:
+(data, res) = self._get_json(server, /v1/repositories/ + name + 
/images,
+   {X-Docker-Token: true})
+except urllib2.HTTPError, e:
+raise ValueError([Image '%s' does not exist % name])
+
+registryserver = res.info().getheader('X-Docker-Endpoints')
+token = res.info().getheader('X-Docker-Token')
+checksums = {}
+for layer in data:
+pass
+(data, res) = self._get_json(registryserver, /v1/repositories/ + 
name + /tags,
+   { Authorization: Token  + token })
+
+cookie = res.info().getheader('Set-Cookie')
+
+if not tag in data:
+raise ValueError([Tag '%s' does not exist for image '%s' % (tag, 
name)])
+imagetagid = data[tag]
+
+(data, res) = self._get_json(registryserver, /v1/images/ + 
imagetagid + /ancestry,
+   { Authorization: Token +token })
+
+if data[0] != imagetagid:
+raise ValueError([Expected first layer id '%s' to match image id

[libvirt] [sandbox PATCH v4 02/21] Fix virt-sandbox-image

2015-08-28 Thread Eren Yagdiran
Authentication fix for Docker REST API.
---
 virt-sandbox-image/virt-sandbox-image.py | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 4f5443b..a9cb0ff 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -1,8 +1,10 @@
 #!/usr/bin/python -Es
 #
 # Authors: Daniel P. Berrange berra...@redhat.com
+#  Eren Yagdiran erenyagdi...@gmail.com
 #
 # Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2015 Universitat Polit??cnica de Catalunya.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -166,7 +168,7 @@ def download_template(name, server, destdir):
 # or more parents, in a linear stack. Here we are getting the list
 # of layers for the image with the tag we used.
 (data, res) = get_json(registryserver, /v1/images/ + imagetagid + 
/ancestry,
-   { Cookie: cookie })
+   { Authorization: Token  + token })
 
 if data[0] != imagetagid:
 raise ValueError([Expected first layer id '%s' to match image id 
'%s',
@@ -188,9 +190,9 @@ def download_template(name, server, destdir):
 if not os.path.exists(jsonfile) or not os.path.exists(datafile):
 # The '/json' URL gives us some metadata about the layer
 res = save_data(registryserver, /v1/images/ + layerid + 
/json,
-{ Cookie: cookie }, jsonfile)
+{ Authorization: Token  + token }, 
jsonfile)
 createdFiles.append(jsonfile)
-layersize = int(res.info().getheader(x-docker-size))
+layersize = int(res.info().getheader(Content-Length))
 
 datacsum = None
 if layerid in checksums:
@@ -199,7 +201,7 @@ def download_template(name, server, destdir):
 # and the '/layer' URL is the actual payload, provided
 # as a tar.gz archive
 save_data(registryserver, /v1/images/ + layerid + /layer,
-  { Cookie: cookie }, datafile, datacsum, layersize)
+  { Authorization: Token  + token }, datafile, 
datacsum, layersize)
 createdFiles.append(datafile)
 
 # Strangely the 'json' data for a layer doesn't include
-- 
2.1.0

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

[libvirt] [sandbox PATCH v4 12/21] Image: Add check_connect function

2015-08-28 Thread Eren Yagdiran
Check if user-specified connect argument is valid
---
 virt-sandbox-image/virt-sandbox-image.py | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index d6b682f..c46abd4 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -122,6 +122,12 @@ def create(args):
 except Exception,e:
 print Create Error %s % str(e)
 
+def check_connect(connectstr):
+supportedDrivers = ['lxc:///','qemu:///session','qemu:///system']
+if not connectstr in supportedDrivers:
+raise ValueError(%s is not supported by Virt-sandbox %connectstr)
+return True
+
 def requires_name(parser):
 parser.add_argument(name,
 help=_(name of the template))
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 16/21] Image: Add Volume Support

2015-08-28 Thread Eren Yagdiran
Volumes let user to map host-paths into sandbox. Docker containers
need volumes for data persistence.
---
 virt-sandbox-image/sources/DockerSource.py | 12 
 virt-sandbox-image/sources/Source.py   |  4 
 virt-sandbox-image/virt-sandbox-image.py   | 22 ++
 3 files changed, 38 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 87fbcf3..1022107 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -28,6 +28,7 @@ import traceback
 import os
 import subprocess
 import shutil
+import collections
 
 class DockerConfParser():
 
@@ -37,6 +38,13 @@ class DockerConfParser():
 def getRunCommand(self):
 cmd = self.json_data['container_config']['Cmd'][2]
 return cmd[cmd.index('') + 1:cmd.rindex('')]
+def getVolumes(self):
+volumes = self.json_data['container_config']['Volumes']
+volumelist = []
+if isinstance(volumes,collections.Iterable):
+  for key,value in volumes.iteritems():
+volumelist.append(key)
+return volumelist
 
 class DockerSource(Source):
 
@@ -393,5 +401,9 @@ class DockerSource(Source):
 commandToRun = configParser.getRunCommand()
 return commandToRun
 
+def get_volume(self,configfile):
+configParser = DockerConfParser(configfile)
+return configParser.getVolumes()
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 9a3da59..8cc508e 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -45,3 +45,7 @@ class Source():
 @abstractmethod
 def get_disk(self,**args):
   pass
+
+@abstractmethod
+def get_volume(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 058738a..79f8d8c 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -132,6 +132,7 @@ def check_connect(connectstr):
 
 def run(args):
 try:
+global storage_dir
 if args.connect is not None:
 check_connect(args.connect)
 source = dynamic_source_loader(args.source)
@@ -150,6 +151,25 @@ def run(args):
 if networkArgs is not None:
 params.append('-N')
 params.append(networkArgs)
+allVolumes = source.get_volume(configfile)
+volumeArgs = args.volume
+if volumeArgs is not None:
+allVolumes = allVolumes + volumeArgs
+for volume in allVolumes:
+volumeSplit = volume.split(:)
+volumelen = len(volumeSplit)
+if volumelen == 2:
+hostPath = volumeSplit[0]
+guestPath = volumeSplit[1]
+elif volumelen == 1:
+guestPath = volumeSplit[0]
+hostPath = storage_dir + guestPath
+if not os.path.exists(hostPath):
+os.makedirs(hostPath)
+else:
+pass
+params.append(--mount)
+params.append(host-bind:%s=%s %(guestPath,hostPath))
 params.append('--')
 params.append(commandToRun)
 cmd = cmd + params
@@ -234,6 +254,8 @@ def gen_run_args(subparser):
 help=_(Igniter command for image))
 parser.add_argument(-n,--network,
 help=_(Network params for running template))
+parser.add_argument(-v,--volume,action=append,
+help=_(Volume params for running template))
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 04/21] Image: virt-sandbox-image default dir constants

2015-08-28 Thread Eren Yagdiran
Conflicts:
virt-sandbox-image/virt-sandbox-image.py
---
 virt-sandbox-image/virt-sandbox-image.py | 8 
 1 file changed, 8 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index fa9e1c8..55aea6a 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -32,6 +32,14 @@ import sys
 import urllib2
 import subprocess
 
+default_privileged_template_dir = /var/lib/libvirt/templates
+default_home_dir = os.environ['HOME']
+default_unprivileged_template_dir = default_home_dir + 
/.local/share/libvirt/templates
+default_privileged_storage_dir = default_privileged_template_dir + /storage
+default_unprivileged_storage_dir = default_unprivileged_template_dir + 
/storage
+debug = False
+verbose = False
+
 import importlib
 def dynamic_source_loader(name):
 name = name[0].upper() + name[1:]
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 05/21] Image: Discard caching bytecode

2015-08-28 Thread Eren Yagdiran
---
 virt-sandbox-image/virt-sandbox-image.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 55aea6a..9e98bf2 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -40,6 +40,8 @@ default_unprivileged_storage_dir = 
default_unprivileged_template_dir + /storage
 debug = False
 verbose = False
 
+sys.dont_write_byte_code = True
+
 import importlib
 def dynamic_source_loader(name):
 name = name[0].upper() + name[1:]
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 15/21] Image: Add network support

2015-08-28 Thread Eren Yagdiran
Virt-sandbox-image will pass exact network arguments to virt-sandbox
---
 virt-sandbox-image/virt-sandbox-image.py | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index c182874..058738a 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -145,9 +145,13 @@ def run(args):
 if args.connect is not None:
 cmd.append(-c)
 cmd.append(args.connect)
-params = ['-m','host-image:/=%s,format=%s' %(diskfile,format),
-   '--',
-   commandToRun]
+params = ['-m','host-image:/=%s,format=%s' %(diskfile,format)]
+networkArgs = args.network
+if networkArgs is not None:
+params.append('-N')
+params.append(networkArgs)
+params.append('--')
+params.append(commandToRun)
 cmd = cmd + params
 subprocess.call(cmd)
 subprocess.call([rm, -rf, diskfile])
@@ -228,6 +232,8 @@ def gen_run_args(subparser):
 help=_(Template directory for saving templates))
 parser.add_argument(-i,--igniter,
 help=_(Igniter command for image))
+parser.add_argument(-n,--network,
+help=_(Network params for running template))
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 06/21] Image: Add check_writable and runtime resolver

2015-08-28 Thread Eren Yagdiran
These helper functions are for selecting right directories according
to running user privileges
---
 virt-sandbox-image/virt-sandbox-image.py | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 9e98bf2..5917dd6 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -32,6 +32,8 @@ import sys
 import urllib2
 import subprocess
 
+template_dir = None
+storage_dir = None
 default_privileged_template_dir = /var/lib/libvirt/templates
 default_home_dir = os.environ['HOME']
 default_unprivileged_template_dir = default_home_dir + 
/.local/share/libvirt/templates
@@ -40,6 +42,29 @@ default_unprivileged_storage_dir = 
default_unprivileged_template_dir + /storage
 debug = False
 verbose = False
 
+def check_dir_writable(path):
+if not os.access(path,os.W_OK):
+return False
+return True
+
+def runtime_dir_resolver():
+global default_privileged_template_dir
+global default_privileged_storage_dir
+global default_unprivileged_template_dir
+global default_unprivileged_storage_dir
+global template_dir
+global storage_dir
+if(check_dir_writable(default_privileged_template_dir)):
+template_dir = default_privileged_template_dir
+storage_dir = default_privileged_storage_dir
+return
+template_dir = default_unprivileged_template_dir
+storage_dir = default_unprivileged_storage_dir
+if not os.path.exists(template_dir):
+os.makedirs(template_dir)
+if not os.path.exists(storage_dir):
+os.makedirs(storage_dir)
+
 sys.dont_write_byte_code = True
 
 import importlib
@@ -380,8 +405,8 @@ def gen_create_args(subparser):
 parser.set_defaults(func=create)
 
 if __name__ == '__main__':
+runtime_dir_resolver()
 parser = argparse.ArgumentParser(description='Sandbox Container Image 
Tool')
-
 subparser = parser.add_subparsers(help=_(commands))
 gen_download_args(subparser)
 gen_delete_args(subparser)
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 11/21] Image: Add run args

2015-08-28 Thread Eren Yagdiran
Commandline parameters for running a template
---
 virt-sandbox-image/virt-sandbox-image.py | 13 +
 1 file changed, 13 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 1da5150..d6b682f 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -178,6 +178,18 @@ def gen_create_args(subparser):
 help=_(format format for image))
 parser.set_defaults(func=create)
 
+def gen_run_args(subparser):
+parser = subparser.add_parser(run,
+  help=_(Run a already built image))
+requires_name(parser)
+requires_source(parser)
+requires_connect(parser)
+parser.add_argument(-t,--template-dir,
+help=_(Template directory for saving templates))
+parser.add_argument(-i,--igniter,
+help=_(Igniter command for image))
+parser.set_defaults(func=run)
+
 if __name__ == '__main__':
 runtime_dir_resolver()
 parser = argparse.ArgumentParser(description='Sandbox Container Image 
Tool')
@@ -185,6 +197,7 @@ if __name__ == '__main__':
 gen_download_args(subparser)
 gen_delete_args(subparser)
 gen_create_args(subparser)
+gen_run_args(subparser)
 
 try:
 args = parser.parse_args()
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 18/21] Add config for environment variables

2015-08-28 Thread Eren Yagdiran
Add the config gobject to store custom environment variables.
This will allow creating custom environment variables on a sandbox
with a parameter formatted like --env key1=val1

Add testcase for custom environment variables

make check now includes testcase for environment variables
---
 libvirt-sandbox/libvirt-sandbox-config.c | 171 ++-
 libvirt-sandbox/libvirt-sandbox-config.h |  13 +++
 libvirt-sandbox/libvirt-sandbox.sym  |   6 ++
 libvirt-sandbox/tests/test-config.c  |  10 ++
 4 files changed, 199 insertions(+), 1 deletion(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-config.c 
b/libvirt-sandbox/libvirt-sandbox-config.c
index 2506072..780d174 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -64,6 +64,7 @@ struct _GVirSandboxConfigPrivate
 GList *networks;
 GList *mounts;
 GList *disks;
+GHashTable* envs;
 
 gchar *secLabel;
 gboolean secDynamic;
@@ -276,6 +277,8 @@ static void gvir_sandbox_config_finalize(GObject *object)
 g_list_foreach(priv-networks, (GFunc)g_object_unref, NULL);
 g_list_free(priv-networks);
 
+g_hash_table_destroy(priv-envs);
+
 g_list_foreach(priv-disks, (GFunc)g_object_unref, NULL);
 g_list_free(priv-disks);
 
@@ -483,6 +486,7 @@ static void gvir_sandbox_config_init(GVirSandboxConfig 
*config)
 priv-arch = g_strdup(uts.machine);
 priv-secDynamic = TRUE;
 
+priv-envs = g_hash_table_new(g_str_hash, g_str_equal);
 priv-uid = geteuid();
 priv-gid = getegid();
 priv-username = g_strdup(g_get_user_name());
@@ -1144,6 +1148,102 @@ gboolean 
gvir_sandbox_config_has_networks(GVirSandboxConfig *config)
 return priv-networks ? TRUE : FALSE;
 }
 
+/**
+ * gvir_sandbox_config_add_env:
+ * @config: (transfer none): the sandbox config
+ * @key: (transfer none): the key for environment variable
+ * @value: (transfer none): the value for environment variable
+ *
+ * Adds a new environment variable to the sandbox
+ *
+ */
+void gvir_sandbox_config_add_env(GVirSandboxConfig *config,
+ gchar *k,
+ gchar *v)
+{
+gchar * key = g_strdup(k);
+gchar * value = g_strdup(v);
+GVirSandboxConfigPrivate *priv = config-priv;
+g_hash_table_insert(priv-envs,key,value);
+}
+
+/**
+ * gvir_sandbox_config_get_envs:
+ * @config: (transfer none): the sandbox config
+ *
+ * Retrieves the hashtable of custom environment variables in the sandbox
+ *
+ * Returns: (transfer full) (element-type gchar gchar): the hashtable of 
environment variables
+ */
+GHashTable *gvir_sandbox_config_get_envs(GVirSandboxConfig *config)
+{
+GVirSandboxConfigPrivate *priv = config-priv;
+return priv-envs;
+}
+
+/**
+ * gvir_sandbox_config_add_env_strv:
+ * @config: (transfer none): the sandbox config
+ * @envs: (transfer none)(array zero-terminated=1): the list of environment 
variables
+ *
+ * Parses @envs whose elements are in the format KEY=VALUE
+ *
+ * --env KEY=VALUE
+ */
+gboolean gvir_sandbox_config_add_env_strv(GVirSandboxConfig *config,
+  gchar **envs,
+  GError **error)
+{
+gsize i = 0;
+while (envs  envs[i]) {
+if (!gvir_sandbox_config_add_env_opts(config,
+   envs[i],
+   error))
+return FALSE;
+i++;
+}
+return TRUE;
+}
+
+/**
+ * gvir_sandbox_config_add_env_opts:
+ * @config: (transfer none): the sandbox config
+ * @env: (transfer none): the env config
+ *
+ * Parses @env in the format KEY=VALUE
+ * creating #GVirSandboxConfigEnv instances for each element. For
+ * example
+ *
+ * --env KEY=VALUE
+ */
+
+gboolean gvir_sandbox_config_add_env_opts(GVirSandboxConfig *config,
+   const char *opt,
+   GError **error)
+{
+gchar *tmp = NULL;
+gchar *key = NULL;
+gchar *value = NULL;
+
+if (!(tmp = g_strdup(opt)))
+return FALSE;
+
+key  = strchr(tmp, '=');
+
+if (!key) {
+g_set_error(error, GVIR_SANDBOX_CONFIG_ERROR, 0,
+_(Wrong environment format on %s), opt);
+return FALSE;
+}
+
+*key = '\0';
+value = key + 1;
+
+gvir_sandbox_config_add_env(config, tmp, value);
+
+g_free(tmp);
+return TRUE;
+}
 
 /**
  * gvir_sandbox_config_add_disk:
@@ -1163,7 +1263,6 @@ void gvir_sandbox_config_add_disk(GVirSandboxConfig 
*config,
 priv-disks = g_list_append(priv-disks, dsk);
 }
 
-
 /**
  * gvir_sandbox_config_get_disks:
  * @config: (transfer none): the sandbox config
@@ -1172,6 +1271,7 @@ void gvir_sandbox_config_add_disk(GVirSandboxConfig 
*config,
  *
  * Returns: (transfer full) (element-type GVirSandboxConfigMount): the list of 
disks
  */
+
 GList *gvir_sandbox_config_get_disks(GVirSandboxConfig *config)
 {
  

[libvirt] [sandbox PATCH v4 21/21] Image: Add custom environment support

2015-08-28 Thread Eren Yagdiran
Any custom key=value pair can be used as a custom environment variable
in virt-sandbox-image.
e.g virt-sandbox-image run ubuntu /var/lib/libvirt/templates -c lxc:/// -i 
/bin/bash -e key1=val1
---
 virt-sandbox-image/sources/DockerSource.py | 10 ++
 virt-sandbox-image/sources/Source.py   |  4 
 virt-sandbox-image/virt-sandbox-image.py   | 17 +
 3 files changed, 31 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 1022107..122e595 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -45,6 +45,12 @@ class DockerConfParser():
   for key,value in volumes.iteritems():
 volumelist.append(key)
 return volumelist
+def getEnvs(self):
+lst = self.json_data['container_config']['Env']
+if lst is not None and isinstance(lst,list):
+  return lst
+else:
+  return []
 
 class DockerSource(Source):
 
@@ -405,5 +411,9 @@ class DockerSource(Source):
 configParser = DockerConfParser(configfile)
 return configParser.getVolumes()
 
+def get_env(self,configfile):
+configParser = DockerConfParser(configfile)
+return configParser.getEnvs()
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 8cc508e..c467ce2 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -49,3 +49,7 @@ class Source():
 @abstractmethod
 def get_volume(self,**args):
   pass
+
+@abstractmethod
+def get_env(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 79f8d8c..285e99c 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -170,6 +170,20 @@ def run(args):
 pass
 params.append(--mount)
 params.append(host-bind:%s=%s %(guestPath,hostPath))
+
+allEnvs = source.get_env(configfile)
+envArgs = args.env
+if envArgs is not None:
+allEnvs = allEnvs + envArgs
+for env in allEnvs:
+envsplit = env.split(=)
+envlen = len(envsplit)
+if envlen == 2:
+params.append(--env)
+params.append(env)
+else:
+pass
+
 params.append('--')
 params.append(commandToRun)
 cmd = cmd + params
@@ -256,6 +270,9 @@ def gen_run_args(subparser):
 help=_(Network params for running template))
 parser.add_argument(-v,--volume,action=append,
 help=_(Volume params for running template))
+parser.add_argument(-e,--env,action=append,
+help=_(Environment params for running template))
+
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 09/21] Image: Add delete function

2015-08-28 Thread Eren Yagdiran
Refactoring delete function from virt-sandbox-image to DockerSource. Delete 
function
can delete templates by name.
---
 virt-sandbox-image/sources/DockerSource.py | 53 +++
 virt-sandbox-image/sources/Source.py   |  4 +++
 virt-sandbox-image/virt-sandbox-image.py   | 58 --
 3 files changed, 64 insertions(+), 51 deletions(-)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 09eea85..760ba6c 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -310,5 +310,58 @@ class DockerSource(Source):
 cmd = cmd + params
 subprocess.call(cmd)
 
+def delete_template(self,**args):
+imageusage = {}
+imageparent = {}
+imagenames = {}
+name = args['name']
+destdir = args['templatedir']
+destdir = destdir if destdir is not None else default_template_dir
+imagedirs = os.listdir(destdir)
+for imagetagid in imagedirs:
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+with open(indexfile,r) as f:
+index = json.load(f)
+imagenames[index[name]] = imagetagid
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+with open(jsonfile,r) as f:
+template = json.load(f)
+
+parent = template.get(parent,None)
+if parent:
+if parent not in imageusage:
+imageusage[parent] = []
+imageusage[parent].append(imagetagid)
+imageparent[imagetagid] = parent
+
+
+if not name in imagenames:
+raise ValueError([Image %s does not exist locally %name])
+
+imagetagid = imagenames[name]
+while imagetagid != None:
+debug(Remove %s\n % imagetagid)
+parent = imageparent.get(imagetagid,None)
+
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+   os.remove(indexfile)
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+os.remove(jsonfile)
+datafile = destdir + / + imagetagid + /template.tar.gz
+if os.path.exists(datafile):
+os.remove(datafile)
+imagedir = destdir + / + imagetagid
+shutil.rmtree(imagedir)
+
+if parent:
+if len(imageusage[parent]) != 1:
+debug(Parent %s is shared\n % parent)
+parent = None
+imagetagid = parent
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 6ac08dc..d66e61e 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -33,3 +33,7 @@ class Source():
 @abstractmethod
 def create_template(self,**args):
   pass
+
+@abstractmethod
+def delete_template(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 745401c..1da5150 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -94,55 +94,6 @@ def debug(msg):
 def info(msg):
 sys.stdout.write(msg)
 
-def delete_template(name, destdir):
-imageusage = {}
-imageparent = {}
-imagenames = {}
-imagedirs = os.listdir(destdir)
-for imagetagid in imagedirs:
-indexfile = destdir + / + imagetagid + /index.json
-if os.path.exists(indexfile):
-with open(indexfile, r) as f:
-index = json.load(f)
-imagenames[index[name]] = imagetagid
-jsonfile = destdir + / + imagetagid + /template.json
-if os.path.exists(jsonfile):
-with open(jsonfile, r) as f:
-template = json.load(f)
-
-parent = template.get(parent, None)
-if parent:
-if parent not in imageusage:
-imageusage[parent] = []
-imageusage[parent].append(imagetagid)
-imageparent[imagetagid] = parent
-
-if not name in imagenames:
-raise ValueError([Image %s does not exist locally % name])
-
-imagetagid = imagenames[name]
-while imagetagid != None:
-debug(Remove %s\n %  imagetagid)
-parent = imageparent.get(imagetagid, None)
-
-indexfile = destdir + / + imagetagid + /index.json
-if os.path.exists(indexfile):
-os.remove(indexfile)
-jsonfile = destdir + / + imagetagid + /template.json
-if os.path.exists(jsonfile):
-os.remove(jsonfile)
-datafile = destdir + / + imagetagid + 

[libvirt] [sandbox PATCH v4 13/21] Image: Add get_disk function to Source

2015-08-28 Thread Eren Yagdiran
Provide a way to know which disk image to use for the sandbox depending on the 
used source
DockerSource will need to locate the topmost disk image among all the layers 
images
---
 virt-sandbox-image/sources/DockerSource.py | 16 
 virt-sandbox-image/sources/Source.py   |  4 
 virt-sandbox-image/virt-sandbox-image.py   |  9 +
 3 files changed, 29 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 3e0362b..87fbcf3 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -372,6 +372,22 @@ class DockerSource(Source):
 parent = None
 imagetagid = parent
 
+def get_disk(self,**args):
+name = args['name']
+destdir = args['templatedir']
+sandboxid = args['id']
+imageList = self._get_image_list(name,destdir)
+toplayer = imageList[0]
+diskfile = destdir + / + toplayer + /template.qcow2
+configfile = destdir + / + toplayer + /template.json
+tempfile = destdir + / + toplayer + / + sandboxid + .qcow2
+cmd = [qemu-img,create,-q,-f,qcow2]
+cmd.append(-o)
+cmd.append(backing_fmt=qcow2,backing_file=%s % diskfile)
+cmd.append(tempfile)
+subprocess.call(cmd)
+return (tempfile,configfile)
+
 def get_command(self,configfile):
 configParser = DockerConfParser(configfile)
 commandToRun = configParser.getRunCommand()
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 9daf62d..9a3da59 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -41,3 +41,7 @@ class Source():
 @abstractmethod
 def get_command(self,**args):
   pass
+
+@abstractmethod
+def get_disk(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index c46abd4..a73619c 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -31,6 +31,8 @@ import shutil
 import sys
 import urllib2
 import subprocess
+import random
+import string
 
 template_dir = None
 storage_dir = None
@@ -128,6 +130,12 @@ def check_connect(connectstr):
 raise ValueError(%s is not supported by Virt-sandbox %connectstr)
 return True
 
+def requires_id(parser):
+randomid = ''.join(random.choice(string.lowercase) for i in range(10))
+parser.add_argument(-d,--id,
+default=randomid,
+help=_(id of the running sandbox))
+
 def requires_name(parser):
 parser.add_argument(name,
 help=_(name of the template))
@@ -187,6 +195,7 @@ def gen_create_args(subparser):
 def gen_run_args(subparser):
 parser = subparser.add_parser(run,
   help=_(Run a already built image))
+requires_id(parser)
 requires_name(parser)
 requires_source(parser)
 requires_connect(parser)
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 14/21] Image: Add run function

2015-08-28 Thread Eren Yagdiran
Run an already-built template
If there is no execution command specified by user, source.get_command will
find the command to invoke
---
 virt-sandbox-image/virt-sandbox-image.py | 25 +
 1 file changed, 25 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index a73619c..c182874 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -130,6 +130,31 @@ def check_connect(connectstr):
 raise ValueError(%s is not supported by Virt-sandbox %connectstr)
 return True
 
+def run(args):
+try:
+if args.connect is not None:
+check_connect(args.connect)
+source = dynamic_source_loader(args.source)
+diskfile,configfile = 
source.get_disk(name=args.name,templatedir=args.template_dir,id=args.id)
+
+format = qcow2
+commandToRun = args.igniter
+if commandToRun is None:
+commandToRun = source.get_command(configfile)
+cmd = ['virt-sandbox']
+if args.connect is not None:
+cmd.append(-c)
+cmd.append(args.connect)
+params = ['-m','host-image:/=%s,format=%s' %(diskfile,format),
+   '--',
+   commandToRun]
+cmd = cmd + params
+subprocess.call(cmd)
+subprocess.call([rm, -rf, diskfile])
+
+except Exception,e:
+print Run Error %s % str(e)
+
 def requires_id(parser):
 randomid = ''.join(random.choice(string.lowercase) for i in range(10))
 parser.add_argument(-d,--id,
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 08/21] Image: Refactor create function

2015-08-28 Thread Eren Yagdiran
Move the docker-related code to the DockerSource and use
the Source mechanism
---
 virt-sandbox-image/sources/DockerSource.py | 100 +
 virt-sandbox-image/sources/Source.py   |   4 ++
 virt-sandbox-image/virt-sandbox-image.py   |  76 +-
 3 files changed, 121 insertions(+), 59 deletions(-)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index f3cf5f3..09eea85 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -210,5 +210,105 @@ class DockerSource(Source):
 debug(FAIL %s\n % str(e))
 raise
 
+def create_template(self,**args):
+name = args['name']
+connect = args['connect']
+templatedir = args['templatedir']
+format = args['format']
+format = format if format is not None else self.default_disk_format
+
+self._create_template(name,
+   connect,
+   templatedir,
+   format)
+
+def _create_template(self,name,connect,templatedir,format):
+self._check_disk_format(format)
+imagelist = self._get_image_list(name,templatedir)
+imagelist.reverse()
+
+parentImage = None
+for imagetagid in imagelist:
+templateImage = templatedir + / + imagetagid + /template. + 
format
+cmd = [qemu-img,create,-f,qcow2]
+if parentImage is not None:
+cmd.append(-o)
+cmd.append(backing_fmt=qcow2,backing_file=%s % parentImage)
+cmd.append(templateImage)
+if parentImage is None:
+cmd.append(10G)
+subprocess.call(cmd)
+
+if parentImage is None:
+self._format_disk(templateImage,format,connect)
+
+self._extract_tarballs(templatedir + / + imagetagid + 
/template.,format,connect)
+parentImage = templateImage
+
+
+def _check_disk_format(self,format):
+supportedFormats = ['qcow2']
+if not format in supportedFormats:
+raise ValueError([Unsupported image format %s % format])
+
+def _get_image_list(self,name,destdir):
+imageparent = {}
+imagenames = {}
+imagedirs = os.listdir(destdir)
+for imagetagid in imagedirs:
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+with open(indexfile,r) as f:
+index = json.load(f)
+imagenames[index[name]] = imagetagid
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+with open(jsonfile,r) as f:
+template = json.load(f)
+parent = template.get(parent,None)
+if parent:
+imageparent[imagetagid] = parent
+if not name in imagenames:
+raise ValueError([Image %s does not exist locally %name])
+imagetagid = imagenames[name]
+imagelist = []
+while imagetagid != None:
+imagelist.append(imagetagid)
+parent = imageparent.get(imagetagid,None)
+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):
+tempdir = /mnt
+tarfile = directory + tar.gz
+diskfile = directory + qcow2
+cmd = ['virt-sandbox']
+if connect is not None:
+cmd.append(-c)
+cmd.append(connect)
+cmd.append(-p)
+params = ['-m',
+  'host-image:/mnt=%s,format=%s' %(diskfile,format),
+  '--',
+  '/bin/tar',
+  'zxf',
+  '%s' %tarfile,
+  '-C',
+  '/mnt']
+cmd = cmd + params
+subprocess.call(cmd)
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 8751689..6ac08dc 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -29,3 +29,7 @@ class Source():
 @abstractmethod
 def download_template(self,**args):
 pass
+
+@abstractmethod
+def create_template(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 4f371d7..745401c 100755
--- 

[libvirt] [sandbox PATCH v4 01/21] Add virt-sandbox-image

2015-08-28 Thread Eren Yagdiran
From: Daniel P Berrange berra...@redhat.com

virt-sandbox-image.py is a python script that lets you download Docker
images easily. It is a proof of concept code and consumes Docker Rest API.
---
 po/POTFILES.in   |   1 +
 virt-sandbox-image/virt-sandbox-image.py | 394 +++
 2 files changed, 395 insertions(+)
 create mode 100644 virt-sandbox-image/virt-sandbox-image.py

diff --git a/po/POTFILES.in b/po/POTFILES.in
index afcb050..7204112 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,3 +11,4 @@ libvirt-sandbox/libvirt-sandbox-context-interactive.c
 libvirt-sandbox/libvirt-sandbox-init-common.c
 libvirt-sandbox/libvirt-sandbox-rpcpacket.c
 libvirt-sandbox/libvirt-sandbox-util.c
+virt-sandbox-image/virt-sandbox-image.py
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
new file mode 100644
index 000..4f5443b
--- /dev/null
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -0,0 +1,394 @@
+#!/usr/bin/python -Es
+#
+# Authors: Daniel P. Berrange berra...@redhat.com
+#
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+import argparse
+import gettext
+import hashlib
+import json
+import os
+import os.path
+import shutil
+import sys
+import urllib2
+import subprocess
+
+default_index_server = index.docker.io
+default_template_dir = /var/lib/libvirt/templates
+
+debug = True
+verbose = True
+
+gettext.bindtextdomain(libvirt-sandbox, /usr/share/locale)
+gettext.textdomain(libvirt-sandbox)
+try:
+gettext.install(libvirt-sandbox,
+localedir=/usr/share/locale,
+unicode=False,
+codeset = 'utf-8')
+except IOError:
+import __builtin__
+__builtin__.__dict__['_'] = unicode
+
+
+def debug(msg):
+sys.stderr.write(msg)
+
+def info(msg):
+sys.stdout.write(msg)
+
+def get_url(server, path, headers):
+url = https://; + server + path
+debug(  Fetching %s... % url)
+req = urllib2.Request(url=url)
+
+if json:
+req.add_header(Accept, application/json)
+
+for h in headers.keys():
+req.add_header(h, headers[h])
+
+return urllib2.urlopen(req)
+
+def get_json(server, path, headers):
+try:
+res = get_url(server, path, headers)
+data = json.loads(res.read())
+debug(OK\n)
+return (data, res)
+except Exception, e:
+debug(FAIL %s\n % str(e))
+raise
+
+def save_data(server, path, headers, dest, checksum=None, datalen=None):
+try:
+res = get_url(server, path, headers)
+
+csum = None
+if checksum is not None:
+csum = hashlib.sha256()
+
+pattern = [., o, O, o]
+patternIndex = 0
+donelen = 0
+
+with open(dest, w) as f:
+while 1:
+buf = res.read(1024*64)
+if not buf:
+break
+if csum is not None:
+csum.update(buf)
+f.write(buf)
+
+if datalen is not None:
+donelen = donelen + len(buf)
+debug(\x1b[s%s (%5d Kb of %5d Kb)\x1b8 % (
+pattern[patternIndex], (donelen/1024), (datalen/1024)
+))
+patternIndex = (patternIndex + 1) % 4
+
+debug(\x1b[K)
+if csum is not None:
+csumstr = sha256: + csum.hexdigest()
+if csumstr != checksum:
+debug(FAIL checksum '%s' does not match '%s' % (csumstr, 
checksum))
+os.remove(dest)
+raise IOError(Checksum '%s' for data does not match '%s' % 
(csumstr, checksum))
+debug(OK\n)
+return res
+except Exception, e:
+debug(FAIL %s\n % str(e))
+raise
+
+
+def download_template(name, server, destdir):
+tag = latest
+
+offset = name.find(':')
+if offset != -1:
+tag = name[offset + 1:]
+name = name[0:offset]
+
+# First we must ask the index server about the image name. THe
+# index server will return an auth token we can use when talking
+# to the registry server. We need this token even when anonymous
+try:
+(data, res) = get_json(server, /v1/repositories/ + name + /images,
+  

[libvirt] [sandbox PATCH v4 19/21] Add environment parameter to virt-sandbox

2015-08-28 Thread Eren Yagdiran
Allow users to add custom environment variables to their sandbox.
---
 bin/virt-sandbox.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index 195515f..e90b698 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -64,6 +64,7 @@ int main(int argc, char **argv) {
 GError *error = NULL;
 gchar *name = NULL;
 gchar **disks = NULL;
+gchar **envs = NULL;
 gchar **mounts = NULL;
 gchar **includes = NULL;
 gchar *includefile = NULL;
@@ -95,6 +96,8 @@ int main(int argc, char **argv) {
   N_(root directory of the sandbox), DIR },
 { disk, ' ', 0, G_OPTION_ARG_STRING_ARRAY, disks,
   N_(add a disk in the guest), TYPE:TAGNAME=SOURCE,format=FORMAT },
+{ env, 'e', 0, G_OPTION_ARG_STRING_ARRAY, envs,
+  N_(add a environment variable for the sandbox), KEY=VALUE },
 { mount, 'm', 0, G_OPTION_ARG_STRING_ARRAY, mounts,
   N_(mount a filesystem in the guest), TYPE:TARGET=SOURCE },
 { include, 'i', 0, G_OPTION_ARG_STRING_ARRAY, includes,
@@ -185,6 +188,13 @@ int main(int argc, char **argv) {
 gvir_sandbox_config_set_username(cfg, root);
 }
 
+if (envs 
+!gvir_sandbox_config_add_env_strv(cfg, envs, error)) {
+g_printerr(_(Unable to parse custom environment variables: %s\n),
+   error  error-message ? error-message : _(Unknown 
failure));
+goto cleanup;
+}
+
 if (disks 
 !gvir_sandbox_config_add_disk_strv(cfg, disks, error)) {
 g_printerr(_(Unable to parse disks: %s\n),
@@ -329,6 +339,10 @@ inheriting the host's root filesystem.
 NB. CDIR must contain a matching install of the libvirt-sandbox
 package. This restriction may be lifted in a future version.
 
+=item B--env key=value
+
+Sets up a custom environment variable on a running sandbox.
+
 =item B--disk TYPE:TAGNAME=SOURCE,format=FORMAT
 
 Sets up a disk inside the sandbox by using BSOURCE with a symlink named as 
BTAGNAME
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 17/21] Image: man file for virt-sandbox-image

2015-08-28 Thread Eren Yagdiran
+
+=head1 SEE ALSO
+
+Cvirt-sandbox(8)
+
+=head1 FILES
+
+Container content will be stored in subdirectories of
+/var/lib/libvirt/templates, by default.
+
+=head1 AUTHORS
+
+Daniel P. Berrange d...@berrange.com
+
+Eren Yagdiran erenyagdi...@gmail.com
+
+=head1 COPYRIGHT
+
+Copyright (C) 2013 Red Hat, Inc.
+Copyright (C) 2015 Universitat Politecnica de Catalunya.
+
+=head1 LICENSE
+
+virt-sandbox-image is distributed under the terms of the GNU LGPL v2+.
+This is free software; see the source for copying conditions.
+There is NO warranty; not even for MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE
-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 00/21] *** virt-sandbox-image v4 ***

2015-08-28 Thread Eren Yagdiran
Hi,

Running sandbox now has its own disk layer.
virt-sandbox now using GHashMap to store key value pairs for environment 
variables
and some minor changes.

Daniel P Berrange (1):
  Add virt-sandbox-image

Eren Yagdiran (20):
  Fix virt-sandbox-image
  Image: Add Hooking Mechanism
  Image: virt-sandbox-image default dir constants
  Image: Discard caching bytecode
  Image: Add check_writable and runtime resolver
  Image: Add download function
  Image: Refactor create function
  Image: Add delete function
  Image: Add get_command function to Source
  Image: Add run args
  Image: Add check_connect function
  Image: Add get_disk function to Source
  Image: Add run function
  Image: Add network support
  Image: Add Volume Support
  Image: man file for virt-sandbox-image
  Add config for environment variables
  Add environment parameter to virt-sandbox
  init-common: Exporting custom environment variables
  Image: Add custom environment support

 .gitignore|   1 +
 bin/Makefile.am   |  21 +-
 bin/virt-sandbox-image.in |   3 +
 bin/virt-sandbox-image.pod| 172 +++
 bin/virt-sandbox.c|  14 +
 configure.ac  |   2 +
 libvirt-sandbox/libvirt-sandbox-config.c  | 171 ++-
 libvirt-sandbox/libvirt-sandbox-config.h  |  13 +
 libvirt-sandbox/libvirt-sandbox-init-common.c |  18 ++
 libvirt-sandbox/libvirt-sandbox.sym   |   6 +
 libvirt-sandbox/tests/test-config.c   |  10 +
 po/POTFILES.in|   1 +
 virt-sandbox-image/Makefile.am|  14 +
 virt-sandbox-image/sources/DockerSource.py| 419 ++
 virt-sandbox-image/sources/Source.py  |  55 
 virt-sandbox-image/sources/__init__.py|  26 ++
 virt-sandbox-image/virt-sandbox-image.py  | 306 +++
 17 files changed, 1247 insertions(+), 5 deletions(-)
 create mode 100644 bin/virt-sandbox-image.in
 create mode 100644 bin/virt-sandbox-image.pod
 create mode 100644 virt-sandbox-image/Makefile.am
 create mode 100644 virt-sandbox-image/sources/DockerSource.py
 create mode 100644 virt-sandbox-image/sources/Source.py
 create mode 100644 virt-sandbox-image/sources/__init__.py
 create mode 100755 virt-sandbox-image/virt-sandbox-image.py

-- 
2.1.0

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


[libvirt] [sandbox PATCH v4 20/21] init-common: Exporting custom environment variables

2015-08-28 Thread Eren Yagdiran
Common-init reads config file and exports custom environment
variables from config file and applies them to the running sandbox.
---
 libvirt-sandbox/libvirt-sandbox-init-common.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c 
b/libvirt-sandbox/libvirt-sandbox-init-common.c
index d35f760..16abf25 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -336,6 +336,21 @@ static gboolean setup_network(GVirSandboxConfig *config, 
GError **error)
 }
 
 
+static gboolean setup_custom_env(GVirSandboxConfig *config, GError **error)
+{
+gboolean ret = FALSE;
+GHashTableIter iter;
+gpointer key, value;
+g_hash_table_iter_init (iter, gvir_sandbox_config_get_envs(config));
+while (g_hash_table_iter_next (iter, key, value)){
+if(setenv(key,value,1)!=0)
+goto cleanup;
+}
+ret = TRUE;
+  cleanup:
+return ret;
+}
+
 static int change_user(const gchar *user,
uid_t uid,
gid_t gid,
@@ -1262,6 +1277,9 @@ int main(int argc, char **argv) {
 if (!setup_disk_tags())
 exit(EXIT_FAILURE);
 
+if (!setup_custom_env(config, error))
+goto error;
+
 if (!setup_network(config, error))
 goto error;
 
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 17/22] Image: man file for virt-sandbox-image

2015-08-18 Thread Eren Yagdiran
+
+=head1 SEE ALSO
+
+Cvirt-sandbox(8)
+
+=head1 FILES
+
+Container content will be stored in subdirectories of
+/var/lib/libvirt/templates, by default.
+
+=head1 AUTHORS
+
+Daniel P. Berrange d...@berrange.com
+
+Eren Yagdiran erenyagdi...@gmail.com
+
+=head1 COPYRIGHT
+
+Copyright (C) 2013 Red Hat, Inc.
+Copyright (C) 2015 Universitat Politecnica de Catalunya.
+
+=head1 LICENSE
+
+virt-sandbox-image is distributed under the terms of the GNU LGPL v2+.
+This is free software; see the source for copying conditions.
+There is NO warranty; not even for MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 00/22] *** Virt-sandbox-image ***

2015-08-18 Thread Eren Yagdiran
V3 Changes:
* License syntax fixed
* Source abstract method get_env fixed
* Discarding byte code generation now resides into a new commit
* Template_dir and storage_dir refactored and runtime resolver is added for 
checking permissions
* -f,--format parameter is refactored. Default is qcow2.
* Ssl warning is now using stderr
* get_disk method in Source now adds another layer with a randomized name


Daniel P Berrange (1):
  Add virt-sandbox-image

Eren Yagdiran (21):
  Fix virt-sandbox-image
  Image: Add Hooking Mechanism
  Image: virt-sandbox-image default dir constants
  Image: Discard caching bytecode
  Image: Add check_writable and runtime resolver
  Image: Add download function
  Image: Refactor create function
  Image: Add delete function
  Image: Add get_command function to Source
  Image: Add run args
  Image: Add check_connect function
  Image: Add get_disk function to Source
  Image: Add run function
  Image: Add network support
  Image: Add Volume Support
  Image: man file for virt-sandbox-image
  Add configuration object for environment variables
  Add environment parameter to virt-sandbox
  Common-init: Exporting custom environment variables
  Add testcase for custom environment variables
  Image: Add custom environment support

 .gitignore|   1 +
 bin/Makefile.am   |  21 +-
 bin/virt-sandbox-image.in |   3 +
 bin/virt-sandbox-image.pod| 172 +++
 bin/virt-sandbox.c|  14 +
 configure.ac  |   2 +
 libvirt-sandbox/Makefile.am   |   2 +
 libvirt-sandbox/libvirt-sandbox-config-all.h  |   1 +
 libvirt-sandbox/libvirt-sandbox-config-env.c  | 199 
 libvirt-sandbox/libvirt-sandbox-config-env.h  |  78 +
 libvirt-sandbox/libvirt-sandbox-config.c  | 187 +++-
 libvirt-sandbox/libvirt-sandbox-config.h  |  12 +
 libvirt-sandbox/libvirt-sandbox-init-common.c |  30 ++
 libvirt-sandbox/libvirt-sandbox.h |   1 +
 libvirt-sandbox/libvirt-sandbox.sym   |   6 +
 libvirt-sandbox/tests/test-config.c   |  10 +
 po/POTFILES.in|   1 +
 virt-sandbox-image/Makefile.am|  14 +
 virt-sandbox-image/sources/DockerSource.py| 421 ++
 virt-sandbox-image/sources/Source.py  |  55 
 virt-sandbox-image/sources/__init__.py|  26 ++
 virt-sandbox-image/virt-sandbox-image.py  | 299 ++
 22 files changed, 1550 insertions(+), 5 deletions(-)
 create mode 100644 bin/virt-sandbox-image.in
 create mode 100644 bin/virt-sandbox-image.pod
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-env.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-env.h
 create mode 100644 virt-sandbox-image/Makefile.am
 create mode 100644 virt-sandbox-image/sources/DockerSource.py
 create mode 100644 virt-sandbox-image/sources/Source.py
 create mode 100644 virt-sandbox-image/sources/__init__.py
 create mode 100755 virt-sandbox-image/virt-sandbox-image.py

-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 11/22] Image: Add run args

2015-08-18 Thread Eren Yagdiran
Commandline parameters for running a template
---
 virt-sandbox-image/virt-sandbox-image.py | 13 +
 1 file changed, 13 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 1da5150..d6b682f 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -178,6 +178,18 @@ def gen_create_args(subparser):
 help=_(format format for image))
 parser.set_defaults(func=create)
 
+def gen_run_args(subparser):
+parser = subparser.add_parser(run,
+  help=_(Run a already built image))
+requires_name(parser)
+requires_source(parser)
+requires_connect(parser)
+parser.add_argument(-t,--template-dir,
+help=_(Template directory for saving templates))
+parser.add_argument(-i,--igniter,
+help=_(Igniter command for image))
+parser.set_defaults(func=run)
+
 if __name__ == '__main__':
 runtime_dir_resolver()
 parser = argparse.ArgumentParser(description='Sandbox Container Image 
Tool')
@@ -185,6 +197,7 @@ if __name__ == '__main__':
 gen_download_args(subparser)
 gen_delete_args(subparser)
 gen_create_args(subparser)
+gen_run_args(subparser)
 
 try:
 args = parser.parse_args()
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 21/22] Add testcase for custom environment variables

2015-08-18 Thread Eren Yagdiran
make check now includes testcase for environment variables
---
 libvirt-sandbox/tests/test-config.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libvirt-sandbox/tests/test-config.c 
b/libvirt-sandbox/tests/test-config.c
index da05187..ac10bab 100644
--- a/libvirt-sandbox/tests/test-config.c
+++ b/libvirt-sandbox/tests/test-config.c
@@ -58,6 +58,13 @@ int main(int argc, char **argv)
 host-bind:/tmp=,
 NULL
 };
+
+ const gchar *envs[] = {
+key1=val1,
+key2=val2,
+NULL
+};
+
 const gchar *disks[] = {
 file:dbdata=/tmp/img.blah,format=qcow2,
 file:cache=/tmp/img.qcow2,
@@ -103,6 +110,9 @@ int main(int argc, char **argv)
 if (!gvir_sandbox_config_add_mount_strv(cfg1, (gchar**)mounts, err))
 goto cleanup;
 
+if (!gvir_sandbox_config_add_env_strv(cfg1, (gchar**)envs, err))
+goto cleanup;
+
 if (!gvir_sandbox_config_add_disk_strv(cfg1, (gchar**)disks, err))
 goto cleanup;
 
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 14/22] Image: Add run function

2015-08-18 Thread Eren Yagdiran
Run an already-built template
If there is no execution command specified by user, source.get_command will
find the command to invoke
---
 virt-sandbox-image/virt-sandbox-image.py | 25 +
 1 file changed, 25 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index c46abd4..278d19a 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -128,6 +128,31 @@ def check_connect(connectstr):
 raise ValueError(%s is not supported by Virt-sandbox %connectstr)
 return True
 
+def run(args):
+try:
+if args.connect is not None:
+check_connect(args.connect)
+source = dynamic_source_loader(args.source)
+diskfile,configfile = 
source.get_disk(name=args.name,templatedir=args.template_dir)
+
+format = qcow2
+commandToRun = args.igniter
+if commandToRun is None:
+commandToRun = source.get_command(configfile)
+cmd = ['virt-sandbox']
+if args.connect is not None:
+cmd.append(-c)
+cmd.append(args.connect)
+params = ['-m','host-image:/=%s,format=%s' %(diskfile,format),
+   '--',
+   commandToRun]
+cmd = cmd + params
+subprocess.call(cmd)
+subprocess.call([rm, -rf, diskfile])
+
+except Exception,e:
+print Run Error %s % str(e)
+
 def requires_name(parser):
 parser.add_argument(name,
 help=_(name of the template))
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 07/22] Image: Add download function

2015-08-18 Thread Eren Yagdiran
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/Makefile.am |   1 +
 virt-sandbox-image/sources/DockerSource.py | 214 +
 virt-sandbox-image/sources/Source.py   |   4 +
 virt-sandbox-image/virt-sandbox-image.py   | 204 +--
 4 files changed, 251 insertions(+), 172 deletions(-)
 create mode 100644 virt-sandbox-image/sources/DockerSource.py

diff --git a/virt-sandbox-image/Makefile.am b/virt-sandbox-image/Makefile.am
index 5ab4d2e..8188c80 100644
--- a/virt-sandbox-image/Makefile.am
+++ b/virt-sandbox-image/Makefile.am
@@ -8,6 +8,7 @@ install-data-local:
$(INSTALL) -m 0755 $(srcdir)/virt-sandbox-image.py 
$(DESTDIR)$(pkgpythondir)
$(INSTALL) -m 0644 $(srcdir)/sources/__init__.py 
$(DESTDIR)$(pkgpythondir)/sources
$(INSTALL) -m 0644 $(srcdir)/sources/Source.py 
$(DESTDIR)$(pkgpythondir)/sources
+   $(INSTALL) -m 0644 $(srcdir)/sources/DockerSource.py 
$(DESTDIR)$(pkgpythondir)/sources
 
 uninstall-local:
rm -f $(DESTDIR)$(pkgpythondir)
diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
new file mode 100644
index 000..f3cf5f3
--- /dev/null
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -0,0 +1,214 @@
+#!/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 erenyagdi...@gmail.com
+#
+
+from Source import Source
+import urllib2
+import sys
+import json
+import traceback
+import os
+import subprocess
+import shutil
+
+class DockerSource(Source):
+
+www_auth_username = None
+www_auth_password = None
+
+def __init__(self):
+self.default_index_server = index.docker.io
+
+def _check_cert_validate(self):
+major = sys.version_info.major
+SSL_WARNING = SSL certificates couldn't be validated by default. You 
need to have 2.7.9/3.4.3 or higher
+SSL_WARNING +=\nSee https://bugs.python.org/issue22417\n;
+py2_7_9_hexversion = 34015728
+py3_4_3_hexversion = 50594800
+if  (major == 2 and sys.hexversion  py2_7_9_hexversion) or (major == 
3 and sys.hexversion  py3_4_3_hexversion):
+sys.stderr.write(SSL_WARNING)
+
+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']
+self._download_template(name,registry,username,password,templatedir)
+
+def _download_template(self,name, server,username,password,destdir):
+
+if username is not None:
+self.www_auth_username = username
+self.www_auth_password = password
+
+self._check_cert_validate()
+tag = latest
+offset = name.find(':')
+if offset != -1:
+tag = name[offset + 1:]
+name = name[0:offset]
+try:
+(data, res) = self._get_json(server, /v1/repositories/ + name + 
/images,
+   {X-Docker-Token: true})
+except urllib2.HTTPError, e:
+raise ValueError([Image '%s' does not exist % name])
+
+registryserver = res.info().getheader('X-Docker-Endpoints')
+token = res.info().getheader('X-Docker-Token')
+checksums = {}
+for layer in data:
+pass
+(data, res) = self._get_json(registryserver, /v1/repositories/ + 
name + /tags,
+   { Authorization: Token  + token })
+
+cookie = res.info().getheader('Set-Cookie')
+
+if not tag in data:
+raise ValueError([Tag '%s' does not exist for image '%s' % (tag, 
name)])
+imagetagid = data[tag]
+
+(data, res) = self._get_json(registryserver, /v1/images/ + 
imagetagid + /ancestry,
+   { Authorization: Token +token })
+
+if data[0] != imagetagid:
+raise ValueError([Expected first layer id '%s' to match image id

[libvirt] [sandbox PATCH v3 08/22] Image: Refactor create function

2015-08-18 Thread Eren Yagdiran
Move the docker-related code to the DockerSource and use
the Source mechanism
---
 virt-sandbox-image/sources/DockerSource.py | 100 +
 virt-sandbox-image/sources/Source.py   |   4 ++
 virt-sandbox-image/virt-sandbox-image.py   |  76 +-
 3 files changed, 121 insertions(+), 59 deletions(-)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index f3cf5f3..09eea85 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -210,5 +210,105 @@ class DockerSource(Source):
 debug(FAIL %s\n % str(e))
 raise
 
+def create_template(self,**args):
+name = args['name']
+connect = args['connect']
+templatedir = args['templatedir']
+format = args['format']
+format = format if format is not None else self.default_disk_format
+
+self._create_template(name,
+   connect,
+   templatedir,
+   format)
+
+def _create_template(self,name,connect,templatedir,format):
+self._check_disk_format(format)
+imagelist = self._get_image_list(name,templatedir)
+imagelist.reverse()
+
+parentImage = None
+for imagetagid in imagelist:
+templateImage = templatedir + / + imagetagid + /template. + 
format
+cmd = [qemu-img,create,-f,qcow2]
+if parentImage is not None:
+cmd.append(-o)
+cmd.append(backing_fmt=qcow2,backing_file=%s % parentImage)
+cmd.append(templateImage)
+if parentImage is None:
+cmd.append(10G)
+subprocess.call(cmd)
+
+if parentImage is None:
+self._format_disk(templateImage,format,connect)
+
+self._extract_tarballs(templatedir + / + imagetagid + 
/template.,format,connect)
+parentImage = templateImage
+
+
+def _check_disk_format(self,format):
+supportedFormats = ['qcow2']
+if not format in supportedFormats:
+raise ValueError([Unsupported image format %s % format])
+
+def _get_image_list(self,name,destdir):
+imageparent = {}
+imagenames = {}
+imagedirs = os.listdir(destdir)
+for imagetagid in imagedirs:
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+with open(indexfile,r) as f:
+index = json.load(f)
+imagenames[index[name]] = imagetagid
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+with open(jsonfile,r) as f:
+template = json.load(f)
+parent = template.get(parent,None)
+if parent:
+imageparent[imagetagid] = parent
+if not name in imagenames:
+raise ValueError([Image %s does not exist locally %name])
+imagetagid = imagenames[name]
+imagelist = []
+while imagetagid != None:
+imagelist.append(imagetagid)
+parent = imageparent.get(imagetagid,None)
+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):
+tempdir = /mnt
+tarfile = directory + tar.gz
+diskfile = directory + qcow2
+cmd = ['virt-sandbox']
+if connect is not None:
+cmd.append(-c)
+cmd.append(connect)
+cmd.append(-p)
+params = ['-m',
+  'host-image:/mnt=%s,format=%s' %(diskfile,format),
+  '--',
+  '/bin/tar',
+  'zxf',
+  '%s' %tarfile,
+  '-C',
+  '/mnt']
+cmd = cmd + params
+subprocess.call(cmd)
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 8751689..6ac08dc 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -29,3 +29,7 @@ class Source():
 @abstractmethod
 def download_template(self,**args):
 pass
+
+@abstractmethod
+def create_template(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 4f371d7..745401c 100755
--- 

[libvirt] [sandbox PATCH v3 06/22] Image: Add check_writable and runtime resolver

2015-08-18 Thread Eren Yagdiran
These helper functions are for selecting right directories according
to running user privileges
---
 virt-sandbox-image/virt-sandbox-image.py | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 9e98bf2..5917dd6 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -32,6 +32,8 @@ import sys
 import urllib2
 import subprocess
 
+template_dir = None
+storage_dir = None
 default_privileged_template_dir = /var/lib/libvirt/templates
 default_home_dir = os.environ['HOME']
 default_unprivileged_template_dir = default_home_dir + 
/.local/share/libvirt/templates
@@ -40,6 +42,29 @@ default_unprivileged_storage_dir = 
default_unprivileged_template_dir + /storage
 debug = False
 verbose = False
 
+def check_dir_writable(path):
+if not os.access(path,os.W_OK):
+return False
+return True
+
+def runtime_dir_resolver():
+global default_privileged_template_dir
+global default_privileged_storage_dir
+global default_unprivileged_template_dir
+global default_unprivileged_storage_dir
+global template_dir
+global storage_dir
+if(check_dir_writable(default_privileged_template_dir)):
+template_dir = default_privileged_template_dir
+storage_dir = default_privileged_storage_dir
+return
+template_dir = default_unprivileged_template_dir
+storage_dir = default_unprivileged_storage_dir
+if not os.path.exists(template_dir):
+os.makedirs(template_dir)
+if not os.path.exists(storage_dir):
+os.makedirs(storage_dir)
+
 sys.dont_write_byte_code = True
 
 import importlib
@@ -380,8 +405,8 @@ def gen_create_args(subparser):
 parser.set_defaults(func=create)
 
 if __name__ == '__main__':
+runtime_dir_resolver()
 parser = argparse.ArgumentParser(description='Sandbox Container Image 
Tool')
-
 subparser = parser.add_subparsers(help=_(commands))
 gen_download_args(subparser)
 gen_delete_args(subparser)
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 15/22] Image: Add network support

2015-08-18 Thread Eren Yagdiran
Virt-sandbox-image will pass exact network arguments to virt-sandbox
---
 virt-sandbox-image/virt-sandbox-image.py | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 278d19a..3ce3a8b 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -143,9 +143,13 @@ def run(args):
 if args.connect is not None:
 cmd.append(-c)
 cmd.append(args.connect)
-params = ['-m','host-image:/=%s,format=%s' %(diskfile,format),
-   '--',
-   commandToRun]
+params = ['-m','host-image:/=%s,format=%s' %(diskfile,format)]
+networkArgs = args.network
+if networkArgs is not None:
+params.append('-N')
+params.append(networkArgs)
+params.append('--')
+params.append(commandToRun)
 cmd = cmd + params
 subprocess.call(cmd)
 subprocess.call([rm, -rf, diskfile])
@@ -219,6 +223,8 @@ def gen_run_args(subparser):
 help=_(Template directory for saving templates))
 parser.add_argument(-i,--igniter,
 help=_(Igniter command for image))
+parser.add_argument(-n,--network,
+help=_(Network params for running template))
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 16/22] Image: Add Volume Support

2015-08-18 Thread Eren Yagdiran
Volumes let user to map host-paths into guest. Docker containers need volumes 
because its
filesystem read-only by default.
---
 virt-sandbox-image/sources/DockerSource.py | 12 
 virt-sandbox-image/sources/Source.py   |  4 
 virt-sandbox-image/virt-sandbox-image.py   | 22 ++
 3 files changed, 38 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 1e7f633..67bcf6b 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -30,6 +30,7 @@ import subprocess
 import shutil
 import random
 import string
+import collections
 
 class DockerConfParser():
 
@@ -39,6 +40,13 @@ class DockerConfParser():
 def getRunCommand(self):
 cmd = self.json_data['container_config']['Cmd'][2]
 return cmd[cmd.index('') + 1:cmd.rindex('')]
+def getVolumes(self):
+volumes = self.json_data['container_config']['Volumes']
+volumelist = []
+if isinstance(volumes,collections.Iterable):
+  for key,value in volumes.iteritems():
+volumelist.append(key)
+return volumelist
 
 class DockerSource(Source):
 
@@ -395,5 +403,9 @@ class DockerSource(Source):
 commandToRun = configParser.getRunCommand()
 return commandToRun
 
+def get_volume(self,configfile):
+configParser = DockerConfParser(configfile)
+return configParser.getVolumes()
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 9a3da59..8cc508e 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -45,3 +45,7 @@ class Source():
 @abstractmethod
 def get_disk(self,**args):
   pass
+
+@abstractmethod
+def get_volume(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 3ce3a8b..e554d8a 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -130,6 +130,7 @@ def check_connect(connectstr):
 
 def run(args):
 try:
+global storage_dir
 if args.connect is not None:
 check_connect(args.connect)
 source = dynamic_source_loader(args.source)
@@ -148,6 +149,25 @@ def run(args):
 if networkArgs is not None:
 params.append('-N')
 params.append(networkArgs)
+allVolumes = source.get_volume(configfile)
+volumeArgs = args.volume
+if volumeArgs is not None:
+allVolumes = allVolumes + volumeArgs
+for volume in allVolumes:
+volumeSplit = volume.split(:)
+volumelen = len(volumeSplit)
+if volumelen == 2:
+hostPath = volumeSplit[0]
+guestPath = volumeSplit[1]
+elif volumelen == 1:
+guestPath = volumeSplit[0]
+hostPath = storage_dir + guestPath
+if not os.path.exists(hostPath):
+os.makedirs(hostPath)
+else:
+pass
+params.append(--mount)
+params.append(host-bind:%s=%s %(guestPath,hostPath))
 params.append('--')
 params.append(commandToRun)
 cmd = cmd + params
@@ -225,6 +245,8 @@ def gen_run_args(subparser):
 help=_(Igniter command for image))
 parser.add_argument(-n,--network,
 help=_(Network params for running template))
+parser.add_argument(-v,--volume,action=append,
+help=_(Volume params for running template))
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 18/22] Add configuration object for environment variables

2015-08-18 Thread Eren Yagdiran
Add the config gobject to store custom environment variables.
This will allow creating custom environment variables on a sandbox
with a parameter formatted like --env key1=val1
---
 libvirt-sandbox/Makefile.am  |   2 +
 libvirt-sandbox/libvirt-sandbox-config-all.h |   1 +
 libvirt-sandbox/libvirt-sandbox-config-env.c | 199 +++
 libvirt-sandbox/libvirt-sandbox-config-env.h |  78 +++
 libvirt-sandbox/libvirt-sandbox-config.c | 187 -
 libvirt-sandbox/libvirt-sandbox-config.h |  12 ++
 libvirt-sandbox/libvirt-sandbox.h|   1 +
 libvirt-sandbox/libvirt-sandbox.sym  |   6 +
 8 files changed, 485 insertions(+), 1 deletion(-)
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-env.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-env.h

diff --git a/libvirt-sandbox/Makefile.am b/libvirt-sandbox/Makefile.am
index 597803e..5383b0d 100644
--- a/libvirt-sandbox/Makefile.am
+++ b/libvirt-sandbox/Makefile.am
@@ -53,6 +53,7 @@ SANDBOX_RPC_FILES = \
 SANDBOX_CONFIG_HEADER_FILES = \
libvirt-sandbox-config.h \
libvirt-sandbox-config-disk.h \
+   libvirt-sandbox-config-env.h \
libvirt-sandbox-config-network.h \
libvirt-sandbox-config-network-address.h \
libvirt-sandbox-config-network-filterref-parameter.h \
@@ -92,6 +93,7 @@ SANDBOX_CONFIG_SOURCE_FILES = \
libvirt-sandbox-util.c \
libvirt-sandbox-config.c \
libvirt-sandbox-config-disk.c \
+   libvirt-sandbox-config-env.c \
libvirt-sandbox-config-network.c \
libvirt-sandbox-config-network-address.c \
libvirt-sandbox-config-network-filterref.c \
diff --git a/libvirt-sandbox/libvirt-sandbox-config-all.h 
b/libvirt-sandbox/libvirt-sandbox-config-all.h
index 8cb25c4..756bb3e 100644
--- a/libvirt-sandbox/libvirt-sandbox-config-all.h
+++ b/libvirt-sandbox/libvirt-sandbox-config-all.h
@@ -32,6 +32,7 @@
 /* Local includes */
 #include libvirt-sandbox/libvirt-sandbox-util.h
 #include libvirt-sandbox/libvirt-sandbox-config-disk.h
+#include libvirt-sandbox/libvirt-sandbox-config-env.h
 #include libvirt-sandbox/libvirt-sandbox-config-mount.h
 #include libvirt-sandbox/libvirt-sandbox-config-mount-file.h
 #include libvirt-sandbox/libvirt-sandbox-config-mount-host-bind.h
diff --git a/libvirt-sandbox/libvirt-sandbox-config-env.c 
b/libvirt-sandbox/libvirt-sandbox-config-env.c
new file mode 100644
index 000..eaf0fb2
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-config-env.c
@@ -0,0 +1,199 @@
+/*
+ * libvirt-sandbox-config-env.c: libvirt sandbox configuration
+ *
+ * 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 erenyagdi...@gmail.com
+ */
+
+#include config.h
+#include string.h
+
+#include libvirt-sandbox/libvirt-sandbox-config-all.h
+
+/**
+ * SECTION: libvirt-sandbox-config-env
+ * @short_description: Disk attachment configuration details
+ * @include: libvirt-sandbox/libvirt-sandbox.h
+ * @see_aloso: #GVirSandboxConfig
+ *
+ * Provides an object to store information about a environment variable in the 
sandbox
+ *
+ */
+
+#define GVIR_SANDBOX_CONFIG_ENV_GET_PRIVATE(obj)  \
+(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_SANDBOX_TYPE_CONFIG_ENV, 
GVirSandboxConfigEnvPrivate))
+
+
+struct _GVirSandboxConfigEnvPrivate
+{
+gchar *key;
+gchar *value;
+};
+
+G_DEFINE_TYPE(GVirSandboxConfigEnv, gvir_sandbox_config_env, G_TYPE_OBJECT);
+
+
+enum {
+PROP_0,
+PROP_KEY,
+PROP_VALUE
+};
+
+enum {
+LAST_SIGNAL
+};
+
+
+
+static void gvir_sandbox_config_env_get_property(GObject *object,
+  guint prop_id,
+  GValue *value,
+  GParamSpec *pspec)
+{
+GVirSandboxConfigEnv *config = GVIR_SANDBOX_CONFIG_ENV(object);
+GVirSandboxConfigEnvPrivate *priv = config-priv;
+
+switch (prop_id) {
+case PROP_KEY

[libvirt] [sandbox PATCH v3 13/22] Image: Add get_disk function to Source

2015-08-18 Thread Eren Yagdiran
Provide a way to know which disk image to use for the sandbox depending on the 
used source
DockerSource will need to locate the topmost disk image among all the layers 
images
---
 virt-sandbox-image/sources/DockerSource.py | 18 ++
 virt-sandbox-image/sources/Source.py   |  4 
 2 files changed, 22 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 3e0362b..1e7f633 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -28,6 +28,8 @@ import traceback
 import os
 import subprocess
 import shutil
+import random
+import string
 
 class DockerConfParser():
 
@@ -372,6 +374,22 @@ class DockerSource(Source):
 parent = None
 imagetagid = parent
 
+def get_disk(self,**args):
+name = args['name']
+destdir = args['templatedir']
+imageList = self._get_image_list(name,destdir)
+toplayer = imageList[0]
+diskfile = destdir + / + toplayer + /template.qcow2
+configfile = destdir + / + toplayer + /template.json
+tempfile = ''.join(random.choice(string.lowercase) for i in range(10))
+tempfile = destdir + / + toplayer + / + tempfile + .qcow2
+cmd = [qemu-img,create,-q,-f,qcow2]
+cmd.append(-o)
+cmd.append(backing_fmt=qcow2,backing_file=%s % diskfile)
+cmd.append(tempfile)
+subprocess.call(cmd)
+return (tempfile,configfile)
+
 def get_command(self,configfile):
 configParser = DockerConfParser(configfile)
 commandToRun = configParser.getRunCommand()
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 9daf62d..9a3da59 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -41,3 +41,7 @@ class Source():
 @abstractmethod
 def get_command(self,**args):
   pass
+
+@abstractmethod
+def get_disk(self,**args):
+  pass
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 02/22] Fix virt-sandbox-image

2015-08-18 Thread Eren Yagdiran
Authentication fix for Docker REST API.
---
 virt-sandbox-image/virt-sandbox-image.py | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 4f5443b..a9cb0ff 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -1,8 +1,10 @@
 #!/usr/bin/python -Es
 #
 # Authors: Daniel P. Berrange berra...@redhat.com
+#  Eren Yagdiran erenyagdi...@gmail.com
 #
 # Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2015 Universitat Polit??cnica de Catalunya.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -166,7 +168,7 @@ def download_template(name, server, destdir):
 # or more parents, in a linear stack. Here we are getting the list
 # of layers for the image with the tag we used.
 (data, res) = get_json(registryserver, /v1/images/ + imagetagid + 
/ancestry,
-   { Cookie: cookie })
+   { Authorization: Token  + token })
 
 if data[0] != imagetagid:
 raise ValueError([Expected first layer id '%s' to match image id 
'%s',
@@ -188,9 +190,9 @@ def download_template(name, server, destdir):
 if not os.path.exists(jsonfile) or not os.path.exists(datafile):
 # The '/json' URL gives us some metadata about the layer
 res = save_data(registryserver, /v1/images/ + layerid + 
/json,
-{ Cookie: cookie }, jsonfile)
+{ Authorization: Token  + token }, 
jsonfile)
 createdFiles.append(jsonfile)
-layersize = int(res.info().getheader(x-docker-size))
+layersize = int(res.info().getheader(Content-Length))
 
 datacsum = None
 if layerid in checksums:
@@ -199,7 +201,7 @@ def download_template(name, server, destdir):
 # and the '/layer' URL is the actual payload, provided
 # as a tar.gz archive
 save_data(registryserver, /v1/images/ + layerid + /layer,
-  { Cookie: cookie }, datafile, datacsum, layersize)
+  { Authorization: Token  + token }, datafile, 
datacsum, layersize)
 createdFiles.append(datafile)
 
 # Strangely the 'json' data for a layer doesn't include
-- 
2.1.0

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

[libvirt] [sandbox PATCH v3 01/22] Add virt-sandbox-image

2015-08-18 Thread Eren Yagdiran
From: Daniel P Berrange berra...@redhat.com

virt-sandbox-image.py is a python script that lets you download Docker
images easily. It is a proof of concept code and consumes Docker Rest API.
---
 po/POTFILES.in   |   1 +
 virt-sandbox-image/virt-sandbox-image.py | 394 +++
 2 files changed, 395 insertions(+)
 create mode 100644 virt-sandbox-image/virt-sandbox-image.py

diff --git a/po/POTFILES.in b/po/POTFILES.in
index afcb050..7204112 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,3 +11,4 @@ libvirt-sandbox/libvirt-sandbox-context-interactive.c
 libvirt-sandbox/libvirt-sandbox-init-common.c
 libvirt-sandbox/libvirt-sandbox-rpcpacket.c
 libvirt-sandbox/libvirt-sandbox-util.c
+virt-sandbox-image/virt-sandbox-image.py
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
new file mode 100644
index 000..4f5443b
--- /dev/null
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -0,0 +1,394 @@
+#!/usr/bin/python -Es
+#
+# Authors: Daniel P. Berrange berra...@redhat.com
+#
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+import argparse
+import gettext
+import hashlib
+import json
+import os
+import os.path
+import shutil
+import sys
+import urllib2
+import subprocess
+
+default_index_server = index.docker.io
+default_template_dir = /var/lib/libvirt/templates
+
+debug = True
+verbose = True
+
+gettext.bindtextdomain(libvirt-sandbox, /usr/share/locale)
+gettext.textdomain(libvirt-sandbox)
+try:
+gettext.install(libvirt-sandbox,
+localedir=/usr/share/locale,
+unicode=False,
+codeset = 'utf-8')
+except IOError:
+import __builtin__
+__builtin__.__dict__['_'] = unicode
+
+
+def debug(msg):
+sys.stderr.write(msg)
+
+def info(msg):
+sys.stdout.write(msg)
+
+def get_url(server, path, headers):
+url = https://; + server + path
+debug(  Fetching %s... % url)
+req = urllib2.Request(url=url)
+
+if json:
+req.add_header(Accept, application/json)
+
+for h in headers.keys():
+req.add_header(h, headers[h])
+
+return urllib2.urlopen(req)
+
+def get_json(server, path, headers):
+try:
+res = get_url(server, path, headers)
+data = json.loads(res.read())
+debug(OK\n)
+return (data, res)
+except Exception, e:
+debug(FAIL %s\n % str(e))
+raise
+
+def save_data(server, path, headers, dest, checksum=None, datalen=None):
+try:
+res = get_url(server, path, headers)
+
+csum = None
+if checksum is not None:
+csum = hashlib.sha256()
+
+pattern = [., o, O, o]
+patternIndex = 0
+donelen = 0
+
+with open(dest, w) as f:
+while 1:
+buf = res.read(1024*64)
+if not buf:
+break
+if csum is not None:
+csum.update(buf)
+f.write(buf)
+
+if datalen is not None:
+donelen = donelen + len(buf)
+debug(\x1b[s%s (%5d Kb of %5d Kb)\x1b8 % (
+pattern[patternIndex], (donelen/1024), (datalen/1024)
+))
+patternIndex = (patternIndex + 1) % 4
+
+debug(\x1b[K)
+if csum is not None:
+csumstr = sha256: + csum.hexdigest()
+if csumstr != checksum:
+debug(FAIL checksum '%s' does not match '%s' % (csumstr, 
checksum))
+os.remove(dest)
+raise IOError(Checksum '%s' for data does not match '%s' % 
(csumstr, checksum))
+debug(OK\n)
+return res
+except Exception, e:
+debug(FAIL %s\n % str(e))
+raise
+
+
+def download_template(name, server, destdir):
+tag = latest
+
+offset = name.find(':')
+if offset != -1:
+tag = name[offset + 1:]
+name = name[0:offset]
+
+# First we must ask the index server about the image name. THe
+# index server will return an auth token we can use when talking
+# to the registry server. We need this token even when anonymous
+try:
+(data, res) = get_json(server, /v1/repositories/ + name + /images,
+  

[libvirt] [sandbox PATCH v3 20/22] Common-init: Exporting custom environment variables

2015-08-18 Thread Eren Yagdiran
Common-init reads config file and export custom environment
variables from config file and apply them to the running sandbox.
---
 libvirt-sandbox/libvirt-sandbox-init-common.c | 30 +++
 1 file changed, 30 insertions(+)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c 
b/libvirt-sandbox/libvirt-sandbox-init-common.c
index d35f760..0b0aa98 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -336,6 +336,33 @@ static gboolean setup_network(GVirSandboxConfig *config, 
GError **error)
 }
 
 
+static gboolean setup_custom_env(GVirSandboxConfig *config, GError **error)
+{
+GList *envs, *tmp;
+gboolean ret = FALSE;
+gchar *key = NULL;
+gchar *value = NULL;
+
+envs = tmp = gvir_sandbox_config_get_envs(config);
+
+while (tmp) {
+GVirSandboxConfigEnv *env = GVIR_SANDBOX_CONFIG_ENV(tmp-data);
+key = g_strdup(gvir_sandbox_config_env_get_key(env));
+value = g_strdup(gvir_sandbox_config_env_get_value(env));
+if(setenv(key,value,1)!=0)
+goto cleanup;
+g_free(key);
+g_free(value);
+tmp = tmp-next;
+}
+
+ret = TRUE;
+ cleanup:
+g_list_foreach(envs, (GFunc)g_object_unref, NULL);
+g_list_free(envs);
+return ret;
+}
+
 static int change_user(const gchar *user,
uid_t uid,
gid_t gid,
@@ -1262,6 +1289,9 @@ int main(int argc, char **argv) {
 if (!setup_disk_tags())
 exit(EXIT_FAILURE);
 
+if (!setup_custom_env(config, error))
+goto error;
+
 if (!setup_network(config, error))
 goto error;
 
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 03/22] Image: Add Hooking Mechanism

2015-08-18 Thread Eren Yagdiran
-1301  
USA
+#
+# Author: Eren Yagdiran erenyagdi...@gmail.com
+
+from abc import ABCMeta, abstractmethod
+
+class Source():
+__metaclass__ = ABCMeta
+def __init__(self):
+pass
diff --git a/virt-sandbox-image/sources/__init__.py 
b/virt-sandbox-image/sources/__init__.py
new file mode 100644
index 000..df8603b
--- /dev/null
+++ b/virt-sandbox-image/sources/__init__.py
@@ -0,0 +1,26 @@
+#!/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 erenyagdi...@gmail.com
+#
+
+import os
+import glob
+modules = glob.glob(os.path.dirname(__file__)+/*.py)
+__all__ = [ os.path.basename(f)[:-3] for f in modules]
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
old mode 100644
new mode 100755
index a9cb0ff..fa9e1c8
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -1,5 +1,5 @@
 #!/usr/bin/python -Es
-#
+# -*- coding: utf-8 -*-
 # Authors: Daniel P. Berrange berra...@redhat.com
 #  Eren Yagdiran erenyagdi...@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 = 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)
-- 
2.1.0

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

[libvirt] [sandbox PATCH v3 04/22] Image: virt-sandbox-image default dir constants

2015-08-18 Thread Eren Yagdiran
Conflicts:
virt-sandbox-image/virt-sandbox-image.py
---
 virt-sandbox-image/virt-sandbox-image.py | 8 
 1 file changed, 8 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index fa9e1c8..55aea6a 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -32,6 +32,14 @@ import sys
 import urllib2
 import subprocess
 
+default_privileged_template_dir = /var/lib/libvirt/templates
+default_home_dir = os.environ['HOME']
+default_unprivileged_template_dir = default_home_dir + 
/.local/share/libvirt/templates
+default_privileged_storage_dir = default_privileged_template_dir + /storage
+default_unprivileged_storage_dir = default_unprivileged_template_dir + 
/storage
+debug = False
+verbose = False
+
 import importlib
 def dynamic_source_loader(name):
 name = name[0].upper() + name[1:]
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 05/22] Image: Discard caching bytecode

2015-08-18 Thread Eren Yagdiran
---
 virt-sandbox-image/virt-sandbox-image.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 55aea6a..9e98bf2 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -40,6 +40,8 @@ default_unprivileged_storage_dir = 
default_unprivileged_template_dir + /storage
 debug = False
 verbose = False
 
+sys.dont_write_byte_code = True
+
 import importlib
 def dynamic_source_loader(name):
 name = name[0].upper() + name[1:]
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 22/22] Image: Add custom environment support

2015-08-18 Thread Eren Yagdiran
Any custom key=value pair can be used as a custom environment variable
in virt-sandbox-image.
e.g virt-sandbox-image run ubuntu /var/lib/libvirt/templates -c lxc:/// -i 
/bin/bash -e key1=val1
---
 virt-sandbox-image/sources/DockerSource.py | 10 ++
 virt-sandbox-image/sources/Source.py   |  4 
 virt-sandbox-image/virt-sandbox-image.py   | 19 +++
 3 files changed, 33 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 67bcf6b..c84b84e 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -47,6 +47,12 @@ class DockerConfParser():
   for key,value in volumes.iteritems():
 volumelist.append(key)
 return volumelist
+def getEnvs(self):
+lst = self.json_data['container_config']['Env']
+if lst is not None and isinstance(lst,list):
+  return lst
+else:
+  return []
 
 class DockerSource(Source):
 
@@ -407,5 +413,9 @@ class DockerSource(Source):
 configParser = DockerConfParser(configfile)
 return configParser.getVolumes()
 
+def get_env(self,configfile):
+configParser = DockerConfParser(configfile)
+return configParser.getEnvs()
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 8cc508e..c467ce2 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -49,3 +49,7 @@ class Source():
 @abstractmethod
 def get_volume(self,**args):
   pass
+
+@abstractmethod
+def get_env(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index e554d8a..dacfa0c 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -145,10 +145,12 @@ def run(args):
 cmd.append(-c)
 cmd.append(args.connect)
 params = ['-m','host-image:/=%s,format=%s' %(diskfile,format)]
+
 networkArgs = args.network
 if networkArgs is not None:
 params.append('-N')
 params.append(networkArgs)
+
 allVolumes = source.get_volume(configfile)
 volumeArgs = args.volume
 if volumeArgs is not None:
@@ -168,6 +170,20 @@ def run(args):
 pass
 params.append(--mount)
 params.append(host-bind:%s=%s %(guestPath,hostPath))
+
+allEnvs = source.get_env(configfile)
+envArgs = args.env
+if envArgs is not None:
+allEnvs = allEnvs + envArgs
+for env in allEnvs:
+envsplit = env.split(=)
+envlen = len(envsplit)
+if envlen == 2:
+params.append(--env)
+params.append(env)
+else:
+pass
+
 params.append('--')
 params.append(commandToRun)
 cmd = cmd + params
@@ -247,6 +263,9 @@ def gen_run_args(subparser):
 help=_(Network params for running template))
 parser.add_argument(-v,--volume,action=append,
 help=_(Volume params for running template))
+parser.add_argument(-e,--env,action=append,
+help=_(Environment params for running template))
+
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 12/22] Image: Add check_connect function

2015-08-18 Thread Eren Yagdiran
Check if user-specified connect argument is valid
---
 virt-sandbox-image/virt-sandbox-image.py | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index d6b682f..c46abd4 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -122,6 +122,12 @@ def create(args):
 except Exception,e:
 print Create Error %s % str(e)
 
+def check_connect(connectstr):
+supportedDrivers = ['lxc:///','qemu:///session','qemu:///system']
+if not connectstr in supportedDrivers:
+raise ValueError(%s is not supported by Virt-sandbox %connectstr)
+return True
+
 def requires_name(parser):
 parser.add_argument(name,
 help=_(name of the template))
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 19/22] Add environment parameter to virt-sandbox

2015-08-18 Thread Eren Yagdiran
Allow users to add custom environment variables to their sandbox.
---
 bin/virt-sandbox.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index 195515f..e90b698 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -64,6 +64,7 @@ int main(int argc, char **argv) {
 GError *error = NULL;
 gchar *name = NULL;
 gchar **disks = NULL;
+gchar **envs = NULL;
 gchar **mounts = NULL;
 gchar **includes = NULL;
 gchar *includefile = NULL;
@@ -95,6 +96,8 @@ int main(int argc, char **argv) {
   N_(root directory of the sandbox), DIR },
 { disk, ' ', 0, G_OPTION_ARG_STRING_ARRAY, disks,
   N_(add a disk in the guest), TYPE:TAGNAME=SOURCE,format=FORMAT },
+{ env, 'e', 0, G_OPTION_ARG_STRING_ARRAY, envs,
+  N_(add a environment variable for the sandbox), KEY=VALUE },
 { mount, 'm', 0, G_OPTION_ARG_STRING_ARRAY, mounts,
   N_(mount a filesystem in the guest), TYPE:TARGET=SOURCE },
 { include, 'i', 0, G_OPTION_ARG_STRING_ARRAY, includes,
@@ -185,6 +188,13 @@ int main(int argc, char **argv) {
 gvir_sandbox_config_set_username(cfg, root);
 }
 
+if (envs 
+!gvir_sandbox_config_add_env_strv(cfg, envs, error)) {
+g_printerr(_(Unable to parse custom environment variables: %s\n),
+   error  error-message ? error-message : _(Unknown 
failure));
+goto cleanup;
+}
+
 if (disks 
 !gvir_sandbox_config_add_disk_strv(cfg, disks, error)) {
 g_printerr(_(Unable to parse disks: %s\n),
@@ -329,6 +339,10 @@ inheriting the host's root filesystem.
 NB. CDIR must contain a matching install of the libvirt-sandbox
 package. This restriction may be lifted in a future version.
 
+=item B--env key=value
+
+Sets up a custom environment variable on a running sandbox.
+
 =item B--disk TYPE:TAGNAME=SOURCE,format=FORMAT
 
 Sets up a disk inside the sandbox by using BSOURCE with a symlink named as 
BTAGNAME
-- 
2.1.0

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


[libvirt] [sandbox PATCH v3 09/22] Image: Add delete function

2015-08-18 Thread Eren Yagdiran
Refactoring delete function from virt-sandbox-image to DockerSource. Delete 
function
can delete templates by name.
---
 virt-sandbox-image/sources/DockerSource.py | 53 +++
 virt-sandbox-image/sources/Source.py   |  4 +++
 virt-sandbox-image/virt-sandbox-image.py   | 58 --
 3 files changed, 64 insertions(+), 51 deletions(-)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 09eea85..760ba6c 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -310,5 +310,58 @@ class DockerSource(Source):
 cmd = cmd + params
 subprocess.call(cmd)
 
+def delete_template(self,**args):
+imageusage = {}
+imageparent = {}
+imagenames = {}
+name = args['name']
+destdir = args['templatedir']
+destdir = destdir if destdir is not None else default_template_dir
+imagedirs = os.listdir(destdir)
+for imagetagid in imagedirs:
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+with open(indexfile,r) as f:
+index = json.load(f)
+imagenames[index[name]] = imagetagid
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+with open(jsonfile,r) as f:
+template = json.load(f)
+
+parent = template.get(parent,None)
+if parent:
+if parent not in imageusage:
+imageusage[parent] = []
+imageusage[parent].append(imagetagid)
+imageparent[imagetagid] = parent
+
+
+if not name in imagenames:
+raise ValueError([Image %s does not exist locally %name])
+
+imagetagid = imagenames[name]
+while imagetagid != None:
+debug(Remove %s\n % imagetagid)
+parent = imageparent.get(imagetagid,None)
+
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+   os.remove(indexfile)
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+os.remove(jsonfile)
+datafile = destdir + / + imagetagid + /template.tar.gz
+if os.path.exists(datafile):
+os.remove(datafile)
+imagedir = destdir + / + imagetagid
+shutil.rmtree(imagedir)
+
+if parent:
+if len(imageusage[parent]) != 1:
+debug(Parent %s is shared\n % parent)
+parent = None
+imagetagid = parent
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 6ac08dc..d66e61e 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -33,3 +33,7 @@ class Source():
 @abstractmethod
 def create_template(self,**args):
   pass
+
+@abstractmethod
+def delete_template(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 745401c..1da5150 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -94,55 +94,6 @@ def debug(msg):
 def info(msg):
 sys.stdout.write(msg)
 
-def delete_template(name, destdir):
-imageusage = {}
-imageparent = {}
-imagenames = {}
-imagedirs = os.listdir(destdir)
-for imagetagid in imagedirs:
-indexfile = destdir + / + imagetagid + /index.json
-if os.path.exists(indexfile):
-with open(indexfile, r) as f:
-index = json.load(f)
-imagenames[index[name]] = imagetagid
-jsonfile = destdir + / + imagetagid + /template.json
-if os.path.exists(jsonfile):
-with open(jsonfile, r) as f:
-template = json.load(f)
-
-parent = template.get(parent, None)
-if parent:
-if parent not in imageusage:
-imageusage[parent] = []
-imageusage[parent].append(imagetagid)
-imageparent[imagetagid] = parent
-
-if not name in imagenames:
-raise ValueError([Image %s does not exist locally % name])
-
-imagetagid = imagenames[name]
-while imagetagid != None:
-debug(Remove %s\n %  imagetagid)
-parent = imageparent.get(imagetagid, None)
-
-indexfile = destdir + / + imagetagid + /index.json
-if os.path.exists(indexfile):
-os.remove(indexfile)
-jsonfile = destdir + / + imagetagid + /template.json
-if os.path.exists(jsonfile):
-os.remove(jsonfile)
-datafile = destdir + / + imagetagid + 

[libvirt] [sandbox PATCH v3 10/22] Image: Add get_command function to Source

2015-08-18 Thread Eren Yagdiran
Provide a way to know how a template can be started depending on the used source
DockerSource will need to parse the topmost config file in order to find the 
igniter command
---
 virt-sandbox-image/sources/DockerSource.py | 14 ++
 virt-sandbox-image/sources/Source.py   |  4 
 2 files changed, 18 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 760ba6c..3e0362b 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -29,6 +29,15 @@ import os
 import subprocess
 import shutil
 
+class DockerConfParser():
+
+def __init__(self,jsonfile):
+with open(jsonfile) as json_file:
+self.json_data = json.load(json_file)
+def getRunCommand(self):
+cmd = self.json_data['container_config']['Cmd'][2]
+return cmd[cmd.index('') + 1:cmd.rindex('')]
+
 class DockerSource(Source):
 
 www_auth_username = None
@@ -363,5 +372,10 @@ class DockerSource(Source):
 parent = None
 imagetagid = parent
 
+def get_command(self,configfile):
+configParser = DockerConfParser(configfile)
+commandToRun = configParser.getRunCommand()
+return commandToRun
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index d66e61e..9daf62d 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -37,3 +37,7 @@ class Source():
 @abstractmethod
 def delete_template(self,**args):
   pass
+
+@abstractmethod
+def get_command(self,**args):
+  pass
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 10/19] Image: Add get_disk function to Source

2015-08-04 Thread Eren Yagdiran
Provide a way to know which disk image to use for the sandbox depending on the 
used source
DockerSource will need to locate the topmost disk image among all the layers 
images
---
 virt-sandbox-image/sources/DockerSource.py | 9 +
 virt-sandbox-image/sources/Source.py   | 4 
 2 files changed, 13 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 2f4646f..74feb3e 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -385,6 +385,15 @@ class DockerSource(Source):
 parent = None
 imagetagid = parent
 
+def get_disk(self,**args):
+name = args['name']
+destdir = args['path']
+imageList = self._get_image_list(name,destdir)
+toplayer = imageList[0]
+diskfile = destdir + / + toplayer + /template.qcow2
+configfile = destdir + / + toplayer + /template.json
+return (diskfile,configfile)
+
 def get_command(self,configfile):
 configParser = DockerConfParser(configfile)
 commandToRun = configParser.getRunCommand()
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 01f8560..6e2f5fb 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -45,3 +45,7 @@ class Source():
 @abstractmethod
 def get_command(self,**args):
   pass
+
+@abstractmethod
+def get_disk(self,**args):
+  pass
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 19/19] Image: Add custom environment support

2015-08-04 Thread Eren Yagdiran
Any custom key=value pair can be used as a custom environment variable
in virt-sandbox-image.
e.g virt-sandbox-image run ubuntu /var/lib/libvirt/templates -c lxc:/// -i 
/bin/bash -e key1=val1
---
 virt-sandbox-image/sources/DockerSource.py | 10 ++
 virt-sandbox-image/sources/Source.py   |  4 
 virt-sandbox-image/virt-sandbox-image.py   | 19 +++
 3 files changed, 33 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 44bc238..54b68b9 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -48,6 +48,12 @@ class DockerConfParser():
   for key,value in volumes.iteritems():
 volumelist.append(key)
 return volumelist
+def getEnvs(self):
+lst = self.json_data['container_config']['Env']
+if lst is not None and isinstance(lst,list):
+  return lst
+else:
+  return []
 
 class DockerSource(Source):
 default_index_server = index.docker.io
@@ -411,5 +417,9 @@ class DockerSource(Source):
 configParser = DockerConfParser(configfile)
 return configParser.getVolumes()
 
+def get_environment(self,configfile):
+configParser = DockerConfParser(configfile)
+return configParser.getEnvs()
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 6898c15..ad82986 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -53,3 +53,7 @@ class Source():
 @abstractmethod
 def get_volume(self,**args):
   pass
+
+@abstractmethod
+def get_env(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index b12b99b..25c8dfa 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -118,10 +118,12 @@ def run(args):
 cmd.append(-c)
 cmd.append(args.connect)
 params = ['-m','host-image:/=%s,format=%s' %(diskfile,format)]
+
 networkArgs = args.network
 if networkArgs is not None:
 params.append('-N')
 params.append(networkArgs)
+
 allVolumes = source.get_volume(configfile)
 volumeArgs = args.volume
 if volumeArgs is not None:
@@ -141,6 +143,20 @@ def run(args):
 pass
 params.append(--mount)
 params.append(host-bind:%s=%s %(guestPath,hostPath))
+
+allEnvs = source.get_environment(configfile)
+envArgs = args.env
+if envArgs is not None:
+allEnvs = allEnvs + envArgs
+for env in allEnvs:
+envsplit = env.split(=)
+envlen = len(envsplit)
+if envlen == 2:
+params.append(--env)
+params.append(env)
+else:
+pass
+
 params.append('--')
 params.append(commandToRun)
 cmd = cmd + params
@@ -215,6 +231,9 @@ def gen_run_args(subparser):
 help=_(Network params for running template))
 parser.add_argument(-v,--volume,action=append,
 help=_(Volume params for running template))
+parser.add_argument(-e,--env,action=append,
+help=_(Environment params for running template))
+
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 06/19] Image: Add delete function

2015-08-04 Thread Eren Yagdiran
Refactoring delete function from virt-sandbox-image to DockerSource. Delete 
function
can delete templates by name.
---
 virt-sandbox-image/sources/DockerSource.py | 53 +++
 virt-sandbox-image/sources/Source.py   |  4 ++
 virt-sandbox-image/virt-sandbox-image.py   | 59 --
 3 files changed, 65 insertions(+), 51 deletions(-)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 9cd0080..03f50aa 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -323,5 +323,58 @@ class DockerSource(Source):
 cmd = cmd + params
 subprocess.call(cmd)
 
+def delete_template(self,**args):
+imageusage = {}
+imageparent = {}
+imagenames = {}
+name = args['name']
+destdir = args['imagepath']
+destdir = destdir if destdir is not None else default_template_dir
+imagedirs = os.listdir(destdir)
+for imagetagid in imagedirs:
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+with open(indexfile,r) as f:
+index = json.load(f)
+imagenames[index[name]] = imagetagid
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+with open(jsonfile,r) as f:
+template = json.load(f)
+
+parent = template.get(parent,None)
+if parent:
+if parent not in imageusage:
+imageusage[parent] = []
+imageusage[parent].append(imagetagid)
+imageparent[imagetagid] = parent
+
+
+if not name in imagenames:
+raise ValueError([Image %s does not exist locally %name])
+
+imagetagid = imagenames[name]
+while imagetagid != None:
+debug(Remove %s\n % imagetagid)
+parent = imageparent.get(imagetagid,None)
+
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+   os.remove(indexfile)
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+os.remove(jsonfile)
+datafile = destdir + / + imagetagid + /template.tar.gz
+if os.path.exists(datafile):
+os.remove(datafile)
+imagedir = destdir + / + imagetagid
+shutil.rmtree(imagedir)
+
+if parent:
+if len(imageusage[parent]) != 1:
+debug(Parent %s is shared\n % parent)
+parent = None
+imagetagid = parent
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 1a63428..ceda58f 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -37,3 +37,7 @@ class Source():
 @abstractmethod
 def create_template(self,**args):
   pass
+
+@abstractmethod
+def delete_template(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 6f65445..ea7ab02 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -67,55 +67,6 @@ def debug(msg):
 def info(msg):
 sys.stdout.write(msg)
 
-def delete_template(name, destdir):
-imageusage = {}
-imageparent = {}
-imagenames = {}
-imagedirs = os.listdir(destdir)
-for imagetagid in imagedirs:
-indexfile = destdir + / + imagetagid + /index.json
-if os.path.exists(indexfile):
-with open(indexfile, r) as f:
-index = json.load(f)
-imagenames[index[name]] = imagetagid
-jsonfile = destdir + / + imagetagid + /template.json
-if os.path.exists(jsonfile):
-with open(jsonfile, r) as f:
-template = json.load(f)
-
-parent = template.get(parent, None)
-if parent:
-if parent not in imageusage:
-imageusage[parent] = []
-imageusage[parent].append(imagetagid)
-imageparent[imagetagid] = parent
-
-if not name in imagenames:
-raise ValueError([Image %s does not exist locally % name])
-
-imagetagid = imagenames[name]
-while imagetagid != None:
-debug(Remove %s\n %  imagetagid)
-parent = imageparent.get(imagetagid, None)
-
-indexfile = destdir + / + imagetagid + /index.json
-if os.path.exists(indexfile):
-os.remove(indexfile)
-jsonfile = destdir + / + imagetagid + /template.json
-if os.path.exists(jsonfile):
-os.remove(jsonfile)
-datafile = destdir + / + imagetagid + /template.tar.gz

[libvirt] [sandbox PATCH v2 07/19] Image: Add get_command function to Source

2015-08-04 Thread Eren Yagdiran
Provide a way to know how a template can be started depending on the used source
DockerSource will need to parse the topmost config file in order to find the 
igniter command
---
 virt-sandbox-image/sources/DockerSource.py | 14 ++
 virt-sandbox-image/sources/Source.py   |  4 
 2 files changed, 18 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 03f50aa..2f4646f 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -32,6 +32,15 @@ import os
 import subprocess
 import shutil
 
+class DockerConfParser():
+
+def __init__(self,jsonfile):
+with open(jsonfile) as json_file:
+self.json_data = json.load(json_file)
+def getRunCommand(self):
+cmd = self.json_data['container_config']['Cmd'][2]
+return cmd[cmd.index('') + 1:cmd.rindex('')]
+
 class DockerSource(Source):
 default_index_server = index.docker.io
 default_template_dir = /var/lib/libvirt/templates
@@ -376,5 +385,10 @@ class DockerSource(Source):
 parent = None
 imagetagid = parent
 
+def get_command(self,configfile):
+configParser = DockerConfParser(configfile)
+commandToRun = configParser.getRunCommand()
+return commandToRun
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index ceda58f..01f8560 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -41,3 +41,7 @@ class Source():
 @abstractmethod
 def delete_template(self,**args):
   pass
+
+@abstractmethod
+def get_command(self,**args):
+  pass
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 14/19] Image: man file for virt-sandbox-image

2015-08-04 Thread Eren Yagdiran
+
+=head1 SEE ALSO
+
+Cvirt-sandbox(8)
+
+=head1 FILES
+
+Container content will be stored in subdirectories of
+/var/lib/libvirt/templates, by default.
+
+=head1 AUTHORS
+
+Daniel P. Berrange d...@berrange.com
+
+Eren Yagdiran erenyagdi...@gmail.com
+
+=head1 COPYRIGHT
+
+Copyright (C) 2013 Red Hat, Inc.
+Copyright (C) 2015 Universitat Politecnica de Catalunya.
+
+=head1 LICENSE
+
+virt-sandbox-image is distributed under the terms of the GNU LGPL v2+.
+This is free software; see the source for copying conditions.
+There is NO warranty; not even for MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 13/19] Image: Add Volume Support

2015-08-04 Thread Eren Yagdiran
Volumes let user to map host-paths into guest. Docker containers need volumes 
because its
filesystem read-only by default.
---
 virt-sandbox-image/sources/DockerSource.py | 12 
 virt-sandbox-image/sources/Source.py   |  4 
 virt-sandbox-image/virt-sandbox-image.py   | 22 ++
 3 files changed, 38 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 74feb3e..44bc238 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -31,6 +31,7 @@ import traceback
 import os
 import subprocess
 import shutil
+import collections
 
 class DockerConfParser():
 
@@ -40,6 +41,13 @@ class DockerConfParser():
 def getRunCommand(self):
 cmd = self.json_data['container_config']['Cmd'][2]
 return cmd[cmd.index('') + 1:cmd.rindex('')]
+def getVolumes(self):
+volumes = self.json_data['container_config']['Volumes']
+volumelist = []
+if isinstance(volumes,collections.Iterable):
+  for key,value in volumes.iteritems():
+volumelist.append(key)
+return volumelist
 
 class DockerSource(Source):
 default_index_server = index.docker.io
@@ -399,5 +407,9 @@ class DockerSource(Source):
 commandToRun = configParser.getRunCommand()
 return commandToRun
 
+def get_volume(self,configfile):
+configParser = DockerConfParser(configfile)
+return configParser.getVolumes()
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 6e2f5fb..6898c15 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -49,3 +49,7 @@ class Source():
 @abstractmethod
 def get_disk(self,**args):
   pass
+
+@abstractmethod
+def get_volume(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 5fc7f44..b12b99b 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -103,6 +103,7 @@ def check_connect(connectstr):
 
 def run(args):
 try:
+default_dir = /var/lib/libvirt/storage
 if args.connect is not None:
 check_connect(args.connect)
 source = dynamic_source_loader(args.source)
@@ -121,6 +122,25 @@ def run(args):
 if networkArgs is not None:
 params.append('-N')
 params.append(networkArgs)
+allVolumes = source.get_volume(configfile)
+volumeArgs = args.volume
+if volumeArgs is not None:
+allVolumes = allVolumes + volumeArgs
+for volume in allVolumes:
+volumeSplit = volume.split(:)
+volumelen = len(volumeSplit)
+if volumelen == 2:
+hostPath = volumeSplit[0]
+guestPath = volumeSplit[1]
+elif volumelen == 1:
+guestPath = volumeSplit[0]
+hostPath = default_dir + guestPath
+if not os.path.exists(hostPath):
+os.makedirs(hostPath)
+else:
+pass
+params.append(--mount)
+params.append(host-bind:%s=%s %(guestPath,hostPath))
 params.append('--')
 params.append(commandToRun)
 cmd = cmd + params
@@ -193,6 +213,8 @@ def gen_run_args(subparser):
 help=_(Igniter command for image))
 parser.add_argument(-n,--network,
 help=_(Network params for running template))
+parser.add_argument(-v,--volume,action=append,
+help=_(Volume params for running template))
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 08/19] Image: Add run args

2015-08-04 Thread Eren Yagdiran
Commandline parameters for running a template
---
 virt-sandbox-image/virt-sandbox-image.py | 13 +
 1 file changed, 13 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index ea7ab02..feee849 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -147,6 +147,18 @@ def gen_create_args(subparser):
 help=_(format format for image))
 parser.set_defaults(func=create)
 
+def gen_run_args(subparser):
+parser = subparser.add_parser(run,
+  help=_(Run a already built image))
+requires_name(parser)
+requires_source(parser)
+requires_connect(parser)
+parser.add_argument(imagepath,
+help=_(path for image))
+parser.add_argument(-i,--igniter,
+help=_(Igniter command for image))
+parser.set_defaults(func=run)
+
 if __name__ == '__main__':
 parser = argparse.ArgumentParser(description='Sandbox Container Image 
Tool')
 
@@ -154,6 +166,7 @@ if __name__ == '__main__':
 gen_download_args(subparser)
 gen_delete_args(subparser)
 gen_create_args(subparser)
+gen_run_args(subparser)
 
 try:
 args = parser.parse_args()
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 15/19] Add configuration object for environment variables

2015-08-04 Thread Eren Yagdiran
Add the config gobject to store custom environment variables.
This will allow creating custom environment variables on a sandbox
with a parameter formatted like --env key1=val1
---
 libvirt-sandbox/Makefile.am  |   2 +
 libvirt-sandbox/libvirt-sandbox-config-all.h |   1 +
 libvirt-sandbox/libvirt-sandbox-config-env.c | 199 +++
 libvirt-sandbox/libvirt-sandbox-config-env.h |  78 +++
 libvirt-sandbox/libvirt-sandbox-config.c | 187 -
 libvirt-sandbox/libvirt-sandbox-config.h |  12 ++
 libvirt-sandbox/libvirt-sandbox.h|   1 +
 libvirt-sandbox/libvirt-sandbox.sym  |   6 +
 8 files changed, 485 insertions(+), 1 deletion(-)
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-env.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-env.h

diff --git a/libvirt-sandbox/Makefile.am b/libvirt-sandbox/Makefile.am
index 597803e..5383b0d 100644
--- a/libvirt-sandbox/Makefile.am
+++ b/libvirt-sandbox/Makefile.am
@@ -53,6 +53,7 @@ SANDBOX_RPC_FILES = \
 SANDBOX_CONFIG_HEADER_FILES = \
libvirt-sandbox-config.h \
libvirt-sandbox-config-disk.h \
+   libvirt-sandbox-config-env.h \
libvirt-sandbox-config-network.h \
libvirt-sandbox-config-network-address.h \
libvirt-sandbox-config-network-filterref-parameter.h \
@@ -92,6 +93,7 @@ SANDBOX_CONFIG_SOURCE_FILES = \
libvirt-sandbox-util.c \
libvirt-sandbox-config.c \
libvirt-sandbox-config-disk.c \
+   libvirt-sandbox-config-env.c \
libvirt-sandbox-config-network.c \
libvirt-sandbox-config-network-address.c \
libvirt-sandbox-config-network-filterref.c \
diff --git a/libvirt-sandbox/libvirt-sandbox-config-all.h 
b/libvirt-sandbox/libvirt-sandbox-config-all.h
index 8cb25c4..756bb3e 100644
--- a/libvirt-sandbox/libvirt-sandbox-config-all.h
+++ b/libvirt-sandbox/libvirt-sandbox-config-all.h
@@ -32,6 +32,7 @@
 /* Local includes */
 #include libvirt-sandbox/libvirt-sandbox-util.h
 #include libvirt-sandbox/libvirt-sandbox-config-disk.h
+#include libvirt-sandbox/libvirt-sandbox-config-env.h
 #include libvirt-sandbox/libvirt-sandbox-config-mount.h
 #include libvirt-sandbox/libvirt-sandbox-config-mount-file.h
 #include libvirt-sandbox/libvirt-sandbox-config-mount-host-bind.h
diff --git a/libvirt-sandbox/libvirt-sandbox-config-env.c 
b/libvirt-sandbox/libvirt-sandbox-config-env.c
new file mode 100644
index 000..eaf0fb2
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-config-env.c
@@ -0,0 +1,199 @@
+/*
+ * libvirt-sandbox-config-env.c: libvirt sandbox configuration
+ *
+ * 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 erenyagdi...@gmail.com
+ */
+
+#include config.h
+#include string.h
+
+#include libvirt-sandbox/libvirt-sandbox-config-all.h
+
+/**
+ * SECTION: libvirt-sandbox-config-env
+ * @short_description: Disk attachment configuration details
+ * @include: libvirt-sandbox/libvirt-sandbox.h
+ * @see_aloso: #GVirSandboxConfig
+ *
+ * Provides an object to store information about a environment variable in the 
sandbox
+ *
+ */
+
+#define GVIR_SANDBOX_CONFIG_ENV_GET_PRIVATE(obj)  \
+(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_SANDBOX_TYPE_CONFIG_ENV, 
GVirSandboxConfigEnvPrivate))
+
+
+struct _GVirSandboxConfigEnvPrivate
+{
+gchar *key;
+gchar *value;
+};
+
+G_DEFINE_TYPE(GVirSandboxConfigEnv, gvir_sandbox_config_env, G_TYPE_OBJECT);
+
+
+enum {
+PROP_0,
+PROP_KEY,
+PROP_VALUE
+};
+
+enum {
+LAST_SIGNAL
+};
+
+
+
+static void gvir_sandbox_config_env_get_property(GObject *object,
+  guint prop_id,
+  GValue *value,
+  GParamSpec *pspec)
+{
+GVirSandboxConfigEnv *config = GVIR_SANDBOX_CONFIG_ENV(object);
+GVirSandboxConfigEnvPrivate *priv = config-priv;
+
+switch (prop_id) {
+case PROP_KEY

[libvirt] [sandbox PATCH v2 11/19] Image: Add run function

2015-08-04 Thread Eren Yagdiran
Run an already-built template
If there is no execution command specified by user, source.get_command will
find the command to invoke
---
 virt-sandbox-image/virt-sandbox-image.py | 24 
 1 file changed, 24 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 4c19fa8..e20ce22 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -101,6 +101,30 @@ def check_connect(connectstr):
 raise ValueError(%s is not supported by Virt-sandbox %connectstr)
 return True
 
+def run(args):
+try:
+if args.connect is not None:
+check_connect(args.connect)
+source = dynamic_source_loader(args.source)
+diskfile,configfile = 
source.get_disk(name=args.name,path=args.imagepath)
+
+format = qcow2
+commandToRun = args.igniter
+if commandToRun is None:
+commandToRun = source.get_command(configfile)
+cmd = ['virt-sandbox']
+if args.connect is not None:
+cmd.append(-c)
+cmd.append(args.connect)
+params = ['-m','host-image:/=%s,format=%s' %(diskfile,format),
+   '--',
+   commandToRun]
+cmd = cmd + params
+subprocess.call(cmd)
+
+except Exception,e:
+print Run Error %s % str(e)
+
 def requires_name(parser):
 parser.add_argument(name,
 help=_(name of the template))
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 00/19] *** Virt-sandbox-image ***

2015-08-04 Thread Eren Yagdiran
virt-sandbox-image.py is a python script that lets you download and run 
templates
from supported sources using virt-sandbox.
Component-based archictecture is accomplished through Source base class.
Docker image support is added through DockerSource.
DockerSource is capable of downloading and running Docker images by consuming 
Docker Registry API.

**Changes for v2**
*Trailing spaces are gone forever. make syntax-check now is ok.
*Python version  2.7.9 or  3.4.3 now gives a warring when downloading a 
docker image from ssl.
*Dynamic resource loader has been changed. Now it uses class naming convention 
in order to load
custom sources. In previous patch series, custom sources used to register 
themselves into a 
common area, so we can load from them
* -c/--connect parameter is for providing URI to the libvirt.
* Private methods now starts with a single underscore instead of double 
underscores
* virt-sandbox-image/sources/__init__.py is added
* Network params can be passed to running sandbox.
* Custom volume support is added through host-bind.
* Custom environment variables can be passed into virt-sandbox
* Custom environment support for virt-sandbox-image


Daniel P Berrange (1):
  Add virt-sandbox-image

Eren Yagdiran (18):
  Fix virt-sandbox-image
  Image: Add Hooking Mechanism
  Image: Add download function
  Image: Refactor create function
  Image: Add delete function
  Image: Add get_command function to Source
  Image: Add run args
  Image: Add check_connect function
  Image: Add get_disk function to Source
  Image: Add run function
  Image: Add network support
  Image: Add Volume Support
  Image: man file for virt-sandbox-image
  Add configuration object for environment variables
  Add environment parameter to virt-sandbox
  Common-init: Exporting custom environment variables
  Add testcase for custom environment variables
  Image: Add custom environment support

 .gitignore|   1 +
 bin/Makefile.am   |  21 +-
 bin/virt-sandbox-image.in |   3 +
 bin/virt-sandbox-image.pod| 172 +++
 bin/virt-sandbox.c|  14 +
 configure.ac  |   2 +
 libvirt-sandbox/Makefile.am   |   2 +
 libvirt-sandbox/libvirt-sandbox-config-all.h  |   1 +
 libvirt-sandbox/libvirt-sandbox-config-env.c  | 199 
 libvirt-sandbox/libvirt-sandbox-config-env.h  |  78 +
 libvirt-sandbox/libvirt-sandbox-config.c  | 187 +++-
 libvirt-sandbox/libvirt-sandbox-config.h  |  12 +
 libvirt-sandbox/libvirt-sandbox-init-common.c |  30 ++
 libvirt-sandbox/libvirt-sandbox.h |   1 +
 libvirt-sandbox/libvirt-sandbox.sym   |   6 +
 libvirt-sandbox/tests/test-config.c   |  10 +
 po/POTFILES.in|   1 +
 virt-sandbox-image/Makefile.am|  14 +
 virt-sandbox-image/sources/DockerSource.py| 425 ++
 virt-sandbox-image/sources/Source.py  |  59 
 virt-sandbox-image/sources/__init__.py|  29 ++
 virt-sandbox-image/virt-sandbox-image.py  | 267 
 22 files changed, 1529 insertions(+), 5 deletions(-)
 create mode 100644 bin/virt-sandbox-image.in
 create mode 100644 bin/virt-sandbox-image.pod
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-env.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-env.h
 create mode 100644 virt-sandbox-image/Makefile.am
 create mode 100644 virt-sandbox-image/sources/DockerSource.py
 create mode 100644 virt-sandbox-image/sources/Source.py
 create mode 100644 virt-sandbox-image/sources/__init__.py
 create mode 100755 virt-sandbox-image/virt-sandbox-image.py

-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 12/19] Image: Add network support

2015-08-04 Thread Eren Yagdiran
Virt-sandbox-image will pass exact network arguments to virt-sandbox
---
 virt-sandbox-image/virt-sandbox-image.py | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index e20ce22..5fc7f44 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -116,9 +116,13 @@ def run(args):
 if args.connect is not None:
 cmd.append(-c)
 cmd.append(args.connect)
-params = ['-m','host-image:/=%s,format=%s' %(diskfile,format),
-   '--',
-   commandToRun]
+params = ['-m','host-image:/=%s,format=%s' %(diskfile,format)]
+networkArgs = args.network
+if networkArgs is not None:
+params.append('-N')
+params.append(networkArgs)
+params.append('--')
+params.append(commandToRun)
 cmd = cmd + params
 subprocess.call(cmd)
 
@@ -187,6 +191,8 @@ def gen_run_args(subparser):
 help=_(path for image))
 parser.add_argument(-i,--igniter,
 help=_(Igniter command for image))
+parser.add_argument(-n,--network,
+help=_(Network params for running template))
 parser.set_defaults(func=run)
 
 if __name__ == '__main__':
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 09/19] Image: Add check_connect function

2015-08-04 Thread Eren Yagdiran
Check if user-specified connect argument is valid
---
 virt-sandbox-image/virt-sandbox-image.py | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index feee849..4c19fa8 100755
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -95,6 +95,12 @@ def create(args):
 except Exception,e:
 print Create Error %s % str(e)
 
+def check_connect(connectstr):
+supportedDrivers = ['lxc:///','qemu:///session','qemu:///system']
+if not connectstr in supportedDrivers:
+raise ValueError(%s is not supported by Virt-sandbox %connectstr)
+return True
+
 def requires_name(parser):
 parser.add_argument(name,
 help=_(name of the template))
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 17/19] Common-init: Exporting custom environment variables

2015-08-04 Thread Eren Yagdiran
Common-init reads config file and export custom environment
variables from config file and apply them to the running sandbox.
---
 libvirt-sandbox/libvirt-sandbox-init-common.c | 30 +++
 1 file changed, 30 insertions(+)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c 
b/libvirt-sandbox/libvirt-sandbox-init-common.c
index d35f760..0b0aa98 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -336,6 +336,33 @@ static gboolean setup_network(GVirSandboxConfig *config, 
GError **error)
 }
 
 
+static gboolean setup_custom_env(GVirSandboxConfig *config, GError **error)
+{
+GList *envs, *tmp;
+gboolean ret = FALSE;
+gchar *key = NULL;
+gchar *value = NULL;
+
+envs = tmp = gvir_sandbox_config_get_envs(config);
+
+while (tmp) {
+GVirSandboxConfigEnv *env = GVIR_SANDBOX_CONFIG_ENV(tmp-data);
+key = g_strdup(gvir_sandbox_config_env_get_key(env));
+value = g_strdup(gvir_sandbox_config_env_get_value(env));
+if(setenv(key,value,1)!=0)
+goto cleanup;
+g_free(key);
+g_free(value);
+tmp = tmp-next;
+}
+
+ret = TRUE;
+ cleanup:
+g_list_foreach(envs, (GFunc)g_object_unref, NULL);
+g_list_free(envs);
+return ret;
+}
+
 static int change_user(const gchar *user,
uid_t uid,
gid_t gid,
@@ -1262,6 +1289,9 @@ int main(int argc, char **argv) {
 if (!setup_disk_tags())
 exit(EXIT_FAILURE);
 
+if (!setup_custom_env(config, error))
+goto error;
+
 if (!setup_network(config, error))
 goto error;
 
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 16/19] Add environment parameter to virt-sandbox

2015-08-04 Thread Eren Yagdiran
Allow users to add custom environment variables to their sandbox.
---
 bin/virt-sandbox.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index 195515f..e90b698 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -64,6 +64,7 @@ int main(int argc, char **argv) {
 GError *error = NULL;
 gchar *name = NULL;
 gchar **disks = NULL;
+gchar **envs = NULL;
 gchar **mounts = NULL;
 gchar **includes = NULL;
 gchar *includefile = NULL;
@@ -95,6 +96,8 @@ int main(int argc, char **argv) {
   N_(root directory of the sandbox), DIR },
 { disk, ' ', 0, G_OPTION_ARG_STRING_ARRAY, disks,
   N_(add a disk in the guest), TYPE:TAGNAME=SOURCE,format=FORMAT },
+{ env, 'e', 0, G_OPTION_ARG_STRING_ARRAY, envs,
+  N_(add a environment variable for the sandbox), KEY=VALUE },
 { mount, 'm', 0, G_OPTION_ARG_STRING_ARRAY, mounts,
   N_(mount a filesystem in the guest), TYPE:TARGET=SOURCE },
 { include, 'i', 0, G_OPTION_ARG_STRING_ARRAY, includes,
@@ -185,6 +188,13 @@ int main(int argc, char **argv) {
 gvir_sandbox_config_set_username(cfg, root);
 }
 
+if (envs 
+!gvir_sandbox_config_add_env_strv(cfg, envs, error)) {
+g_printerr(_(Unable to parse custom environment variables: %s\n),
+   error  error-message ? error-message : _(Unknown 
failure));
+goto cleanup;
+}
+
 if (disks 
 !gvir_sandbox_config_add_disk_strv(cfg, disks, error)) {
 g_printerr(_(Unable to parse disks: %s\n),
@@ -329,6 +339,10 @@ inheriting the host's root filesystem.
 NB. CDIR must contain a matching install of the libvirt-sandbox
 package. This restriction may be lifted in a future version.
 
+=item B--env key=value
+
+Sets up a custom environment variable on a running sandbox.
+
 =item B--disk TYPE:TAGNAME=SOURCE,format=FORMAT
 
 Sets up a disk inside the sandbox by using BSOURCE with a symlink named as 
BTAGNAME
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 05/19] Image: Refactor create function

2015-08-04 Thread Eren Yagdiran
Move the docker-related code to the DockerSource and use
the Source mechanism
---
 virt-sandbox-image/sources/DockerSource.py | 100 +
 virt-sandbox-image/sources/Source.py   |   4 ++
 virt-sandbox-image/virt-sandbox-image.py   |  70 
 3 files changed, 118 insertions(+), 56 deletions(-)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index cf81ffe..9cd0080 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -223,5 +223,105 @@ class DockerSource(Source):
 debug(FAIL %s\n % str(e))
 raise
 
+def create_template(self,**args):
+name = args['name']
+connect = args['connect']
+path = args['imagepath']
+path = path if path is not None else self.default_image_path
+format = args['format']
+format = format if format is not None else self.default_disk_format
+
+self._create_template(name,
+   connect,
+   path,
+   format,
+   path)
+
+def _create_template(self,name,connect,image_path,format,destdir):
+self._check_disk_format(format)
+imagelist = self._get_image_list(name,destdir)
+imagelist.reverse()
+
+parentImage = None
+for imagetagid in imagelist:
+templateImage = destdir + / + imagetagid + /template. + format
+cmd = [qemu-img,create,-f,qcow2]
+if parentImage is not None:
+cmd.append(-o)
+cmd.append(backing_fmt=qcow2,backing_file=%s % parentImage)
+cmd.append(templateImage)
+if parentImage is None:
+cmd.append(10G)
+subprocess.call(cmd)
+
+if parentImage is None:
+self._format_disk(templateImage,format,connect)
+
+self._extract_tarballs(destdir + / + imagetagid + 
/template.,format,connect)
+parentImage = templateImage
+
+
+def _check_disk_format(self,format):
+supportedFormats = ['qcow2']
+if not format in supportedFormats:
+raise ValueError([Unsupported image format %s % format])
+
+def _get_image_list(self,name,destdir):
+imageparent = {}
+imagenames = {}
+imagedirs = os.listdir(destdir)
+for imagetagid in imagedirs:
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+with open(indexfile,r) as f:
+index = json.load(f)
+imagenames[index[name]] = imagetagid
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+with open(jsonfile,r) as f:
+template = json.load(f)
+parent = template.get(parent,None)
+if parent:
+imageparent[imagetagid] = parent
+if not name in imagenames:
+raise ValueError([Image %s does not exist locally %name])
+imagetagid = imagenames[name]
+imagelist = []
+while imagetagid != None:
+imagelist.append(imagetagid)
+parent = imageparent.get(imagetagid,None)
+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)
+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):
+tempdir = /mnt
+tarfile = directory + tar.gz
+diskfile = directory + qcow2
+cmd = ['virt-sandbox']
+if connect is not None:
+cmd.append(-c)
+cmd.append(connect)
+params = ['-m',
+  'host-image:/mnt=%s,format=%s' %(diskfile,format),
+  '--',
+  '/bin/tar',
+  'zxvf',
+  '%s' %tarfile,
+  '-C',
+  '/mnt']
+cmd = cmd + params
+subprocess.call(cmd)
+
 def debug(msg):
 sys.stderr.write(msg)
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 08bf335..1a63428 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -33,3 +33,7 @@ class Source():
 @abstractmethod
 def download_template(self,**args):
 pass
+
+@abstractmethod
+def create_template(self,**args):
+  pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 2573c29..6f65445 

[libvirt] [sandbox PATCH v2 01/19] Add virt-sandbox-image

2015-08-04 Thread Eren Yagdiran
From: Daniel P Berrange berra...@redhat.com

virt-sandbox-image.py is a python script that lets you download Docker
images easily. It is a proof of concept code and consumes Docker Rest API.
---
 po/POTFILES.in   |   1 +
 virt-sandbox-image/virt-sandbox-image.py | 394 +++
 2 files changed, 395 insertions(+)
 create mode 100644 virt-sandbox-image/virt-sandbox-image.py

diff --git a/po/POTFILES.in b/po/POTFILES.in
index afcb050..7204112 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,3 +11,4 @@ libvirt-sandbox/libvirt-sandbox-context-interactive.c
 libvirt-sandbox/libvirt-sandbox-init-common.c
 libvirt-sandbox/libvirt-sandbox-rpcpacket.c
 libvirt-sandbox/libvirt-sandbox-util.c
+virt-sandbox-image/virt-sandbox-image.py
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
new file mode 100644
index 000..4f5443b
--- /dev/null
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -0,0 +1,394 @@
+#!/usr/bin/python -Es
+#
+# Authors: Daniel P. Berrange berra...@redhat.com
+#
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+import argparse
+import gettext
+import hashlib
+import json
+import os
+import os.path
+import shutil
+import sys
+import urllib2
+import subprocess
+
+default_index_server = index.docker.io
+default_template_dir = /var/lib/libvirt/templates
+
+debug = True
+verbose = True
+
+gettext.bindtextdomain(libvirt-sandbox, /usr/share/locale)
+gettext.textdomain(libvirt-sandbox)
+try:
+gettext.install(libvirt-sandbox,
+localedir=/usr/share/locale,
+unicode=False,
+codeset = 'utf-8')
+except IOError:
+import __builtin__
+__builtin__.__dict__['_'] = unicode
+
+
+def debug(msg):
+sys.stderr.write(msg)
+
+def info(msg):
+sys.stdout.write(msg)
+
+def get_url(server, path, headers):
+url = https://; + server + path
+debug(  Fetching %s... % url)
+req = urllib2.Request(url=url)
+
+if json:
+req.add_header(Accept, application/json)
+
+for h in headers.keys():
+req.add_header(h, headers[h])
+
+return urllib2.urlopen(req)
+
+def get_json(server, path, headers):
+try:
+res = get_url(server, path, headers)
+data = json.loads(res.read())
+debug(OK\n)
+return (data, res)
+except Exception, e:
+debug(FAIL %s\n % str(e))
+raise
+
+def save_data(server, path, headers, dest, checksum=None, datalen=None):
+try:
+res = get_url(server, path, headers)
+
+csum = None
+if checksum is not None:
+csum = hashlib.sha256()
+
+pattern = [., o, O, o]
+patternIndex = 0
+donelen = 0
+
+with open(dest, w) as f:
+while 1:
+buf = res.read(1024*64)
+if not buf:
+break
+if csum is not None:
+csum.update(buf)
+f.write(buf)
+
+if datalen is not None:
+donelen = donelen + len(buf)
+debug(\x1b[s%s (%5d Kb of %5d Kb)\x1b8 % (
+pattern[patternIndex], (donelen/1024), (datalen/1024)
+))
+patternIndex = (patternIndex + 1) % 4
+
+debug(\x1b[K)
+if csum is not None:
+csumstr = sha256: + csum.hexdigest()
+if csumstr != checksum:
+debug(FAIL checksum '%s' does not match '%s' % (csumstr, 
checksum))
+os.remove(dest)
+raise IOError(Checksum '%s' for data does not match '%s' % 
(csumstr, checksum))
+debug(OK\n)
+return res
+except Exception, e:
+debug(FAIL %s\n % str(e))
+raise
+
+
+def download_template(name, server, destdir):
+tag = latest
+
+offset = name.find(':')
+if offset != -1:
+tag = name[offset + 1:]
+name = name[0:offset]
+
+# First we must ask the index server about the image name. THe
+# index server will return an auth token we can use when talking
+# to the registry server. We need this token even when anonymous
+try:
+(data, res) = get_json(server, /v1/repositories/ + name + /images,
+  

[libvirt] [sandbox PATCH v2 02/19] Fix virt-sandbox-image

2015-08-04 Thread Eren Yagdiran
Authentication fix for Docker REST API.
---
 virt-sandbox-image/virt-sandbox-image.py | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 4f5443b..a9cb0ff 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -1,8 +1,10 @@
 #!/usr/bin/python -Es
 #
 # Authors: Daniel P. Berrange berra...@redhat.com
+#  Eren Yagdiran erenyagdi...@gmail.com
 #
 # Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2015 Universitat Polit??cnica de Catalunya.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -166,7 +168,7 @@ def download_template(name, server, destdir):
 # or more parents, in a linear stack. Here we are getting the list
 # of layers for the image with the tag we used.
 (data, res) = get_json(registryserver, /v1/images/ + imagetagid + 
/ancestry,
-   { Cookie: cookie })
+   { Authorization: Token  + token })
 
 if data[0] != imagetagid:
 raise ValueError([Expected first layer id '%s' to match image id 
'%s',
@@ -188,9 +190,9 @@ def download_template(name, server, destdir):
 if not os.path.exists(jsonfile) or not os.path.exists(datafile):
 # The '/json' URL gives us some metadata about the layer
 res = save_data(registryserver, /v1/images/ + layerid + 
/json,
-{ Cookie: cookie }, jsonfile)
+{ Authorization: Token  + token }, 
jsonfile)
 createdFiles.append(jsonfile)
-layersize = int(res.info().getheader(x-docker-size))
+layersize = int(res.info().getheader(Content-Length))
 
 datacsum = None
 if layerid in checksums:
@@ -199,7 +201,7 @@ def download_template(name, server, destdir):
 # and the '/layer' URL is the actual payload, provided
 # as a tar.gz archive
 save_data(registryserver, /v1/images/ + layerid + /layer,
-  { Cookie: cookie }, datafile, datacsum, layersize)
+  { Authorization: Token  + token }, datafile, 
datacsum, layersize)
 createdFiles.append(datafile)
 
 # Strangely the 'json' data for a layer doesn't include
-- 
2.1.0

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

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

2015-08-04 Thread Eren Yagdiran
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/Makefile.am |   1 +
 virt-sandbox-image/sources/DockerSource.py | 227 +
 virt-sandbox-image/sources/Source.py   |   4 +
 virt-sandbox-image/virt-sandbox-image.py   | 199 -
 4 files changed, 259 insertions(+), 172 deletions(-)
 create mode 100644 virt-sandbox-image/sources/DockerSource.py

diff --git a/virt-sandbox-image/Makefile.am b/virt-sandbox-image/Makefile.am
index 5ab4d2e..8188c80 100644
--- a/virt-sandbox-image/Makefile.am
+++ b/virt-sandbox-image/Makefile.am
@@ -8,6 +8,7 @@ install-data-local:
$(INSTALL) -m 0755 $(srcdir)/virt-sandbox-image.py 
$(DESTDIR)$(pkgpythondir)
$(INSTALL) -m 0644 $(srcdir)/sources/__init__.py 
$(DESTDIR)$(pkgpythondir)/sources
$(INSTALL) -m 0644 $(srcdir)/sources/Source.py 
$(DESTDIR)$(pkgpythondir)/sources
+   $(INSTALL) -m 0644 $(srcdir)/sources/DockerSource.py 
$(DESTDIR)$(pkgpythondir)/sources
 
 uninstall-local:
rm -f $(DESTDIR)$(pkgpythondir)
diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
new file mode 100644
index 000..cf81ffe
--- /dev/null
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -0,0 +1,227 @@
+'''
+*
+* libvirt-sandbox-config-diskaccess.h: libvirt sandbox configuration
+*
+* 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 erenyagdi...@gmail.com
+*
+'''
+#!/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 _check_cert_validate(self):
+major = sys.version_info.major
+SSL_WARNING = SSL certificates couldn't be validated by default. You 
need to have 2.7.9/3.4.3 or higher
+SSL_WARNING +=\nSee https://bugs.python.org/issue22417;
+py2_7_9_hexversion = 34015728
+py3_4_3_hexversion = 50594800
+if  (major == 2 and sys.hexversion  py2_7_9_hexversion) or (major == 
3 and sys.hexversion  py3_4_3_hexversion):
+print SSL_WARNING
+
+def _check_dir_writable(self,path):
+if not os.access(path,os.W_OK):
+raise ValueError([%s is not writable for saving template data 
%path])
+
+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):
+
+if username is not None:
+self.www_auth_username = username
+self.www_auth_password = password
+
+self._check_cert_validate()
+self._check_dir_writable(destdir)
+tag = latest
+offset = name.find(':')
+if offset != -1:
+tag = name[offset + 1:]
+name = name[0:offset]
+try:
+(data, res) = self._get_json(server, /v1/repositories/ + name + 
/images,
+   {X-Docker-Token: true})
+except urllib2.HTTPError, e:
+raise ValueError([Image '%s' does not exist % name])
+
+registryserver = res.info().getheader('X-Docker-Endpoints')
+token = res.info().getheader('X-Docker-Token')
+checksums = {}
+for layer in data:
+pass
+(data, res) = self

[libvirt] [sandbox PATCH v2 18/19] Add testcase for custom environment variables

2015-08-04 Thread Eren Yagdiran
make check now includes testcase for environment variables
---
 libvirt-sandbox/tests/test-config.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libvirt-sandbox/tests/test-config.c 
b/libvirt-sandbox/tests/test-config.c
index da05187..ac10bab 100644
--- a/libvirt-sandbox/tests/test-config.c
+++ b/libvirt-sandbox/tests/test-config.c
@@ -58,6 +58,13 @@ int main(int argc, char **argv)
 host-bind:/tmp=,
 NULL
 };
+
+ const gchar *envs[] = {
+key1=val1,
+key2=val2,
+NULL
+};
+
 const gchar *disks[] = {
 file:dbdata=/tmp/img.blah,format=qcow2,
 file:cache=/tmp/img.qcow2,
@@ -103,6 +110,9 @@ int main(int argc, char **argv)
 if (!gvir_sandbox_config_add_mount_strv(cfg1, (gchar**)mounts, err))
 goto cleanup;
 
+if (!gvir_sandbox_config_add_env_strv(cfg1, (gchar**)envs, err))
+goto cleanup;
+
 if (!gvir_sandbox_config_add_disk_strv(cfg1, (gchar**)disks, err))
 goto cleanup;
 
-- 
2.1.0

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


[libvirt] [sandbox PATCH v2 03/19] Image: Add Hooking Mechanism

2015-08-04 Thread Eren Yagdiran
 Street, Fifth Floor, Boston, MA  02110-1301  
USA
+*
+* Author: Eren Yagdiran erenyagdi...@gmail.com
+*
+'''
+#!/usr/bin/python
+
+from abc import ABCMeta, abstractmethod
+
+class Source():
+__metaclass__ = ABCMeta
+def __init__(self):
+pass
diff --git a/virt-sandbox-image/sources/__init__.py 
b/virt-sandbox-image/sources/__init__.py
new file mode 100644
index 000..4830c7a
--- /dev/null
+++ b/virt-sandbox-image/sources/__init__.py
@@ -0,0 +1,29 @@
+'''
+*
+* libvirt-sandbox-config-diskaccess.h: libvirt sandbox configuration
+*
+* 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 erenyagdi...@gmail.com
+*
+'''
+#!/usr/bin/python
+
+import os
+import glob
+modules = glob.glob(os.path.dirname(__file__)+/*.py)
+__all__ = [ os.path.basename(f)[:-3] for f in modules]
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
old mode 100644
new mode 100755
index a9cb0ff..b20b240
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -1,5 +1,5 @@
 #!/usr/bin/python -Es
-#
+# -*- coding: utf-8 -*-
 # Authors: Daniel P. Berrange berra...@redhat.com
 #  Eren Yagdiran erenyagdi...@gmail.com
 #
@@ -38,6 +38,17 @@ default_template_dir = /var/lib/libvirt/templates
 debug = True
 verbose = True
 
+sys.dont_write_bytecode = True
+
+import importlib
+def dynamic_source_loader(name):
+name = name[0].upper() + name[1:]
+modname = 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)
 try:
-- 
2.1.0

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

[libvirt] [sandbox PATCH 11/11] Image: Add run function

2015-07-23 Thread Eren Yagdiran
Run an already-built template
If there is no execution command specified by user, source.get_command will
find the command to invoke
---
 virt-sandbox-image/virt-sandbox-image.py | 20 
 1 file changed, 20 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index fd02567..ca17b3b 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -117,6 +117,26 @@ def check_driver(driver):
 raise ValueError(%s is not supported by Virt-sandbox %driver)
 return True
 
+def run(args):
+try:
+check_driver(args.driver)
+source = dynamic_source_loader(args.source)
+diskfile,configfile = 
source.get_disk(name=args.name,path=args.imagepath)
+
+format = qcow2
+commandToRun = args.command
+if commandToRun is None:
+commandToRun = source.get_command(configfile)
+cmd = ['virt-sandbox',
+   '-c',args.driver,
+   '-m','host-image:/=%s,format=%s' %(diskfile,format),
+   '--',
+   commandToRun]
+subprocess.call(cmd)
+
+except Exception,e:
+print Run Error %s % str(e)
+
 def requires_name(parser):
 parser.add_argument(name,
 help=_(name of the template))
-- 
2.1.0

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


[libvirt] [sandbox PATCH 07/11] Image: Add get_command function to Source

2015-07-23 Thread Eren Yagdiran
Provide a way to know how a template can be started depending on the used source
DockerSource will need to parse the topmost config file in order to find the 
igniter command
---
 virt-sandbox-image/sources/DockerSource.py | 14 ++
 virt-sandbox-image/sources/Source.py   |  4 
 2 files changed, 18 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 180d3f2..4326624 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -9,6 +9,15 @@ import os
 import subprocess
 import shutil
 
+class DockerConfParser():
+
+def __init__(self,jsonfile):
+with open(jsonfile) as json_file:
+self.json_data = json.load(json_file)
+def getRunCommand(self):
+cmd = self.json_data['container_config']['Cmd'][2]
+return cmd[cmd.index('') + 1:cmd.rindex('')]
+
 class DockerSource(Source):
 default_index_server = index.docker.io
 default_template_dir = /var/lib/libvirt/templates
@@ -333,6 +342,11 @@ class DockerSource(Source):
 parent = None
 imagetagid = parent
 
+def get_command(self,configfile):
+configParser = DockerConfParser(configfile)
+commandToRun = configParser.getRunCommand()
+return commandToRun
+
 def debug(msg):
 sys.stderr.write(msg)
 
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 36c4343..c4087ca 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -19,3 +19,7 @@ class Source():
 def delete_template(self,**args):
   pass
 
+@abstractmethod
+def get_command(self,**args):
+  pass
+
-- 
2.1.0

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


[libvirt] [sandbox PATCH 10/11] Image: Add get_disk function to Source

2015-07-23 Thread Eren Yagdiran
Provide a way to know which disk image to use for the sandbox depending on the 
used source
DockerSource will need to locate the topmost disk image among all the layers 
images
---
 virt-sandbox-image/sources/DockerSource.py | 9 +
 virt-sandbox-image/sources/Source.py   | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 4326624..01ef901 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -342,6 +342,15 @@ class DockerSource(Source):
 parent = None
 imagetagid = parent
 
+def get_disk(self,**args):
+name = args['name']
+destdir = args['path']
+imageList = self.__get_image_list(name,destdir)
+toplayer = imageList[0]
+diskfile = destdir + / + toplayer + /template.qcow2
+configfile = destdir + / + toplayer + /template.json
+return (diskfile,configfile)
+
 def get_command(self,configfile):
 configParser = DockerConfParser(configfile)
 commandToRun = configParser.getRunCommand()
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index c4087ca..739de78 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -23,3 +23,5 @@ class Source():
 def get_command(self,**args):
   pass
 
+def get_disk(self,**args):
+  pass
-- 
2.1.0

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


[libvirt] [sandbox PATCH 00/11] Virt-sandbox-image

2015-07-23 Thread Eren Yagdiran
Hello,

virt-sandbox-image.py is a python script that lets you download and run 
templates
from supported sources using virt-sandbox.
Component-based archictecture is accomplished through Source base class.
Docker image support is added through DockerSource.
DockerSource is capable of downloading and running Docker images by consuming 
Docker Registry API.


Daniel P Berrange (1):
  Add virt-sandbox-image

Eren Yagdiran (10):
  Fix virt-sandbox-image
  Image: Add Hooking Mechanism
  Image: Add download function
  Image: Refactor create function
  Image: Add delete function
  Image: Add get_command function to Source
  Image: Add run args
  Image: Add check_driver function
  Image: Add get_disk function to Source
  Image: Add run function

 po/POTFILES.in |   1 +
 virt-sandbox-image/sources/DockerSource.py | 364 +
 virt-sandbox-image/sources/Source.py   |  27 +++
 virt-sandbox-image/virt-sandbox-image.py   | 233 ++
 4 files changed, 625 insertions(+)
 create mode 100644 virt-sandbox-image/sources/DockerSource.py
 create mode 100644 virt-sandbox-image/sources/Source.py
 create mode 100644 virt-sandbox-image/virt-sandbox-image.py

-- 
2.1.0

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


[libvirt] [sandbox PATCH 08/11] Image: Add run args

2015-07-23 Thread Eren Yagdiran
Commandline parameters for running a template
---
 virt-sandbox-image/virt-sandbox-image.py | 13 +
 1 file changed, 13 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index c320105..81b825c 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -164,6 +164,18 @@ def gen_create_args(subparser):
 help=_(format format for image))
 parser.set_defaults(func=create)
 
+def gen_run_args(subparser):
+parser = subparser.add_parser(run,
+  help=_(Run a already built image))
+requires_name(parser)
+requires_source(parser)
+requires_driver(parser)
+parser.add_argument(imagepath,
+help=_(path for image))
+parser.add_argument(-c,--command,
+help=_(Igniter command for image))
+parser.set_defaults(func=run)
+
 if __name__ == '__main__':
 parser = argparse.ArgumentParser(description='Sandbox Container Image 
Tool')
 
@@ -171,6 +183,7 @@ if __name__ == '__main__':
 gen_download_args(subparser)
 gen_delete_args(subparser)
 gen_create_args(subparser)
+gen_run_args(subparser)
 
 try:
 args = parser.parse_args()
-- 
2.1.0

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


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

2015-07-23 Thread Eren Yagdiran
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 000..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):
+
+if username is not None:
+self.www_auth_username = username
+self.www_auth_password = password
+
+tag = latest
+offset = name.find(':')
+if offset != -1:
+tag = name[offset + 1:]
+name = name[0:offset]
+try:
+(data, res) = self.__get_json(server, /v1/repositories/ + name + 
/images,
+   {X-Docker-Token: true})
+except urllib2.HTTPError, e:
+raise ValueError([Image '%s' does not exist % name])
+
+registryserver = res.info().getheader('X-Docker-Endpoints')
+token = res.info().getheader('X-Docker-Token')
+checksums = {}
+for layer in data:
+pass
+(data, res) = self.__get_json(registryserver, /v1/repositories/ + 
name + /tags,
+   { Authorization: Token  + token })
+
+cookie = res.info().getheader('Set-Cookie')
+
+if not tag in data:
+raise ValueError([Tag '%s' does not exist for image '%s' % (tag, 
name)])
+imagetagid = data[tag]
+
+(data, res) = self.__get_json(registryserver, /v1/images/ + 
imagetagid + /ancestry,
+   { Authorization: Token +token })
+
+if data[0] != imagetagid:
+raise ValueError([Expected first layer id '%s' to match image id 
'%s',
+  data[0], imagetagid])
+
+try:
+createdFiles = []
+createdDirs = []
+
+for layerid in data:
+templatedir = destdir + / + layerid
+if not os.path.exists(templatedir):
+os.mkdir(templatedir)
+createdDirs.append(templatedir)
+
+jsonfile = templatedir + /template.json
+datafile = templatedir + /template.tar.gz
+
+if not os.path.exists(jsonfile) or not 
os.path.exists(datafile):
+res = self.__save_data(registryserver, /v1/images/ + 
layerid + /json,
+{ Authorization: Token  + token }, 
jsonfile)
+createdFiles.append(jsonfile)
+
+layersize = int(res.info().getheader(Content-Length))
+
+datacsum = None
+if layerid in checksums:
+datacsum = checksums[layerid]
+
+self.__save_data(registryserver, /v1/images/ + layerid + 
/layer,
+  { Authorization: Token +token }, datafile, 
datacsum, layersize)
+createdFiles.append(datafile)
+
+index = {
+name: name,
+}
+
+indexfile = destdir + / + imagetagid + /index.json
+print(Index file  + indexfile)
+with open(indexfile, w) as f:
+ f.write(json.dumps(index))
+except Exception as e:
+traceback.print_exc()
+for f in createdFiles:
+try:
+os.remove(f)
+except:
+pass
+for d in createdDirs:
+

[libvirt] [sandbox PATCH 05/11] Image: Refactor create function

2015-07-23 Thread Eren Yagdiran
Move the docker-related code to the DockerSource and use
the Source mechanism
---
 virt-sandbox-image/sources/DockerSource.py | 95 ++
 virt-sandbox-image/sources/Source.py   |  5 ++
 virt-sandbox-image/virt-sandbox-image.py   | 72 +-
 3 files changed, 115 insertions(+), 57 deletions(-)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index 5bcd613..f33f94b 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -185,6 +185,101 @@ class DockerSource(Source):
 debug(FAIL %s\n % str(e))
 raise
 
+def create_template(self,**args):
+name = args['name']
+driver = args['driver']
+path = args['imagepath'] 
+path = path if path is not None else self.default_image_path
+format = args['format'] 
+format = format if format is not None else self.default_disk_format
+
+self.__create_template(name,
+   driver,
+   path,
+   format,
+   path)
+
+def __create_template(self,name,driver,image_path,format,destdir):
+self.__check_disk_format(format)
+
+imagelist = self.__get_image_list(name,destdir)
+imagelist.reverse()
+
+parentImage = None
+for imagetagid in imagelist:
+templateImage = destdir + / + imagetagid + /template. + format
+cmd = [qemu-img,create,-f,qcow2]
+if parentImage is not None:
+cmd.append(-o)
+cmd.append(backing_fmt=qcow2,backing_file=%s % parentImage)
+cmd.append(templateImage)
+if parentImage is None:
+cmd.append(10G)
+subprocess.call(cmd)
+
+if parentImage is None:
+self.__format_disk(templateImage,format,driver)
+
+self.__extract_tarballs(destdir + / + imagetagid + 
/template.,format,driver)
+parentImage = templateImage
+
+
+def __check_disk_format(self,format):
+supportedFormats = ['qcow2']
+if not format in supportedFormats:
+raise ValueError([Unsupported image format %s % format])
+
+def __get_image_list(self,name,destdir):
+imageparent = {}
+imagenames = {}
+imagedirs = os.listdir(destdir)
+for imagetagid in imagedirs:
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+with open(indexfile,r) as f:
+index = json.load(f)
+imagenames[index[name]] = imagetagid
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+with open(jsonfile,r) as f:
+template = json.load(f)
+parent = template.get(parent,None)
+if parent:
+imageparent[imagetagid] = parent
+if not name in imagenames:
+raise ValueError([Image %s does not exist locally %name])
+imagetagid = imagenames[name]
+imagelist = []
+while imagetagid != None:
+imagelist.append(imagetagid)
+parent = imageparent.get(imagetagid,None)
+imagetagid = parent
+return imagelist
+
+def __format_disk(self,disk,format,driver):
+cmd = ['virt-sandbox',
+   '-c',driver,
+   '--disk=file:disk_image=%s,format=%s' %(disk,format),
+   '/sbin/mkfs.ext3',
+   '/dev/disk/by-tag/disk_image']
+subprocess.call(cmd)
+
+def __extract_tarballs(self,directory,format,driver):
+tempdir = /mnt
+tarfile = directory + tar.gz
+diskfile = directory + qcow2
+cmd = ['virt-sandbox',
+   '-c',driver,
+   '-m',
+   'host-image:/mnt=%s,format=%s' %(diskfile,format),
+   '--',
+   '/bin/tar',
+   'zxvf',
+   '%s' %tarfile,
+   '-C',
+   '/mnt']
+subprocess.call(cmd)
+
 def debug(msg):
 sys.stderr.write(msg)
 
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 99f44bb..89db14a 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -11,3 +11,8 @@ class Source():
 def download_template(self,**args):
 pass
 
+@abstractmethod
+def create_template(self,**args):
+  pass
+
+
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 1392e8f..58055b3 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -132,60 +132,6 @@ def delete_template(name, destdir):
 parent = None
 imagetagid = parent
 
-

[libvirt] [sandbox PATCH 09/11] Image: Add check_driver function

2015-07-23 Thread Eren Yagdiran
Check if user-specified driver argument is valid
---
 virt-sandbox-image/virt-sandbox-image.py | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 81b825c..fd02567 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -111,6 +111,12 @@ def create(args):
 except Exception,e:
 print Create Error %s % str(e)
 
+def check_driver(driver):
+supportedDrivers = ['lxc:///','qemu:///session','qemu:///system']
+if not driver in supportedDrivers:
+raise ValueError(%s is not supported by Virt-sandbox %driver)
+return True
+
 def requires_name(parser):
 parser.add_argument(name,
 help=_(name of the template))
-- 
2.1.0

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


[libvirt] [sandbox PATCH 02/11] Fix virt-sandbox-image

2015-07-23 Thread Eren Yagdiran
Authentication fix for Docker REST API.
---
 virt-sandbox-image/virt-sandbox-image.py | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 4da3dde..324e568 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -1,8 +1,10 @@
 #!/usr/bin/python -Es
 #
 # Authors: Daniel P. Berrange berra...@redhat.com
+#  Eren Yagdiran erenyagdi...@gmail.com
 #
 # Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2015 Universitat Polit??cnica de Catalunya.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -168,7 +170,7 @@ def download_template(name, server, destdir):
 # or more parents, in a linear stack. Here we are getting the list
 # of layers for the image with the tag we used.
 (data, res) = get_json(registryserver, /v1/images/ + imagetagid + 
/ancestry,
-   { Cookie: cookie })
+   { Authorization: Token  + token })
 
 if data[0] != imagetagid:
 raise ValueError([Expected first layer id '%s' to match image id 
'%s',
@@ -190,9 +192,9 @@ def download_template(name, server, destdir):
 if not os.path.exists(jsonfile) or not os.path.exists(datafile):
 # The '/json' URL gives us some metadata about the layer
 res = save_data(registryserver, /v1/images/ + layerid + 
/json,
-{ Cookie: cookie }, jsonfile)
+{ Authorization: Token  + token }, 
jsonfile)
 createdFiles.append(jsonfile)
-layersize = int(res.info().getheader(x-docker-size))
+layersize = int(res.info().getheader(Content-Length))
 
 datacsum = None
 if layerid in checksums:
@@ -201,7 +203,7 @@ def download_template(name, server, destdir):
 # and the '/layer' URL is the actual payload, provided
 # as a tar.gz archive
 save_data(registryserver, /v1/images/ + layerid + /layer,
-  { Cookie: cookie }, datafile, datacsum, layersize)
+  { Authorization: Token  + token }, datafile, 
datacsum, layersize)
 createdFiles.append(datafile)
 
 # Strangely the 'json' data for a layer doesn't include
-- 
2.1.0

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

[libvirt] [sandbox PATCH 06/11] Image: Add delete function

2015-07-23 Thread Eren Yagdiran
Refactoring delete function from virt-sandbox-image to DockerSource. Delete 
function
can delete templates by name.
---
 virt-sandbox-image/sources/DockerSource.py | 53 +++
 virt-sandbox-image/sources/Source.py   |  3 ++
 virt-sandbox-image/virt-sandbox-image.py   | 59 --
 3 files changed, 64 insertions(+), 51 deletions(-)

diff --git a/virt-sandbox-image/sources/DockerSource.py 
b/virt-sandbox-image/sources/DockerSource.py
index f33f94b..180d3f2 100644
--- a/virt-sandbox-image/sources/DockerSource.py
+++ b/virt-sandbox-image/sources/DockerSource.py
@@ -280,6 +280,59 @@ class DockerSource(Source):
'/mnt']
 subprocess.call(cmd)
 
+def delete_template(self,**args):
+imageusage = {}
+imageparent = {}
+imagenames = {}
+name = args['name']
+destdir = args['imagepath']
+destdir = destdir if destdir is not None else default_template_dir
+imagedirs = os.listdir(destdir)
+for imagetagid in imagedirs:
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+with open(indexfile,r) as f:
+index = json.load(f)
+imagenames[index[name]] = imagetagid
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+with open(jsonfile,r) as f:
+template = json.load(f)
+
+parent = template.get(parent,None)
+if parent:
+if parent not in imageusage:
+imageusage[parent] = []
+imageusage[parent].append(imagetagid)
+imageparent[imagetagid] = parent
+
+
+if not name in imagenames:
+raise ValueError([Image %s does not exist locally %name])
+
+imagetagid = imagenames[name]
+while imagetagid != None:
+debug(Remove %s\n % imagetagid)
+parent = imageparent.get(imagetagid,None)
+
+indexfile = destdir + / + imagetagid + /index.json
+if os.path.exists(indexfile):
+   os.remove(indexfile)
+jsonfile = destdir + / + imagetagid + /template.json
+if os.path.exists(jsonfile):
+os.remove(jsonfile)
+datafile = destdir + / + imagetagid + /template.tar.gz
+if os.path.exists(datafile):
+os.remove(datafile)
+imagedir = destdir + / + imagetagid
+shutil.rmtree(imagedir)
+
+if parent:
+if len(imageusage[parent]) != 1:
+debug(Parent %s is shared\n % parent)
+parent = None
+imagetagid = parent
+
 def debug(msg):
 sys.stderr.write(msg)
 
diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
index 89db14a..36c4343 100644
--- a/virt-sandbox-image/sources/Source.py
+++ b/virt-sandbox-image/sources/Source.py
@@ -15,4 +15,7 @@ class Source():
 def create_template(self,**args):
   pass
 
+@abstractmethod
+def delete_template(self,**args):
+  pass
 
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 58055b3..c320105 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -83,55 +83,6 @@ def debug(msg):
 def info(msg):
 sys.stdout.write(msg)
 
-def delete_template(name, destdir):
-imageusage = {}
-imageparent = {}
-imagenames = {}
-imagedirs = os.listdir(destdir)
-for imagetagid in imagedirs:
-indexfile = destdir + / + imagetagid + /index.json
-if os.path.exists(indexfile):
-with open(indexfile, r) as f:
-index = json.load(f)
-imagenames[index[name]] = imagetagid
-jsonfile = destdir + / + imagetagid + /template.json
-if os.path.exists(jsonfile):
-with open(jsonfile, r) as f:
-template = json.load(f)
-
-parent = template.get(parent, None)
-if parent:
-if parent not in imageusage:
-imageusage[parent] = []
-imageusage[parent].append(imagetagid)
-imageparent[imagetagid] = parent
-
-if not name in imagenames:
-raise ValueError([Image %s does not exist locally % name])
-
-imagetagid = imagenames[name]
-while imagetagid != None:
-debug(Remove %s\n %  imagetagid)
-parent = imageparent.get(imagetagid, None)
-
-indexfile = destdir + / + imagetagid + /index.json
-if os.path.exists(indexfile):
-os.remove(indexfile)
-jsonfile = destdir + / + imagetagid + /template.json
-if os.path.exists(jsonfile):
-os.remove(jsonfile)
-datafile = destdir + / + imagetagid + /template.tar.gz
-if 

[libvirt] [sandbox PATCH 01/11] Add virt-sandbox-image

2015-07-23 Thread Eren Yagdiran
From: Daniel P Berrange berra...@redhat.com

virt-sandbox-image.py is a python script that lets you download Docker
images easily. It is a proof of concept code and consumes Docker Rest API.
---
 po/POTFILES.in   |   1 +
 virt-sandbox-image/virt-sandbox-image.py | 397 +++
 2 files changed, 398 insertions(+)
 create mode 100644 virt-sandbox-image/virt-sandbox-image.py

diff --git a/po/POTFILES.in b/po/POTFILES.in
index afcb050..7204112 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,3 +11,4 @@ libvirt-sandbox/libvirt-sandbox-context-interactive.c
 libvirt-sandbox/libvirt-sandbox-init-common.c
 libvirt-sandbox/libvirt-sandbox-rpcpacket.c
 libvirt-sandbox/libvirt-sandbox-util.c
+virt-sandbox-image/virt-sandbox-image.py
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
new file mode 100644
index 000..4da3dde
--- /dev/null
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -0,0 +1,397 @@
+#!/usr/bin/python -Es
+#
+# Authors: Daniel P. Berrange berra...@redhat.com
+#
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+import argparse
+import gettext
+import hashlib
+import json
+import os
+import os.path
+import shutil
+import sys
+import urllib2
+import subprocess
+
+default_index_server = index.docker.io
+default_template_dir = /var/lib/libvirt/templates
+
+debug = True
+verbose = True
+
+gettext.bindtextdomain(libvirt-sandbox, /usr/share/locale)
+gettext.textdomain(libvirt-sandbox)
+try:
+gettext.install(libvirt-sandbox,
+localedir=/usr/share/locale,
+unicode=False,
+codeset = 'utf-8')
+except IOError:
+import __builtin__
+__builtin__.__dict__['_'] = unicode
+
+
+def debug(msg):
+sys.stderr.write(msg)
+
+def info(msg):
+sys.stdout.write(msg)
+
+def get_url(server, path, headers):
+url = https://; + server + path
+debug(  Fetching %s... % url)
+
+req = urllib2.Request(url=url)
+
+if json:
+req.add_header(Accept, application/json)
+
+for h in headers.keys():
+req.add_header(h, headers[h])
+
+return urllib2.urlopen(req)
+
+def get_json(server, path, headers):
+try:
+res = get_url(server, path, headers)
+data = json.loads(res.read())
+debug(OK\n)
+return (data, res)
+except Exception, e:
+debug(FAIL %s\n % str(e))
+raise
+
+def save_data(server, path, headers, dest, checksum=None, datalen=None):
+try:
+res = get_url(server, path, headers)
+
+csum = None
+if checksum is not None:
+csum = hashlib.sha256()
+
+pattern = [., o, O, o]
+patternIndex = 0
+donelen = 0
+
+with open(dest, w) as f:
+while 1:
+buf = res.read(1024*64)
+if not buf:
+break
+if csum is not None:
+csum.update(buf)
+f.write(buf)
+
+if datalen is not None:
+donelen = donelen + len(buf)
+debug(\x1b[s%s (%5d Kb of %5d Kb)\x1b8 % (
+pattern[patternIndex], (donelen/1024), (datalen/1024)
+))
+patternIndex = (patternIndex + 1) % 4
+
+debug(\x1b[K)
+if csum is not None:
+csumstr = sha256: + csum.hexdigest()
+if csumstr != checksum:
+debug(FAIL checksum '%s' does not match '%s' % (csumstr, 
checksum))
+os.remove(dest)
+raise IOError(Checksum '%s' for data does not match '%s' % 
(csumstr, checksum))
+
+debug(OK\n)
+return res
+except Exception, e:
+debug(FAIL %s\n % str(e))
+raise
+
+
+def download_template(name, server, destdir):
+tag = latest
+
+offset = name.find(':')
+if offset != -1:
+tag = name[offset + 1:]
+name = name[0:offset]
+
+# First we must ask the index server about the image name. THe
+# index server will return an auth token we can use when talking
+# to the registry server. We need this token even when anonymous
+try:
+(data, res) = get_json(server, /v1/repositories/ + name + /images,
+  

[libvirt] [sandbox PATCH 03/11] Image: Add Hooking Mechanism

2015-07-23 Thread Eren Yagdiran
Any custom source provider can be added to virt-sandbox-image as a source
---
 virt-sandbox-image/sources/Source.py |  8 
 virt-sandbox-image/virt-sandbox-image.py | 30 +-
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 virt-sandbox-image/sources/Source.py

diff --git a/virt-sandbox-image/sources/Source.py 
b/virt-sandbox-image/sources/Source.py
new file mode 100644
index 000..cfc75d3
--- /dev/null
+++ b/virt-sandbox-image/sources/Source.py
@@ -0,0 +1,8 @@
+#!/usr/bin/python
+
+from abc import ABCMeta, abstractmethod
+
+class Source():
+__metaclass__ = ABCMeta
+def __init__(self):
+pass
diff --git a/virt-sandbox-image/virt-sandbox-image.py 
b/virt-sandbox-image/virt-sandbox-image.py
index 324e568..99ed46e 100644
--- a/virt-sandbox-image/virt-sandbox-image.py
+++ b/virt-sandbox-image/virt-sandbox-image.py
@@ -1,5 +1,5 @@
 #!/usr/bin/python -Es
-#
+# -*- coding: utf-8 -*-
 # Authors: Daniel P. Berrange berra...@redhat.com
 #  Eren Yagdiran erenyagdi...@gmail.com
 #
@@ -38,6 +38,34 @@ default_template_dir = /var/lib/libvirt/templates
 debug = True
 verbose = True
 
+sys.dont_write_bytecode = True
+
+
+##Hook mechanism starts##
+import __builtin__
+from sources.Source import Source
+__builtin__.hookHolder = {}
+def add_hook(driverName,clazz):
+holder = __builtin__.hookHolder
+if not issubclass(clazz,Source):
+raise Exception(Loading %s failed. Make sure it is a subclass Of %s 
%(clazz,Source))
+holder[driverName] = clazz
+
+def init_from_name(name):
+holder = __builtin__.hookHolder
+return holder.get(name,None)
+
+__builtin__.add_hook = add_hook
+__builtin__.init_from_name = init_from_name
+from sources import *
+
+def dynamic_source_loader(name):
+obj = init_from_name(name)
+if obj == None:
+raise IOError
+return obj()
+##Hook mechanism ends
+
 gettext.bindtextdomain(libvirt-sandbox, /usr/share/locale)
 gettext.textdomain(libvirt-sandbox)
 try:
-- 
2.1.0

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


[libvirt] [sandbox PATCH 06/10] Add gvir_sandbox_config_has_disks function

2015-06-26 Thread Eren Yagdiran
From: Cédric Bosdonnat cbosdon...@suse.com

Add helper function to check if a config contains disk devices.
---
 libvirt-sandbox/libvirt-sandbox-config.c | 7 +++
 libvirt-sandbox/libvirt-sandbox-config.h | 1 +
 libvirt-sandbox/libvirt-sandbox.sym  | 1 +
 3 files changed, 9 insertions(+)

diff --git a/libvirt-sandbox/libvirt-sandbox-config.c 
b/libvirt-sandbox/libvirt-sandbox-config.c
index d01135f..3e0c7e9 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -1305,6 +1305,13 @@ gboolean 
gvir_sandbox_config_add_disk_opts(GVirSandboxConfig *config,
 }
 
 
+gboolean gvir_sandbox_config_has_disks(GVirSandboxConfig *config)
+{
+GVirSandboxConfigPrivate *priv = config-priv;
+return priv-disks != NULL;
+}
+
+
 /**
  * gvir_sandbox_config_add_mount:
  * @config: (transfer none): the sandbox config
diff --git a/libvirt-sandbox/libvirt-sandbox-config.h 
b/libvirt-sandbox/libvirt-sandbox-config.h
index deaea68..ebbebf2 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.h
+++ b/libvirt-sandbox/libvirt-sandbox-config.h
@@ -131,6 +131,7 @@ gboolean 
gvir_sandbox_config_add_disk_strv(GVirSandboxConfig *config,
 gboolean gvir_sandbox_config_add_disk_opts(GVirSandboxConfig *config,
const char *disk,
GError **error);
+gboolean gvir_sandbox_config_has_disks(GVirSandboxConfig *config);
 
 void gvir_sandbox_config_add_mount(GVirSandboxConfig *config,
GVirSandboxConfigMount *mnt);
diff --git a/libvirt-sandbox/libvirt-sandbox.sym 
b/libvirt-sandbox/libvirt-sandbox.sym
index bb717ed..e5f8660 100644
--- a/libvirt-sandbox/libvirt-sandbox.sym
+++ b/libvirt-sandbox/libvirt-sandbox.sym
@@ -217,4 +217,5 @@ LIBVIRT_SANDBOX_0.5.2 {
gvir_sandbox_config_add_disk_strv;
gvir_sandbox_config_add_disk_opts;
gvir_sandbox_config_disk_get_type;
+gvir_sandbox_config_has_disks;
 } LIBVIRT_SANDBOX_0.2.1;
-- 
2.1.0

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

[libvirt] [sandbox PATCH 00/10] Patches for Libvirt-sandbox

2015-06-26 Thread Eren Yagdiran
Hello,

These patches provide disk support for libvirt-sandbox.
Implemented '--disk' parameter will be useful when integrating Docker image 
support for libvirt-sandbox.

--Main diffs compared to previous patches.

Since many hypervisors, including kvm, will not even honour requested
names for disk devices we link each device under /dev/disk/by-tag

e.g /dev/disk/by-tag/foobar - /dev/sda

We populate disks.cfg with tag to device mapping when we build the sandbox.
After that, in each init-process {Common,Qemu}, we basically read the 
configuration
and populate the right symlinks under /dev/disk/by-tag

The common functions for modifying directories are moved under Init-util. 
{Common,Qemu} inits are using them.

Cédric Bosdonnat (2):
  Add gvir_sandbox_config_has_disks function
  qemu: use devtmpfs rather than tmpfs to auto-populate /dev

Eren Yagdiran (8):
  Add an utility function for guessing filetype from file extension
  Add configuration object for disk support
  Add disk parameter to virt-sandbox
  Add disk support to the container builder
  Add disk support to machine builder
  Init-util : Common directory functions for init-common and init-qemu
  Common-init: Building symlink from disks.cfg
  Common-builder: /dev/disk/by-tag/thetag to /dev/vdN

 bin/virt-sandbox.c |  37 +++
 libvirt-sandbox/Makefile.am|   7 +-
 .../libvirt-sandbox-builder-container.c|  33 ++-
 libvirt-sandbox/libvirt-sandbox-builder-machine.c  |  44 ++-
 libvirt-sandbox/libvirt-sandbox-builder.c  |  73 -
 libvirt-sandbox/libvirt-sandbox-config-disk.c  | 273 +++
 libvirt-sandbox/libvirt-sandbox-config-disk.h  |  82 ++
 libvirt-sandbox/libvirt-sandbox-config.c   | 300 +
 libvirt-sandbox/libvirt-sandbox-config.h   |  11 +
 libvirt-sandbox/libvirt-sandbox-init-common.c  |  54 +++-
 libvirt-sandbox/libvirt-sandbox-init-qemu.c| 145 ++
 libvirt-sandbox/libvirt-sandbox-init-util.c|  57 
 libvirt-sandbox/libvirt-sandbox-init-util.h|  40 +++
 libvirt-sandbox/libvirt-sandbox-util.c |  72 +
 libvirt-sandbox/libvirt-sandbox-util.h |   5 +
 libvirt-sandbox/libvirt-sandbox.h  |   1 +
 libvirt-sandbox/libvirt-sandbox.sym|   5 +
 libvirt-sandbox/tests/test-config.c|  11 +
 po/POTFILES.in |   1 +
 19 files changed, 1105 insertions(+), 146 deletions(-)
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-disk.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-disk.h
 create mode 100644 libvirt-sandbox/libvirt-sandbox-init-util.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-init-util.h
 create mode 100644 libvirt-sandbox/libvirt-sandbox-util.c

-- 
2.1.0

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

[libvirt] [sandbox PATCH 10/10] Common-builder: /dev/disk/by-tag/thetag to /dev/vdN

2015-06-26 Thread Eren Yagdiran
Common builder counts the disks devices and populates disks.cfg according to 
that.Disk devices
are always come first than host-based images.In builder-machine, mounts of the 
host-based images
will be mounted later.
---
 libvirt-sandbox/libvirt-sandbox-builder-machine.c |  6 +-
 libvirt-sandbox/libvirt-sandbox-builder.c | 73 +--
 2 files changed, 71 insertions(+), 8 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c 
b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
index 4148d4b..db956cf 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
@@ -283,9 +283,10 @@ static gboolean 
gvir_sandbox_builder_machine_write_mount_cfg(GVirSandboxConfig *
 error);
 gboolean ret = FALSE;
 GList *mounts = gvir_sandbox_config_get_mounts(config);
+GList *disks = gvir_sandbox_config_get_disks(config);
 GList *tmp = NULL;
 size_t nHostBind = 0;
-size_t nHostImage = 0;
+guint nVirtioDev = g_list_length(disks);
 
 if (!fos)
 goto cleanup;
@@ -304,7 +305,7 @@ static gboolean 
gvir_sandbox_builder_machine_write_mount_cfg(GVirSandboxConfig *
 fstype = 9p;
 options = g_strdup(trans=virtio,version=9p2000.u);
 } else if (GVIR_SANDBOX_IS_CONFIG_MOUNT_HOST_IMAGE(mconfig)) {
-source = g_strdup_printf(/dev/vd%c, (char)('a' + nHostImage++));
+source = g_strdup_printf(/dev/vd%c, (char)('a' + nVirtioDev++));
 fstype = ext4;
 options = g_strdup();
 } else if (GVIR_SANDBOX_IS_CONFIG_MOUNT_GUEST_BIND(mconfig)) {
@@ -351,6 +352,7 @@ static gboolean 
gvir_sandbox_builder_machine_write_mount_cfg(GVirSandboxConfig *
  cleanup:
 g_list_foreach(mounts, (GFunc)g_object_unref, NULL);
 g_list_free(mounts);
+g_list_free(disks);
 if (fos)
 g_object_unref(fos);
 if (!ret)
diff --git a/libvirt-sandbox/libvirt-sandbox-builder.c 
b/libvirt-sandbox/libvirt-sandbox-builder.c
index bcad652..4ba7a84 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder.c
@@ -312,14 +312,75 @@ static gboolean 
gvir_sandbox_builder_construct_features(GVirSandboxBuilder *buil
 return TRUE;
 }
 
+static gboolean gvir_sandbox_builder_construct_disk_cfg(GVirSandboxConfig 
*config,
+const gchar *statedir,
+GError **error)
+{
 
-static gboolean gvir_sandbox_builder_construct_devices(GVirSandboxBuilder 
*builder G_GNUC_UNUSED,
-   GVirSandboxConfig 
*config G_GNUC_UNUSED,
-   const gchar *statedir 
G_GNUC_UNUSED,
-   GVirConfigDomain 
*domain G_GNUC_UNUSED,
-   GError **error 
G_GNUC_UNUSED)
+guint nVirtioDev = 0;
+gchar *dskfile = g_strdup_printf(%s/config/disks.cfg, statedir);
+GFile *file = g_file_new_for_path(dskfile);
+GFileOutputStream *fos = g_file_replace(file,
+NULL,
+FALSE,
+G_FILE_CREATE_REPLACE_DESTINATION,
+NULL,
+error);
+gboolean ret = FALSE;
+GList *disks = gvir_sandbox_config_get_disks(config);
+GList *tmp = NULL;
+const gchar *tag;
+
+if (!fos)
+goto cleanup;
+
+tmp = disks;
+while (tmp) {
+GVirSandboxConfigDisk *mconfig = GVIR_SANDBOX_CONFIG_DISK(tmp-data);
+gchar *device = g_strdup_printf(/dev/vd%c, (char)('a' + 
(nVirtioDev)++));
+gchar *line;
+
+tag = gvir_sandbox_config_disk_get_tag(mconfig);
+
+line = g_strdup_printf(%s\t%s\n,
+   tag, device);
+g_free(device);
+
+if (!g_output_stream_write_all(G_OUTPUT_STREAM(fos),
+   line, strlen(line),
+   NULL, NULL, error)) {
+g_free(line);
+goto cleanup;
+}
+g_free(line);
+
+tmp = tmp-next;
+}
+
+if (!g_output_stream_close(G_OUTPUT_STREAM(fos), NULL, error))
+goto cleanup;
+
+ret = TRUE;
+ cleanup:
+g_list_foreach(disks, (GFunc)g_object_unref, NULL);
+g_list_free(disks);
+if (fos)
+g_object_unref(fos);
+if (!ret)
+g_file_delete(file, NULL, NULL);
+g_object_unref(file);
+g_free(dskfile);
+return ret;
+
+}
+
+static gboolean gvir_sandbox_builder_construct_devices(GVirSandboxBuilder 
*builder,
+   GVirSandboxConfig 
*config,
+

[libvirt] [sandbox PATCH 05/10] Add disk support to machine builder

2015-06-26 Thread Eren Yagdiran
Use the new disk configuration in the container builder to provide disks in
qemu sandboxes. The disks are virtio devices, but those shouldn't be
known by the user.
---
 libvirt-sandbox/libvirt-sandbox-builder-machine.c | 38 ---
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c 
b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
index 5e6bf72..4148d4b 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
@@ -174,7 +174,8 @@ static gchar 
*gvir_sandbox_builder_machine_mkinitrd(GVirSandboxConfig *config,
 if (gvir_sandbox_config_has_networks(config))
 gvir_sandbox_config_initrd_add_module(initrd, virtio_net.ko);
 if (gvir_sandbox_config_has_mounts_with_type(config,
- 
GVIR_SANDBOX_TYPE_CONFIG_MOUNT_HOST_IMAGE))
+ 
GVIR_SANDBOX_TYPE_CONFIG_MOUNT_HOST_IMAGE) ||
+gvir_sandbox_config_has_disks(config))
 gvir_sandbox_config_initrd_add_module(initrd, virtio_blk.ko);
 gvir_sandbox_config_initrd_add_module(initrd, virtio_console.ko);
 #if 0
@@ -503,9 +504,9 @@ static gboolean 
gvir_sandbox_builder_machine_construct_devices(GVirSandboxBuilde
 GVirConfigDomainConsole *con;
 GVirConfigDomainSerial *ser;
 GVirConfigDomainChardevSourcePty *src;
-GList *tmp = NULL, *mounts = NULL, *networks = NULL;
+GList *tmp = NULL, *mounts = NULL, *networks = NULL, *disks = NULL;
 size_t nHostBind = 0;
-size_t nHostImage = 0;
+size_t nVirtioDev = 0;
 gchar *configdir = g_strdup_printf(%s/config, statedir);
 gboolean ret = FALSE;
 
@@ -538,6 +539,35 @@ static gboolean 
gvir_sandbox_builder_machine_construct_devices(GVirSandboxBuilde
 g_object_unref(fs);
 
 
+tmp = disks = gvir_sandbox_config_get_disks(config);
+while(tmp){
+GVirSandboxConfigDisk *dconfig = GVIR_SANDBOX_CONFIG_DISK(tmp-data);
+
+if (GVIR_SANDBOX_IS_CONFIG_DISK(dconfig)){
+gchar *device = g_strdup_printf(vd%c, (char)('a' + 
nVirtioDev++));
+
+disk = gvir_config_domain_disk_new();
+diskDriver = gvir_config_domain_disk_driver_new();
+gvir_config_domain_disk_set_type(disk,
+ 
gvir_sandbox_config_disk_get_disk_type(dconfig));
+gvir_config_domain_disk_driver_set_format(diskDriver,
+  
gvir_sandbox_config_disk_get_format(dconfig));
+gvir_config_domain_disk_set_source(disk, 
gvir_sandbox_config_disk_get_source(dconfig));
+gvir_config_domain_disk_set_target_bus(disk,
+   
GVIR_CONFIG_DOMAIN_DISK_BUS_VIRTIO);
+gvir_config_domain_disk_set_target_dev(disk,
+   device);
+gvir_config_domain_disk_set_driver(disk, diskDriver);
+gvir_config_domain_add_device(domain, 
GVIR_CONFIG_DOMAIN_DEVICE(disk));
+g_object_unref(disk);
+g_free(device);
+}
+tmp = tmp-next;
+}
+
+g_list_foreach(disks, (GFunc)g_object_unref, NULL);
+g_list_free(disks);
+
 tmp = mounts = gvir_sandbox_config_get_mounts(config);
 while (tmp) {
 GVirSandboxConfigMount *mconfig = GVIR_SANDBOX_CONFIG_MOUNT(tmp-data);
@@ -563,7 +593,7 @@ static gboolean 
gvir_sandbox_builder_machine_construct_devices(GVirSandboxBuilde
 GVirSandboxConfigMountFile *mfile = 
GVIR_SANDBOX_CONFIG_MOUNT_FILE(mconfig);
 GVirSandboxConfigMountHostImage *mimage = 
GVIR_SANDBOX_CONFIG_MOUNT_HOST_IMAGE(mconfig);
 GVirConfigDomainDiskFormat format;
-gchar *target = g_strdup_printf(vd%c, (char)('a' + 
nHostImage++));
+gchar *target = g_strdup_printf(vd%c, (char)('a' + 
nVirtioDev++));
 
 disk = gvir_config_domain_disk_new();
 gvir_config_domain_disk_set_type(disk, 
GVIR_CONFIG_DOMAIN_DISK_FILE);
-- 
2.1.0

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


[libvirt] [sandbox PATCH 02/10] Add configuration object for disk support

2015-06-26 Thread Eren Yagdiran
Add the config gobject, functions to store and load the new configuration
fragments and test. This will allow creating sandboxes with attached
disk with a parameter formatted like file:tag=/source/file.qcow2,format=qcow2
---
 libvirt-sandbox/Makefile.am   |   2 +
 libvirt-sandbox/libvirt-sandbox-config-disk.c | 273 
 libvirt-sandbox/libvirt-sandbox-config-disk.h |  82 +++
 libvirt-sandbox/libvirt-sandbox-config.c  | 293 ++
 libvirt-sandbox/libvirt-sandbox-config.h  |  10 +
 libvirt-sandbox/libvirt-sandbox.h |   1 +
 libvirt-sandbox/libvirt-sandbox.sym   |   4 +
 libvirt-sandbox/tests/test-config.c   |  11 +
 8 files changed, 676 insertions(+)
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-disk.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-disk.h

diff --git a/libvirt-sandbox/Makefile.am b/libvirt-sandbox/Makefile.am
index 6917f04..8237c50 100644
--- a/libvirt-sandbox/Makefile.am
+++ b/libvirt-sandbox/Makefile.am
@@ -55,6 +55,7 @@ SANDBOX_HEADER_FILES = \
libvirt-sandbox-main.h \
libvirt-sandbox-util.h \
libvirt-sandbox-config.h \
+   libvirt-sandbox-config-disk.h \
libvirt-sandbox-config-network.h \
libvirt-sandbox-config-network-address.h \
libvirt-sandbox-config-network-filterref-parameter.h \
@@ -86,6 +87,7 @@ SANDBOX_SOURCE_FILES = \
libvirt-sandbox-main.c \
libvirt-sandbox-util.c \
libvirt-sandbox-config.c \
+   libvirt-sandbox-config-disk.c \
libvirt-sandbox-config-network.c \
libvirt-sandbox-config-network-address.c \
libvirt-sandbox-config-network-filterref.c \
diff --git a/libvirt-sandbox/libvirt-sandbox-config-disk.c 
b/libvirt-sandbox/libvirt-sandbox-config-disk.c
new file mode 100644
index 000..0781714
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-config-disk.c
@@ -0,0 +1,273 @@
+/*
+ * libvirt-sandbox-config-disk.c: libvirt sandbox configuration
+ *
+ * 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 erenyagdi...@gmail.com
+ */
+
+#include config.h
+#include string.h
+
+#include libvirt-sandbox/libvirt-sandbox.h
+
+/**
+ * SECTION: libvirt-sandbox-config-disk
+ * @short_description: Disk attachment configuration details
+ * @include: libvirt-sandbox/libvirt-sandbox.h
+ * @see_aloso: #GVirSandboxConfig
+ *
+ * Provides an object to store information about a disk attachment in the 
sandbox
+ *
+ */
+
+#define GVIR_SANDBOX_CONFIG_DISK_GET_PRIVATE(obj)  \
+(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_SANDBOX_TYPE_CONFIG_DISK, 
GVirSandboxConfigDiskPrivate))
+
+
+struct _GVirSandboxConfigDiskPrivate
+{
+GVirConfigDomainDiskType type;
+gchar *tag;
+gchar *source;
+GVirConfigDomainDiskFormat format;
+};
+
+G_DEFINE_TYPE(GVirSandboxConfigDisk, gvir_sandbox_config_disk, G_TYPE_OBJECT);
+
+
+enum {
+PROP_0,
+PROP_TYPE,
+PROP_TAG,
+PROP_SOURCE,
+PROP_FORMAT
+};
+
+enum {
+LAST_SIGNAL
+};
+
+
+
+static void gvir_sandbox_config_disk_get_property(GObject *object,
+  guint prop_id,
+  GValue *value,
+  GParamSpec *pspec)
+{
+GVirSandboxConfigDisk *config = GVIR_SANDBOX_CONFIG_DISK(object);
+GVirSandboxConfigDiskPrivate *priv = config-priv;
+
+switch (prop_id) {
+case PROP_TAG:
+g_value_set_string(value, priv-tag);
+break;
+case PROP_SOURCE:
+g_value_set_string(value, priv-source);
+break;
+case PROP_TYPE:
+g_value_set_enum(value, priv-type);
+break;
+case PROP_FORMAT:
+g_value_set_enum(value, priv-format);
+break;
+default:
+G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+}
+}
+
+
+static void gvir_sandbox_config_disk_set_property(GObject *object

[libvirt] [sandbox PATCH 04/10] Add disk support to the container builder

2015-06-26 Thread Eren Yagdiran
Use the new disk configuration in the container builder to provide disks in
lxc containers sandboxes.
---
 .../libvirt-sandbox-builder-container.c| 33 +-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-builder-container.c 
b/libvirt-sandbox/libvirt-sandbox-builder-container.c
index 59bfee1..900acf2 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-container.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-container.c
@@ -218,14 +218,45 @@ static gboolean 
gvir_sandbox_builder_container_construct_devices(GVirSandboxBuil
 GVirConfigDomainInterfaceNetwork *iface;
 GVirConfigDomainConsole *con;
 GVirConfigDomainChardevSourcePty *src;
-GList *tmp = NULL, *mounts = NULL, *networks = NULL;
+GVirConfigDomainDisk *disk;
+GVirConfigDomainDiskDriver *diskDriver;
+GList *tmp = NULL, *mounts = NULL, *networks = NULL, *disks = NULL;
 gchar *configdir = g_strdup_printf(%s/config, statedir);
 gboolean ret = FALSE;
+size_t nVirtioDev = 0;
 
 if 
(!GVIR_SANDBOX_BUILDER_CLASS(gvir_sandbox_builder_container_parent_class)-
 construct_devices(builder, config, statedir, domain, error))
 goto cleanup;
 
+
+tmp = disks = gvir_sandbox_config_get_disks(config);
+while(tmp){
+GVirSandboxConfigDisk *dconfig = GVIR_SANDBOX_CONFIG_DISK(tmp-data);
+
+if (GVIR_SANDBOX_IS_CONFIG_DISK(dconfig)){
+gchar *device = g_strdup_printf(sd%c, (char)('a' + 
nVirtioDev++));
+disk = gvir_config_domain_disk_new();
+diskDriver = gvir_config_domain_disk_driver_new();
+gvir_config_domain_disk_set_type(disk,
+ 
gvir_sandbox_config_disk_get_disk_type(dconfig));
+gvir_config_domain_disk_driver_set_format(diskDriver,
+  
gvir_sandbox_config_disk_get_format(dconfig));
+gvir_config_domain_disk_set_source(disk,
+   
gvir_sandbox_config_disk_get_source(dconfig));
+gvir_config_domain_disk_set_target_dev(disk,device);
+gvir_config_domain_disk_set_driver(disk, diskDriver);
+gvir_config_domain_add_device(domain,
+  GVIR_CONFIG_DOMAIN_DEVICE(disk));
+g_object_unref(disk);
+}
+tmp = tmp-next;
+}
+
+g_list_foreach(disks, (GFunc)g_object_unref, NULL);
+g_list_free(disks);
+
+
 fs = gvir_config_domain_filesys_new();
 gvir_config_domain_filesys_set_type(fs, GVIR_CONFIG_DOMAIN_FILESYS_MOUNT);
 gvir_config_domain_filesys_set_access_type(fs, 
GVIR_CONFIG_DOMAIN_FILESYS_ACCESS_PASSTHROUGH);
-- 
2.1.0

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


[libvirt] [sandbox PATCH 03/10] Add disk parameter to virt-sandbox

2015-06-26 Thread Eren Yagdiran
Allow users to add disk images to their sandbox. Only disk images are supported 
so far, but the
parameter is intentionally designed for future changes.
---
 bin/virt-sandbox.c | 37 +
 1 file changed, 37 insertions(+)

diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index 1ab2f8a..3373c7f 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -63,6 +63,7 @@ int main(int argc, char **argv) {
 GMainLoop *loop = NULL;
 GError *error = NULL;
 gchar *name = NULL;
+gchar **disks = NULL;
 gchar **mounts = NULL;
 gchar **includes = NULL;
 gchar *includefile = NULL;
@@ -92,6 +93,8 @@ int main(int argc, char **argv) {
   N_(name of the sandbox), NAME },
 { root, 'r', 0, G_OPTION_ARG_STRING, root,
   N_(root directory of the sandbox), DIR },
+{ disk, ' ', 0, G_OPTION_ARG_STRING_ARRAY, disks,
+  N_(add a disk in the guest), TYPE:TAGNAME=SOURCE,FORMAT=FORMAT },
 { mount, 'm', 0, G_OPTION_ARG_STRING_ARRAY, mounts,
   N_(mount a filesystem in the guest), TYPE:TARGET=SOURCE },
 { include, 'i', 0, G_OPTION_ARG_STRING_ARRAY, includes,
@@ -182,6 +185,13 @@ int main(int argc, char **argv) {
 gvir_sandbox_config_set_username(cfg, root);
 }
 
+if (disks 
+!gvir_sandbox_config_add_disk_strv(cfg, disks, error)) {
+g_printerr(_(Unable to parse disks: %s\n),
+   error  error-message ? error-message : _(Unknown 
failure));
+goto cleanup;
+}
+
 if (mounts 
 !gvir_sandbox_config_add_mount_strv(cfg, mounts, error)) {
 g_printerr(_(Unable to parse mounts: %s\n),
@@ -319,6 +329,33 @@ inheriting the host's root filesystem.
 NB. CDIR must contain a matching install of the libvirt-sandbox
 package. This restriction may be lifted in a future version.
 
+=item B--disk TYPE:TAGNAME=SOURCE,FORMAT=FORMAT
+
+Sets up a disk inside the sandbox by using BSOURCE with a symlink named as 
BTAGNAME
+and type BTYPE and format BFORMAT. Example: 
file:hda=/var/lib/sandbox/demo/tmp.qcow2,format=qcow2
+Format is an optional parameter.
+
+=over 4
+
+=item BTYPE
+
+Type parameter can be set to file.
+
+=item BTAGNAME
+
+TAGNAME will be created under /dev/disk/by-tag/TAGNAME. It will be linked to 
the device under /dev
+
+=item BSOURCE
+
+Source parameter needs to point a file which must be a one of the valid domain 
disk formats supported by qemu.
+
+=item BFORMAT
+
+Format parameter must be set to the same disk format as the file passed on 
source parameter.
+This parameter is optional and the format can be guessed from the image 
extension
+
+=back
+
 =item B-m TYPE:DST=SRC, B--mount TYPE:DST=SRC
 
 Sets up a mount inside the sandbox at BDST backed by BSRC. The
-- 
2.1.0

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


[libvirt] [sandbox PATCH 09/10] Common-init: Building symlink from disks.cfg

2015-06-26 Thread Eren Yagdiran
Similar to the existing mounts.cfg, the mapping between the device and the tag 
is
passed by a new disks.cfg file. Common-init reads disks.cfg and maps the tags
to corresponding devices
---
 libvirt-sandbox/libvirt-sandbox-init-common.c | 54 ++-
 1 file changed, 52 insertions(+), 2 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c 
b/libvirt-sandbox/libvirt-sandbox-init-common.c
index 68f96ba..a0e6e0a 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -46,6 +46,7 @@
 #include grp.h
 
 #include libvirt-sandbox-rpcpacket.h
+#include libvirt-sandbox-init-util.h
 
 static gboolean debug = FALSE;
 static gboolean verbose = FALSE;
@@ -60,6 +61,54 @@ static void sig_child(int sig ATTR_UNUSED)
 abort();
 }
 
+static gboolean setup_disk_tags(void) {
+FILE *fp;
+gboolean ret = FALSE;
+static char line[1024];
+if (debug)
+fprintf(stderr, libvirt-sandbox-init-common: %s: populate 
/dev/disk/by-tag/\n,
+__func__);
+fp = fopen(SANDBOXCONFIGDIR /disks.cfg, r);
+if (fp == NULL) {
+fprintf(stderr, libvirt-sandbox-init-common: %s: cannot open  
SANDBOXCONFIGDIR /disks.cfg: %s\n,
+__func__, strerror(errno));
+
+goto cleanup;
+}
+if (g_mkdir_with_parents(/dev/disk/by-tag,0755)  0) {
+   fprintf(stderr, libvirt-sandbox-init-common: %s: cannot create the 
directory: %s\n,
+   __func__, strerror(errno));
+
+   goto cleanup;
+}
+while (fgets(line, sizeof line, fp)) {
+char *tag = line;
+char *device = strchr(tag, '\t');
+gchar *path = NULL;
+*device = '\0';
+device++;
+char *tmp = strchr(device, '\n');
+*tmp = '\0';
+path = g_strdup_printf(/dev/disk/by-tag/%s, tag);
+
+if (debug)
+fprintf(stderr, libvirt-sandbox-init-common: %s: %s - %s\n,
+__func__, path, device);
+
+if (symlink(device, path)  0) {
+fprintf(stderr, libvirt-sandbox-init-common: %s: cannot create 
symlink %s - %s: %s\n,
+__func__, path, device, strerror(errno));
+g_free(path);
+goto cleanup;
+}
+
+g_free(path);
+}
+ret = TRUE;
+ cleanup:
+fclose(fp);
+return ret;
+}
 
 static int
 start_shell(void)
@@ -258,8 +307,6 @@ static gboolean 
setup_network_device(GVirSandboxConfigNetwork *config,
 return ret;
 }
 
-
-
 static gboolean setup_network(GVirSandboxConfig *config, GError **error)
 {
 int i = 0;
@@ -1215,6 +1262,9 @@ int main(int argc, char **argv) {
 start_shell()  0)
 exit(EXIT_FAILURE);
 
+if (!setup_disk_tags())
+exit(EXIT_FAILURE);
+
 if (!setup_network(config, error))
 goto error;
 
-- 
2.1.0

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


[libvirt] [sandbox PATCH 01/10] Add an utility function for guessing filetype from file extension

2015-06-26 Thread Eren Yagdiran
Consider the file name extension as the image type, except for .img that are 
usually RAW images
---
 libvirt-sandbox/Makefile.am|  1 +
 libvirt-sandbox/libvirt-sandbox-util.c | 72 ++
 libvirt-sandbox/libvirt-sandbox-util.h |  5 +++
 po/POTFILES.in |  1 +
 4 files changed, 79 insertions(+)
 create mode 100644 libvirt-sandbox/libvirt-sandbox-util.c

diff --git a/libvirt-sandbox/Makefile.am b/libvirt-sandbox/Makefile.am
index 96302cb..6917f04 100644
--- a/libvirt-sandbox/Makefile.am
+++ b/libvirt-sandbox/Makefile.am
@@ -84,6 +84,7 @@ SANDBOX_HEADER_FILES = \
$(NULL)
 SANDBOX_SOURCE_FILES = \
libvirt-sandbox-main.c \
+   libvirt-sandbox-util.c \
libvirt-sandbox-config.c \
libvirt-sandbox-config-network.c \
libvirt-sandbox-config-network-address.c \
diff --git a/libvirt-sandbox/libvirt-sandbox-util.c 
b/libvirt-sandbox/libvirt-sandbox-util.c
new file mode 100644
index 000..079ecd6
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-util.c
@@ -0,0 +1,72 @@
+/*
+ * libvirt-sandbox-util.c: libvirt sandbox util functions
+ *
+ * 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 erenyagdi...@gmail.com
+ */
+
+#include config.h
+#include string.h
+#include errno.h
+#include glib/gi18n.h
+
+#include libvirt-sandbox/libvirt-sandbox.h
+
+#define GVIR_SANDBOX_UTIL_ERROR gvir_sandbox_util_error_quark()
+
+static GQuark
+gvir_sandbox_util_error_quark(void)
+{
+return g_quark_from_static_string(gvir-sandbox-util);
+}
+
+gint gvir_sandbox_util_guess_image_format(const gchar *path,
+  GError **error)
+{
+gchar *tmp;
+
+if ((tmp = strchr(path, '.')) == NULL) {
+return -1;
+}
+tmp = tmp + 1;
+
+if (g_str_equal(tmp,img)==TRUE){
+   return GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW;
+}
+
+return gvir_sandbox_util_disk_format_from_str(tmp, error);
+}
+
+gint gvir_sandbox_util_disk_format_from_str(const gchar *value,
+GError **error)
+{
+GEnumClass *enum_class = 
g_type_class_ref(GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT);
+GEnumValue *enum_value;
+gint ret = -1;
+
+if (!(enum_value = g_enum_get_value_by_nick(enum_class, value))) {
+g_set_error(error, GVIR_SANDBOX_UTIL_ERROR, 0,
+_(Unknown disk format '%s'), value);
+goto cleanup;
+}
+ret = enum_value-value;
+
+ cleanup:
+g_type_class_unref(enum_class);
+return ret;
+}
diff --git a/libvirt-sandbox/libvirt-sandbox-util.h 
b/libvirt-sandbox/libvirt-sandbox-util.h
index ae6b74b..890ae7f 100644
--- a/libvirt-sandbox/libvirt-sandbox-util.h
+++ b/libvirt-sandbox/libvirt-sandbox-util.h
@@ -29,6 +29,11 @@
 
 G_BEGIN_DECLS
 
+gint gvir_sandbox_util_guess_image_format(const gchar *path, GError **error);
+
+
+gint gvir_sandbox_util_disk_format_from_str(const gchar *value, GError 
**error);
+
 /**
  * LIBVIRT_SANDBOX_CLASS_PADDING: (skip)
  */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 653abc5..f291b98 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,3 +9,4 @@ libvirt-sandbox/libvirt-sandbox-console-rpc.c
 libvirt-sandbox/libvirt-sandbox-context.c
 libvirt-sandbox/libvirt-sandbox-init-common.c
 libvirt-sandbox/libvirt-sandbox-rpcpacket.c
+libvirt-sandbox/libvirt-sandbox-util.c
-- 
2.1.0

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

[libvirt] [sandbox PATCH 08/10] Init-util : Common directory functions for init-common and init-qemu

2015-06-26 Thread Eren Yagdiran
 mode 100644
index 000..4bc02cc
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-init-util.c
@@ -0,0 +1,57 @@
+/*
+ * libvirt-sandbox-init-util.c: libvirt sandbox init util functions
+ *
+ * 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 erenyagdi...@gmail.com
+ */
+
+#include config.h
+#include string.h
+#include errno.h
+#include sys/stat.h
+#include stdlib.h
+#include stdio.h
+
+#include libvirt-sandbox-init-util.h
+
+int gvir_sandbox_init_util_mkdir(const char *dir, int mode, int debug)
+{
+gvir_sandbox_init_util_mkparent(dir, 0755,debug);
+
+if (debug  0)
+fprintf(stderr, libvirt-sandbox-init-util: %s: %s (mode=%o)\n, 
__func__, dir, mode);
+
+if (mkdir(dir, mode)  0) {
+if (errno != EEXIST) {
+fprintf(stderr, libvirt-sandbox-init-util: %s: cannot make 
directory %s: %s\n,__func__, dir, strerror(errno));
+return -1;
+}
+}
+return 0;
+}
+
+int gvir_sandbox_init_util_mkparent(const char *dir, int mode,int debug)
+{
+char *tmp = strrchr(dir, '/');
+if (tmp  tmp != dir) {
+char *parent = strndup(dir, tmp - dir);
+gvir_sandbox_init_util_mkdir(parent, mode,debug);
+free(parent);
+}
+return 0;
+}
diff --git a/libvirt-sandbox/libvirt-sandbox-init-util.h 
b/libvirt-sandbox/libvirt-sandbox-init-util.h
new file mode 100644
index 000..bb3e27a
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-init-util.h
@@ -0,0 +1,40 @@
+/*
+ * libvirt-sandbox-init-util.h: libvirt sandbox init util header
+ *
+ * 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 erenyagdi...@gmail.com
+ */
+
+#ifndef __LIBVIRT_SANDBOX_INIT_UTIL_H__
+#define __LIBVIRT_SANDBOX_INIT_UTIL_H__
+
+int gvir_sandbox_init_util_mkdir(const char *dir, int mode, int debug);
+
+int gvir_sandbox_init_util_mkparent(const char *dir, int mode, int debug);
+
+
+#endif /* __LIBVIRT_SANDBOX_INIT_UTIL_H__ */
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  indent-tabs-mode: nil
+ *  tab-width: 8
+ * End:
+ */
-- 
2.1.0

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

[libvirt] [sandbox PATCH 07/10] qemu: use devtmpfs rather than tmpfs to auto-populate /dev

2015-06-26 Thread Eren Yagdiran
From: Cédric Bosdonnat cbosdon...@suse.com

When using devtmpfs we don't need to care about the device nodes
creation: it's less risk to forget some. It also eases the creation of
the devices in the init-qemu.
---
 libvirt-sandbox/libvirt-sandbox-init-qemu.c | 94 +
 1 file changed, 1 insertion(+), 93 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-qemu.c 
b/libvirt-sandbox/libvirt-sandbox-init-qemu.c
index 750c9de..33cebed 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-qemu.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-qemu.c
@@ -53,7 +53,6 @@ static int has_command_arg(const char *name,
 
 static int debug = 0;
 static char line[1024];
-static char line2[1024];
 
 static void exit_poweroff(void) __attribute__((noreturn));
 
@@ -173,50 +172,6 @@ mount_9pfs(const char *src, const char *dst, int mode, int 
readonly)
 }
 }
 
-static int virtioblk_major = 0;
-static void
-create_virtioblk_device(const char *dev)
-{
-int minor;
-
-if (virtioblk_major == 0) {
-FILE *fp = fopen(/proc/devices, r);
-if (!fp) {
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot read 
/proc/devices: %s\n,
-__func__, strerror(errno));
-exit_poweroff();
-}
-while (fgets(line2, sizeof line2, fp)) {
-if (strstr(line2, virtblk)) {
-char *end;
-long l = strtol(line2, end, 10);
-if (line2 == end) {
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot 
extract device major from '%s'\n,
-__func__, line2);
-fclose(fp);
-exit_poweroff();
-}
-virtioblk_major = l;
-break;
-}
-}
-fclose(fp);
-
-if (virtioblk_major == 0) {
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot find 
virtioblk device major in /proc/devices\n,
-__func__);
-exit_poweroff();
-}
-}
-
-minor = (dev[strlen(dev)-1] - 'a') * 16;
-
-if (mknod(dev, S_IFBLK |0700, makedev(virtioblk_major, minor))  0) {
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot make dev '%s' 
'%llu': %s\n,
-__func__, dev, makedev(virtioblk_major, minor), 
strerror(errno));
-exit_poweroff();
-}
-}
 
 int
 main(int argc ATTR_UNUSED, char **argv ATTR_UNUSED)
@@ -283,59 +238,14 @@ main(int argc ATTR_UNUSED, char **argv ATTR_UNUSED)
 }
 
 /* Main special filesystems */
-mount_other(/dev, tmpfs, 0755);
+mount_other(/dev, devtmpfs, 0755);
 mount_other_opts(/dev/pts, devpts, gid=5,mode=620,ptmxmode=000, 
0755);
 mount_other(/sys, sysfs, 0755);
 mount_other(/proc, proc, 0755);
 //mount_other(/selinux, selinuxfs, 0755);
 mount_other(/dev/shm, tmpfs, 01777);
 
-if (mkdir(/dev/input, 0777)  0) {
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot make directory 
/dev/input: %s\n,
-__func__, strerror(errno));
-exit_poweroff();
-}
-
-#define MKNOD(file, mode, dev)  \
-do {\
-if (mknod(file, mode, dev)  0) {   \
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot make dev %s 
%llu: %s\n, \
-__func__, file, (unsigned long long)dev, strerror(errno)); 
\
-exit_poweroff();\
-}   \
-} while (0)
-
-umask();
-MKNOD(/dev/null, S_IFCHR |0666, makedev(1, 3));
-MKNOD(/dev/zero, S_IFCHR |0666, makedev(1, 5));
-MKNOD(/dev/full, S_IFCHR |0666, makedev(1, 7));
-MKNOD(/dev/random, S_IFCHR |0666, makedev(1, 8));
-MKNOD(/dev/urandom, S_IFCHR |0666, makedev(1, 9));
-MKNOD(/dev/console, S_IFCHR |0700, makedev(5, 1));
-MKNOD(/dev/tty, S_IFCHR |0700, makedev(5, 0));
-MKNOD(/dev/tty0, S_IFCHR |0700, makedev(4, 0));
-MKNOD(/dev/tty1, S_IFCHR |0700, makedev(4, 1));
-MKNOD(/dev/tty2, S_IFCHR |0700, makedev(4, 2));
-MKNOD(/dev/ttyS0, S_IFCHR |0700, makedev(4, 64));
-MKNOD(/dev/ttyS1, S_IFCHR |0700, makedev(4, 65));
-MKNOD(/dev/ttyS2, S_IFCHR |0700, makedev(4, 66));
-MKNOD(/dev/ttyS3, S_IFCHR |0700, makedev(4, 67));
-MKNOD(/dev/hvc0, S_IFCHR |0700, makedev(229, 0));
-MKNOD(/dev/hvc1, S_IFCHR |0700, makedev(229, 1));
-MKNOD(/dev/hvc2, S_IFCHR |0700, makedev(229, 2));
-MKNOD(/dev/fb, S_IFCHR |0700, makedev(29, 0));
-MKNOD(/dev/fb0, S_IFCHR |0700, makedev(29, 0));
-MKNOD(/dev/mem, S_IFCHR |0600, makedev(1, 1));
-MKNOD(/dev/rtc, S_IFCHR |0700, makedev(254, 0));
-MKNOD(/dev/rtc0, S_IFCHR |0700, makedev(254, 0));
-MKNOD(/dev/ptmx, S_IFCHR |0777, makedev(5, 2));
-MKNOD(/dev/input/event0, S_IFCHR |0700, 

[libvirt] [sandbox PATCH 08/10] Init-util : Common directory functions for init-common and init-qemu

2015-06-25 Thread Eren Yagdiran
, opts)  0) {
diff --git a/libvirt-sandbox/libvirt-sandbox-init-util.c 
b/libvirt-sandbox/libvirt-sandbox-init-util.c
new file mode 100644
index 000..2660652
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-init-util.c
@@ -0,0 +1,58 @@
+/*
+ * libvirt-sandbox-init-util.c: libvirt sandbox init util functions
+ *
+ * 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 erenyagdi...@gmail.com
+ */
+
+#include config.h
+#include string.h
+#include errno.h
+#include sys/stat.h
+#include stdlib.h
+#include stdio.h
+
+#include libvirt-sandbox-init-util.h
+
+int gvir_sandbox_init_util_mkdir(const char *dir, int mode, int debug)
+{
+gvir_sandbox_init_util_mkparent(dir, 0755,debug);
+
+if (debug  0)
+fprintf(stderr, libvirt-sandbox-init-util: %s: %s (mode=%o)\n, 
__func__, dir, mode);
+
+if (mkdir(dir, mode)  0) {
+if (errno != EEXIST) {
+fprintf(stderr, libvirt-sandbox-init-util: %s: cannot make 
directory %s: %s\n,__func__, dir, strerror(errno));
+return -1;
+}
+}
+return 0;
+}
+
+int gvir_sandbox_init_util_mkparent(const char *dir, int mode,int debug)
+{
+char *tmp = strrchr(dir, '/');
+if (tmp  tmp != dir) {
+char *parent = strndup(dir, tmp - dir);
+gvir_sandbox_init_util_mkdir(parent, mode,debug);
+free(parent);
+}
+return 0;
+}
+
diff --git a/libvirt-sandbox/libvirt-sandbox-init-util.h 
b/libvirt-sandbox/libvirt-sandbox-init-util.h
new file mode 100644
index 000..01cccf1
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-init-util.h
@@ -0,0 +1,41 @@
+/*
+ * libvirt-sandbox-init-util.h: libvirt sandbox init util header
+ *
+ * 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 erenyagdi...@gmail.com
+ */
+
+#ifndef __LIBVIRT_SANDBOX_INIT_UTIL_H__
+#define __LIBVIRT_SANDBOX_INIT_UTIL_H__
+
+int gvir_sandbox_init_util_mkdir(const char *dir, int mode, int debug);
+
+int gvir_sandbox_init_util_mkparent(const char *dir, int mode, int debug);
+
+
+#endif /* __LIBVIRT_SANDBOX_INIT_UTIL_H__ */
+
+/*
+ * Local variables:
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  indent-tabs-mode: nil
+ *  tab-width: 8
+ * End:
+ */
+
-- 
2.1.0

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

[libvirt] [sandbox PATCH 03/10] Add disk parameter to virt-sandbox

2015-06-25 Thread Eren Yagdiran
Allow users to add disk images to their sandbox. Only disk images are supported 
so far, but the
parameter is intentionally designed for future changes.
---
 bin/virt-sandbox.c | 37 +
 1 file changed, 37 insertions(+)

diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index 1ab2f8a..ac56346 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -63,6 +63,7 @@ int main(int argc, char **argv) {
 GMainLoop *loop = NULL;
 GError *error = NULL;
 gchar *name = NULL;
+gchar **disks = NULL;
 gchar **mounts = NULL;
 gchar **includes = NULL;
 gchar *includefile = NULL;
@@ -92,6 +93,8 @@ int main(int argc, char **argv) {
   N_(name of the sandbox), NAME },
 { root, 'r', 0, G_OPTION_ARG_STRING, root,
   N_(root directory of the sandbox), DIR },
+{ disk, ' ', 0, G_OPTION_ARG_STRING_ARRAY, disks,
+  N_(add a disk in the guest), TYPE:TARGET=SOURCE,FORMAT=FORMAT },
 { mount, 'm', 0, G_OPTION_ARG_STRING_ARRAY, mounts,
   N_(mount a filesystem in the guest), TYPE:TARGET=SOURCE },
 { include, 'i', 0, G_OPTION_ARG_STRING_ARRAY, includes,
@@ -182,6 +185,13 @@ int main(int argc, char **argv) {
 gvir_sandbox_config_set_username(cfg, root);
 }
 
+if (disks 
+!gvir_sandbox_config_add_disk_strv(cfg, disks, error)) {
+g_printerr(_(Unable to parse disks: %s\n),
+   error  error-message ? error-message : _(Unknown 
failure));
+goto cleanup;
+}
+
 if (mounts 
 !gvir_sandbox_config_add_mount_strv(cfg, mounts, error)) {
 g_printerr(_(Unable to parse mounts: %s\n),
@@ -319,6 +329,33 @@ inheriting the host's root filesystem.
 NB. CDIR must contain a matching install of the libvirt-sandbox
 package. This restriction may be lifted in a future version.
 
+=item B--disk TYPE:TARGET=SOURCE,FORMAT=FORMAT
+
+Sets up a disk inside the sandbox by using BSOURCE with target device 
BTARGET
+and type BTYPE and format BFORMAT. Example: 
file:hda=/var/lib/sandbox/demo/tmp.qcow2,format=qcow2
+Format is an optional parameter.
+
+=over 4
+
+=item BTYPE
+
+Type parameter can be set to file.
+
+=item BTARGET
+
+Target parameter can be set to hda or any other libvirt supported target disk
+
+=item BSOURCE
+
+Source parameter needs to point a file which must be a one of the valid domain 
disk formats supported by qemu.
+
+=item BFORMAT
+
+Format parameter must be set to the same disk format as the file passed on 
source parameter.
+This parameter is optional and the format can be guessed from the image 
extension
+
+=back
+
 =item B-m TYPE:DST=SRC, B--mount TYPE:DST=SRC
 
 Sets up a mount inside the sandbox at BDST backed by BSRC. The
-- 
2.1.0

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


[libvirt] [sandbox PATCH 00/10] Patches for Libvirt-sandbox

2015-06-25 Thread Eren Yagdiran
Hello,

These patches provide disk support for libvirt-sandbox.
Implemented '--disk' parameter will be useful when integrating Docker image 
support for libvirt-sandbox.

--Main diffs compared to previous patches.

Since many hypervisors, including kvm, will not even honour requested
names for disk devices we link each device under /dev/disk/by-tag

e.g /dev/disk/by-tag/foobar - /dev/sda

We populate disks.cfg with tag to device mapping when we build the sandbox.
After that, in each init-process {Common,Qemu}, we basically read the 
configuration
and populate the right symlinks under /dev/disk/by-tag

The common functions for modifying directories are moved under Init-util. 
{Common,Qemu} inits are using them.

Cédric Bosdonnat (2):
  Add gvir_sandbox_config_has_disks function
  qemu: use devtmpfs rather than tmpfs to auto-populate /dev

Eren Yagdiran (8):
  Add an utility function for guessing filetype from file extension
  Add configuration object for disk support
  Add disk parameter to virt-sandbox
  Add disk support to the container builder
  Add disk support to machine builder
  Init-util : Common directory functions for init-common and init-qemu
  Common-init: Building symlink from disks.cfg
  Common-builder: /dev/disk/by-tag/thetag to /dev/vdN

 bin/virt-sandbox.c |  37 +++
 libvirt-sandbox/Makefile.am|   7 +-
 .../libvirt-sandbox-builder-container.c|  37 ++-
 libvirt-sandbox/libvirt-sandbox-builder-machine.c  |  44 ++-
 libvirt-sandbox/libvirt-sandbox-builder.c  |  73 -
 libvirt-sandbox/libvirt-sandbox-config-disk.c  | 274 +++
 libvirt-sandbox/libvirt-sandbox-config-disk.h  |  82 ++
 libvirt-sandbox/libvirt-sandbox-config.c   | 300 +
 libvirt-sandbox/libvirt-sandbox-config.h   |  11 +
 libvirt-sandbox/libvirt-sandbox-init-common.c  |  51 +++-
 libvirt-sandbox/libvirt-sandbox-init-qemu.c| 151 ++-
 libvirt-sandbox/libvirt-sandbox-init-util.c|  58 
 libvirt-sandbox/libvirt-sandbox-init-util.h|  41 +++
 libvirt-sandbox/libvirt-sandbox-util.c |  72 +
 libvirt-sandbox/libvirt-sandbox-util.h |   5 +
 libvirt-sandbox/libvirt-sandbox.h  |   1 +
 libvirt-sandbox/libvirt-sandbox.sym|   5 +
 libvirt-sandbox/tests/test-config.c|  11 +
 po/POTFILES.in |   1 +
 19 files changed, 1112 insertions(+), 149 deletions(-)
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-disk.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-disk.h
 create mode 100644 libvirt-sandbox/libvirt-sandbox-init-util.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-init-util.h
 create mode 100644 libvirt-sandbox/libvirt-sandbox-util.c

-- 
2.1.0

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

[libvirt] [sandbox PATCH 10/10] Common-builder: /dev/disk/by-tag/thetag to /dev/vdN

2015-06-25 Thread Eren Yagdiran
Common builder counts the disks devices and populates disks.cfg according to 
that.Disk devices
are always come first than host-based images.In builder-machine, mounts of the 
host-based images
will be mounted later.
---
 libvirt-sandbox/libvirt-sandbox-builder-machine.c |  6 +-
 libvirt-sandbox/libvirt-sandbox-builder.c | 73 +--
 2 files changed, 71 insertions(+), 8 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c 
b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
index 4148d4b..db956cf 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
@@ -283,9 +283,10 @@ static gboolean 
gvir_sandbox_builder_machine_write_mount_cfg(GVirSandboxConfig *
 error);
 gboolean ret = FALSE;
 GList *mounts = gvir_sandbox_config_get_mounts(config);
+GList *disks = gvir_sandbox_config_get_disks(config);
 GList *tmp = NULL;
 size_t nHostBind = 0;
-size_t nHostImage = 0;
+guint nVirtioDev = g_list_length(disks);
 
 if (!fos)
 goto cleanup;
@@ -304,7 +305,7 @@ static gboolean 
gvir_sandbox_builder_machine_write_mount_cfg(GVirSandboxConfig *
 fstype = 9p;
 options = g_strdup(trans=virtio,version=9p2000.u);
 } else if (GVIR_SANDBOX_IS_CONFIG_MOUNT_HOST_IMAGE(mconfig)) {
-source = g_strdup_printf(/dev/vd%c, (char)('a' + nHostImage++));
+source = g_strdup_printf(/dev/vd%c, (char)('a' + nVirtioDev++));
 fstype = ext4;
 options = g_strdup();
 } else if (GVIR_SANDBOX_IS_CONFIG_MOUNT_GUEST_BIND(mconfig)) {
@@ -351,6 +352,7 @@ static gboolean 
gvir_sandbox_builder_machine_write_mount_cfg(GVirSandboxConfig *
  cleanup:
 g_list_foreach(mounts, (GFunc)g_object_unref, NULL);
 g_list_free(mounts);
+g_list_free(disks);
 if (fos)
 g_object_unref(fos);
 if (!ret)
diff --git a/libvirt-sandbox/libvirt-sandbox-builder.c 
b/libvirt-sandbox/libvirt-sandbox-builder.c
index bcad652..d83fd9f 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder.c
@@ -312,14 +312,75 @@ static gboolean 
gvir_sandbox_builder_construct_features(GVirSandboxBuilder *buil
 return TRUE;
 }
 
+static gboolean gvir_sandbox_builder_construct_disk_cfg(GVirSandboxConfig 
*config,
+const gchar *statedir,
+GError **error)
+{
 
-static gboolean gvir_sandbox_builder_construct_devices(GVirSandboxBuilder 
*builder G_GNUC_UNUSED,
-   GVirSandboxConfig 
*config G_GNUC_UNUSED,
-   const gchar *statedir 
G_GNUC_UNUSED,
-   GVirConfigDomain 
*domain G_GNUC_UNUSED,
-   GError **error 
G_GNUC_UNUSED)
+guint nVirtioDev = 0;
+gchar *dskfile = g_strdup_printf(%s/config/disks.cfg, statedir);
+GFile *file = g_file_new_for_path(dskfile);
+GFileOutputStream *fos = g_file_replace(file,
+NULL,
+FALSE,
+G_FILE_CREATE_REPLACE_DESTINATION,
+NULL,
+error);
+gboolean ret = FALSE;
+GList *disks = gvir_sandbox_config_get_disks(config);
+GList *tmp = NULL;
+const gchar *target;
+
+if (!fos)
+goto cleanup;
+
+tmp = disks;
+while (tmp) {
+GVirSandboxConfigDisk *mconfig = GVIR_SANDBOX_CONFIG_DISK(tmp-data);
+gchar *device = g_strdup_printf(/dev/vd%c, (char)('a' + 
(nVirtioDev)++));
+gchar *line;
+
+target = gvir_sandbox_config_disk_get_target(mconfig);
+
+line = g_strdup_printf(%s\t%s\n,
+   target, device);
+g_free(device);
+
+if (!g_output_stream_write_all(G_OUTPUT_STREAM(fos),
+   line, strlen(line),
+   NULL, NULL, error)) {
+g_free(line);
+goto cleanup;
+}
+g_free(line);
+
+tmp = tmp-next;
+}
+
+if (!g_output_stream_close(G_OUTPUT_STREAM(fos), NULL, error))
+goto cleanup;
+
+ret = TRUE;
+ cleanup:
+g_list_foreach(disks, (GFunc)g_object_unref, NULL);
+g_list_free(disks);
+if (fos)
+g_object_unref(fos);
+if (!ret)
+g_file_delete(file, NULL, NULL);
+g_object_unref(file);
+g_free(dskfile);
+return ret;
+
+}
+
+static gboolean gvir_sandbox_builder_construct_devices(GVirSandboxBuilder 
*builder,
+   GVirSandboxConfig 
*config,
+

[libvirt] [sandbox PATCH 05/10] Add disk support to machine builder

2015-06-25 Thread Eren Yagdiran
Use the new disk configuration in the container builder to provide disks in
qemu sandboxes. The disks are virtio devices, but those shouldn't be
known by the user.
---
 libvirt-sandbox/libvirt-sandbox-builder-machine.c | 38 ---
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c 
b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
index 5e6bf72..4148d4b 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
@@ -174,7 +174,8 @@ static gchar 
*gvir_sandbox_builder_machine_mkinitrd(GVirSandboxConfig *config,
 if (gvir_sandbox_config_has_networks(config))
 gvir_sandbox_config_initrd_add_module(initrd, virtio_net.ko);
 if (gvir_sandbox_config_has_mounts_with_type(config,
- 
GVIR_SANDBOX_TYPE_CONFIG_MOUNT_HOST_IMAGE))
+ 
GVIR_SANDBOX_TYPE_CONFIG_MOUNT_HOST_IMAGE) ||
+gvir_sandbox_config_has_disks(config))
 gvir_sandbox_config_initrd_add_module(initrd, virtio_blk.ko);
 gvir_sandbox_config_initrd_add_module(initrd, virtio_console.ko);
 #if 0
@@ -503,9 +504,9 @@ static gboolean 
gvir_sandbox_builder_machine_construct_devices(GVirSandboxBuilde
 GVirConfigDomainConsole *con;
 GVirConfigDomainSerial *ser;
 GVirConfigDomainChardevSourcePty *src;
-GList *tmp = NULL, *mounts = NULL, *networks = NULL;
+GList *tmp = NULL, *mounts = NULL, *networks = NULL, *disks = NULL;
 size_t nHostBind = 0;
-size_t nHostImage = 0;
+size_t nVirtioDev = 0;
 gchar *configdir = g_strdup_printf(%s/config, statedir);
 gboolean ret = FALSE;
 
@@ -538,6 +539,35 @@ static gboolean 
gvir_sandbox_builder_machine_construct_devices(GVirSandboxBuilde
 g_object_unref(fs);
 
 
+tmp = disks = gvir_sandbox_config_get_disks(config);
+while(tmp){
+GVirSandboxConfigDisk *dconfig = GVIR_SANDBOX_CONFIG_DISK(tmp-data);
+
+if (GVIR_SANDBOX_IS_CONFIG_DISK(dconfig)){
+gchar *device = g_strdup_printf(vd%c, (char)('a' + 
nVirtioDev++));
+
+disk = gvir_config_domain_disk_new();
+diskDriver = gvir_config_domain_disk_driver_new();
+gvir_config_domain_disk_set_type(disk,
+ 
gvir_sandbox_config_disk_get_disk_type(dconfig));
+gvir_config_domain_disk_driver_set_format(diskDriver,
+  
gvir_sandbox_config_disk_get_format(dconfig));
+gvir_config_domain_disk_set_source(disk, 
gvir_sandbox_config_disk_get_source(dconfig));
+gvir_config_domain_disk_set_target_bus(disk,
+   
GVIR_CONFIG_DOMAIN_DISK_BUS_VIRTIO);
+gvir_config_domain_disk_set_target_dev(disk,
+   device);
+gvir_config_domain_disk_set_driver(disk, diskDriver);
+gvir_config_domain_add_device(domain, 
GVIR_CONFIG_DOMAIN_DEVICE(disk));
+g_object_unref(disk);
+g_free(device);
+}
+tmp = tmp-next;
+}
+
+g_list_foreach(disks, (GFunc)g_object_unref, NULL);
+g_list_free(disks);
+
 tmp = mounts = gvir_sandbox_config_get_mounts(config);
 while (tmp) {
 GVirSandboxConfigMount *mconfig = GVIR_SANDBOX_CONFIG_MOUNT(tmp-data);
@@ -563,7 +593,7 @@ static gboolean 
gvir_sandbox_builder_machine_construct_devices(GVirSandboxBuilde
 GVirSandboxConfigMountFile *mfile = 
GVIR_SANDBOX_CONFIG_MOUNT_FILE(mconfig);
 GVirSandboxConfigMountHostImage *mimage = 
GVIR_SANDBOX_CONFIG_MOUNT_HOST_IMAGE(mconfig);
 GVirConfigDomainDiskFormat format;
-gchar *target = g_strdup_printf(vd%c, (char)('a' + 
nHostImage++));
+gchar *target = g_strdup_printf(vd%c, (char)('a' + 
nVirtioDev++));
 
 disk = gvir_config_domain_disk_new();
 gvir_config_domain_disk_set_type(disk, 
GVIR_CONFIG_DOMAIN_DISK_FILE);
-- 
2.1.0

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


[libvirt] [sandbox PATCH 04/10] Add disk support to the container builder

2015-06-25 Thread Eren Yagdiran
Use the new disk configuration in the container builder to provide disks in
lxc containers sandboxes.
---
 .../libvirt-sandbox-builder-container.c| 37 +-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-builder-container.c 
b/libvirt-sandbox/libvirt-sandbox-builder-container.c
index 59bfee1..3318c30 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-container.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-container.c
@@ -218,14 +218,49 @@ static gboolean 
gvir_sandbox_builder_container_construct_devices(GVirSandboxBuil
 GVirConfigDomainInterfaceNetwork *iface;
 GVirConfigDomainConsole *con;
 GVirConfigDomainChardevSourcePty *src;
-GList *tmp = NULL, *mounts = NULL, *networks = NULL;
+GVirConfigDomainDisk *disk;
+GVirConfigDomainDiskDriver *diskDriver;
+GList *tmp = NULL, *mounts = NULL, *networks = NULL, *disks = NULL;
 gchar *configdir = g_strdup_printf(%s/config, statedir);
 gboolean ret = FALSE;
+size_t nVirtioDev = 0;
 
 if 
(!GVIR_SANDBOX_BUILDER_CLASS(gvir_sandbox_builder_container_parent_class)-
 construct_devices(builder, config, statedir, domain, error))
 goto cleanup;
 
+
+tmp = disks = gvir_sandbox_config_get_disks(config);
+while(tmp){
+GVirSandboxConfigDisk *dconfig = GVIR_SANDBOX_CONFIG_DISK(tmp-data);
+
+if (GVIR_SANDBOX_IS_CONFIG_DISK(dconfig)){
+
+gchar *device = g_strdup_printf(vd%c, (char)('a' + 
nVirtioDev++));
+disk = gvir_config_domain_disk_new();
+diskDriver = gvir_config_domain_disk_driver_new();
+gvir_config_domain_disk_set_type(disk,
+ 
gvir_sandbox_config_disk_get_disk_type(dconfig));
+gvir_config_domain_disk_driver_set_format(diskDriver,
+  
gvir_sandbox_config_disk_get_format(dconfig));
+gvir_config_domain_disk_driver_set_name(diskDriver, nbd);
+gvir_config_domain_disk_set_source(disk,
+   
gvir_sandbox_config_disk_get_source(dconfig));
+gvir_config_domain_disk_set_target_bus(disk,
+   
GVIR_CONFIG_DOMAIN_DISK_BUS_VIRTIO);
+gvir_config_domain_disk_set_target_dev(disk,device);
+gvir_config_domain_disk_set_driver(disk, diskDriver);
+gvir_config_domain_add_device(domain,
+  GVIR_CONFIG_DOMAIN_DEVICE(disk));
+g_object_unref(disk);
+}
+tmp = tmp-next;
+}
+
+g_list_foreach(disks, (GFunc)g_object_unref, NULL);
+g_list_free(disks);
+
+
 fs = gvir_config_domain_filesys_new();
 gvir_config_domain_filesys_set_type(fs, GVIR_CONFIG_DOMAIN_FILESYS_MOUNT);
 gvir_config_domain_filesys_set_access_type(fs, 
GVIR_CONFIG_DOMAIN_FILESYS_ACCESS_PASSTHROUGH);
-- 
2.1.0

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


[libvirt] [sandbox PATCH 07/10] qemu: use devtmpfs rather than tmpfs to auto-populate /dev

2015-06-25 Thread Eren Yagdiran
From: Cédric Bosdonnat cbosdon...@suse.com

When using devtmpfs we don't need to care about the device nodes
creation: it's less risk to forget some. It also eases the creation of
the devices in the init-qemu.
---
 libvirt-sandbox/libvirt-sandbox-init-qemu.c | 94 +
 1 file changed, 1 insertion(+), 93 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-qemu.c 
b/libvirt-sandbox/libvirt-sandbox-init-qemu.c
index 750c9de..33cebed 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-qemu.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-qemu.c
@@ -53,7 +53,6 @@ static int has_command_arg(const char *name,
 
 static int debug = 0;
 static char line[1024];
-static char line2[1024];
 
 static void exit_poweroff(void) __attribute__((noreturn));
 
@@ -173,50 +172,6 @@ mount_9pfs(const char *src, const char *dst, int mode, int 
readonly)
 }
 }
 
-static int virtioblk_major = 0;
-static void
-create_virtioblk_device(const char *dev)
-{
-int minor;
-
-if (virtioblk_major == 0) {
-FILE *fp = fopen(/proc/devices, r);
-if (!fp) {
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot read 
/proc/devices: %s\n,
-__func__, strerror(errno));
-exit_poweroff();
-}
-while (fgets(line2, sizeof line2, fp)) {
-if (strstr(line2, virtblk)) {
-char *end;
-long l = strtol(line2, end, 10);
-if (line2 == end) {
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot 
extract device major from '%s'\n,
-__func__, line2);
-fclose(fp);
-exit_poweroff();
-}
-virtioblk_major = l;
-break;
-}
-}
-fclose(fp);
-
-if (virtioblk_major == 0) {
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot find 
virtioblk device major in /proc/devices\n,
-__func__);
-exit_poweroff();
-}
-}
-
-minor = (dev[strlen(dev)-1] - 'a') * 16;
-
-if (mknod(dev, S_IFBLK |0700, makedev(virtioblk_major, minor))  0) {
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot make dev '%s' 
'%llu': %s\n,
-__func__, dev, makedev(virtioblk_major, minor), 
strerror(errno));
-exit_poweroff();
-}
-}
 
 int
 main(int argc ATTR_UNUSED, char **argv ATTR_UNUSED)
@@ -283,59 +238,14 @@ main(int argc ATTR_UNUSED, char **argv ATTR_UNUSED)
 }
 
 /* Main special filesystems */
-mount_other(/dev, tmpfs, 0755);
+mount_other(/dev, devtmpfs, 0755);
 mount_other_opts(/dev/pts, devpts, gid=5,mode=620,ptmxmode=000, 
0755);
 mount_other(/sys, sysfs, 0755);
 mount_other(/proc, proc, 0755);
 //mount_other(/selinux, selinuxfs, 0755);
 mount_other(/dev/shm, tmpfs, 01777);
 
-if (mkdir(/dev/input, 0777)  0) {
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot make directory 
/dev/input: %s\n,
-__func__, strerror(errno));
-exit_poweroff();
-}
-
-#define MKNOD(file, mode, dev)  \
-do {\
-if (mknod(file, mode, dev)  0) {   \
-fprintf(stderr, libvirt-sandbox-init-qemu: %s: cannot make dev %s 
%llu: %s\n, \
-__func__, file, (unsigned long long)dev, strerror(errno)); 
\
-exit_poweroff();\
-}   \
-} while (0)
-
-umask();
-MKNOD(/dev/null, S_IFCHR |0666, makedev(1, 3));
-MKNOD(/dev/zero, S_IFCHR |0666, makedev(1, 5));
-MKNOD(/dev/full, S_IFCHR |0666, makedev(1, 7));
-MKNOD(/dev/random, S_IFCHR |0666, makedev(1, 8));
-MKNOD(/dev/urandom, S_IFCHR |0666, makedev(1, 9));
-MKNOD(/dev/console, S_IFCHR |0700, makedev(5, 1));
-MKNOD(/dev/tty, S_IFCHR |0700, makedev(5, 0));
-MKNOD(/dev/tty0, S_IFCHR |0700, makedev(4, 0));
-MKNOD(/dev/tty1, S_IFCHR |0700, makedev(4, 1));
-MKNOD(/dev/tty2, S_IFCHR |0700, makedev(4, 2));
-MKNOD(/dev/ttyS0, S_IFCHR |0700, makedev(4, 64));
-MKNOD(/dev/ttyS1, S_IFCHR |0700, makedev(4, 65));
-MKNOD(/dev/ttyS2, S_IFCHR |0700, makedev(4, 66));
-MKNOD(/dev/ttyS3, S_IFCHR |0700, makedev(4, 67));
-MKNOD(/dev/hvc0, S_IFCHR |0700, makedev(229, 0));
-MKNOD(/dev/hvc1, S_IFCHR |0700, makedev(229, 1));
-MKNOD(/dev/hvc2, S_IFCHR |0700, makedev(229, 2));
-MKNOD(/dev/fb, S_IFCHR |0700, makedev(29, 0));
-MKNOD(/dev/fb0, S_IFCHR |0700, makedev(29, 0));
-MKNOD(/dev/mem, S_IFCHR |0600, makedev(1, 1));
-MKNOD(/dev/rtc, S_IFCHR |0700, makedev(254, 0));
-MKNOD(/dev/rtc0, S_IFCHR |0700, makedev(254, 0));
-MKNOD(/dev/ptmx, S_IFCHR |0777, makedev(5, 2));
-MKNOD(/dev/input/event0, S_IFCHR |0700, 

[libvirt] [sandbox PATCH 06/10] Add gvir_sandbox_config_has_disks function

2015-06-25 Thread Eren Yagdiran
From: Cédric Bosdonnat cbosdon...@suse.com

Add helper function to check if a config contains disk devices.
---
 libvirt-sandbox/libvirt-sandbox-config.c | 7 +++
 libvirt-sandbox/libvirt-sandbox-config.h | 1 +
 libvirt-sandbox/libvirt-sandbox.sym  | 1 +
 3 files changed, 9 insertions(+)

diff --git a/libvirt-sandbox/libvirt-sandbox-config.c 
b/libvirt-sandbox/libvirt-sandbox-config.c
index 3342706..f800cf9 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -1305,6 +1305,13 @@ gboolean 
gvir_sandbox_config_add_disk_opts(GVirSandboxConfig *config,
 }
 
 
+gboolean gvir_sandbox_config_has_disks(GVirSandboxConfig *config)
+{
+GVirSandboxConfigPrivate *priv = config-priv;
+return priv-disks != NULL;
+}
+
+
 /**
  * gvir_sandbox_config_add_mount:
  * @config: (transfer none): the sandbox config
diff --git a/libvirt-sandbox/libvirt-sandbox-config.h 
b/libvirt-sandbox/libvirt-sandbox-config.h
index deaea68..ebbebf2 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.h
+++ b/libvirt-sandbox/libvirt-sandbox-config.h
@@ -131,6 +131,7 @@ gboolean 
gvir_sandbox_config_add_disk_strv(GVirSandboxConfig *config,
 gboolean gvir_sandbox_config_add_disk_opts(GVirSandboxConfig *config,
const char *disk,
GError **error);
+gboolean gvir_sandbox_config_has_disks(GVirSandboxConfig *config);
 
 void gvir_sandbox_config_add_mount(GVirSandboxConfig *config,
GVirSandboxConfigMount *mnt);
diff --git a/libvirt-sandbox/libvirt-sandbox.sym 
b/libvirt-sandbox/libvirt-sandbox.sym
index bb717ed..e5f8660 100644
--- a/libvirt-sandbox/libvirt-sandbox.sym
+++ b/libvirt-sandbox/libvirt-sandbox.sym
@@ -217,4 +217,5 @@ LIBVIRT_SANDBOX_0.5.2 {
gvir_sandbox_config_add_disk_strv;
gvir_sandbox_config_add_disk_opts;
gvir_sandbox_config_disk_get_type;
+gvir_sandbox_config_has_disks;
 } LIBVIRT_SANDBOX_0.2.1;
-- 
2.1.0

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

[libvirt] [sandbox PATCH 00/10] Patches for Libvirt-sandbox

2015-06-25 Thread Eren Yagdiran
Hello,

These patches provide disk support for libvirt-sandbox.
Implemented '--disk' parameter will be useful when integrating Docker image 
support for libvirt-sandbox.

--Main diffs compared to previous patches.

Since many hypervisors, including kvm, will not even honour requested
names for disk devices we link each device under /dev/disk/by-tag

e.g /dev/disk/by-tag/foobar - /dev/sda

We populate disks.cfg with tag to device mapping when we build the sandbox.
After that, in each init-process {Common,Qemu}, we basically read the 
configuration
and populate the right symlinks under /dev/disk/by-tag

The common functions for modifying directories are moved under Init-util. 
{Common,Qemu} inits are using them.

Cédric Bosdonnat (2):
  Add gvir_sandbox_config_has_disks function
  qemu: use devtmpfs rather than tmpfs to auto-populate /dev

Eren Yagdiran (8):
  Add an utility function for guessing filetype from file extension
  Add configuration object for disk support
  Add disk parameter to virt-sandbox
  Add disk support to the container builder
  Add disk support to machine builder
  Init-util : Common directory functions for init-common and init-qemu
  Common-init: Building symlink from disks.cfg
  Common-builder: /dev/disk/by-tag/thetag to /dev/vdN

 bin/virt-sandbox.c |  37 +++
 libvirt-sandbox/Makefile.am|   7 +-
 .../libvirt-sandbox-builder-container.c|  37 ++-
 libvirt-sandbox/libvirt-sandbox-builder-machine.c  |  44 ++-
 libvirt-sandbox/libvirt-sandbox-builder.c  |  73 -
 libvirt-sandbox/libvirt-sandbox-config-disk.c  | 274 +++
 libvirt-sandbox/libvirt-sandbox-config-disk.h  |  82 ++
 libvirt-sandbox/libvirt-sandbox-config.c   | 300 +
 libvirt-sandbox/libvirt-sandbox-config.h   |  11 +
 libvirt-sandbox/libvirt-sandbox-init-common.c  |  51 +++-
 libvirt-sandbox/libvirt-sandbox-init-qemu.c| 151 ++-
 libvirt-sandbox/libvirt-sandbox-init-util.c|  58 
 libvirt-sandbox/libvirt-sandbox-init-util.h|  41 +++
 libvirt-sandbox/libvirt-sandbox-util.c |  72 +
 libvirt-sandbox/libvirt-sandbox-util.h |   5 +
 libvirt-sandbox/libvirt-sandbox.h  |   1 +
 libvirt-sandbox/libvirt-sandbox.sym|   5 +
 libvirt-sandbox/tests/test-config.c|  11 +
 po/POTFILES.in |   1 +
 19 files changed, 1112 insertions(+), 149 deletions(-)
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-disk.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-disk.h
 create mode 100644 libvirt-sandbox/libvirt-sandbox-init-util.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-init-util.h
 create mode 100644 libvirt-sandbox/libvirt-sandbox-util.c

-- 
2.1.0

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

[libvirt] [sandbox PATCH 09/10] Common-init: Building symlink from disks.cfg

2015-06-25 Thread Eren Yagdiran
Similar to the existing mounts.cfg, the mapping between the device and the tag 
is
passed by a new disks.cfg file. Common-init reads disks.cfg and maps the tags
to corresponding devices
---
 libvirt-sandbox/libvirt-sandbox-init-common.c | 51 +--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c 
b/libvirt-sandbox/libvirt-sandbox-init-common.c
index 68f96ba..f8b2ea5 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -46,6 +46,7 @@
 #include grp.h
 
 #include libvirt-sandbox-rpcpacket.h
+#include libvirt-sandbox-init-util.h
 
 static gboolean debug = FALSE;
 static gboolean verbose = FALSE;
@@ -60,6 +61,51 @@ static void sig_child(int sig ATTR_UNUSED)
 abort();
 }
 
+static gboolean setup_disk_tags(void) {
+FILE *fp;
+gboolean ret = FALSE;
+static char line[1024];
+if (debug)
+fprintf(stderr, libvirt-sandbox-init-common: %s: populate 
/dev/disk/by-tag/\n,
+   __func__);
+fp = fopen(SANDBOXCONFIGDIR /disks.cfg, r);
+if (fp == NULL) {
+fprintf(stderr, libvirt-sandbox-init-common: %s: cannot open  
SANDBOXCONFIGDIR /disks.cfg: %s\n,
+__func__, strerror(errno));
+
+goto cleanup;
+}
+gvir_sandbox_init_util_mkdir(/dev/disk/by-tag, 0755, debug == TRUE ? 1 : 
0);
+while (fgets(line, sizeof line, fp)) {
+char path[1024];
+char *tag = line;
+char *device = strchr(tag, '\t');
+*device = '\0';
+device++;
+char *tmp = strchr(device, '\n');
+*tmp = '\0';
+
+if (sprintf(path, /dev/disk/by-tag/%s, tag)  0) {
+fprintf(stderr, libvirt-sandbox-init-common: %s: cannot compute 
disk path: %s\n,
+__func__, strerror(errno));
+goto cleanup;
+}
+
+if (debug)
+fprintf(stderr, libvirt-sandbox-init-common: %s: %s - %s\n,
+__func__, path, device);
+
+if (symlink(device, path)  0) {
+fprintf(stderr, libvirt-sandbox-init-common: %s: cannot create 
symlink %s - %s: %s\n,
+__func__, path, device, strerror(errno));
+goto cleanup;
+}
+}
+ret = TRUE;
+ cleanup:
+fclose(fp);
+return ret;
+}
 
 static int
 start_shell(void)
@@ -258,8 +304,6 @@ static gboolean 
setup_network_device(GVirSandboxConfigNetwork *config,
 return ret;
 }
 
-
-
 static gboolean setup_network(GVirSandboxConfig *config, GError **error)
 {
 int i = 0;
@@ -1215,6 +1259,9 @@ int main(int argc, char **argv) {
 start_shell()  0)
 exit(EXIT_FAILURE);
 
+if (!setup_disk_tags())
+exit(EXIT_FAILURE);
+
 if (!setup_network(config, error))
 goto error;
 
-- 
2.1.0

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


[libvirt] [sandbox PATCH 01/10] Add an utility function for guessing filetype from file extension

2015-06-25 Thread Eren Yagdiran
Consider the file name extension as the image type, except for .img that are 
usually RAW images
---
 libvirt-sandbox/Makefile.am|  1 +
 libvirt-sandbox/libvirt-sandbox-util.c | 72 ++
 libvirt-sandbox/libvirt-sandbox-util.h |  5 +++
 po/POTFILES.in |  1 +
 4 files changed, 79 insertions(+)
 create mode 100644 libvirt-sandbox/libvirt-sandbox-util.c

diff --git a/libvirt-sandbox/Makefile.am b/libvirt-sandbox/Makefile.am
index 96302cb..6917f04 100644
--- a/libvirt-sandbox/Makefile.am
+++ b/libvirt-sandbox/Makefile.am
@@ -84,6 +84,7 @@ SANDBOX_HEADER_FILES = \
$(NULL)
 SANDBOX_SOURCE_FILES = \
libvirt-sandbox-main.c \
+   libvirt-sandbox-util.c \
libvirt-sandbox-config.c \
libvirt-sandbox-config-network.c \
libvirt-sandbox-config-network-address.c \
diff --git a/libvirt-sandbox/libvirt-sandbox-util.c 
b/libvirt-sandbox/libvirt-sandbox-util.c
new file mode 100644
index 000..32d4c4e
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-util.c
@@ -0,0 +1,72 @@
+/*
+ * libvirt-sandbox-util.c: libvirt sandbox util functions
+ *
+ * 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 erenyagdi...@gmail.com
+ */
+
+#include config.h
+#include string.h
+#include errno.h
+#include glib/gi18n.h
+
+#include libvirt-sandbox/libvirt-sandbox.h
+
+#define GVIR_SANDBOX_UTIL_ERROR gvir_sandbox_util_error_quark()
+
+static GQuark
+gvir_sandbox_util_error_quark(void)
+{
+return g_quark_from_static_string(gvir-sandbox-util);
+}
+
+gint gvir_sandbox_util_guess_image_format(const gchar *path,
+  GError **error)
+{
+gchar *tmp;
+
+if ((tmp = strchr(path, '.')) == NULL) {
+return -1;
+}
+tmp = tmp + 1;
+
+if (strcmp(tmp,img)==0){
+   return GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW;
+}
+
+return gvir_sandbox_util_disk_format_from_str(tmp, error);
+}
+
+gint gvir_sandbox_util_disk_format_from_str(const gchar *value,
+GError **error)
+{
+GEnumClass *enum_class = 
g_type_class_ref(GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT);
+GEnumValue *enum_value;
+gint ret = -1;
+
+if (!(enum_value = g_enum_get_value_by_nick(enum_class, value))) {
+g_set_error(error, GVIR_SANDBOX_UTIL_ERROR, 0,
+_(Unknown disk format '%s'), value);
+goto cleanup;
+}
+ret = enum_value-value;
+
+ cleanup:
+g_type_class_unref(enum_class);
+return ret;
+}
diff --git a/libvirt-sandbox/libvirt-sandbox-util.h 
b/libvirt-sandbox/libvirt-sandbox-util.h
index ae6b74b..890ae7f 100644
--- a/libvirt-sandbox/libvirt-sandbox-util.h
+++ b/libvirt-sandbox/libvirt-sandbox-util.h
@@ -29,6 +29,11 @@
 
 G_BEGIN_DECLS
 
+gint gvir_sandbox_util_guess_image_format(const gchar *path, GError **error);
+
+
+gint gvir_sandbox_util_disk_format_from_str(const gchar *value, GError 
**error);
+
 /**
  * LIBVIRT_SANDBOX_CLASS_PADDING: (skip)
  */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 653abc5..f291b98 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,3 +9,4 @@ libvirt-sandbox/libvirt-sandbox-console-rpc.c
 libvirt-sandbox/libvirt-sandbox-context.c
 libvirt-sandbox/libvirt-sandbox-init-common.c
 libvirt-sandbox/libvirt-sandbox-rpcpacket.c
+libvirt-sandbox/libvirt-sandbox-util.c
-- 
2.1.0

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

[libvirt] [sandbox PATCH 02/10] Add configuration object for disk support

2015-06-25 Thread Eren Yagdiran
Add the config gobject, functions to store and load the new configuration
fragments and test. This will allow creating sandboxes with attached
disk with a parameter formatted like file:hda=/source/file.qcow2,format=qcow2
---
 libvirt-sandbox/Makefile.am   |   2 +
 libvirt-sandbox/libvirt-sandbox-config-disk.c | 274 
 libvirt-sandbox/libvirt-sandbox-config-disk.h |  82 +++
 libvirt-sandbox/libvirt-sandbox-config.c  | 293 ++
 libvirt-sandbox/libvirt-sandbox-config.h  |  10 +
 libvirt-sandbox/libvirt-sandbox.h |   1 +
 libvirt-sandbox/libvirt-sandbox.sym   |   4 +
 libvirt-sandbox/tests/test-config.c   |  11 +
 8 files changed, 677 insertions(+)
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-disk.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-disk.h

diff --git a/libvirt-sandbox/Makefile.am b/libvirt-sandbox/Makefile.am
index 6917f04..8237c50 100644
--- a/libvirt-sandbox/Makefile.am
+++ b/libvirt-sandbox/Makefile.am
@@ -55,6 +55,7 @@ SANDBOX_HEADER_FILES = \
libvirt-sandbox-main.h \
libvirt-sandbox-util.h \
libvirt-sandbox-config.h \
+   libvirt-sandbox-config-disk.h \
libvirt-sandbox-config-network.h \
libvirt-sandbox-config-network-address.h \
libvirt-sandbox-config-network-filterref-parameter.h \
@@ -86,6 +87,7 @@ SANDBOX_SOURCE_FILES = \
libvirt-sandbox-main.c \
libvirt-sandbox-util.c \
libvirt-sandbox-config.c \
+   libvirt-sandbox-config-disk.c \
libvirt-sandbox-config-network.c \
libvirt-sandbox-config-network-address.c \
libvirt-sandbox-config-network-filterref.c \
diff --git a/libvirt-sandbox/libvirt-sandbox-config-disk.c 
b/libvirt-sandbox/libvirt-sandbox-config-disk.c
new file mode 100644
index 000..04f1cf0
--- /dev/null
+++ b/libvirt-sandbox/libvirt-sandbox-config-disk.c
@@ -0,0 +1,274 @@
+/*
+ * libvirt-sandbox-config-disk.c: libvirt sandbox configuration
+ *
+ * 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 erenyagdi...@gmail.com
+ */
+
+#include config.h
+#include string.h
+
+#include libvirt-sandbox/libvirt-sandbox.h
+
+/**
+ * SECTION: libvirt-sandbox-config-disk
+ * @short_description: Disk attachment configuration details
+ * @include: libvirt-sandbox/libvirt-sandbox.h
+ * @see_aloso: #GVirSandboxConfig
+ *
+ * Provides an object to store information about a disk attachment in the 
sandbox
+ *
+ */
+
+#define GVIR_SANDBOX_CONFIG_DISK_GET_PRIVATE(obj)  \
+(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_SANDBOX_TYPE_CONFIG_DISK, 
GVirSandboxConfigDiskPrivate))
+
+
+struct _GVirSandboxConfigDiskPrivate
+{
+GVirConfigDomainDiskType type;
+gchar *target;
+gchar *source;
+GVirConfigDomainDiskFormat format;
+};
+
+G_DEFINE_TYPE(GVirSandboxConfigDisk, gvir_sandbox_config_disk, G_TYPE_OBJECT);
+
+
+enum {
+PROP_0,
+PROP_TYPE,
+PROP_TARGET,
+PROP_SOURCE,
+PROP_FORMAT
+};
+
+enum {
+LAST_SIGNAL
+};
+
+
+
+static void gvir_sandbox_config_disk_get_property(GObject *object,
+  guint prop_id,
+  GValue *value,
+  GParamSpec *pspec)
+{
+GVirSandboxConfigDisk *config = GVIR_SANDBOX_CONFIG_DISK(object);
+GVirSandboxConfigDiskPrivate *priv = config-priv;
+
+switch (prop_id) {
+case PROP_TARGET:
+g_value_set_string(value, priv-target);
+break;
+case PROP_SOURCE:
+g_value_set_string(value, priv-source);
+break;
+case PROP_TYPE:
+g_value_set_enum(value, priv-type);
+break;
+case PROP_FORMAT:
+g_value_set_enum(value, priv-format);
+break;
+default:
+G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+}
+}
+
+
+static void gvir_sandbox_config_disk_set_property

  1   2   >