Statistics
| Branch: | Tag: | Revision:

root / docs / examplesdir / imageregister.rst @ f084bdc8

History | View | Annotate | Download (16.5 kB)

1
Image registration
2
==================
3

    
4
In Synnefo, an image is loaded as a file to the storage service (Pithos+), and
5
then is registered to the image service (Plankton). The image location at the
6
storage server is unique in each a deployment and also a key for identifying
7
the image.
8

    
9
The image location format at user level::
10

    
11
    pithos://<user_uuid>/<container>/<object path>
12

    
13
    e.g., pithos://my-u53r-1d/images/debian_base3.diskdump
14

    
15
In **file** and **container** contexts, users may also use the shortcut:
16

    
17
    /<container>/<object path>
18

    
19
    e.g., /images/debian_base3.diskdump
20

    
21
Register an image
22
-----------------
23

    
24
Let the image file `debian_base3.diskdump` be a debian image located at the
25
current local directory.
26

    
27
Upload the image to container `images`
28

    
29
.. code-block:: console
30

    
31
    $ kamaki file upload debian_base3.diskdump /images
32

    
33
Register the image object with the name 'Debian Base Alpha'
34

    
35
.. code-block:: console
36

    
37
    kamaki image register --name 'Debian Base Alpha' --location=/images/debian_base3.diskdump
38
    checksum:         3cb03556ec971f...e8dd6190443b560cb7
39
    container-format: bare
40
    created-at:       2013-06-19 08:00:22
41
    deleted-at:
42
    disk-format:      diskdump
43
    id:               7h1rd-1m4g3-1d
44
    is-public:        False
45
    location:         pithos://s0m3-u53r-1d/images/debian_base3.diskdump
46
    name:             Debian Base Alpha
47
    owner:            s0m3-u53r-1d
48
    properties:
49
    size:             903471104
50
    status:           available
51
    updated-at:       2013-06-19 08:01:00
52
    Metadata file uploaded as /images/debian_base3.diskdump.meta (version 1352)
53

    
54
.. warning:: The image created by the above command will not be able to create
55
    a working virtual server, although the registration will be successful. In
56
    the synnefo universe, an image has to be registered along with some
57
    `properties <http://www.synnefo.org/docs/snf-image/latest/usage.html#image-properties>`_.
58

    
59
.. note:: The `image register` command automatically creates a meta file and
60
    uploads it to the same location as the image. The meta file can be
61
    downloaded and reused for more image registrations.
62

    
63
Here is another way to perform the two operations above: **/image register**
64
with the **\- -upload-image-file** argument. This single operation will upload
65
the image file and then register it as an image, and is equivalent to
66
sequentially calling **/file upload** and **/image register**.
67

    
68
In other words, the preceding and following command sequences are equivalent.
69

    
70
.. code-block:: console
71

    
72
        kamaki image register --name='Debian Base Alpha'
73
            --location=/images/debian_base3.diskdump
74
            --upload-image-file=debian_base3.diskdump
75

    
76

    
77
Read the metafile
78

    
79
.. code-block:: console
80

    
81
    kamaki file cat /images/debian_base3.diskdump.meta
82
    {
83
      "status": "available",
84
      "name": "Debian Base Gama",
85
      "checksum": "3cb03556ec971f...e8dd6190443b560cb7",
86
      "id": "7h1rd-1m4g3-1d2",
87
      "updated-at": "2013-06-19 08:01:00",
88
      "created-at": "2013-06-19 08:00:22",
89
      "properties": {},
90
      "location": "pithos://s0m3-u53r-1d/images/debian_base3.diskdump",
91
      "is-public": "False",
92
      "owner": "s0m3-u53r-1d",
93
      "disk-format": "diskdump",
94
      "size": "903471104",
95
      "deleted-at": "",
96
      "container-format": "bare"
97
    }
98

    
99
Images registered by me
100
-----------------------
101

    
102
List all images, then list only images owned by the user with id s0m3-u53r-1d
103

    
104
.. code-block:: console
105

    
106
    kamaki image list
107
    f1r57-1m4g3-1d Debian Base Alpha
108
        container_format: bare
109
        disk_format:      diskdump
110
        size:             474066944
111
        status:           available
112
    53c0nd-1m4g3-1d Beta Debian Base
113
        container_format: bare
114
        disk_format:      diskdump
115
        size:             474066944
116
        status:           available
117
    7h1rd-1m4g3-1d Debian Base Gama
118
        container_format: bare
119
        disk_format:      diskdump
120
        size:             474066944
121
        status:           available
122
    kamaki image list --owner=s0m3-u53r-1d
123
    7h1rd-1m4g3-1d Debian Base Gama
124
        container_format: bare
125
        disk_format:      diskdump
126
        size:             474066944
127
        status:           available
128

    
129
.. note:: To get the current user id, use `kamaki user info`
130

    
131
Unregister an image
132
-------------------
133

    
134
An image can be unregistered by its image id, but only if the current user is
135
also the image owner. In this example, there is only one image owned by current
136
user.
137

    
138
Unregister image owned by current user
139

    
140
.. code-block:: console
141

    
142
    kamaki image unregister 7h1rd-1m4g3-1d
143

    
144
Check if the image is deleted
145

    
146
.. code-block:: console
147

    
148
    kamaki image list --owner=s0m3-u53r-1d
149

    
150
Attempt to unregister an image of another user
151

    
152
.. code-block:: console
153

    
154
    kamaki image unregister f1r57-1m4g3-1d
155
    (403) FORBIDDEN forbidden ()
156

    
157
Register with properties
158
------------------------
159

    
160
.. warning:: A succesfully registered image will not be functional, if the
161
    image properties are not defined correctly. Read the
162
    `documentation <http://www.synnefo.org/docs/snf-image/latest/usage.html#image-properties>`_
163
    for more information.
164

    
165
The image will be registered again, but with some custom properties::
166

    
167
    OSFAMILY: linux
168
    USER: someuser
169

    
170
In theory, these properties can be added freely by the user, and they are not
171
required by the image server. In practice, some properties are absolutely
172
vital for an image to be useful, although not necessary for registration.
173
An attempt to register an image with custom properties:
174

    
175
.. code-block:: console
176

    
177
    kamaki image register --name='Debian Base Gama' --location=/images/debian_base3.diskdump -p OS=linux -p user=someuser
178
    Metadata file /images/debian_base3.diskdump.meta already exists
179

    
180
It's true that a metafile with this name is already there, but we can override
181
it (**-f**)
182

    
183
.. code-block:: console
184

    
185
    kamaki image register -f --name='Debian Base Gama' --location=/images/debian_base3.diskdump -p OS=linux -p user=someuser
186

    
187
Register with a meta file
188
-------------------------
189

    
190
Download the meta file of the image (it was uploaded recently)
191

    
192
.. code-block:: console
193

    
194
    kamaki file download /images/debian_base3.diskdump.meta
195
    Downloading /images/debian_base3.diskdump.meta --> /home/someuser/debian_base3.diskdump.meta
196
    Done
197

    
198
The metadata file can be edited. Let's edit the file to add these properties::
199

    
200
    OS: linux
201
    USER: root
202

    
203
The resulting file will look like this:
204

    
205
.. code-block:: javascript
206

    
207
    {
208
      "status": "available",
209
      "name": "Debian Base Gama",
210
      "checksum": "3cb03556ec971f...e8dd6190443b560cb7",
211
      "id": "7h1rd-1m4g3-1d2",
212
      "updated-at": "2013-06-19 08:01:00",
213
      "created-at": "2013-06-19 08:00:22",
214
      "properties": {
215
        "OS": "linux",
216
        "USER": "root"
217
      },
218
      "location": "pithos://s0m3-u53r-1d/images/debian_base3.diskdump",
219
      "is-public": "False",
220
      "owner": "s0m3-u53r-1d",
221
      "disk-format": "diskdump",
222
      "size": "903471104",
223
      "deleted-at": "",
224
      "container-format": "bare"
225
    }
226

    
227
.. warning:: make sure the file is in a valid json format, otherwise image
228
    register will fail
