[ostree: 15/19] ostbuild: Some work on qemu deployment



commit bcab6748a57635ff98b6e793f718d409fd1f689f
Author: Colin Walters <walters verbum org>
Date:   Mon May 14 22:43:25 2012 -0400

    ostbuild: Some work on qemu deployment

 Makefile-ostbuild.am                               |    2 +
 src/ostbuild/pyostbuild/builtin_deploy_qemu.py     |   21 +++++--
 src/ostbuild/pyostbuild/builtin_deploy_root.py     |   23 +++++--
 .../pyostbuild/builtin_privhelper_deploy_qemu.py   |    4 +-
 .../pyostbuild/builtin_privhelper_run_qemu.py      |   62 ++++++++++++++++++++
 src/ostbuild/pyostbuild/builtin_run_qemu.py        |   49 +++++++++++++++
 src/ostbuild/pyostbuild/main.py                    |    2 +
 7 files changed, 147 insertions(+), 16 deletions(-)
---
diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am
index dd1b2c7..41fbbe2 100644
--- a/Makefile-ostbuild.am
+++ b/Makefile-ostbuild.am
@@ -30,9 +30,11 @@ pyostbuild_PYTHON =					\
 	src/ostbuild/pyostbuild/builtin_compile_one.py	\
 	src/ostbuild/pyostbuild/builtin_deploy_qemu.py	\
 	src/ostbuild/pyostbuild/builtin_deploy_root.py	\
+	src/ostbuild/pyostbuild/builtin_run_qemu.py	\
 	src/ostbuild/pyostbuild/builtin_import_tree.py	\
 	src/ostbuild/pyostbuild/builtin_pull_components.py	\
 	src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py	\
+	src/ostbuild/pyostbuild/builtin_privhelper_run_qemu.py	\
 	src/ostbuild/pyostbuild/builtin_git_mirror.py	\
 	src/ostbuild/pyostbuild/builtin_prefix.py	\
 	src/ostbuild/pyostbuild/builtin_resolve.py	\
diff --git a/src/ostbuild/pyostbuild/builtin_deploy_qemu.py b/src/ostbuild/pyostbuild/builtin_deploy_qemu.py
index 549bbca..f06b669 100755
--- a/src/ostbuild/pyostbuild/builtin_deploy_qemu.py
+++ b/src/ostbuild/pyostbuild/builtin_deploy_qemu.py
@@ -37,22 +37,29 @@ class OstbuildDeployQemu(builtins.Builtin):
     def execute(self, argv):
         parser = argparse.ArgumentParser(description=self.short_description)
         parser.add_argument('--prefix')
-        parser.add_argument('--bin-snapshot')
+        parser.add_argument('--snapshot')
+        parser.add_argument('targets', nargs='*')
 
         args = parser.parse_args(argv)
         self.args = args
         
         self.parse_config()
-        self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
-        
-        target_names = []
-        for target in self.bin_snapshot['targets']:
-            target_names.append(target['name'])
+        self.parse_snapshot(args.prefix, args.snapshot)
 
+        if len(args.targets) > 0:
+            targets = args.targets
+        else:
+            targets = []
+            prefix = self.snapshot['prefix']
+            for target_component_type in ['runtime', 'devel']:
+                for architecture in self.snapshot['architectures']:
+                    name = '%s-%s-%s' % (prefix, architecture, target_component_type)
+                    targets.append(name)
+        
         helper = privileged_subproc.PrivilegedSubprocess()
         shadow_path = os.path.join(self.workdir, 'shadow-repo')
         child_args = ['ostbuild', 'privhelper-deploy-qemu', shadow_path]
-        child_args.extend(target_names)
+        child_args.extend(targets)
         helper.spawn_sync(child_args)
         
 builtins.register(OstbuildDeployQemu)
diff --git a/src/ostbuild/pyostbuild/builtin_deploy_root.py b/src/ostbuild/pyostbuild/builtin_deploy_root.py
index 13f9f17..f56d8f8 100755
--- a/src/ostbuild/pyostbuild/builtin_deploy_root.py
+++ b/src/ostbuild/pyostbuild/builtin_deploy_root.py
@@ -37,22 +37,31 @@ class OstbuildDeployRoot(builtins.Builtin):
     def execute(self, argv):
         parser = argparse.ArgumentParser(description=self.short_description)
         parser.add_argument('--prefix')
-        parser.add_argument('--bin-snapshot')
+        parser.add_argument('--snapshot')
+        parser.add_argument('targets', nargs='*')
 
         args = parser.parse_args(argv)
         self.args = args
         
         self.parse_config()
-        self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
+        self.parse_snapshot(args.prefix, args.snapshot)
         
-        target_names = []
-        for target in self.bin_snapshot['targets']:
-            target_names.append(target['name'])
+        if len(args.targets) > 0:
+            targets = args.targets
+        else:
+            targets = []
+            prefix = self.snapshot['prefix']
+            for target_component_type in ['runtime', 'devel']:
+                for architecture in self.snapshot['architectures']:
+                    name = '%s-%s-%s' % (prefix, architecture, target_component_type)
+                    targets.append(name)
 
         helper = privileged_subproc.PrivilegedSubprocess()
         sys_repo = os.path.join(self.ostree_dir, 'repo')
         shadow_path = os.path.join(self.workdir, 'shadow-repo')
