Bases: pylorax.base.DataHolder
Bases: pylorax.base.BaseLoraxClass
Bases: object
Info about the kernels in boot_dir
Create template for pxe to live configuration
Parameters: |
---|
Find root of ostree deployment
Parameters: | phys_root (str) – Path to physical root |
---|---|
Returns: | Relative path of ostree deployment root |
Return type: | str |
Raises Exception: | |
More than one deployment roots were found |
Return the size of the kickstart’s disk partitions
Parameters: | ks (Kickstart object) – The kickstart |
---|---|
Returns: | The size of the disk, in GiB |
Generate an appliance description file
disk_img Full path of the disk image name Name of the appliance, passed to the template template Full path of Mako template outfile Full path of file to write, using template networks List of networks from the kickstart ram Ram, in MB, passed to template. Default is 1024 vcpus CPUs, passed to template. Default is 1 arch CPU architecture. Default is ‘x86_64’ title Title, passed to template. Default is ‘Linux’ project Project, passed to template. Default is ‘Linux’ releasever Release version, passed to template. Default is 17
Install to an image
Use virt or anaconda to install to an image.
Returns the full path of of the image created.
Create live images from direcory or rootfs image
Parameters: | |
---|---|
Returns: | Path of directory with created images |
Return type: | str |
Take the content from the disk image and make a livecd out of it
Then on boot dracut reads /etc/cmdline which points to the squashfs.img mounts that and then mounts LiveOS/rootfs.img as /
Make the squashfs image from a directory
Result is in work_dir+RUNTIME
Take disk_img and put it into LiveOS/rootfs.img and squashfs this tree into work_dir+RUNTIME
Mount boot partition to /boot of root fs mounted in img_mount
Used for OSTree so it finds deployment configurations on live rootfs
param img_mount: object with mounted disk image root partition type img_mount: imgutils.PartitionMount
Rebuild intrds for pxe live image (root=live:http://)
Parameters: |
---|
Run the image creator process
Parameters: | opts (Either a DataHolder or ArgumentParser) – Commandline options to control the process |
---|---|
Returns: | The result directory and the disk image path. |
Return type: | Tuple of str |
This function takes the opts arguments and creates the selected output image. See the cmdline –help for livemedia-creator for the possible options
(Yes, this is not ideal, but we can fix that later)
Run an external program and capture standard out. @param command The command to run. @param argv A list of arguments. @param stdin The file descriptor to read stdin from. @param stderr The file descriptor to redirect stderr to. @param root The directory to chroot to before running command. @param preexec_fn function to pass to Popen @param cwd working directory to pass to Popen @param raise_err raise CalledProcessError when the returncode is not 0 @return The output of command from stdout.
Run an external program and redirect the output to a file. @param command The command to run. @param argv A list of arguments. @param stdin The file descriptor to read stdin from. @param stdout The file descriptor to redirect stdout to. @param stderr The file descriptor to redirect stderr to. @param root The directory to chroot to before running command. @param preexec_fn function to pass to Popen @param cwd working directory to pass to Popen @param raise_err raise CalledProcessError when the returncode is not 0 @return The return code of command.
Bases: object
Mount a partitioned image file using kpartx
Make a compressed archive of the given rootdir. command is a list of the archiver commands to run compression should be “xz”, “gzip”, “lzma”, “bzip2”, or None. compressargs will be used on the compression commandline.
Copy a tree of files using cp -a, thus preserving modes, timestamps, links, acls, sparse files, xattrs, selinux contexts, etc. If preserve is False, uses cp -R (useful for modeless filesystems) raises CalledProcessError if copy fails.
Return a default image name with the correct suffix for the compression type.
Parameters: | |
---|---|
Returns: | basename with compression suffix |
If the compression is unknown it defaults to xz
Attach a devicemapper device to the given device, with the given size. If name is None, a random name will be chosen. Returns the device name. raises CalledProcessError if dmsetup fails.
Detach the named devicemapper device. Returns False if dmsetup fails.
Copy each of the items listed in grafts into dest. If the key ends with ‘/’ it’s assumed to be a directory which should be created, otherwise just the leading directories will be created.
Return the loop device associated with the path. Raises RuntimeError if more than one loop is associated
Attach a loop device to the given file. Return the loop device name. Raises CalledProcessError if losetup fails.
Detach the given loop device. Return False on failure.
Make sure the loop device is attached to the outfile.
It seems that on rare occasions losetup can return before the /dev/loopX is ready for use, causing problems with mkfs. This tries to make sure that the loop device really is associated with the backing file before continuing.
Raise RuntimeError if it isn’t setup after 5 tries.
Copy the / partition of a partitioned disk image to an un-partitioned disk image.
diskimage is the full path to partitioned disk image with a / fsimage is the full path of the output fs image file label is the label to apply to the image. Defaults to “Anaconda”
Generic filesystem image creation function. fstype should be a filesystem type - “mkfs.${fstype}” must exist. graft should be a dict: {“some/path/in/image”: “local/file/or/dir”};
if the path ends with a ‘/’ it’s assumed to be a directory.
Will raise CalledProcessError if something goes wrong.
use qemu-img to create a file of the given size. options is a list of options passed to qemu-img
Default format is qcow2, override by passing “-f”, fmt in options.
Make rootfs image from a directory
Parameters: |
---|
use os.ftruncate to create a sparse file of the given size.
Make a squashfs image containing the given rootdir.
Mount the given device at the given mountpoint, using the given opts. opts should be a comma-separated string of mount options. if mnt is none, a temporary directory will be created and its path will be returned. raises CalledProcessError if mount fails.
Bases: object
Mount the iso on a temporary directory and check to make sure the vmlinuz and initrd.img files exist Check the iso for a LiveOS directory and set a flag. Extract the iso’s label.
initrd_path can be used to point to a boot.iso tree with a newer initrd.img than the iso has. The iso is still used for stage2.
Bases: object
Run virt-install using an iso and kickstart(s)
Bases: object
Contains all the stuff needed to setup a thread to listen to the logs from the virtual install
Bases: SocketServer.BaseRequestHandler
Handle monitoring and saving the logfiles from the virtual install
Bases: SocketServer.TCPServer
Add path to logfile Add log error flag Add a kill switch
Bases: object
This class parses and executes Lorax templates. Sample usage:
# install a bunch of packages runner = LoraxTemplateRunner(inroot=rundir, outroot=rundir, yum=yum_obj) runner.run(“install-packages.ltmpl”)
# modify a runtime dir runner = LoraxTemplateRunner(inroot=rundir, outroot=newrun) runner.run(“runtime-transmogrify.ltmpl”)
NOTES:
Parsing procedure is roughly: 1. Mako template expansion (on the whole file) 2. For each line of the result,
- Whitespace splitting (using shlex.split())
- Brace expansion (using brace_expand())
- If the first token is the name of a function, call that function with the rest of the line as arguments
Parsing and execution are separate passes - so you can’t use the result of a command in an %if statement (or any other control statements)!
Commands that run external programs (systemctl, gconfset) currently use the host‘s copy of that program, which may cause problems if there’s a big enough difference between the host and the image you’re modifying.
The commands are not executed under a real chroot, so absolute symlinks will point outside the inroot/outroot. Be careful with symlinks!
ADDING NEW COMMANDS:
append FILE STRING Append STRING (followed by a newline character) to FILE. Python character escape sequences (‘n’, ‘t’, etc.) will be converted to the appropriate characters. Examples:
append /etc/depmod.d/dd.conf “search updates built-in” append /etc/resolv.conf “”
chmod FILEGLOB OCTALMODE Change the mode of all the files matching FILEGLOB to OCTALMODE.
copy SRC DEST Copy SRC to DEST. If DEST is a directory, SRC will be copied inside it. If DEST doesn’t exist, SRC will be copied to a file with that name, if the path leading to it exists.
createaddrsize INITRD_ADDRESS INITRD ADDRSIZE Create the initrd.addrsize file required in LPAR boot process. Examples:
createaddrsize ${INITRD_ADDRESS} ${outroot}/${BOOTDIR}/initrd.img ${outroot}/${BOOTDIR}/initrd.addrsize
gconfset PATH KEYTYPE VALUE [OUTFILE] Set the given gconf PATH, with type KEYTYPE, to the given value. OUTFILE defaults to /etc/gconf/gconf.xml.defaults if not given. Example:
gconfset /apps/metacity/general/num_workspaces int 1
install SRC DEST Copy the given file (or files, if a glob is used) from the input tree to the given destination in the output tree. The path to DEST must exist in the output tree. If DEST is a directory, SRC will be copied into that directory. If DEST doesn’t exist, SRC will be copied to a file with that name, assuming the rest of the path exists. This is pretty much like how the ‘cp’ command works. Examples:
install usr/share/myconfig/grub.conf /boot install /usr/share/myconfig/grub.conf.in /boot/grub.conf
installimg SRCDIR DESTFILE Create a compressed cpio archive of the contents of SRCDIR and place it in DESTFILE.
If SRCDIR doesn’t exist or is empty nothing is created.
installinitrd SECTION SRC DEST Same as installkernel, but for “initrd”.
installkernel SECTION SRC DEST Install the kernel from SRC in the input tree to DEST in the output tree, and then add an item to the treeinfo data store, in the named SECTION, where “kernel” = DEST.
installpkg [–required] PKGGLOB [PKGGLOB ...] Request installation of all packages matching the given globs. Note that this is just a request - nothing is actually installed until the ‘run_pkg_transaction’ command is given.
installupgradeinitrd SECTION SRC DEST Same as installkernel, but for “upgrade”.
log MESSAGE Emit the given log message. Be sure to put it in quotes! Example:
log “Reticulating splines, please wait...”
mkdir DIR [DIR ...] Create the named DIR(s). Will create leading directories as needed. Example:
mkdir /images
remove FILEGLOB [FILEGLOB ...] Remove all the named files or directories. Will not raise exceptions if the file(s) are not found.
removefrom PKGGLOB [–allbut] FILEGLOB [FILEGLOB...] Remove all files matching the given file globs from the package (or packages) named. If ‘–allbut’ is used, all the files from the given package(s) will be removed except the ones which match the file globs. Examples:
removefrom usbutils /usr/bin/* removefrom xfsprogs –allbut /sbin/*
removekmod GLOB [GLOB...] [–allbut] KEEPGLOB [KEEPGLOB...] Remove all files and directories matching the given file globs from the kernel modules directory.
If ‘–allbut’ is used, all the files from the modules will be removed except the ones which match the file globs. There must be at least one initial GLOB to search and one KEEPGLOB to keep. The KEEPGLOB is expanded to be KEEPGLOB so that it will match anywhere in the path.
This only removes files from under /lib/modules/*/kernel/
removepkg PKGGLOB [PKGGLOB...] Delete the named package(s). IMPLEMENTATION NOTES:
RPM scriptlets (%preun/%postun) are not run. Files are deleted, but directories are left behind.
replace PATTERN REPLACEMENT FILEGLOB [FILEGLOB ...] Find-and-replace the given PATTERN (Python-style regex) with the given REPLACEMENT string for each of the files listed. Example:
replace @VERSION@ ${product.version} /boot/grub.conf /boot/isolinux.cfg
Actually install all the packages requested by previous ‘installpkg’ commands.
runcmd CMD [–chdir=DIR] [ARG ...] Run the given command with the given arguments. If “–chdir=DIR” is given, change to the named directory before executing the command.
NOTE: All paths given MUST be COMPLETE, ABSOLUTE PATHS to the file or files mentioned. ${root}/${inroot}/${outroot} are good for constructing these paths.
FURTHER NOTE: Please use this command only as a last resort! Whenever possible, you should use the existing template commands. If the existing commands don’t do what you need, fix them!
(this should be replaced with a “find” function) runcmd find ${root} -name “.pyo” -type f -delete %for f in find(root, name=”.pyo”):
remove ${f}
%endfor
Bases: object
Builds the anaconda runtime image.
Bases: object
Builds the arch-specific boot images. inroot should be the installtree root (the newly-built runtime dir)
Copy the hook scripts in hooks into the installroot’s /tmp/ and return a list of commands to pass to dracut when creating the initramfs
hooks is a list of tuples with the name of the hook script and the target dracut hook directory (eg. [(“99anaconda-copy-ks.sh”, “/lib/dracut/hooks/pre-pivot”)])
Return the path to the lorax dracut hooks scripts
Use the configured share dir if it is setup, otherwise default to /usr/share/lorax/dracut_hooks
Rebuild all the initrds in the tree. If backup is specified, each initrd will be renamed with backup as a suffix before rebuilding. If backup is empty, the existing initrd files will be overwritten. If suffix is specified, the existing initrd is untouched and a new image is built with the filename “${prefix}-${kernel.version}.img”