Statistics
| Branch: | Tag: | Revision:

root / docs / examplesdir / imageregister.rst @ abfaa6d9

History | View | Annotate | Download (18.1 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 at user level::
10

    
11
    <container>:<object path>
12

    
13
    e.g.:
14

    
15
    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

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

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

    
27
Upload the image to container `pithos`
28

    
29
.. code-block:: console
30

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

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

    
38
.. code-block:: console
39

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

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

    
62
Another way to perform the two operations above is to call **/image register**
63
with the **\- -upload-image-file** argument. This single operation will upload
64
the image file and then register it as an image, and is equivalent to manually
65
calling **/file upload** and **/image register**.
66

    
67
In other words, the example that follows is equivalent to calling the two
68
operations above.
69

    
70
.. code-block:: console
71

    
72
        [kamaki]: image register 'Debian Base Alpha'
73
            pithos:debian_base3.diskdump
74
            --upload-image-file='debian_base3.diskdump'
75
        [kamaki]:
76

    
77

    
78
Read the metafile
79

    
80
.. code-block:: console
81

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

    
101
Images registered by me
102
-----------------------
103

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

    
106
.. code-block:: console
107

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

    
132
.. note:: To get the current user id, use `user authenticate` in kamaki
133

    
134
Unregister an image
135
-------------------
136

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

    
141
Unregister image owned by current user
142

    
143
.. code-block:: console
144

    
145
    [kamaki]: image unregister 7h1rd-1m4g3-1d
146
    [kamaki]:
147

    
148
Check if the image is deleted
149

    
150
.. code-block:: console
151

    
152
    [kamaki]: image list --owner=s0m3-u53r-1d
153
    [kamaki]:
154

    
155
Attempt to unregister an image of another user
156

    
157
.. code-block:: console
158

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

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

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

    
168
    OS: Linux
169
    user: someuser
170

    
171
These properties can be added freely by the user, and they have no significance
172
for the image server, but they could be used to help using the image more
173
efficiently.
174

    
175
Attempt to register with properties
176

    
177
.. code-block:: console
178

    
179
    [kamaki]: image register 'Debian Base Gama' pithos:debian_base3.diskdump -p OS=Linux -p user=someuser
180
    Metadata file pithos:debian_base3.diskdump.meta already exists
181
    [kamaki]:
182

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

    
185
.. code-block:: console
186

    
187
    [kamaki]: image register -f 'Debian Base Gama' pithos:debian_base3.diskdump -p OS=Linux -p user=someuser
188
    [kamaki]:
189

    
190
Register with a meta file
191
-------------------------
192

    
193
Download the meta file of the image (it was uploaded recently)
194

    
195
.. code-block:: console
196

    
197
    [kamaki]: file download pithos:debian_base3.diskdump.meta
198
    Downloading pithos:debian_base3.diskdump.meta --> /home/someuser/debian_base3.diskdump.meta
199
    Done
200
    [kamaki]:
201

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

    
204
    OS: Linux
205
    user: root
206

    
207
The resulting file will look like this:
208

    
209
.. code-block:: javascript
210

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

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

    
234
In the following registration, a different name will be used for the image.
235

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

    
238
.. code-block:: console
239

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

    
260
Metadata and Property modification
261
----------------------------------
262

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

    
268
Let's rename the image:
269

    
270
.. code-block:: console
271

    
272
    [kamaki]: image meta set 7h1rd-1m4g3-1d --name='Changed Name'
273
    [kamaki]:
274

    
275
If we, now, get the image metadata, we will see 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/pithos/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 meta set 7h1rd-1m4g3-1d --publish --name='Debian Base Gama'
305
    [kamaki]: image meta set 7h1rd-1m4g3-1d --unpublish
306
    [kamaki]:
307

    
308
The first call published the image (set is-public to True) and also restored
309
the name to "Debian Base Gama". The second one unpublished the image (set
310
is-public to False).
311

    
312
To delete metadata, use the image meta delete method:
313

    
314
.. code-block:: console
315

    
316
    [kamaki]: image meta delete 7h1rd-1m4g3-1d status
317
    [kamaki]:
318

    
319
will empty the value of "status".
320

    
321
These operations can be used for properties with the same semantics:
322

    
323
.. code-block:: console
324

    
325
    [kamaki]: image meta set 7h1rd-1m4g3-1d -p user=user
326
    [kamaki]: image info 7h1rd-1m4g3-1d
327
    ...
328
    properties:
329
            OS:     Linux
330
            USER:   user
331
    ...
332
    [kamaki]:
333

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

    
337
.. code-block:: console
338

    
339
    [kamaki]: image meta set 7h1rd-1m4g3-1d -p greet='Hi there' -p user=root
340
    [kamaki]: image info 7h1rd-1m4g3-1d
341
    ...
342
    properties:
343
            OS:     Linux
344
            USER:   root
345
            GREET:  Hi there
346
    ...
347
    [kamaki]: image meta delete 7h1rd-1m4g3-1d -p greet
348
    [kamaki]: image info 7h1rd-1m4g3-1d
349
    ...
350
    properties:
351
            OS:     Linux
352
            USER:   root
353
    ...
354
    [kamaki]:
355

    
356

    
357
Reregistration: priorities and overrides
358
----------------------------------------
359

    
360
Let's review the examples presented above::
361

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

    
367
**The image id is related to the image object**
368

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

    
373
**An explicit name overrides the metafile**
374

    
375
Each image needs a name and this is given as the first argument of the
376
`register` command. This name overrides the name in the metafile.
377

    
378
**Reregistration is not update, but an override**
379

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

    
384
Command line wins the metafile
385
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
386

    
387
Let's compine the metafile with a command line attribute `user: admin`
388

    
389
.. code-block:: console
390

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

    
411
Although the property `OS` was read from the metafile, the property `USER` was
412
set by the command line property to `admin`.
413

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

    
418
Multiple metafile versions
419
--------------------------
420

    
421
.. warning:: Make sure your container is set to auto, otherwise, there will be
422
    no object versions
423

    
424
    .. code-block:: console
425

    
426
        [kamaki]: file versioning get pithos
427
        x-container-policy-versioning: auto
428
        [kamaki]:
429

    
430
    To set versioning to auto
431

    
432
    .. code-block:: console
433

    
434
        [kamaki]: file versioning set auto pithos
435
        [kamaki]:
436

    
437
In the above examples, the image was registered many times by overriding the
438
metafile. It is possible to avoid writing a metafile, as well as accessing
439
older versions of the file.
440

    
441
Register the image without uploading a metafile
442

    
443
.. code-block:: console
444

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

    
464
Uploaded metafiles are kept in versions, thanks to Pithos+ versioning support
465

    
466
.. code-block:: console
467

    
468
    [kamaki]: file versions pithos:debian_base3.diskdump.meta
469
    1352
470
     created: 19-06-2013 11:00:22
471
    1359
472
     created: 19-06-2013 11:01:00
473
    1377
474
     created: 19-06-2013 11:34:37
475
    [kamaki]:
476

    
477
Consult the first version of the metafile
478

    
479
.. code-block:: console
480

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

    
500
Download the second version
501

    
502
.. code-block:: console
503

    
504
    [kamaki]: file download --object-version=1359 pithos:debian_base3.diskdump.meta debian_base3.diskdump.meta.v1359
505
    Downloading pithos:debian_base3.diskdump.meta --> /home/someuser/debian_base3.diskdump.meta.v1359
506
    Done
507
    [kamaki]:
508

    
509
Batch image upload
510
------------------
511

    
512
Let a directory at /home/someuser/images with a variety of images needed to be
513
uploaded and registered.
514

    
515
Batch-upload the images
516

    
517
.. code-block:: console
518

    
519
    [kamaki]: file upload -R images pithos
520
    mkdir pithos:images
521
    Uploading /home/someuser/images/debian.diskdump --> pithos:images/debian.diskdump
522
    Uploading /home/someuser/images/win8.diskdump --> pithos:images/win8.diskdump
523
    ...
524
    Done
525
    [kamaki]:
526

    
527
Make sure the images are uploaded to pithos:images/ remote directory object
528

    
529
.. code-block:: console
530

    
531
    [kamaki]: file list pithos:images/
532
    D       images/
533
    983MB   images/debian.diskdump
534
    2.2GB   images/win8.diskdump
535
    ...
536
    [kamaki]:
537

    
538
Use the host shell capabilities to streamline the registration, so exit kamaki
539

    
540
.. code-block:: console
541

    
542
    [kamaki]: /exit
543

    
544
The following is a bash script that attempts to register the already uploaded
545
images:
546

    
547
.. code-block:: bash
548

    
549
    #!/bin/bash
550

    
551
    userid=... # e.g. s0m3-u53r-1d
552
    container=... # e.g. pithos
553

    
554
    for path in images/*.diskdump; do
555
        location=$container:${path}
556
        kamaki image register $path $location
557
    done
558

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

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

    
565
.. code-block:: console
566

    
567
    $ for path in images/*.diskdump; do
568
        location=pithos:${path}
569
        echo "- - - Register ${path} - - -"
570
        kamaki image register $path $location --public
571
    done
572
    - - - Register images/debian.diskdump ---
573
    checksum:         3cb03556ec971f...e8dd6190443b560cb7
574
    container-format: bare
575
    created-at:       2013-06-19 08:00:22
576
    deleted-at:
577
    disk-format:      diskdump
578
    id:               d3b14n-1m4g3-1d
579
    is-public:        False
580
    location:         pithos://s0m3-u53r-1d/pithos/images/debian.diskdump
581
    name:             images/debian.diskdump
582
    owner:            s0m3-u53r-1d
583
    properties:
584
    size:             903471104
585
    status:           available
586
    updated-at:       2013-06-19 08:01:00
587
    Metadata file uploaded as pithos:images/debian.diskdump.meta (version 4201)
588
    - - - Register images/win8.diskdump ---
589
    checksum:         4cb03556ec971f...e8dd6190443b560cb6
590
    container-format: bare
591
    created-at:       2013-06-19 08:00:22
592
    deleted-at:
593
    disk-format:      diskdump
594
    id:               w1nd0w5-1m4g3-1d
595
    is-public:        False
596
    location:         pithos://s0m3-u53r-1d/pithos/images/win8.diskdump
597
    name:             images/win8.diskdump
598
    owner:            s0m3-u53r-1d
599
    properties:
600
    size:             2103471104
601
    status:           available
602
    updated-at:       2013-06-19 08:01:00
603
    Metadata file uploaded as pithos:images/debian.diskdump.meta (version 4301)
604
    ...
605
    $
606

    
607
.. note:: All images can be re-registered, either individually or with a batch
608
    process.
609

    
610