mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-19 22:50:35 +03:00
ostbuild: Some work on qemu deployment
This commit is contained in:
parent
3a20f6a913
commit
bcab6748a5
@ -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 \
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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')
|
||||
|
62
src/ostbuild/pyostbuild/builtin_privhelper_run_qemu.py
Executable file
62
src/ostbuild/pyostbuild/builtin_privhelper_run_qemu.py
Executable file
@ -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)
|
49
src/ostbuild/pyostbuild/builtin_run_qemu.py
Executable file
49
src/ostbuild/pyostbuild/builtin_run_qemu.py
Executable file
@ -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)
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user