mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 18:00:35 +00:00
commit
71d8d1ddcf
6 changed files with 93 additions and 2 deletions
25
plugins/image_commands/README.md
Normal file
25
plugins/image_commands/README.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Image script plugin
|
||||
|
||||
This plugin gives the possibility to the user to execute commands.
|
||||
|
||||
Plugin is defined in the manifest file, plugin section with:
|
||||
|
||||
"image_commands": {
|
||||
"enabled": true,
|
||||
"commands": [ [ "touch", "/var/www/index.html" ]],
|
||||
}
|
||||
|
||||
The *commands* element is an array of commands. Each command is an array describing the executable and its arguments.
|
||||
|
||||
Command is executed in current context. It is possible to use variables to access the image or execute chroot commands in the image.
|
||||
|
||||
Available variables are:
|
||||
{root} : image mount point (to copy files for example or chroot commands)
|
||||
{filesystem} : used filesystem
|
||||
{image} : image file path
|
||||
|
||||
Example:
|
||||
|
||||
[[ "touch", "{root}/var/www/hello" ],
|
||||
[ "/usr/sbin/chroot", "{root}", "touch", "/var/www/hello.{filesystem}"]]
|
||||
|
11
plugins/image_commands/__init__.py
Normal file
11
plugins/image_commands/__init__.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
|
||||
def tasks(tasklist, manifest):
|
||||
from image_commands import ImageExecuteCommand
|
||||
tasklist.add(ImageExecuteCommand())
|
||||
|
||||
def validate_manifest(data, schema_validate):
|
||||
from os import path
|
||||
schema_path = path.normpath(path.join(path.dirname(__file__), 'manifest-schema.json'))
|
||||
schema_validate(data, schema_path)
|
||||
|
26
plugins/image_commands/image_commands.py
Normal file
26
plugins/image_commands/image_commands.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from base import Task
|
||||
from common import phases
|
||||
import os
|
||||
from common.tasks.packages import ImagePackages
|
||||
from common.tasks.host import CheckPackages
|
||||
from common.tasks.filesystem import MountVolume
|
||||
|
||||
|
||||
class ImageExecuteCommand(Task):
|
||||
description = 'Execute command in the image'
|
||||
phase = phases.system_modification
|
||||
|
||||
def run(self, info):
|
||||
from common.tools import log_check_call
|
||||
|
||||
for user_cmd in info.manifest.plugins['image_commands']['commands']:
|
||||
command = []
|
||||
for elt in user_cmd:
|
||||
fragment = elt.format(
|
||||
root=info.root,
|
||||
image=info.loopback_file,
|
||||
filesystem=info.manifest.volume['filesystem'])
|
||||
command.append(fragment)
|
||||
log_check_call(command)
|
||||
|
||||
|
29
plugins/image_commands/manifest-schema.json
Normal file
29
plugins/image_commands/manifest-schema.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "Image commands plugin manifest",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"plugins": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"image_commands": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"commands": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["commands"]
|
||||
}
|
||||
},
|
||||
"required": ["image_commands"]
|
||||
}
|
||||
},
|
||||
"required": ["plugins"]
|
||||
}
|
|
@ -11,7 +11,7 @@ class HostPackages(Task):
|
|||
after = [packages.HostPackages]
|
||||
|
||||
def run(self, info):
|
||||
info.host_packages.update(['qemu-utils', 'parted', 'grub2', 'sysv-rc'])
|
||||
info.host_packages.update(['qemu-utils', 'parted', 'grub2', 'sysv-rc', 'kpartx'])
|
||||
if info.manifest.volume['filesystem'] == 'xfs':
|
||||
info.host_packages.add('xfsprogs')
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class HostPackages(Task):
|
|||
after = [packages.HostPackages]
|
||||
|
||||
def run(self, info):
|
||||
info.host_packages.update(['qemu-utils', 'parted', 'grub2', 'sysv-rc'])
|
||||
info.host_packages.update(['qemu-utils', 'parted', 'grub2', 'sysv-rc', 'kpartx'])
|
||||
if info.manifest.volume['filesystem'] == 'xfs':
|
||||
info.host_packages.add('xfsprogs')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue