Statistics
| Branch: | Tag: | Revision:

root / docs / examplesdir / imageregister.rst @ bf88122d

History | View | Annotate | Download (16.7 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

    
22
Register an image
23
-----------------
24

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

    
28
Upload the image to container `images`
29

    
30
.. code-block:: console
31

    
32
    $ kamaki file upload debian_base3.diskdump /images
33

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

    
36
.. code-block:: console
37

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

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

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

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

    
69
<<<<<<< HEAD:docs/collection_of_examples/imageregister.rst
70
In other words, the example that follows is equivalent to calling the two
71
operations above.
72
=======
73
In other words, the preceding and following command sequences are equivalent.
74
>>>>>>> release-0.11:docs/examplesdir/imageregister.rst
75

    
76
.. code-block:: console
77

    
78
        kamaki image register --name='Debian Base Alpha'
79
            --location=/images/debian_base3.diskdump
80
            --upload-image-file=debian_base3.diskdump
81

    
82

    
83
Read the metafile
84

    
85
.. code-block:: console
86

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

    
105
Images registered by me
106
-----------------------
107

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

    
110
.. code-block:: console
111

    
112
    kamaki image list
113
    f1r57-1m4g3-1d Debian Base Alpha
114
        container_format: bare
115
        disk_format:      diskdump
116
        size:             474066944
117
        status:           available
118
    53c0nd-1m4g3-1d Beta Debian Base
119
        container_format: bare
120
        disk_format:      diskdump
121
        size:             474066944
122
        status:           available
123
    7h1rd-1m4g3-1d Debian Base Gama
124
        container_format: bare
125
        disk_format:      diskdump
126
        size:             474066944
127
        status:           available
128
    kamaki image list --owner=s0m3-u53r-1d
129
    7h1rd-1m4g3-1d Debian Base Gama
130
        container_format: bare
131
        disk_format:      diskdump
132
        size:             474066944
133
        status:           available
134

    
135
.. note:: To get the current user id, use `kamaki user info`
136

    
137
Unregister an image
138
-------------------
139

    
140
An image can be unregistered by its image id, but only if the current user is
141
also the image owner. In this example, there is only one image owned by current
142
user.
143

    
144
Unregister image owned by current user
145

    
146
.. code-block:: console
147

    
148
    kamaki image unregister 7h1rd-1m4g3-1d
149

    
150
Check if the image is deleted
151

    
152
.. code-block:: console
153

    
154
    kamaki image list --owner=s0m3-u53r-1d
155

    
156
Attempt to unregister an image of another user
157

    
158
.. code-block:: console
159

    
160
    kamaki image unregister f1r57-1m4g3-1d
161
    (403) FORBIDDEN forbidden ()
162

    
163
Register with properties
164
------------------------
165

    
166
.. warning:: A succesfully registered image will not be functional, if the
167
    image properties are not defined correctly. Read the
168
    `documentation <http://www.synnefo.org/docs/snf-image/latest/usage.html#image-properties>`_
169
    for more information.
170

    
171
The image will be registered again, but with some custom properties::
172

    
173
    OSFAMILY: linux
174
    USER: someuser
175

    
176
In theory, these properties can be added freely by the user, and they are not
177
required by the image server. In practice, some properties are absolutely
178
vital for an image to be useful, although not necessary for registration.
179
An attempt to register an image with custom properties:
180

    
181
.. code-block:: console
182

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

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

    
189
.. code-block:: console
190

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

    
193
Register with a meta file
194
-------------------------
195

    
196
Download the meta file of the image (it was uploaded recently)
197

    
198
.. code-block:: console
199

    
200
    kamaki file download /images/debian_base3.diskdump.meta
201
    Downloading /images/debian_base3.diskdump.meta --> /home/someuser/debian_base3.diskdump.meta
202
    Done
203

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

    
206
    OS: linux
207
    USER: root
208

    
209
The resulting file will look like this:
210

    
211
.. code-block:: javascript
212

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

    
233
.. warning:: make sure the file is in a valid json format, otherwise image
234
    register will fail
235

    
236
In the following registration, the image name will change to a new one.
237

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

    
240
.. code-block:: console
241

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

    
261
Metadata and Property modification
262
----------------------------------
263

    
264
According to the OpenStack terminology, the terms **metadata** and
265
**properties** are two different thinks, if we talk about images. **Metadata**
266
are all kinds of named metadata on an image. Some of them are assigned by the
267
system, some others are custom and set by the users who register the image.
268
These custom **metadata** are called **properties**.
269

    
270
Image **metadata** and custom **properties** can be modified even after the
271
image is registered. Metadata are fixed image attributes, like name, disk
272
format etc. while custom properties are set by the image owner and, usually,
273
refer to attributes of the images OS.
274

    
275
Let's rename the image:
276

    
277
.. code-block:: console
278

    
279
    kamaki image modify 7h1rd-1m4g3-1d --name='Changed Name'
280

    
281
A look at the image metadata reveals that the name is changed:
282

    
283
.. code-block:: console
284

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

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

    
308
.. code-block:: console
309

    
310
    kamaki image modify 7h1rd-1m4g3-1d --publish --name='Debian Base Gama'
311
    kamaki image modify 7h1rd-1m4g3-1d --unpublish
312

    
313
The first call publishes the image (set is-public to True) and also restores
314
the name to "Debian Base Gama". The second one unpublishes the image (set
315
is-public to False).
316

    
317
These operations can be used for properties with the same semantics:
318

    
319
.. code-block:: console
320

    
321
    kamaki image modify 7h1rd-1m4g3-1d -p user=user
322
    kamaki image info 7h1rd-1m4g3-1d
323
    ...
324
    properties:
325
            OS:     linux
326
            USER:   user
327
    ...
328
    kamaki
329

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

    
333
.. code-block:: console
334

    
335
    kamaki image modify 7h1rd-1m4g3-1d -p greet='Hi there' -p user=root
336
    kamaki image info 7h1rd-1m4g3-1d
337
    ...
338
    properties:
339
            OS:     linux
340
            USER:   root
341
            GREET:  Hi there
342
    ...
343
    kamaki image modify 7h1rd-1m4g3-1d --property-del greet
344
    kamaki image info 7h1rd-1m4g3-1d
345
    ...
346
    properties:
347
            OS:     linux
348
            USER:   root
349
    ...
350
    kamaki
351

    
352

    
353
Reregistration: priorities and overrides
354
----------------------------------------
355

    
356
Let's review the examples presented above::
357

    
358
    - Register an image with name `Debian Base Gama`
359
    - Unregister the image
360
    - Register a new image of the uploaded image object, with custom properties
361
    - Reregister the image with a meta file and modified properties and name
362

    
363
**The image id is related to the image object**
364

    
365
Although the image was unregistered and reregistered, the image id, that is
366
produced automatically at the server side, was the same. This is due to the
367
fact that image ids are 1 to 1 related to image objects uploaded to Pithos+
368

    
369
**An explicit image name overrides the metafile**
370

    
371
Each image needs a name and this is given as the first argument of the
372
`register` command. This name overrides the name in the metafile.
373

    
374
**Reregistration is not an update, but an override**
375

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

    
380
Command line wins the metafile
381
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
382

    
383
Let's compine the metafile with a command line attribute `user: admin`
384

    
385
.. code-block:: console
386

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

    
407
Although the property `OS` was read from the metafile, the property `USER` was
408
set by the command line property to `admin`.
409

    
410
.. note:: This feature allows the use of a metafile as a template for uploading
411
    multiple images with many common attributes but slight modifications per
412
    image
413

    
414
Multiple metafile versions
415
--------------------------
416

    
417
.. warning:: Make sure your container is set to auto, otherwise, there will be
418
    no object versions
419

    
420
    .. code-block:: console
421

    
422
        kamaki container info images | grep versioning
423
        x-container-policy-versioning: auto
424

    
425
    To set versioning to auto
426

    
427
    .. code-block:: console
428

    
429
        kamaki container modify images --versioning=auto
430

    
431
In the above examples, the image was registered many times by overriding the
432
metafile. It is possible to avoid writing a metafile, as well as accessing
433
older versions of the file.
434

    
435
Register the image without uploading a metafile
436

    
437
.. code-block:: console
438

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

    
458
Uploaded metafiles are kept in versions, thanks to Pithos+ versioning support
459

    
460
.. code-block:: console
461

    
462
    kamaki file info /images/debian_base3.diskdump.meta --object-versions
463
    1352
464
     created: 19-06-2013 11:00:22
465
    1359
466
     created: 19-06-2013 11:01:00
467
    1377
468
     created: 19-06-2013 11:34:37
469
    kamaki
470

    
471
Consult the first version of the metafile
472

    
473
.. code-block:: console
474

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

    
493
Download the second version
494

    
495
.. code-block:: console
496

    
497
    kamaki file download --object-version=1359 /images/debian_base3.diskdump.meta debian_base3.diskdump.meta.v1359
498
    Downloading /images/debian_base3.diskdump.meta --> /home/someuser/debian_base3.diskdump.meta.v1359
499
    Done
500

    
501
Batch image upload
502
------------------
503

    
504
Let a directory at /home/someuser/images with a variety of images needed to be
505
uploaded and registered.
506

    
507
Batch-upload the images
508

    
509
.. code-block:: console
510

    
511
    kamaki file upload -r images /images
512
    mkdir /images/images
513
    Uploading /home/someuser/images/debian.diskdump --> /images/images/debian.diskdump
514
    Uploading /home/someuser/images/win8.diskdump --> /images/images/win8.diskdump
515
    ...
516
    Done
517

    
518
Make sure the images are uploaded to /images/images/ remote directory object
519

    
520
.. code-block:: console
521

    
522
    kamaki file list /images/images/
523
    D       images/
524
    983MB   images/debian.diskdump
525
    2.2GB   images/win8.diskdump
526
    ...
527
    kamaki
528

    
529
Use the host shell capabilities to streamline the registration, so exit kamaki
530

    
531
.. code-block:: console
532

    
533
    kamaki /exit