GithubHelp home page GithubHelp logo

simhaonline / lxdprofilegenerator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clsergent/lxdprofilegenerator

0.0 0.0 0.0 7 KB

A simple python script to populate YAML templates for LXD

Python 100.00%

lxdprofilegenerator's Introduction

LXDProfileGenerator

A simple python script to populate YAML profiles for LXD

User guide

The script takes a YAML template as input, updates it using a YAML file (-u UPDATE), and outputs a YAML file (-p PROFILE).

Type $python3 lxd_profile_generator.py -h to get this short help :

usage: lxd_profile_generator.py [-h] [-u UPDATE] [-p PROFILE] [-c] [-V] [-s] template

Script to generate LXD profiles from templates

positional arguments:
  template              YAML template used to generate the profile

optional arguments:
  -h, --help            show this help message and exit
  -u UPDATE, --update UPDATE
                        YAML values applied to the template
  -p PROFILE, --profile PROFILE
                        YAML profile generated
  -c, --cloud-init      parse cloud-init data
  -V, --verbose         make script verbose
  -s, --skip-errors     skip errors

Update rules

The script compares the template and the update dictionaries according to the following rules, which are applied recursively :

  • dicts are compared to find matching keys :
    • keys missing in template are added using updatevalues
    • keys present in both dicts lead to a recursive search
    • keys missing in update remain untouched
  • template lists are extended by counterpart updatelists
  • other templatevalues are updated by their update counterpart if their type is identical (None value match any value).

Cloud-init data dicts, which are stored as plain strings in LXD profile YAML, are also compared with update dict, but their top key (data.<something>) must be inserted in the top dict of update. The required comment #cloud-config is also added at the required place in the output YAML file.

Dependencies

This script should run on python3.5 and later. However, it has only be tested on python3.9

The PyYAML module is required. Credits and documentation may be found at https://pyyaml.org.
The module may be installed easily using pip : python3 -m pip install pyyaml
A C backend can also be used to speed up PyYAML, but it is not mandatory and requires to modify YAML_LOADER and YAML_DUMPER constants in the script.

License

This repository and its content are licensed under the EUPL-1.2-or-later.

Check https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12

lxdprofilegenerator's People

Contributors

clsergent avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.