-        helper.spawn_sync(['ostree', '--repo=' + sys_repo,
-                           'pull-local', shadow_path])
+        child_args = ['ostree', '--repo=' + sys_repo,
+                      'pull-local', shadow_path]
+        child_args.extend(['trees/' + x for x in targets])
+        helper.spawn_sync(child_args)
         
 builtins.register(OstbuildDeployRoot)
diff --git a/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py b/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py
index 2fc852c..a14eb1c 100755
--- a/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py
+++ b/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py
@@ -93,12 +93,12 @@ class OstbuildPrivhelperDeployQemu(builtins.Builtin):
         try:
             subprocess.check_call(['mount', '-o', 'loop', self.qemu_path, self.mountpoint])
             child_args = ['ostree', '--repo=' + repo_path, 'pull-local', args.srcrepo]
-            child_args.extend(args.targets)
+            child_args.extend(['trees/' + x for x in args.targets])
             run_sync(child_args)
 
             first_target = args.targets[0]
             for target in args.targets:
-                run_sync(['ostree', '--repo=' + repo_path, 'checkout', '--atomic-retarget', target],
+                run_sync(['ostree', '--repo=' + repo_path, 'checkout', '--atomic-retarget', 'trees/'+ target, target],
                          cwd=os.path.join(self.mountpoint, 'ostree'))
             current_link_path = os.path.join(self.mountpoint, 'ostree', 'current')
             os.symlink(first_target, current_link_path + '.tmp')
diff --git a/src/ostbuild/pyostbuild/builtin_privhelper_run_qemu.py b/src/ostbuild/pyostbuild/builtin_privhelper_run_qemu.py
new file mode 100755
index 0000000..7f069d1
--- /dev/null
+++ b/src/ostbuild/pyostbuild/builtin_privhelper_run_qemu.py
@@ -0,0 +1,62 @@
+# Copyright (C) 2012 Colin Walters <walters verbum org>
+#
+# 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 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,subprocess,tempfile,re,shutil
+import argparse
+import time
+import urlparse
+import json
+from StringIO import StringIO
+
+from . import builtins
+from .ostbuildlog import log, fatal
+from .subprocess_helpers import run_sync
+from . import ostbuildrc
+from . import fileutil
+
+class OstbuildPrivhelperRunQemu(builtins.Builtin):
+    name = "privhelper-run-qemu"
+    short_description = "Helper for run-qemu"
+
+    def __init__(self):
+        builtins.Builtin.__init__(self)
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+        parser.add_argument('target')
+
+        args = parser.parse_args(argv)
+
+        if os.geteuid() != 0:
+            fatal("This helper can only be run as root")
+
+        self.ostree_dir = self.find_ostree_dir()
+        self.qemu_path = os.path.join(self.ostree_dir, "ostree-qemu.img")
+
+        release = os.uname()[2]
+
+        qemu = 'qemu-kvm'
+        kernel = '/boot/vmlinuz-%s' % (release, )
+        initramfs = '/boot/initramfs-ostree-%s.img' % (release, )
+        memory = '512M'
+        extra_args = 'root=/dev/sda rd.pymouth=0 ostree=%s' % (args.target, )
+
+        args = [qemu, '-kernel', kernel, '-initrd', initramfs,
+                '-hda', self.qemu_path, '-m', memory, '-append', extra_args]
+        os.execvp(qemu, args)
+        
+builtins.register(OstbuildPrivhelperRunQemu)
diff --git a/src/ostbuild/pyostbuild/builtin_run_qemu.py b/src/ostbuild/pyostbuild/builtin_run_qemu.py
new file mode 100755
index 0000000..ca33f4f
--- /dev/null
+++ b/src/ostbuild/pyostbuild/builtin_run_qemu.py
@@ -0,0 +1,49 @@
+# Copyright (C) 2012 Colin Walters <walters verbum org>
+#
+# 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 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., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,subprocess,tempfile,re,shutil
+import argparse
+import time
+import urlparse
+import json
+from StringIO import StringIO
+
+from . import builtins
+from .ostbuildlog import log, fatal
+from . import ostbuildrc
+from . import privileged_subproc
+
+class OstbuildRunQemu(builtins.Builtin):
+    name = "run-qemu"
+    short_description = "Run QEMU image"
+
+    def __init__(self):
+        builtins.Builtin.__init__(self)
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+        parser.add_argument('target')
+
+        args = parser.parse_args(argv)
+        
+        self.parse_config()
+        
+        helper = privileged_subproc.PrivilegedSubprocess()
+        child_args = ['ostbuild', 'privhelper-run-qemu', args.target]
+        helper.spawn_sync(child_args)
+        
+builtins.register(OstbuildRunQemu)
diff --git a/src/ostbuild/pyostbuild/main.py b/src/ostbuild/pyostbuild/main.py
index a86cb95..bf5ec94 100755
--- a/src/ostbuild/pyostbuild/main.py
+++ b/src/ostbuild/pyostbuild/main.py
@@ -30,9 +30,11 @@ from . import builtin_compile_one
 from . import builtin_deploy_root
 from . import builtin_deploy_qemu
 from . import builtin_import_tree
+from . import builtin_run_qemu
 from . import builtin_git_mirror
 from . import builtin_pull_components
 from . import builtin_privhelper_deploy_qemu
+from . import builtin_privhelper_run_qemu
 from . import builtin_prefix
 from . import builtin_resolve
 from . import builtin_modify_snapshot



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]