Merge pull request #95 from osallou/python

Plugin: image_commands
This commit is contained in:
Anders Ingemann 2013-09-09 15:11:14 -07:00
commit 71d8d1ddcf
6 changed files with 93 additions and 2 deletions

View 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}"]]

View 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)

View 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)

View 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"]
}

View file

@ -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')

View file

@ -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')