forked from ungleich-public/cdist
		
	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 os | ||||||
| import subprocess | import subprocess | ||||||
| import stat | import stat | ||||||
|  | import sys | ||||||
| import shutil | import shutil | ||||||
| import tempfile | import tempfile | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| import cdist.config | import cdist.config | ||||||
| import cdist.exec.local | import cdist.exec.local | ||||||
| import cdist.exec.remote | import cdist.exec.remote | ||||||
| 
 | 
 | ||||||
| log = logging.getLogger(__name__) | 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): | class PreOSExistsError(cdist.Error): | ||||||
|     def __init__(self, path): |     def __init__(self, path): | ||||||
|         self.path = path |         self.path = path | ||||||
|  | @ -65,32 +91,9 @@ KERNEL kernel | ||||||
| INITRD initramfs | INITRD initramfs | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
|         self._init_helper() |  | ||||||
| 
 |  | ||||||
|     def _init_helper(self): |     def _init_helper(self): | ||||||
|         self.helper = {} |         self.helper = {} | ||||||
|         self.helper["manifest"]  = """ |         self.helper["manifest"]  = self.initial_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["remote_exec"]  = """#!/bin/sh |         self.helper["remote_exec"]  = """#!/bin/sh | ||||||
| #        echo $@ | #        echo $@ | ||||||
| #        set -x | #        set -x | ||||||
|  | @ -200,7 +203,25 @@ cp -L "$src" "$real_dst" | ||||||
|         self.create_pxeconfig() |         self.create_pxeconfig() | ||||||
|         self.create_pxelinux() |         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): |     def config(self): | ||||||
|  |         self._init_helper() | ||||||
|  | 
 | ||||||
|         handle, path = tempfile.mkstemp(prefix='cdist.stdin.') |         handle, path = tempfile.mkstemp(prefix='cdist.stdin.') | ||||||
|         with tempfile.TemporaryDirectory() as tempdir: |         with tempfile.TemporaryDirectory() as tempdir: | ||||||
|             host = self.target_dir |             host = self.target_dir | ||||||
|  | @ -226,11 +247,21 @@ cp -L "$src" "$real_dst" | ||||||
|         self = cls(target_dir=args.target_dir[0], |         self = cls(target_dir=args.target_dir[0], | ||||||
|             arch=args.arch) |             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: |         if args.bootstrap: | ||||||
|             self.bootstrap() |             self.bootstrap() | ||||||
|  | 
 | ||||||
|  |         # Configure the OS | ||||||
|         if args.config: |         if args.config: | ||||||
|             self.config() |             self.config() | ||||||
|         if args.pxe_boot: | 
 | ||||||
|             self.create_pxe(args.pxe_boot) |         # Output pxe files | ||||||
|         if args.iso_boot: |         if args.pxe_boot_dir: | ||||||
|             self.create_iso(args.iso_boot) |             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 |     - add option for different initial manifest | ||||||
|         - allow -, stdin usage |         - allow -, stdin usage | ||||||
|  |         - allow to replace current manifest (later) | ||||||
| 
 | 
 | ||||||
|     - add option for additional manifest |     x trigger | ||||||
|         - allow -, stdin usage |  | ||||||
| 
 |  | ||||||
|     - trigger |  | ||||||
|         - can be handled in the manifest of the user |         - can be handled in the manifest of the user | ||||||
| 
 | 
 | ||||||
|     - remove /var/cache/apt/archives/* ? |     - remove /var/cache/apt/archives/* ? | ||||||
|  |         - later, optimisation level | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     - bug: cdist config als root! | ||||||
| 
 | 
 | ||||||
|     - fix linux-image name (amd64) |     - fix linux-image name (amd64) | ||||||
| 
 | 
 | ||||||
|  |     - ln -s /sbin/init /init | ||||||
|  | 
 | ||||||
|     - blog! |     - blog! | ||||||
|         - self configuring |         - self configuring | ||||||
| 
 | 
 | ||||||
|     - pxe |     x pxe | ||||||
|         /pxe/ |         /pxe/ | ||||||
|             - pxelinux.0 |             - pxelinux.0 | ||||||
|             - linux |             - linux | ||||||
|  | @ -31,6 +35,9 @@ | ||||||
|                 - default |                 - default | ||||||
| 
 | 
 | ||||||
|     - iso |     - iso | ||||||
|  |         - later | ||||||
|  |     - usb stick (+efi version) | ||||||
|  |         - later | ||||||
| 
 | 
 | ||||||
|     - add unit tests |     - 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 | INFO: /home/users/nico/preos-tests/preos03: Finished successful run in 2.546635866165161 seconds | ||||||
| [1:16] bento:~%  | [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', |     parser['preos'].add_argument('-r', '--replace-manifest', | ||||||
|          help='Instead of appending to the built in manifest, replace the internal manifest',  |          help='Instead of appending to the built in manifest, replace the internal manifest',  | ||||||
|          action="store_true") |          action="store_true") | ||||||
|     parser['preos'].add_argument('-I', '--iso-boot', | #    parser['preos'].add_argument('-I', '--iso-boot-dir', | ||||||
|          help='Create ISO for booting in given location') | #         help='Create ISO for booting in given location') | ||||||
|     parser['preos'].add_argument('-p', '--pxe-boot', |     parser['preos'].add_argument('-p', '--pxe-boot-dir', | ||||||
|          help='Create PXE files for booting in given location') |          help='Create PXE files for booting in given location') | ||||||
|     parser['preos'].add_argument('target_dir', nargs=1, |     parser['preos'].add_argument('target_dir', nargs=1, | ||||||
|         help='Select target directory') |         help='Select target directory') | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue