图像发生器

image-generator的Python项目详细描述


一个基于python的lxc图像生成器。

它将从一个yaml文件中读取一个配置,启动一个容器 因此,复制并运行特定的脚本,最后创建 LXC图像。

先决条件

sudo apt update && sudo apt install -y python3-pip lxd

安装之后,您需要配置lxd环境。 根据所需的图像和脚本,容器可能需要 Internet连接,因此请确保为 您的容器:

sudo lxd init

Name of the storage backend to use (dir or zfs)[default=dir]:
Would you like LXD to be available over the network (yes/no)[default=no]? yes
Address to bind LXD to (not including port)[default=all]:
Port to bind LXD to [default=8443]:
Trust password for new clients:
Again:
Do you want to configure the LXD bridge (yes/no)[default=yes]?
   Do you want to setup an IPv4 subnet? Yes
      Default values apply for next questions
   Do you want to setup an IPv6 subnet? No

安装图像生成器工具

安装方式:

pip3 install image-generator

如何使用

可以用两种方式运行它。single actionconfig file。配置文件是一个yaml文件,根目录上包含 要使用某些参数按顺序执行的操作的列表。

每个action都有下面列出的特定参数 章节

配置

您至少已经下载了一个lxc图像,可以在 本地LXC图像存储

lxc image list

如果没有,可以使用 以下命令:

lxc image copy ubuntu:16.04 local:

注意下一步需要的指纹。

配置文件应该如下所示:

connect:url:< The URL with port where to reach lxd engine ># Mandatorytrust-password:< The trust password you have set for the lxd environment ># Mandatorycreate-container:container-name:< The name of the container which will be created >                                 # default:"image-generator"container-image-fingerprint:< The fingeprint of the image which will be used as base image for the container ># Mandatory; you do not need the complete image fingerprint, the one shown by lxc image list is enoughcopy-files:file-tarball:< Path to the tar archive containing all scripts you want to push on the image >  # default:"./etc/files.tar"file-dest:< Path where to copy the content of the tar archive on the container ># default /root/files.tarexecute-script:script:< Which script to be executed ># Mandatoryclean-tmp-files:< remove the temporary files used for copying the tarball on the container>  # default:False# lxc always assumes you are in /root, thus take care if you use relative paths to the scripts herecreate-image:destination:< Path of the folder where the image will be saved >         # default:"/tmp"alias:<additional alias to give to the created image>                    # default:"Publishedbyimage-generator"name:<name of the result image># generated-image# if the destination does not yet contain the ending tar.gz it will be added automaticallyclean:container:< remove the container used for creating the lxc image>                        # default:Trueimage-store:< remove the image created from the container from your local image store>   # default:True# You can (re)import the images anytime by lxc image import < Your path to the desired image.tar.gz > --alias < Your Alias here >

运行

注意如果在运行图像生成器时遇到此错误:

Traceback (most recent call last):
  File "/usr/bin/pip3", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib/python3.5/locale.py", line 594, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

然后,作为快速修复,您可以运行:

exportLC_ALL=C

查看帮助

image-generator --help
usage: image-generator [-h][-f FILE][-d][-action ACTION][-params PARAMS][-dry]

optional arguments:
  -h, --help            show this help message and exit
  -f FILE, --file FILE  the file scenario with the action to execute
  -d, --debug           show debug prints
  -action ACTION        The action to execute
  -params PARAMS        The parameters to the action
  -dry                  Run dryrun

然后用sudo运行

sudo image-generator -f <PATH-TO-THE-CONFIGURATION-FILE>

sudo权限是必需的,因为它是 正在提取从lxd下载的图像。

测试它

对于测试,可以通过运行进行干运行:

sudo image-generator -f <PATH-TO-THE-CONFIGURATION-FILE> -dry --debug

它将执行除安装脚本之外的每个步骤,最后 同时删除下载的图像。

卸载

卸载方式:

pip3 uninstall image-generator

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用“Wed,01 Jul 2015 17:32:41 EDT”解析字符串   java Storm apache升级(1.0.0到2.0.0)   java类驻留在不同的目录中,而不是包指定的目录。为什么?   将Java中的图像缩放到非常小的维度   java如何通过子文档从自定义方面访问ElasticSearch parentdoc字段   java如何在RationalSoftwareArchitect中使用findbugs?   Java中的事件提升处理   java值被添加到arrayList的所有索引中,而不是在“”时添加到最后一个索引中。正在使用arraylist的add()方法   JFrame中的java JPanel派生类   java如何用循环和异步方法模拟类   java Android阻止可绘制背景超出视图范围   为客户排序Java阵列   java Apache poi如何将工作表设置为枚举位置值属性?   java Rhino在使用自定义类参数调用javascript函数时出错   java格式化日期从年月日到年月日   spring如何修复java。lang.illegalargumentexception在此特定场景中是否尝试创建具有null实体的合并事件?   java如何创建更好的对象