docs: Update the doc to reflect the latest changes
[snf-image] / docs / interface.rst
1 Interface
2 =========
3
4 Ganeti OS Interface
5 ^^^^^^^^^^^^^^^^^^^
6
7 *snf-image* requires ganeti-os-interface v20 to operate and it introduces the
8 following OS Parameters:
9
10  * **img_format** (required if *config_url* is missing): the image format type
11    (:ref:`details <image-format>`)
12  * **img_id** (required if *config_url* is missing): the URI used to identify
13    the image (:ref:`details <image-id>`)
14  * **img_passwd** (required if *config_url* is missing): the password to be
15    injected to the image
16  * **img_properties** (optional): additional image properties used to customize
17    the image (:ref:`details <image-properties>`)
18  * **img_personality** (optional): files to be injected into the image
19    filesystem (:ref:`details <image-personality>`)
20  * **config_url** (optional): the url to download configuration data from
21
22 .. _image-format:
23
24 Image Format (img_format)
25 ^^^^^^^^^^^^^^^^^^^^^^^^^
26
27 snf-image supports 3 different types of image formats:
28
29  * **diskdump** (recommended): a raw dump of a disk
30  * **extdump**: a raw dump of an ext{2,3,4} file system
31  * **ntfsdump**: a raw dump of an NTFS file system
32
33 These are also the only valid values for the **img_format** OS parameter.
34 The **diskdump** type is the newest and recommended type. Thus, all sample
35 images we provide are of this type. For more details about the internals of
36 image formats please see the :ref:`corresponding advanced section
37 <image-format-advanced>`.
38
39 .. _image-id:
40
41 Image ID (img_id)
42 ^^^^^^^^^^^^^^^^^
43
44 The **img_id** OS parameter points to the actual Image that we want to deploy.
45 It is a URI and its prefix denotes the type of :ref:`back-end <storage-backends>`
46 to be used. If no prefix is used, it defaults to the local back-end:
47
48  * **Local back-end**:
49    To select it, the prefix should be ``local://``, followed by the name of the
50    image. All local images are expected to be found under a predefined image
51    directory (``/var/lib/snf-image`` by default).
52
53   | For example, if we want to deploy the image file:
54   | ``/var/lib/snf-image/slackware.diskdump``
55   | We need to assign:
56   | ``img_id=local://slackware.diskdump``
57
58  * **Network back-end**:
59    If the **imd_id** starts with ``http:``, ``https:``, ``ftp:`` or ``ftps:``,
60    snf-image will treat the **img_id** as a remote URL and will try to fetch the
61    image using `cURL <http://curl.haxx.se/>`_.
62
63   | For example, if we want to deploy an image from an http location:
64   | ``img_id=http://www.synnefo.org/path/to/image/slackware-image``
65
66  * **Pithos back-end**:
67    If the **img_id** is prefixed with ``pithos://`` or ``pithosmap://`` the
68    image is considered to reside on a Pithos deployment. For ``pithosmap://``
69    images, the user needs to have set a valid value for the
70    ``PITHOS_DATA`` variable in snf-image's configuration file
71    (``/etc/default/snf-image`` by default). For ``pithos://`` images, in
72    addition to ``PITHOS_DATA``, the user needs to have set a valid value for the
73    ``PITHOS_DB`` variable, too.
74
75   | For example, if we want to deploy using a full Pithos URI:
76   | ``img_id=pithos://<user-uuid>/<container>/<slackware-image>``
77   | or if we already know the map:
78   | ``img_id=pithosmap://<slackware-image-map-name>``
79
80  * **Null back-end**:
81    To select the Null back-end and skip the fetching and extraction step, we set
82    ``img_id=null``.
83
84 .. _image-properties:
85
86 Image Properties (img_properties)
87 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88
89 *snf-image* may use a number of properties to properly configure the image.
90 Those image properties are passed to snf-image by Ganeti through the
91 *img_poroperties* OS parameter (see Ganeti OS Interface). The name of all image
92 properties is case-insensitive. For the diskdump format some properties are
93 mandatory. For {ext,ntfs}dump formats all image properties are optional.
94
95 We can group image properties in two categories:
96
97 1. Generic properties (*OSFAMILY*, *ROOT_PARTITION*, *USERS*)
98 2. Configuration tasks to run (*EXCLUDE_ALL_TASKS*, *EXCLUDE_TASK_<task_name>*)
99    (see here for :ref:`valid configuration tasks <image-configuration-tasks>`)
100
101 A list of all properties follows:
102
103 Mandatory properties (for diskdump only)
104 ++++++++++++++++++++++++++++++++++++++++
105
106  * **OSFAMILY=linux|windows|freebsd|netbsd|openbsd**
107    This specifies whether the image is a Linux, a Windows or a \*BSD Image.
108    {ext,ntfs}dump formats are self descriptive regarding this property.
109  * **ROOT_PARTITION=n**
110    This specifies the partition number of the root partition. As mentioned
111    earlier, for now, only primary partitions are supported. This property is
112    trivial for {ext,ntfs}dump formats (they only host one partition).
113
114 Optional properties
115 +++++++++++++++++++
116
117  * **USERS="username1 username2...."**
118    This is a space-separated list of users, whose password will be reset by
119    *snf-image*. The use of this property is optional, but highly recommended.
120    For now, if this property is missing, the users are chosen according to a
121    set of rules, but those rules may change or even be dropped in the future.
122    The rules we currently use are listed below:
123
124      * For Windows images, the *Administrator*'s password is reset.
125      * For Linux and \*BSD images, the *root* password is reset.
126
127  * **DO_SYNC=yes**
128    By default in ResizeUnmounted task, when ``resize2fs`` is executed to
129    enlarge a ext[234] file system, ``fsync()`` is disabled to speed up the
130    whole process. I for some reason you need to disable this behavior, use the
131    *DO_SYNC* image property.
132
133  * **PASSWORD_HASHING_METHOD=md5|sha1|blowfish|sha256|sha512**
134    This property can be used on Unix instances to specify the method to be used
135    to hash the users password. By default this is determined by the type of the
136    instance. For Linux and FreeBSD instances ``sha512`` is used, for OpenBSD
137    ``blowfish`` and for NetBSD ``sha1``. Use this property with care. Most
138    systems don't support all hashing methods (see
139    `here <http://pythonhosted.org/passlib/modular_crypt_format.html#mcf-identifiers>`_
140    for more info).
141
142  * **EXCLUDE_ALL_TASKS=yes**
143    If this property is defined with a value other than null, then during the
144    deployment, the image will not be configured at all. This is really handy
145    because it gives the ability to deploy images hosting operating systems
146    whose configuration is not supported by snf-image.
147
148  * **EXCLUDE_TASK_<task_name>=yes**
149    This family of properties gives the ability to exclude individual
150    configuration tasks from running. Hence, if the property
151    *EXCLUDE_TASK_DeleteSSHKeys* with a value other than null is passed to
152    *snf-image*, the aforementioned configuration step will not be executed, and
153    the SSH Keys found in the image will not be removed during the deployment.
154    Task exclusion provides great flexibility, but it needs to be used with
155    great care. Tasks depend on each other and although those dependencies are
156    well documented, automatic task dependency resolution isn't yet supported in
157    *snf-image*. If you exclude task A but not task B which depends on A, you
158    will probably end up with an unsuccessful deployment because B will fail and
159    exit in an abnormal way. You can read more about configuration tasks here.
160
161 img_properties OS parameter
162 +++++++++++++++++++++++++++
163
164 Image properties are passed to snf_image through the img_properties OS
165 parameter as a simple json string like the one below:
166
167 | {
168 |     "PROPERTY1": "VALUE1",
169 |     "PROPERTY2": "VALUE2",
170 |     "PROPERTY3": "VALUE3",
171 |     ...
172 |     ...
173 |     ...
174 |     "PROPERTYn": "VALUEn"
175 | }
176
177
178 A real life example for creating a new Ganeti instance and passing image
179 properties to snf-image looks like this:
180
181 .. code-block:: console
182
183    ``gnt-instance add -O img_properties='{"OSFAMILY":"linux"\,"ROOT_PARTITION":"2"\,"USERS":"root guest"}',img_format=diskdump,img_id=...``
184
185 .. _image-personality:
186
187 Image Personality (img_personality)
188 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189
190 This parameter is an extension of the Server Personality notation proposed by
191 the OpenStack Compute API v1.1 and defines a list of files to be injected into
192 the image file system.
193
194 Format
195 ++++++
196
197 The format of this parameter is a JSON array of objects. Each object in the
198 array supports the following keys:
199
200  * **path**: The absolute path of the file (string)
201  * **contents**: The content of the file encoded as a base64 string (string)
202  * **owner**: The user ownership of the file (string)
203  * **group**: The group ownership of the file (string)
204  * **mode**: The permission mode of the file (number)
205
206 The first two (path, contents) are mandatory. The others (owner, group, mode)
207 are optional and their default value is root, root and 0440 respectively.
208
209 Example
210 +++++++
211
212 The JSON string below defines two files (*/tmp/test1*, */tmp/test2*) whose
213 content is ``test1\n`` and ``test2\n``, they are both owned by *root:root* and
214 their permissions are ``-rw-r--r--`` [#]_
215
216 | [
217 |     {
218 |         "path": "/tmp/test1",
219 |         "contents": "dGVzdDENCg==",
220 |         "owner": "root",
221 |         "group": "root",
222 |         "mode": 0644
223 |     },
224 |     {
225 |         "path": "/tmp/test2",
226 |         "contents": "dGVzdDINCg==",
227 |         "owner": "root",
228 |         "group": "root",
229 |         "mode": 420
230 |     }
231 | ]
232
233 .. [#] The first mode is in octal representation and the second in decimal.