Package: osconfiglib
osconfiglibosconfiglib is a Python library designed to ease the process of layer-based configuration for virtual machines (QCOW2). The library provides utilities to manage layers, apply configurations, and includes a CLI tool for easy management.InstallationTo install osconfiglib, add the following to the dependencies section of your project'spyproject.toml:osconfiglib="^1.0.0"Then run:$pipinstall-rrequirements.txtUsageHere's a basic example of how you can use osconfiglib:fromosconfiglib.layersimportsquash_layers,export_squashed_layerfromosconfiglib.virt_customizeimportapply_squashed_layer# Use osconfiglib to squash layerssquashed_layer=squash_layers(base_image_path,os_recipe_toml_path)# Export the squashed layerexport_squashed_layer(squashed_layer,output_image_path)# Apply the squashed layer to a base imageapply_squashed_layer(base_image_path,squashed_layer,output_image_path,python_version="python3")CLI Usageosconfiglib also includes a CLI tool to manage your layers. Here are some examples of how to use it:# List all layers$osconfigliblistlayers# Check version$osconfiglib--version# Add RPM to a layer$osconfiglibaddrpmmylayertmux# Add a file to a layer$osconfiglibaddfilemylayer~/.tmux.conf/home/user# Create a new layer$osconfiglibcreatelayernewLayer# Delete a layer$osconfiglibdeletelayer<layer>Repository StructureWhen using osconfiglib to manage layers, your repository should follow this structure:my-build/
├── configs/
│   ├── bin/
│   │   └── custom-executable
│   ├── etc/
│   │   └── custom-executable.conf
│   └── usr/local/bin
│       └── symlink-to-something
├── package-lists/
│   ├── rpm-requirements.txt
│   ├── dep-requirements.txt
│   └── pip-requirements.txt
└── scripts/
    ├── 01-first-script-to-run.sh
    └── 02-second-script-to-run.shconfigs/: This directory is where you put custom config files that go in the root filesystem. Examples can include custom dns, dhcpd, tftp, and other services required for this "layer".package-lists/: This directory contains lists for RedHat and Debian packages based on the flavor of Linux. A separate file is included for pip requirements for the system Python.scripts/: Scripts are run in alphabetical order. If you number them you can control the order of the scripts.You can refer to thisos-layer-templatefor a complete template of the repository structure.TOML File UsageYou can define your layers in a TOML file for easy import, squash, and application. Here's an example of a TOML file:name="Ubuntu-Python-Dev"version="1.0.0"[layers][[layer]]type="git"url="https://github.com/user/os-ubuntu.git"branch_or_tag="main"[[layer]]type="git"url="https://github.com/user/os-python.git"branch_or_tag="main"[[layer]]type="local"path="/path/to/your/local/os-custom-configs"This TOML file defines three layers. Theos-ubuntuandos-pythonlayers are git layers. Theos-custom-configslayer is a local layer, stored in your filesystem.To use these layers:Import the layers using theimport_layersfunction:import_layers('path/to/your/layers.toml')This function will import all the layers defined in your TOML file into your local cache. For git layers, the repositories will be cloned. For local layers, they are already in your filesystem, so they won't be imported.Squash the layers using thesquash_layersfunction:squashed_layer=squash_layers(layers)This function will combine all the layers into a single squashed layer.You can either export the squashed layer into a tarball using theexport_squashed_layerfunction:export_squashed_layer(squashed_layer,'path/to/your/output.tar.gz')Or apply the squashed layer to a base image using theapply_squashed_layerfunction:apply_squashed_layer('path/to/your/base.qcow2',squashed_layer,'path/to/your/output.qcow2')If you want to export or apply layers based on a TOML file directly, you can use thetoml_exportortoml_applyfunctions:toml_export('path/to/your/layers.toml','path/to/your/output.tar.gz')toml_apply('path/to/your/layers.toml','path/to/your/base.qcow2','path/to/your/output.qcow2')Thetoml_exportfunction will export a squashed layer based on the layers defined in the TOML file. Thetoml_applyfunction will apply a squashed layer based on the layers defined in the TOML file to a base image.DevelopingTo run the test suite, install the dev dependencies and run pytest:$pipinstall-rdev-requirements.txt
$pytestContactIf you have any issues or questions, feel free tocontact me atbrandon.geraci@gmail.com.