Commit de126475 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Merge branch 'feature-custom-task' into develop

parents bddf7543 44976456
......@@ -214,6 +214,76 @@ like this:
``{"subtype": "error", "type": "image-helper", "messages": ["The image contains a(n) MSDOS partition table. For FreeBSD images only GUID Partition Tables are supported."], "timestamp": 1379507910.799365}``
.. _configuration-tasks-environment:
Configuration Tasks Enviroment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When an *snf-image-helper* configuration task runs, it expects to find the
required information in its enviroment. In the table below we describe the
enviroment variables that are present when the configuration tasks run.
+-------------------------------+---------------------------------------------+
|Name |Details |
+===============================+=============================================+
|SNF_IMAGE_DEV_COUNT |The number of the instance's disks |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_DEV_%N |The device file of the Nth disk |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_DEV |The device file of the first disk (we keep |
| |this for backward compatibility) |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_PERSONALITY |The value of the img_personality OS |
| |parameter |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_HOSTNAME |The instance's name |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_PASSWD |The value of the img_passwd OS parameter. |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_PASSWD_HASH |The value of the img_passwd_hash OS |
| |parameter. |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_PROPERTY_* |The value of a specific image property |
| |that was specified in json through the |
| |img_properties OS parameter. |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_RESIZE_PART |The number of the partition that will be |
| |enlarged. |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_TARGET |The directory the instance's file systems are|
| |mounted under. |
+-------------------------------+---------------------------------------------+
|NIC_COUNT |The number of the instance's network |
| |interfaces |
+-------------------------------+---------------------------------------------+
|NIC_%N_* |The ganeti provided environment variable |
| |for the Nth network interface. Check `here <h|
| |ttp://docs.ganeti.org/ganeti/current/man/gane|
| |ti-os-interface.html>`_ |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_DHCP_TAGS |The value of the DHCP_TAGS configuration |
| |parameter (see |
| |:ref:`Configuration Parameters |
| |<configuration-parameters>`) |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_STATEFUL_DHCPV6_TAGS |The value of the STATEFUL_DHCPV6_TAGS |
| |configuration parameter (see |
| |:ref:`Configuration Parameters |
| |<configuration-parameters>`) |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_STATELESS_DHCPV6_TAGS|The value of the STATELESS_DHCPV6_TAGS |
| |configuration parameter (see |
| |:ref:`Configuration Parameters |
| |<configuration-parameters>`) |
+-------------------------------+---------------------------------------------+
|SNF_IMAGE_UNATTEND |The value of the UNATTED configuration |
| |parameter (see |
| |:ref:`Configuration Parameters |
| |<configuration-parameters>`) |
+-------------------------------+---------------------------------------------+
.. rubric:: Footnotes
.. [#f1] http://technet.microsoft.com/en-us/library/hh824938.aspx
......@@ -215,49 +215,55 @@ will fail.
missing a warning is produced. Only *SNF_IMAGE_TARGET* is required for this
task to run.
**RunCustomTask**: Run a user-defined task specified by the
*SNF_IMAGE_PROPERTY_CUSTOM_TASK* variable. If the variable is missing or empty,
a warning is produced.
**UmountImage**: Umounts the file systems previously mounted by MountImage. The
only environment variable required is *SNF_IMAGE_TARGET*.
+-------------------------------+---+--------------------------------------------+-------------------------------------------+
| | | Dependencies | Enviromental Variables [#]_ |
+ Name | +------------------+-------------------------+-------------------------+-----------------+
| |Pr.| Run-After | Run-Before | Required | Optional |
+===============================+===+==================+=========================+=========================+=================+
|FixPartitionTable |10 | |FilesystemResizeUnmounted|DEV | |
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|FilesystemResizeUnmounted |20 |FixPartitionTable |MountImage |DEV | |
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|MountImage |30 | |UmountImage |DEV | |
| | | | |TARGET | |
| | | | |PROPERTY_ROOT_PARTITION | |
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|AddSwap |40 |MountImage |EnforcePersonality |TARGET |PROPERTY_OSFAMILY|
| | | | | |PROPERTY_SWAP |
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|DeleteSSHKeys |40 |MountImage |EnforcePersonality |TARGET |PROPERTY_OSFAMILY|
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|DisableRemoteDesktopConnections|40 |EnforcePersonality|UmountImage |TARGET |PROPERTY_OSFAMILY|
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|InstallUnattend |40 |MountImage |EnforcePersonality |TARGET |PROPERTY_OSFAMILY|
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|SELinuxAutorelabel |40 |MountImage |EnforcePersonality |TARGET |PROPERTY_OSFAMILY|
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|AssignHostname |50 |InstallUnattend |EnforcePersonality |TARGET | |
| | | | |HOSTNAME |PROPERTY_OSFAMILY|
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|ChangePassword |50 |InstallUnattend |EnforcePersonality |TARGET |PROPERTY_USERS |
| | | | | |PROPERTY_OSFAMILY|
| | | | | |PASSWD |
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|ConfigureNetwork |50 |InstallUnattend |EnforcePersonality |TARGET |NIC_* |
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|FilesystemResizeMounted |50 |InstallUnattend |EnforcePersonality |TARGET |PROPERTY_OSFAMILY|
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|EnforcePersonality |60 |MountImage |UmountImage |TARGET |PERSONALITY |
| | | | | |PROPERTY_OSFAMILY|
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
|UmountImage |80 |MountImage | |TARGET | |
+-------------------------------+---+------------------+-------------------------+-------------------------+-----------------+
+-------------------------------+---+--------------------------------------------+----------------------------------------------+
| | | Dependencies | Enviromental Variables [#]_ |
+ Name | +------------------+-------------------------+-------------------------+--------------------+
| |Pr.| Run-After | Run-Before | Required | Optional |
+===============================+===+==================+=========================+=========================+====================+
|FixPartitionTable |10 | |FilesystemResizeUnmounted|DEV | |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|FilesystemResizeUnmounted |20 |FixPartitionTable |MountImage |DEV | |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|MountImage |30 | |UmountImage |DEV | |
| | | | |TARGET | |
| | | | |PROPERTY_ROOT_PARTITION | |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|AddSwap |40 |MountImage |EnforcePersonality |TARGET |PROPERTY_OSFAMILY |
| | | | | |PROPERTY_SWAP |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|DeleteSSHKeys |40 |MountImage |EnforcePersonality |TARGET |PROPERTY_OSFAMILY |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|DisableRemoteDesktopConnections|40 |EnforcePersonality|UmountImage |TARGET |PROPERTY_OSFAMILY |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|InstallUnattend |40 |MountImage |EnforcePersonality |TARGET |PROPERTY_OSFAMILY |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|SELinuxAutorelabel |40 |MountImage |EnforcePersonality |TARGET |PROPERTY_OSFAMILY |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|AssignHostname |50 |InstallUnattend |EnforcePersonality |TARGET | |
| | | | |HOSTNAME |PROPERTY_OSFAMILY |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|ChangePassword |50 |InstallUnattend |EnforcePersonality |TARGET |PROPERTY_USERS |
| | | | | |PROPERTY_OSFAMILY |
| | | | | |PASSWD |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|ConfigureNetwork |50 |InstallUnattend |EnforcePersonality |TARGET |NIC_* |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|FilesystemResizeMounted |50 |InstallUnattend |EnforcePersonality |TARGET |PROPERTY_OSFAMILY |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|EnforcePersonality |60 |MountImage |UmountImage |TARGET |PERSONALITY |
| | | | | |PROPERTY_OSFAMILY |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|RunCustomTask |70 |MountImage |UmountImage |TARGET |PROPERTY_CUSTOM_TASK|
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
|UmountImage |80 |MountImage | |TARGET | |
+-------------------------------+---+------------------+-------------------------+-------------------------+--------------------+
.. [#] all environment variables are prefixed with *SNF_IMAGE_*
......@@ -121,6 +121,8 @@ some external programs in ``/etc/default/snf-image``:
# CURL="curl"
# TAR="tar"
.. _configuration-parameters:
Configuration parameters
^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -138,6 +140,8 @@ The most common configuration parameters the user may need to overwrite are:
* **STATELESS_DHCPV6_TAGS**: To specify which Ganeti networks support SLAAC
and stateless DHCPv6
* **STATEFUL_DHCPV6_TAGS**: To specify which Ganeti networks support DHCPv6
* **UNATTEND**: To specify a custom Unattend.xml file to use on Windows
instead of the default one
Paths of external programs
^^^^^^^^^^^^^^^^^^^^^^^^^^
......
......@@ -194,6 +194,12 @@ All image formats properties
to be swap. Defining *SWAP=c* will configure the third disk of the VM to be
swap.This property only applies to Linux instances.
* **CUSTOM_TASK=<base64_encoded_content>**
This property can be used to run a user-defined configuration task. The
value of this property should host the base64-encoded body of the task. If
you want to write a custom configuration task check
:ref:`Configuration Tasks Environment<configuration-tasks-environment>`.
* **EXCLUDE_ALL_TASKS=yes**
If this property is defined with a value other than null, then during the
deployment, the image will not be configured at all. This is really handy
......
......@@ -41,6 +41,7 @@ HIVEXGET=hivexget
HIVEXREGEDIT=hivexregedit
BTRFS=btrfs
XFS_GROWFS=xfs_growfs
BASE64=base64
CLEANUP=( )
ERRORS=( )
......
#! /bin/bash
# Copyright (C) 2015 GRNET S.A.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
### BEGIN TASK INFO
# Provides: RunCustomTask
# RunBefore: UmountImage
# RunAfter: MountImage
# Short-Description: Run a user defined task on the image
### END TASK INFO
set -e
. "@commondir@/common.sh"
trap task_cleanup EXIT
report_task_start
# Check if the task should be prevented from running.
check_if_excluded
check_if_mounted_excluded
if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
fi
if [ -z "$SNF_IMAGE_PROPERTY_CUSTOM_TASK" ]; then
warn "No custom task specified to run"
exit 0
fi
custom_task="$(mktemp)"
add_cleanup rm "$custom_task"
chmod +x "$custom_task"
$BASE64 --decode > "$custom_task" <<< "$SNF_IMAGE_PROPERTY_CUSTOM_TASK"
$custom_task
exit 0
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
......@@ -14,6 +14,7 @@ dist_tasks_SCRIPTS = \
50ConfigureNetwork \
50FilesystemResizeMounted \
60EnforcePersonality \
70RunCustomTask \
80UmountImage
edit = sed \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment