Statistics
| Branch: | Tag: | Revision:

root / docs / examplesdir / imageregister.rst @ 023d5ada

History | View | Annotate | Download (16.8 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 make an image public or
307
private:
308

    
309
.. code-block:: console
310

    
311
    kamaki image modify 7h1rd-1m4g3-1d --public --name='Debian Base Gama'
312
    kamaki image modify 7h1rd-1m4g3-1d --private
313

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

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

    
320
.. code-block:: console
321

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

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

    
334
.. code-block:: console
335

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

    
353

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

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

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

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

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

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

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

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

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

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

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

    
386
.. code-block:: console
387

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

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

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

    
415
Multiple metafile versions
416
--------------------------
417

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

    
421
    .. code-block:: console
422

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

    
426
    To set versioning to auto
427

    
428
    .. code-block:: console
429

    
430
        kamaki container modify images --versioning=auto
431

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

    
436
Register the image without uploading a metafile
437

    
438
.. code-block:: console
439

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

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

    
461
.. code-block:: console
462

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

    
472
Consult the first version of the metafile
473

    
474
.. code-block:: console
475

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

    
494
Download the second version
495

    
496
.. code-block:: console
497

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

    
502
Batch image upload
503
------------------
504

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

    
508
Batch-upload the images
509

    
510
.. code-block:: console
511

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

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

    
521
.. code-block:: console
522

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

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

    
532
.. code-block:: console
533

    
534
    kamaki /exit