Statistics
| Branch: | Tag: | Revision:

root / docs / collection_of_examples / imageregister.rst @ 82cc4b8f

History | View | Annotate | Download (17.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 through out a deployment and also necessary for the
7
image to exist.
8

    
9
The image location format::
10

    
11
    pithos://<user id>/<container>/<object path>
12

    
13
    e.g.:
14

    
15
    pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump
16

    
17
The crussial element in an image location is the container (e.g. `pithos`) and
18
the image object path (e.g. `debian_base3.diskdump`).
19

    
20
Register an image
21
-----------------
22

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

    
26
Upload the image to container `pithos`
27

    
28
.. code-block:: console
29

    
30
    [kamaki]: file upload debian_base3.diskdump pithos
31
    Uploading /home/someuser/debian_base3.diskdump --> pithos:debian_base3.diskdump
32
    Done
33
    [kamaki]:
34

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

    
37
.. code-block:: console
38

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

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

    
61
Read the metafile
62

    
63
.. code-block:: console
64

    
65
    [kamaki]: file cat pithos:debian_base3.diskdump
66
    {
67
      "status": "available", 
68
      "name": "Debian Base Gama", 
69
      "checksum": "3cb03556ec971f...e8dd6190443b560cb7", 
70
      "id": "7h1rd-1m4g3-1d2", 
71
      "updated-at": "2013-06-19 08:01:00", 
72
      "created-at": "2013-06-19 08:00:22", 
73
      "properties": {}, 
74
      "location": "pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump", 
75
      "is-public": "False", 
76
      "owner": "s0m3-u53r-1d", 
77
      "disk-format": "diskdump", 
78
      "size": "903471104", 
79
      "deleted-at": "", 
80
      "container-format": "bare"
81
    }
82
    [kamaki]:
83

    
84
Images registered by me
85
-----------------------
86

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

    
89
.. code-block:: console
90

    
91
    [kamaki]: image list
92
    f1r57-1m4g3-1d Debian Base Alpha
93
        container_format: bare
94
        disk_format:      diskdump
95
        size:             474066944
96
        status:           available
97
    53c0nd-1m4g3-1d Beta Debian Base
98
        container_format: bare
99
        disk_format:      diskdump
100
        size:             474066944
101
        status:           available
102
    7h1rd-1m4g3-1d Debian Base Gama
103
        container_format: bare
104
        disk_format:      diskdump
105
        size:             474066944
106
        status:           available
107
    [kamaki]: image list --owner=s0m3-u53r-1d
108
    7h1rd-1m4g3-1d Debian Base Gama
109
        container_format: bare
110
        disk_format:      diskdump
111
        size:             474066944
112
        status:           available
113
    [kamaki]:
114

    
115
.. note:: To get the current user id, use `user authenticate` in kamaki
116

    
117
Unregister an image
118
-------------------
119

    
120
An image can be unregistered by its image id, but only if the current user is
121
also the image owner. In this example, there is only one image owned by current
122
user.
123

    
124
Unregister image owned by current user 
125

    
126
.. code-block:: console
127

    
128
    [kamaki]: image unregister 7h1rd-1m4g3-1d
129
    [kamaki]:
130

    
131
Check if the image is deleted
132

    
133
.. code-block:: console
134

    
135
    [kamaki]: image list --owner=s0m3-u53r-1d
136
    [kamaki]:
137

    
138
Attempt to unregister an image of another user
139

    
140
.. code-block:: console
141

    
142
    [kamaki]: image unregister f1r57-1m4g3-1d
143
    (403) FORBIDDEN forbidden ()
144
    [kamaki]:
145

    
146
Register with properties
147
------------------------
148

    
149
The image will be registered again, but with some custom properties::
150

    
151
    OS: Linux
152
    user: someuser
153

    
154
These properties can be added freely by the user, and they have no significance
155
for the image server, but they could be used to help using the image more
156
efficiently.
157

    
158
Attempt to register with properties
159

    
160
.. code-block:: console
161

    
162
    [kamaki]: image register 'Debian Base Gama' pithos:debian_base3.diskdump -p OS=Linux -p user=someuser
163
    Metadata file pithos:debian_base3.diskdump.meta already exists
164
    [kamaki]:
165

    
166
It's true that the metafile is already there, but we can override it (**-f**)
167

    
168
.. code-block:: console
169

    
170
    [kamaki]: image register -f 'Debian Base Gama' pithos:debian_base3.diskdump -p OS=Linux -p user=someuser
171
    [kamaki]:
172

    
173
Register with a meta file
174
-------------------------
175

    
176
Download the meta file of the image (it was uploaded recently)
177

    
178
.. code-block:: console
179

    
180
    [kamaki]: file download pithos:debian_base3.diskdump.meta
181
    Downloading pithos:debian_base3.diskdump.meta --> /home/someuser/debian_base3.diskdump.meta
182
    Done
183
    [kamaki]:
184

    
185
The metadata file can be edited. Let's edit the file, by adding properties::
186

    
187
    OS: Linux
188
    user: root
189

    
190
The resulting file will look like this:
191

    
192
.. code-block:: javascript
193

    
194
    {
195
      "status": "available", 
196
      "name": "Debian Base Gama", 
197
      "checksum": "3cb03556ec971f...e8dd6190443b560cb7", 
198
      "id": "7h1rd-1m4g3-1d2", 
199
      "updated-at": "2013-06-19 08:01:00", 
200
      "created-at": "2013-06-19 08:00:22", 
201
      "properties": {
202
        "OS": "Linux",
203
        "USER": "root"
204
      }, 
205
      "location": "pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump", 
206
      "is-public": "False", 
207
      "owner": "s0m3-u53r-1d", 
208
      "disk-format": "diskdump", 
209
      "size": "903471104", 
210
      "deleted-at": "", 
211
      "container-format": "bare"
212
    }
213

    
214
.. warning:: make sure the file is in a valid json format, otherwise image
215
    register will fail
216

    
217
In the following registration, a different name will be used for the image.
218

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

    
221
.. code-block:: console
222

    
223
    [kamaki]: image register -f 'Debian Base Delta' pithos:debian_base3.diskdump --metafile=debian_base3.diskdump.meta
224
    checksum:         3cb03556ec971f...e8dd6190443b560cb7
225
    container-format: bare
226
    created-at:       2013-06-19 08:00:22
227
    deleted-at:       
228
    disk-format:      diskdump
229
    id:               7h1rd-1m4g3-1d
230
    is-public:        False
231
    location:         pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump
232
    name:             Debian Base Delta
233
    owner:            s0m3-u53r-1d
234
    properties:      
235
            OS:     Linux
236
            USER:   root
237
    size:             903471104
238
    status:           available
239
    updated-at:       2013-06-19 08:01:00
240
    Metadata file uploaded as pithos:debian_base3.diskdump.meta (version 1359)
241
    [kamaki]:
242

    
243
Metadata and Property modification
244
----------------------------------
245

    
246
Image metadata and custom properties can be modified even after the image is
247
registered. Metadata are fixed image attributes, like name, disk format etc.
248
while custom properties are set by the image owner and, usually, refer to
249
attributes of the images OS.
250

    
251
Let's rename the image:
252

    
253
.. code-block:: console
254

    
255
    [kamaki]: image meta set 7h1rd-1m4g3-1d --name='Changed Name'
256
    [kamaki]:
257

    
258
If we, now, get the image metadata, we will see that the name is changed:
259

    
260
.. code-block:: console
261

    
262
    [kamaki]: image info 7h1rd-1m4g3-1d
263
    checksum:         3cb03556ec971f...e8dd6190443b560cb7
264
    container-format: bare
265
    created-at:       2013-06-19 08:00:22
266
    deleted-at:       
267
    disk-format:      diskdump
268
    id:               7h1rd-1m4g3-1d
269
    is-public:        False
270
    location:         pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump
271
    name:             Changed Name
272
    owner:            s0m3-u53r-1d
273
    properties:      
274
            OS:     Linux
275
            USER:   root
276
    size:             903471104
277
    status:           available
278
    updated-at:       2013-06-19 08:01:00
279
    [kamaki]:
280

    
281
We can use the same idea to change the values of other metadata like disk
282
format, container format or status. On the other hand, we cannot modify the
283
id, owner, location, checksum and dates. E.g., to publish and unpublish:
284

    
285
.. code-block:: console
286

    
287
    [kamaki]: image meta set 7h1rd-1m4g3-1d --publish --name='Debian Base Gama'
288
    [kamaki]: image meta set 7h1rd-1m4g3-1d --unpublish
289
    [kamaki]:
290

    
291
The first call published the image (set is-public to True) and also restored
292
the name to "Debian Base Gama". The second one unpublished the image (set
293
is-public to False).
294

    
295
To delete metadata, use the image meta delete method:
296

    
297
.. code-block:: console
298

    
299
    [kamaki]: image meta delete 7h1rd-1m4g3-1d status
300
    [kamaki]:
301

    
302
will empty the value of "status".
303

    
304
These operations can be used for properties with the same semantics:
305

    
306
.. code-block:: console
307

    
308
    [kamaki]: image meta set 7h1rd-1m4g3-1d -p user=user
309
    [kamaki]: image info 7h1rd-1m4g3-1d
310
    ...
311
    properties:
312
            OS:     Linux
313
            USER:   user
314
    ...
315
    [kamaki]:
316

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

    
320
.. code-block:: console
321

    
322
    [kamaki]: image meta set 7h1rd-1m4g3-1d -p greet='Hi there' -p user=root
323
    [kamaki]: image info 7h1rd-1m4g3-1d
324
    ...
325
    properties:
326
            OS:     Linux
327
            USER:   root
328
            GREET:  Hi there
329
    ...
330
    [kamaki]: image meta delete 7h1rd-1m4g3-1d -p greet
331
    [kamaki]: image info 7h1rd-1m4g3-1d
332
    ...
333
    properties:
334
            OS:     Linux
335
            USER:   root
336
    ...
337
    [kamaki]:
338

    
339

    
340
Reregistration: priorities and overrides
341
----------------------------------------
342

    
343
Let's review the examples presented above::
344

    
345
    - Register an image with name `Debian Base Gama`
346
    - Unregister the image
347
    - Register a new image of the uploaded image object, with custom properties
348
    - Reregister the image with a meta file and modified properties and name
349

    
350
**The image id is related to the image object**
351

    
352
Although the image was unregistered and reregistered, the image id, that is
353
produced automatically at the server side, was the same. This is due to the
354
fact that image ids are 1 to 1 related to image objects uploaded to Pithos+
355

    
356
**An explicit name overrides the metafile**
357

    
358
Each image needs a name and this is given as the first argument of the
359
`register` command. This name overrides the name in the metafile.
360

    
361
**Reregistration is not update, but an override**
362

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

    
367
Command line wins the metafile
368
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
369

    
370
Let's compine the metafile with a command line attribute `user: admin`
371

    
372
.. code-block:: console
373

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

    
394
Although the property `OS` was read from the metafile, the property `USER` was
395
set by the command line property to `admin`.
396

    
397
.. note:: This feature allows the use of a metafile as a template for uploading
398
    multiple images with many common attributes but slight modifications per
399
    image
400

    
401
Multiple metafile versions
402
--------------------------
403

    
404
.. warning:: Make sure your container is set to auto, otherwise, there will be
405
    no object versions
406

    
407
    .. code-block:: console
408

    
409
        [kamaki]: file versioning get pithos
410
        x-container-policy-versioning: auto
411
        [kamaki]:
412

    
413
    To set versioning to auto
414

    
415
    .. code-block:: console
416

    
417
        [kamaki]: file versioning set auto pithos
418
        [kamaki]:
419

    
420
In the above examples, the image was registered many times by overriding the
421
metafile. It is possible to avoid writing a metafile, as well as accessing
422
older versions of the file.
423

    
424
Register the image without uploading a metafile
425

    
426
.. code-block:: console
427

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

    
447
Uploaded metafiles are kept in versions, thanks to Pithos+ versioning support
448

    
449
.. code-block:: console
450

    
451
    [kamaki]: file versions pithos:debian_base3.diskdump.meta
452
    1352
453
     created: 19-06-2013 11:00:22
454
    1359
455
     created: 19-06-2013 11:01:00
456
    1377
457
     created: 19-06-2013 11:34:37
458
    [kamaki]:
459

    
460
Consult the first version of the metafile
461

    
462
.. code-block:: console
463

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

    
483
Download the second version
484

    
485
.. code-block:: console
486

    
487
    [kamaki]: file download --object-version=1359 pithos:debian_base3.diskdump.meta debian_base3.diskdump.meta.v1359
488
    Downloading pithos:debian_base3.diskdump.meta --> /home/someuser/debian_base3.diskdump.meta.v1359
489
    Done
490
    [kamaki]:
491

    
492
Batch image upload
493
------------------
494

    
495
Let a directory at /home/someuser/images with a variety of images needed to be
496
uploaded and registered.
497

    
498
Batch-upload the images
499

    
500
.. code-block:: console
501

    
502
    [kamaki]: file upload -R images pithos
503
    mkdir pithos:images
504
    Uploading /home/someuser/images/debian.diskdump --> pithos:images/debian.diskdump
505
    Uploading /home/someuser/images/win8.diskdump --> pithos:images/win8.diskdump
506
    ...
507
    Done
508
    [kamaki]:
509

    
510
Make sure the images are uploaded to pithos:images/ remote directory object
511

    
512
.. code-block:: console
513

    
514
    [kamaki]: file list pithos:images/
515
    D       images/
516
    983MB   images/debian.diskdump
517
    2.2GB   images/win8.diskdump
518
    ...
519
    [kamaki]:
520

    
521
Use the host shell capabilities to streamline the registration, so exit kamaki
522

    
523
.. code-block:: console
524

    
525
    [kamaki]: /exit
526

    
527
The following is a bash script that attempts to register the already uploaded
528
images:
529

    
530
.. code-block:: bash
531

    
532
    #!/bin/bash
533

    
534
    userid=... # e.g. s0m3-u53r-1d
535
    container=... # e.g. pithos
536

    
537
    for path in images/*.diskdump; do
538
        location=$container:${path}
539
        kamaki image register $path $location
540
    done
541

    
542
Let's use the script (enriched with a separator message) to batch-register the
543
images (all images will be named after their relative paths).
544

    
545
Also, let the registered images be public (accessible to all users for creating
546
VMs) by adding the **--public** flag argument when calling `image register`.
547

    
548
.. code-block:: console
549

    
550
    $ for path in images/*.diskdump; do
551
        location=pithos:${path}
552
        echo "- - - Register ${path} - - -"
553
        kamaki image register $path $location --public
554
    done
555
    - - - Register images/debian.diskdump ---
556
    checksum:         3cb03556ec971f...e8dd6190443b560cb7
557
    container-format: bare
558
    created-at:       2013-06-19 08:00:22
559
    deleted-at:       
560
    disk-format:      diskdump
561
    id:               d3b14n-1m4g3-1d
562
    is-public:        False
563
    location:         pithos://s0m3-u53r-1d/pithos/images/debian.diskdump
564
    name:             images/debian.diskdump
565
    owner:            s0m3-u53r-1d
566
    properties:
567
    size:             903471104
568
    status:           available
569
    updated-at:       2013-06-19 08:01:00
570
    Metadata file uploaded as pithos:images/debian.diskdump.meta (version 4201)
571
    - - - Register images/win8.diskdump ---
572
    checksum:         4cb03556ec971f...e8dd6190443b560cb6
573
    container-format: bare
574
    created-at:       2013-06-19 08:00:22
575
    deleted-at:       
576
    disk-format:      diskdump
577
    id:               w1nd0w5-1m4g3-1d
578
    is-public:        False
579
    location:         pithos://s0m3-u53r-1d/pithos/images/win8.diskdump
580
    name:             images/win8.diskdump
581
    owner:            s0m3-u53r-1d
582
    properties:
583
    size:             2103471104
584
    status:           available
585
    updated-at:       2013-06-19 08:01:00
586
    Metadata file uploaded as pithos:images/debian.diskdump.meta (version 4301)
587
    ...
588
    $
589

    
590
.. note:: All images can be re-registered, either individually or with a batch
591
    process.
592

    
593