disable unsupported iso - create /init - include support for another initial manifest
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
parent
0d78ab313f
commit
11ba4640b4
3 changed files with 87 additions and 37 deletions
|
@ -24,16 +24,42 @@ import glob
|
|||
import os
|
||||
import subprocess
|
||||
import stat
|
||||
import sys
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
|
||||
import cdist.config
|
||||
import cdist.exec.local
|
||||
import cdist.exec.remote
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_MANIFEST = """
|
||||
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
|
||||
|
||||
# initramfs requires /init
|
||||
__link /init --source /sbin/init --type symbolic
|
||||
|
||||
__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
|
||||
"""
|
||||
|
||||
class PreOSExistsError(cdist.Error):
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
@ -65,32 +91,9 @@ KERNEL kernel
|
|||
INITRD initramfs
|
||||
"""
|
||||
|
||||
self._init_helper()
|
||||
|
||||
def _init_helper(self):
|
||||
self.helper = {}
|
||||
self.helper["manifest"] = """
|
||||
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["manifest"] = self.initial_manifest
|
||||
self.helper["remote_exec"] = """#!/bin/sh
|
||||
# echo $@
|
||||
# set -x
|
||||
|
@ -200,7 +203,25 @@ cp -L "$src" "$real_dst"
|
|||
self.create_pxeconfig()
|
||||
self.create_pxelinux()
|
||||
|
||||
|
||||
def setup_initial_manifest(self, user_initial_manifest, replace_manifest):
|
||||
if user_initial_manifest:
|
||||
if user_initial_manifest == '-':
|
||||
user_initial_manifest_content = sys.stdin.read()
|
||||
else:
|
||||
with open(user_initial_manifest, "r") as fd:
|
||||
user_initial_manifest_content = fd.read()
|
||||
else:
|
||||
user_initial_manifest_content = ""
|
||||
|
||||
if replace_manifest:
|
||||
self.initial_manifest = user_initial_manifest_content
|
||||
else:
|
||||
self.initial_manifest = "{default}\n# User supplied manifest\n{user}".format(default=DEFAULT_MANIFEST, user=user_initial_manifest_content)
|
||||
|
||||
def config(self):
|
||||
self._init_helper()
|
||||
|
||||
handle, path = tempfile.mkstemp(prefix='cdist.stdin.')
|
||||
with tempfile.TemporaryDirectory() as tempdir:
|
||||
host = self.target_dir
|
||||
|
@ -226,11 +247,21 @@ cp -L "$src" "$real_dst"
|
|||
self = cls(target_dir=args.target_dir[0],
|
||||
arch=args.arch)
|
||||
|
||||
# read initial manifest first - it may come from stdin
|
||||
if args.config:
|
||||
self.setup_initial_manifest(args.initial_manifest, args.replace_manifest)
|
||||
|
||||
# Bootstrap: creates base directory
|
||||
if args.bootstrap:
|
||||
self.bootstrap()
|
||||
|
||||
# Configure the OS
|
||||
if args.config:
|
||||
self.config()
|
||||
if args.pxe_boot:
|
||||
self.create_pxe(args.pxe_boot)
|
||||
if args.iso_boot:
|
||||
self.create_iso(args.iso_boot)
|
||||
|
||||
# Output pxe files
|
||||
if args.pxe_boot_dir:
|
||||
self.create_pxe(args.pxe_boot_dir)
|
||||
|
||||
#if args.iso_boot_dir:
|
||||
# self.create_iso(args.iso_boot)
|
||||
|
|
|
@ -8,21 +8,25 @@
|
|||
|
||||
- add option for different initial manifest
|
||||
- allow -, stdin usage
|
||||
- allow to replace current manifest (later)
|
||||
|
||||
- add option for additional manifest
|
||||
- allow -, stdin usage
|
||||
|
||||
- trigger
|
||||
x trigger
|
||||
- can be handled in the manifest of the user
|
||||
|
||||
- remove /var/cache/apt/archives/* ?
|
||||
- later, optimisation level
|
||||
|
||||
|
||||
- bug: cdist config als root!
|
||||
|
||||
- fix linux-image name (amd64)
|
||||
|
||||
- ln -s /sbin/init /init
|
||||
|
||||
- blog!
|
||||
- self configuring
|
||||
|
||||
- pxe
|
||||
x pxe
|
||||
/pxe/
|
||||
- pxelinux.0
|
||||
- linux
|
||||
|
@ -31,6 +35,9 @@
|
|||
- default
|
||||
|
||||
- iso
|
||||
- later
|
||||
- usb stick (+efi version)
|
||||
- later
|
||||
|
||||
- add unit tests
|
||||
|
||||
|
@ -81,3 +88,15 @@ INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/linux-
|
|||
INFO: /home/users/nico/preos-tests/preos03: Finished successful run in 2.546635866165161 seconds
|
||||
[1:16] bento:~%
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
[21:14] bento:vm-tests% qemu-system-x86_64 -m 2G -boot order=cn -drive file=testhd1,if=virtio -net nic -net user,tftp=$(pwd -P)/tftp,bootfile=/pxelinux.0
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
[21:16] bento:preos-tests% sudo cdist preos -vp /home/users/nico/vm-tests/tftp /home/users/nico/preos-tests/preos03/
|
||||
INFO: cdist: version 3.0.0-42-g0d78ab3
|
||||
INFO: cdist.preos: Creating kernel ...
|
||||
INFO: cdist.preos: Creating initramfs ...
|
||||
760780 blocks
|
||||
INFO: cdist.preos: Creating pxe configuration ...
|
||||
INFO: cdist.preos: Creating pxelinux.0 ...
|
||||
|
||||
|
|
|
@ -101,9 +101,9 @@ def commandline():
|
|||
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',
|
||||
# parser['preos'].add_argument('-I', '--iso-boot-dir',
|
||||
# help='Create ISO for booting in given location')
|
||||
parser['preos'].add_argument('-p', '--pxe-boot-dir',
|
||||
help='Create PXE files for booting in given location')
|
||||
parser['preos'].add_argument('target_dir', nargs=1,
|
||||
help='Select target directory')
|
||||
|
|
Loading…
Reference in a new issue