mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-10-07 17:40:30 +00:00
Merge pull request #298 from nbraud/file_copy
file_copy: Fix manifest and document
This commit is contained in:
commit
aa4cab4084
4 changed files with 63 additions and 39 deletions
26
bootstrapvz/plugins/file_copy/README.rst
Normal file
26
bootstrapvz/plugins/file_copy/README.rst
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
File copy
|
||||||
|
---------
|
||||||
|
|
||||||
|
This plugin lets you copy files from the host to the VM under construction,
|
||||||
|
create directories, and set permissions and ownership.
|
||||||
|
|
||||||
|
Note that this necessarily violates the `first development guideline`_.
|
||||||
|
|
||||||
|
.. _first development guideline: https://github.com/andsens/bootstrap-vz/blob/master/CONTRIBUTING.rst#the-manifest-should-always-fully-describe-the-resulting-image
|
||||||
|
|
||||||
|
|
||||||
|
Settings
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
The ``file_copy`` plugin takes a (non-empty) ``files`` list, and optionnaly a ``mkdirs`` list.
|
||||||
|
|
||||||
|
Files (items in the ``files`` list) must be objects with the following properties:
|
||||||
|
* ``src`` and ``dst`` (required) are the source and destination paths.
|
||||||
|
``src`` is relative to the current directory, whereas ``dst`` is a path in the VM.
|
||||||
|
* ``permissions`` (optional) is a permission string in a format appropriate for ``chmod(1)``.
|
||||||
|
* ``owner`` and ``group`` (optional) are respectively a user and group specification,
|
||||||
|
in a format appropriate for ``chown(1)`` and ``chgrp(1)``.
|
||||||
|
|
||||||
|
Folders (items in the ``mkdirs`` list) must be objects with the following properties:
|
||||||
|
* ``dir`` (required) is the path of the directory.
|
||||||
|
* ``permissions``, ``owner`` and ``group`` are the same as for files.
|
|
@ -3,13 +3,18 @@ import tasks
|
||||||
|
|
||||||
def validate_manifest(data, validator, error):
|
def validate_manifest(data, validator, error):
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
|
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
|
||||||
validator(data, schema_path)
|
validator(data, schema_path)
|
||||||
|
|
||||||
|
for i, file_entry in enumerate(data['plugins']['file_copy']['files']):
|
||||||
|
srcfile = file_entry['src']
|
||||||
|
if not os.path.isfile(srcfile):
|
||||||
|
msg = 'The source file %s does not exist.' % srcfile
|
||||||
|
error(msg, ['plugins', 'file_copy', 'files', i])
|
||||||
|
|
||||||
|
|
||||||
def resolve_tasks(taskset, manifest):
|
def resolve_tasks(taskset, manifest):
|
||||||
taskset.add(tasks.ValidateSourcePaths)
|
|
||||||
|
|
||||||
if ('mkdirs' in manifest.plugins['file_copy']):
|
if ('mkdirs' in manifest.plugins['file_copy']):
|
||||||
taskset.add(tasks.MkdirCommand)
|
taskset.add(tasks.MkdirCommand)
|
||||||
if ('files' in manifest.plugins['file_copy']):
|
if ('files' in manifest.plugins['file_copy']):
|
||||||
|
|
|
@ -7,31 +7,38 @@ properties:
|
||||||
properties:
|
properties:
|
||||||
mkdirs:
|
mkdirs:
|
||||||
items:
|
items:
|
||||||
dir:
|
type: object
|
||||||
$ref: '#/definitions/absolute_path'
|
properties:
|
||||||
permissions:
|
dir:
|
||||||
type: string
|
type: string
|
||||||
owner:
|
permissions:
|
||||||
type: string
|
type: string
|
||||||
group:
|
owner:
|
||||||
type: string
|
type: string
|
||||||
|
group:
|
||||||
|
type: string
|
||||||
|
required: [dir]
|
||||||
|
additionalProperties: false
|
||||||
|
|
||||||
files:
|
files:
|
||||||
items:
|
|
||||||
src:
|
|
||||||
$ref: '#/definitions/absolute_path'
|
|
||||||
dst:
|
|
||||||
$ref: '#/definitions/absolute_path'
|
|
||||||
permissions:
|
|
||||||
type: string
|
|
||||||
owner:
|
|
||||||
type: string
|
|
||||||
group:
|
|
||||||
type: string
|
|
||||||
minItems: 1
|
|
||||||
type: array
|
type: array
|
||||||
required:
|
minItems: 1
|
||||||
- src
|
items:
|
||||||
- dst
|
type: object
|
||||||
|
properties:
|
||||||
|
src:
|
||||||
|
type: string
|
||||||
|
dst:
|
||||||
|
type: string
|
||||||
|
permissions:
|
||||||
|
type: string
|
||||||
|
owner:
|
||||||
|
type: string
|
||||||
|
group:
|
||||||
|
type: string
|
||||||
|
required: [src, dst]
|
||||||
|
additionalProperties: false
|
||||||
|
|
||||||
required:
|
required:
|
||||||
- files
|
- files
|
||||||
type: object
|
type: object
|
||||||
|
|
|
@ -5,20 +5,6 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
class ValidateSourcePaths(Task):
|
|
||||||
description = 'Check whether the files to be copied exist'
|
|
||||||
phase = phases.preparation
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def run(cls, info):
|
|
||||||
from bootstrapvz.common.exceptions import TaskError
|
|
||||||
for file_entry in info.manifest.plugins['file_copy']['files']:
|
|
||||||
srcfile = file_entry['src']
|
|
||||||
if not os.path.isfile(srcfile):
|
|
||||||
msg = 'The source file %s does not exist.' % srcfile
|
|
||||||
raise TaskError(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def modify_path(info, path, entry):
|
def modify_path(info, path, entry):
|
||||||
from bootstrapvz.common.tools import log_check_call
|
from bootstrapvz.common.tools import log_check_call
|
||||||
if 'permissions' in entry:
|
if 'permissions' in entry:
|
||||||
|
|
Loading…
Add table
Reference in a new issue