various updates for preos

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2014-01-10 10:46:09 +01:00
parent ea286c600f
commit 4fb55b8d92
3 changed files with 133 additions and 24 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# 2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2013-2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@ -39,6 +39,9 @@ class PreOSExistsError(cdist.Error):
def __str__(self):
return 'Path %s already exists' % self.path
class PreOSBootstrapError(cdist.Error):
pass
class PreOS(object):
@ -52,14 +55,39 @@ class PreOS(object):
self.options = [ "--include=openssh-server",
"--arch=%s" % self.arch ]
self.pxelinux = "/usr/lib/syslinux/pxelinux.0"
self.pxelinux-cfg = """
DEFAULT linux
LABEL linux
KERNEL linux
INITRD initramfs
APPEND ro root=/dev/sda1 initrd=initrd.img
self._init_helper()
def _init_helper(self):
self.helper = {}
self.helper["manifest"] = """
for pkg in linux-image-amd64 openssh-server; do
for pkg in \
file \
linux-image-amd64
openssh-server
syslinux \
gdisk util-linux \
btrfs-tools e2fsprogs jfsutils reiser4progs xfsprogs; do
__package $pkg --state present
done
__file /etc/network/interfaces --source - --mode 0644 << eof
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 init dhcp
eof
"""
self.helper["remote_exec"] = """#!/bin/sh
# echo $@
@ -78,13 +106,16 @@ chmod +x "$script"
relative_script="${script#$chroot}"
# ensure PATH is setup
export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin
# run in chroot
chroot "$chroot" "$relative_script"
"""
self.helper["remote_copy"] = """#!/bin/sh
echo $@
set -x
# echo $@
# set -x
src=$1; shift
dst=$1; shift
real_dst=$(echo $dst | sed 's,:,,')
@ -106,9 +137,14 @@ cp -L "$src" "$real_dst"
log.debug("Bootstrap: %s" % cmd)
subprocess.call(cmd)
# try:
subprocess.check_call(cmd)
# except subprocess.CalledProcessError:
# raise
cmd = [ "chroot", self.target_dir, "/usr/bin/apt-get update" ]
# Required to run this - otherwise apt-get install fails
cmd = [ "chroot", self.target_dir, "/usr/bin/apt-get", "update" ]
subprocess.check_call(cmd)
def create_helper_files(self, base_dir):
for key, val in self.helper.items():
@ -117,6 +153,9 @@ cp -L "$src" "$real_dst"
fd.write(val)
os.chmod(filename, stat.S_IRUSR | stat.S_IXUSR)
def create_pxe(self, base_dir):
pass
def config(self):
handle, path = tempfile.mkstemp(prefix='cdist.stdin.')
with tempfile.TemporaryDirectory() as tempdir:

View File

@ -1,20 +1,83 @@
- debootstrap
x setup arch
x allow cdist to configure debootstrapped directory using cdist
x include sshd
x configure network (eth0, dhcp)
x various mkfs variants
- various fdisk tools
- include trigger
- replace with cdist config later?
- add option for different initial manifest
- allow -, stdin usage
- get kernel
- create initramfs
- later:
- configure chroot using cdist
- add option for additional manifest
- allow -, stdin usage
- trigger
- can be handled in the manifest of the user
packages:
linux-image-amd64
- remove /var/cache/apt/archives/* ?
- temporary manifest
- fix linux-image name (amd64)
- bugs with sudo
[22:50:04] bento:~# ln -s ~nico/.cdist/ ~
- blog!
- self configuring
- pxe
/pxe/
- pxelinux.0
- linux
- initramfs
- pxelinux.cfg/
- default
- iso
- add unit tests
--------------------------------------------------------------------------------
[1:16] bento:~% sudo cdist preos -vc ~nico/preos-tests/preos03
INFO: cdist: version 3.0.0-38-gea286c6
INFO: /home/users/nico/preos-tests/preos03: Running global explorers
INFO: /home/users/nico/preos-tests/preos03: Running initial manifest /tmp/tmpxbquwe/manifest
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __file/etc/network/interfaces
INFO: /home/users/nico/preos-tests/preos03: Generating code for __file/etc/network/interfaces
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/xfsprogs
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/reiser4progs
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/jfsutils
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/e2fsprogs
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/btrfs-tools
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/file
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/syslinux
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/openssh-server
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/linux-image-amd64
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/linux-image-amd64
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/linux-image-amd64
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/openssh-server
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/openssh-server
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/syslinux
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/syslinux
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/file
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/file
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/btrfs-tools
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/btrfs-tools
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/e2fsprogs
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/e2fsprogs
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/jfsutils
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/jfsutils
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/reiser4progs
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/reiser4progs
INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/xfsprogs
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/xfsprogs
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/xfsprogs
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/reiser4progs
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/jfsutils
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/e2fsprogs
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/btrfs-tools
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/file
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/syslinux
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/openssh-server
INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/linux-image-amd64
INFO: /home/users/nico/preos-tests/preos03: Finished successful run in 2.546635866165161 seconds
[1:16] bento:~%

View File

@ -89,15 +89,22 @@ def commandline():
parents=[parser['loglevel']])
parser['preos'].add_argument('-a', '--arch',
help='Select architecture for preos', default="amd64")
parser['preos'].add_argument('-A', '--additional-manifest',
help='Add stuff to configuration manifest', default="amd64")
parser['preos'].add_argument('-b', '--bootstrap',
help='Bootstrap directory with OS', action="store_true")
help='Bootstrap directory with PreOS', action="store_true")
parser['preos'].add_argument('-c', '--configure',
help='Configure previously bootstrapped directory', action="store_true",
dest="config")
parser['preos'].add_argument('-i', '--initramfs',
help='Create Linux initramfs', action="store_true")
parser['preos'].add_argument('-k', '--kernel',
help='Create Linux kernel', action="store_true")
help='Configure previously bootstrapped directory',
action="store_true", dest="config")
parser['preos'].add_argument('-i', '--initial-manifest',
help='Initial manifest for configuration (added to built in)')
parser['preos'].add_argument('-r', '--replace-manifest',
help='Instead of appending to the built in manifest, replace the internal manifest',
action="store_true")
parser['preos'].add_argument('-I', '--iso-boot',
help='Create ISO for booting in given location')
parser['preos'].add_argument('-p', '--pxe-boot',
help='Create PXE files for booting in given location')
parser['preos'].add_argument('target_dir', nargs=1,
help='Select target directory')
parser['preos'].set_defaults(func=cdist.preos.PreOS.commandline)