229

    
230
In the following registration, the image name will change to a new one.
231

    
232
Register the image (don't forget the -f parameter, to override the metafile).
233

    
234
.. code-block:: console
235

    
236
    kamaki image register -f --name='Debian Base Delta' --location=/images/debian_base3.diskdump --metafile=debian_base3.diskdump.meta
237
    checksum:         3cb03556ec971f...e8dd6190443b560cb7
238
    container-format: bare
239
    created-at:       2013-06-19 08:00:22
240
    deleted-at:
241
    disk-format:      diskdump
242
    id:               7h1rd-1m4g3-1d
243
    is-public:        False
244
    location:         pithos://s0m3-u53r-1d/images/debian_base3.diskdump
245
    name:             Debian Base Delta
246
    owner:            s0m3-u53r-1d
247
    properties:
248
            OS:     linux
249
            USER:   root
250
    size:             903471104
251
    status:           available
252
    updated-at:       2013-06-19 08:01:00
253
    Metadata file uploaded as /images/debian_base3.diskdump.meta (version 1359)
254

    
255
Metadata and Property modification
256
----------------------------------
257

    
258
According to the OpenStack terminology, the terms **metadata** and
259
**properties** are two different thinks, if we talk about images. **Metadata**
260
are all kinds of named metadata on an image. Some of them are assigned by the
261
system, some others are custom and set by the users who register the image.
262
These custom **metadata** are called **properties**.
263

    
264
Image **metadata** and custom **properties** can be modified even after the
265
image is registered. Metadata are fixed image attributes, like name, disk
266
format etc. while custom properties are set by the image owner and, usually,
267
refer to attributes of the images OS.
268

    
269
Let's rename the image:
270

    
271
.. code-block:: console
272

    
273
    kamaki image modify 7h1rd-1m4g3-1d --name='Changed Name'
274

    
275
A look at the image metadata reveals that the name is changed:
276

    
277
.. code-block:: console
278

    
279
    kamaki image info 7h1rd-1m4g3-1d
280
    checksum:         3cb03556ec971f...e8dd6190443b560cb7
281
    container-format: bare
282
    created-at:       2013-06-19 08:00:22
283
    deleted-at:
284
    disk-format:      diskdump
285
    id:               7h1rd-1m4g3-1d
286
    is-public:        False
287
    location:         pithos://s0m3-u53r-1d/images/debian_base3.diskdump
288
    name:             Changed Name
289
    owner:            s0m3-u53r-1d
290
    properties:
291
            OS:     linux
292
            USER:   root
293
    size:             903471104
294
    status:           available
295
    updated-at:       2013-06-19 08:01:00
296
    kamaki
297

    
298
We can use the same idea to change the values of other metadata like disk
299
format, container format or status. On the other hand, we cannot modify the
300
id, owner, location, checksum and dates. e.g., to publish and unpublish:
301

    
302
.. code-block:: console
303

    
304
    kamaki image modify 7h1rd-1m4g3-1d --publish --name='Debian Base Gama'
305
    kamaki image modify 7h1rd-1m4g3-1d --unpublish
306

    
307
The first call publishes the image (set is-public to True) and also restores
308
the name to "Debian Base Gama". The second one unpublishes the image (set
309
is-public to False).
310

    
311
These operations can be used for properties with the same semantics:
312

    
313
.. code-block:: console
314

    
315
    kamaki image modify 7h1rd-1m4g3-1d -p user=user
316
    kamaki image info 7h1rd-1m4g3-1d
317
    ...
318
    properties:
319
            OS:     linux
320
            USER:   user
321
    ...
322
    kamaki
323

    
324
Just to test the feature, let's create a property "greet" with value
325
"hi there", and then remove it. Also, let's restore the value of USER:
326

    
327
.. code-block:: console
328

    
329
    kamaki image modify 7h1rd-1m4g3-1d -p greet='Hi there' -p user=root
330
    kamaki image info 7h1rd-1m4g3-1d
331
    ...
332
    properties:
333
            OS:     linux
334
            USER:   root
335
            GREET:  Hi there
336
    ...
337
    kamaki image modify 7h1rd-1m4g3-1d -p greet=
338
    kamaki image info 7h1rd-1m4g3-1d
339
    ...
340
    properties:
341
            OS:     linux
342
            USER:   root
343
    ...
344
    kamaki
345

    
346

    
347
Reregistration: priorities and overrides
348
----------------------------------------
349

    
350
Let's review the examples presented above::
351

    
352
    - Register an image with name `Debian Base Gama`
353
    - Unregister the image
354
    - Register a new image of the uploaded image object, with custom properties
355
    - Reregister the image with a meta file and modified properties and name
356

    
357
**The image id is related to the image object**
358

    
359
Although the image was unregistered and reregistered, the image id, that is
360
produced automatically at the server side, was the same. This is due to the
361
fact that image ids are 1 to 1 related to image objects uploaded to Pithos+
362

    
363
**An explicit image name overrides the metafile**
364

    
365
Each image needs a name and this is given as the first argument of the
366
`register` command. This name overrides the name in the metafile.
367

    
368
**Reregistration is not an update, but an override**
369

    
370
The property `user: root` won over `user: someuser`, because it was set last.
371
Actually, all properties were replaced by the new ones, when the image was
372
reregistered, and the same holds with all customizable attributes of the image.
373

    
374
Command line wins the metafile
375
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
376

    
377
Let's compine the metafile with a command line attribute `user: admin`
378

    
379
.. code-block:: console
380

    
381
    kamaki image register -f --name='Debian Base Delta' --location=/images/debian_base3.diskdump --metafile=debian_base3.diskdump.meta
382
    checksum:         3cb03556ec971f...e8dd6190443b560cb7
383
    container-format: bare
384
    created-at:       2013-06-19 08:00:22
385
    deleted-at:
386
    disk-format:      diskdump
387
    id:               7h1rd-1m4g3-1d
388
    is-public:        False
389
    location:         pithos://s0me-u53r/images/s0m3-u53r-1d/images/debian_base3.diskdump
390
    name:             Debian Base Delta
391
    owner:            s0m3-u53r-1d
392
    properties:
393
            OS:     linux
394
            USER:   root
395
    size:             903471104
396
    status:           available
397
    updated-at:       2013-06-19 08:01:00
398
    Metadata file uploaded as /images/debian_base3.diskdump.meta (version 1377)
399
    kamaki
400

    
401
Although the property `OS` was read from the metafile, the property `USER` was
402
set by the command line property to `admin`.
403

    
404
.. note:: This feature allows the use of a metafile as a template for uploading
405
    multiple images with many common attributes but slight modifications per
406
    image
407

    
408
Multiple metafile versions
409
--------------------------
410

    
411
.. warning:: Make sure your container is set to auto, otherwise, there will be
412
    no object versions
413

    
414
    .. code-block:: console
415

    
416
        kamaki container info images | grep versioning
417
        x-container-policy-versioning: auto
418

    
419
    To set versioning to auto
420

    
421
    .. code-block:: console
422

    
423
        kamaki container modify images --versioning=auto
424

    
425
In the above examples, the image was registered many times by overriding the
426
metafile. It is possible to avoid writing a metafile, as well as accessing
427
older versions of the file.
428

    
429
Register the image without uploading a metafile
430

    
431
.. code-block:: console
432

    
433
    kamaki image register --name='Debian Base Delta' --location=/images/debian_base3.diskdump --metafile=debian_base3.diskdump.meta --no-metafile-upload
434
    checksum:         3cb03556ec971f...e8dd6190443b560cb7
435
    container-format: bare
436
    created-at:       2013-06-19 08:00:22
437
    deleted-at:
438
    disk-format:      diskdump
439
    id:               7h1rd-1m4g3-1d
440
    is-public:        False
441
    location:         pithos://s0m3-u53r/images/s0m3-u53r-1d/images/debian_base3.diskdump
442
    name:             Debian Base Delta
443
    owner:            s0m3-u53r-1d
444
    properties:
445
            OS:     linux
446
            USER:   root
447
    size:             903471104
448
    status:           available
449
    updated-at:       2013-06-19 08:01:00
450
    kamaki
451

    
452
Uploaded metafiles are kept in versions, thanks to Pithos+ versioning support
453

    
454
.. code-block:: console
455

    
456
    kamaki file info /images/debian_base3.diskdump.meta --object-versions
457
    1352
458
     created: 19-06-2013 11:00:22
459
    1359
460
     created: 19-06-2013 11:01:00
461
    1377
462
     created: 19-06-2013 11:34:37
463
    kamaki
464

    
465
Consult the first version of the metafile
466

    
467
.. code-block:: console
468

    
469
    kamaki file cat --object-version=1352 /images/debian_base3.diskdump.meta
470
    {
471
      "status": "available",
472
      "name": "Debian Base Gama",
473
      "checksum": "3cb03556ec971f...e8dd6190443b560cb7",
474
      "id": "7h1rd-1m4g3-1d2",
475
      "updated-at": "2013-06-19 08:01:00",
476
      "created-at": "2013-06-19 08:00:22",
477
      "properties": {},
478
      "location": "pithos://s0m3-u53r/images/s0m3-u53r-1d/images/debian_base3.diskdump",
479
      "is-public": "False",
480
      "owner": "s0m3-u53r-1d",
481
      "disk-format": "diskdump",
482
      "size": "903471104",
483
      "deleted-at": "",
484
      "container-format": "bare"
485
    }
486

    
487
Download the second version
488

    
489
.. code-block:: console
490

    
491
    kamaki file download --object-version=1359 /images/debian_base3.diskdump.meta debian_base3.diskdump.meta.v1359
492
    Downloading /images/debian_base3.diskdump.meta --> /home/someuser/debian_base3.diskdump.meta.v1359
493
    Done
494

    
495
Batch image upload
496
------------------
497

    
498
Let a directory at /home/someuser/images with a variety of images needed to be
499
uploaded and registered.
500

    
501
Batch-upload the images
502

    
503
.. code-block:: console
504

    
505
    kamaki file upload -r images /images
506
    mkdir /images/images
507
    Uploading /home/someuser/images/debian.diskdump --> /images/images/debian.diskdump
508
    Uploading /home/someuser/images/win8.diskdump --> /images/images/win8.diskdump
509
    ...
510
    Done
511

    
512
Make sure the images are uploaded to /images/images/ remote directory object
513

    
514
.. code-block:: console
515

    
516
    kamaki file list /images/images/
517
    D       images/
518
    983MB   images/debian.diskdump
519
    2.2GB   images/win8.diskdump
520
    ...
521
    kamaki
522

    
523
Use the host shell capabilities to streamline the registration, so exit kamaki
524

    
525
.. code-block:: console
526

    
527
    kamaki /exit