root / docs / examplesdir / imageregister.rst @ 16d7b9ff
History | View | Annotate | Download (18.3 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 |
.. note:: The image API requires the image location in the form |
18 |
|
19 |
*pithos://<user uuid>/<container>/<object path>* |
20 |
|
21 |
The translation between |
22 |
the two formats is handled internally by kamaki. The latest format is still |
23 |
acceptable by kamaki due to backward compatibility but it is going to be deprecated from kamaki 0.12 and on. |
24 |
|
25 |
|
26 |
Register an image |
27 |
----------------- |
28 |
|
29 |
Let the image file `debian_base3.diskdump` be a debian image located at the |
30 |
current directory. |
31 |
|
32 |
Upload the image to container `pithos` |
33 |
|
34 |
.. code-block:: console |
35 |
|
36 |
[kamaki]: file upload debian_base3.diskdump pithos |
37 |
Uploading /home/someuser/debian_base3.diskdump --> pithos:debian_base3.diskdump |
38 |
Done |
39 |
[kamaki]: |
40 |
|
41 |
Register the image object with the name 'Debian Base Alpha' |
42 |
|
43 |
.. code-block:: console |
44 |
|
45 |
[kamaki]: image register 'Debian Base Alpha' pithos:debian_base3.diskdump |
46 |
checksum: 3cb03556ec971f...e8dd6190443b560cb7 |
47 |
container-format: bare |
48 |
created-at: 2013-06-19 08:00:22 |
49 |
deleted-at: |
50 |
disk-format: diskdump |
51 |
id: 7h1rd-1m4g3-1d |
52 |
is-public: False |
53 |
location: pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump |
54 |
name: Debian Base Alpha |
55 |
owner: s0m3-u53r-1d |
56 |
properties: |
57 |
size: 903471104 |
58 |
status: available |
59 |
updated-at: 2013-06-19 08:01:00 |
60 |
Metadata file uploaded as pithos:debian_base3.diskdump.meta (version 1352) |
61 |
[kamaki]: |
62 |
|
63 |
.. note:: The `image register` command automatically creates a meta file and |
64 |
uploads it to the same location as the image. The meta file can be |
65 |
downloaded and reused for more image registrations. |
66 |
|
67 |
Another way to perform the two operations above is to call **/image register** |
68 |
with the **\- -upload-image-file** argument. This single operation will upload |
69 |
the image file and then register it as an image, and is equivalent to manually |
70 |
calling **/file upload** and **/image register**. |
71 |
|
72 |
In other words, the preceding and following command sequences are equivalent. |
73 |
|
74 |
.. code-block:: console |
75 |
|
76 |
[kamaki]: image register 'Debian Base Alpha' |
77 |
pithos:debian_base3.diskdump |
78 |
--upload-image-file='debian_base3.diskdump' |
79 |
[kamaki]: |
80 |
|
81 |
|
82 |
Read the metafile |
83 |
|
84 |
.. code-block:: console |
85 |
|
86 |
[kamaki]: file cat pithos:debian_base3.diskdump |
87 |
{ |
88 |
"status": "available", |
89 |
"name": "Debian Base Gama", |
90 |
"checksum": "3cb03556ec971f...e8dd6190443b560cb7", |
91 |
"id": "7h1rd-1m4g3-1d2", |
92 |
"updated-at": "2013-06-19 08:01:00", |
93 |
"created-at": "2013-06-19 08:00:22", |
94 |
"properties": {}, |
95 |
"location": "pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump", |
96 |
"is-public": "False", |
97 |
"owner": "s0m3-u53r-1d", |
98 |
"disk-format": "diskdump", |
99 |
"size": "903471104", |
100 |
"deleted-at": "", |
101 |
"container-format": "bare" |
102 |
} |
103 |
[kamaki]: |
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 |
[kamaki]: |
135 |
|
136 |
.. note:: To get the current user id, use `user authenticate` in kamaki |
137 |
|
138 |
Unregister an image |
139 |
------------------- |
140 |
|
141 |
An image can be unregistered by its image id, but only if the current user is |
142 |
also the image owner. In this example, there is only one image owned by current |
143 |
user. |
144 |
|
145 |
Unregister image owned by current user |
146 |
|
147 |
.. code-block:: console |
148 |
|
149 |
[kamaki]: image unregister 7h1rd-1m4g3-1d |
150 |
[kamaki]: |
151 |
|
152 |
Check if the image is deleted |
153 |
|
154 |
.. code-block:: console |
155 |
|
156 |
[kamaki]: image list --owner=s0m3-u53r-1d |
157 |
[kamaki]: |
158 |
|
159 |
Attempt to unregister an image of another user |
160 |
|
161 |
.. code-block:: console |
162 |
|
163 |
[kamaki]: image unregister f1r57-1m4g3-1d |
164 |
(403) FORBIDDEN forbidden () |
165 |
[kamaki]: |
166 |
|
167 |
Register with properties |
168 |
------------------------ |
169 |
|
170 |
The image will be registered again, but with some custom properties:: |
171 |
|
172 |
OS: Linux |
173 |
user: someuser |
174 |
|
175 |
These properties can be added freely by the user, and they are not required by |
176 |
the image server, but they can be used by many applications. |
177 |
|
178 |
Attempt to register an image with custom properties |
179 |
|
180 |
.. code-block:: console |
181 |
|
182 |
[kamaki]: image register 'Debian Base Gama' pithos:debian_base3.diskdump -p OS=Linux -p user=someuser |
183 |
Metadata file pithos:debian_base3.diskdump.meta already exists |
184 |
[kamaki]: |
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 'Debian Base Gama' pithos:debian_base3.diskdump -p OS=Linux -p user=someuser |
192 |
[kamaki]: |
193 |
|
194 |
Register with a meta file |
195 |
------------------------- |
196 |
|
197 |
Download the meta file of the image (it was uploaded recently) |
198 |
|
199 |
.. code-block:: console |
200 |
|
201 |
[kamaki]: file download pithos:debian_base3.diskdump.meta |
202 |
Downloading pithos:debian_base3.diskdump.meta --> /home/someuser/debian_base3.diskdump.meta |
203 |
Done |
204 |
[kamaki]: |
205 |
|
206 |
The metadata file can be edited. Let's edit the file to add these properties:: |
207 |
|
208 |
OS: Linux |
209 |
user: root |
210 |
|
211 |
The resulting file will look like this: |
212 |
|
213 |
.. code-block:: javascript |
214 |
|
215 |
{ |
216 |
"status": "available", |
217 |
"name": "Debian Base Gama", |
218 |
"checksum": "3cb03556ec971f...e8dd6190443b560cb7", |
219 |
"id": "7h1rd-1m4g3-1d2", |
220 |
"updated-at": "2013-06-19 08:01:00", |
221 |
"created-at": "2013-06-19 08:00:22", |
222 |
"properties": { |
223 |
"OS": "Linux", |
224 |
"USER": "root" |
225 |
}, |
226 |
"location": "pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump", |
227 |
"is-public": "False", |
228 |
"owner": "s0m3-u53r-1d", |
229 |
"disk-format": "diskdump", |
230 |
"size": "903471104", |
231 |
"deleted-at": "", |
232 |
"container-format": "bare" |
233 |
} |
234 |
|
235 |
.. warning:: make sure the file is in a valid json format, otherwise image |
236 |
register will fail |
237 |
|
238 |
In the following registration, a different name will be used for the image. |
239 |
|
240 |
Register the image (don't forget the -f parameter, to override the metafile). |
241 |
|
242 |
.. code-block:: console |
243 |
|
244 |
[kamaki]: image register -f 'Debian Base Delta' pithos:debian_base3.diskdump --metafile=debian_base3.diskdump.meta |
245 |
checksum: 3cb03556ec971f...e8dd6190443b560cb7 |
246 |
container-format: bare |
247 |
created-at: 2013-06-19 08:00:22 |
248 |
deleted-at: |
249 |
disk-format: diskdump |
250 |
id: 7h1rd-1m4g3-1d |
251 |
is-public: False |
252 |
location: pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump |
253 |
name: Debian Base Delta |
254 |
owner: s0m3-u53r-1d |
255 |
properties: |
256 |
OS: Linux |
257 |
USER: root |
258 |
size: 903471104 |
259 |
status: available |
260 |
updated-at: 2013-06-19 08:01:00 |
261 |
Metadata file uploaded as pithos:debian_base3.diskdump.meta (version 1359) |
262 |
[kamaki]: |
263 |
|
264 |
Metadata and Property modification |
265 |
---------------------------------- |
266 |
|
267 |
Image metadata and custom properties can be modified even after the image is |
268 |
registered. Metadata are fixed image attributes, like name, disk format etc. |
269 |
while custom properties are set by the image owner and, usually, refer to |
270 |
attributes of the images OS. |
271 |
|
272 |
Let's rename the image: |
273 |
|
274 |
.. code-block:: console |
275 |
|
276 |
[kamaki]: image meta set 7h1rd-1m4g3-1d --name='Changed Name' |
277 |
[kamaki]: |
278 |
|
279 |
A look at the image metadata reveals that the name is changed: |
280 |
|
281 |
.. code-block:: console |
282 |
|
283 |
[kamaki]: image info 7h1rd-1m4g3-1d |
284 |
checksum: 3cb03556ec971f...e8dd6190443b560cb7 |
285 |
container-format: bare |
286 |
created-at: 2013-06-19 08:00:22 |
287 |
deleted-at: |
288 |
disk-format: diskdump |
289 |
id: 7h1rd-1m4g3-1d |
290 |
is-public: False |
291 |
location: pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump |
292 |
name: Changed Name |
293 |
owner: s0m3-u53r-1d |
294 |
properties: |
295 |
OS: Linux |
296 |
USER: root |
297 |
size: 903471104 |
298 |
status: available |
299 |
updated-at: 2013-06-19 08:01:00 |
300 |
[kamaki]: |
301 |
|
302 |
We can use the same idea to change the values of other metadata like disk |
303 |
format, container format or status. On the other hand, we cannot modify the |
304 |
id, owner, location, checksum and dates. e.g., to publish and unpublish: |
305 |
|
306 |
.. code-block:: console |
307 |
|
308 |
[kamaki]: image meta set 7h1rd-1m4g3-1d --publish --name='Debian Base Gama' |
309 |
[kamaki]: image meta set 7h1rd-1m4g3-1d --unpublish |
310 |
[kamaki]: |
311 |
|
312 |
The first call publishes the image (set is-public to True) and also restores |
313 |
the name to "Debian Base Gama". The second one unpublishes the image (set |
314 |
is-public to False). |
315 |
|
316 |
To delete metadata, use the image meta delete method. For example, the |
317 |
following will set the value of *status* to an empty string: |
318 |
|
319 |
.. code-block:: console |
320 |
|
321 |
[kamaki]: image meta delete 7h1rd-1m4g3-1d status |
322 |
[kamaki]: |
323 |
|
324 |
|
325 |
These operations can be used for properties with the same semantics: |
326 |
|
327 |
.. code-block:: console |
328 |
|
329 |
[kamaki]: image meta set 7h1rd-1m4g3-1d -p user=user |
330 |
[kamaki]: image info 7h1rd-1m4g3-1d |
331 |
... |
332 |
properties: |
333 |
OS: Linux |
334 |
USER: user |
335 |
... |
336 |
[kamaki]: |
337 |
|
338 |
Just to test the feature, let's create a property "greet" with value |
339 |
"hi there", and then remove it. Also, let's restore the value of USER: |
340 |
|
341 |
.. code-block:: console |
342 |
|
343 |
[kamaki]: image meta set 7h1rd-1m4g3-1d -p greet='Hi there' -p user=root |
344 |
[kamaki]: image info 7h1rd-1m4g3-1d |
345 |
... |
346 |
properties: |
347 |
OS: Linux |
348 |
USER: root |
349 |
GREET: Hi there |
350 |
... |
351 |
[kamaki]: image meta delete 7h1rd-1m4g3-1d -p greet |
352 |
[kamaki]: image info 7h1rd-1m4g3-1d |
353 |
... |
354 |
properties: |
355 |
OS: Linux |
356 |
USER: root |
357 |
... |
358 |
[kamaki]: |
359 |
|
360 |
|
361 |
Reregistration: priorities and overrides |
362 |
---------------------------------------- |
363 |
|
364 |
Let's review the examples presented above:: |
365 |
|
366 |
- Register an image with name `Debian Base Gama` |
367 |
- Unregister the image |
368 |
- Register a new image of the uploaded image object, with custom properties |
369 |
- Reregister the image with a meta file and modified properties and name |
370 |
|
371 |
**The image id is related to the image object** |
372 |
|
373 |
Although the image was unregistered and reregistered, the image id, that is |
374 |
produced automatically at the server side, was the same. This is due to the |
375 |
fact that image ids are 1 to 1 related to image objects uploaded to Pithos+ |
376 |
|
377 |
**An explicit image name overrides the metafile** |
378 |
|
379 |
Each image needs a name and this is given as the first argument of the |
380 |
`register` command. This name overrides the name in the metafile. |
381 |
|
382 |
**Reregistration is not an update, but an override** |
383 |
|
384 |
The property `user: root` won over `user: someuser`, because it was set last. |
385 |
Actually, all properties were replaced by the new ones, when the image was |
386 |
reregistered, and the same holds with all customizable attributes of the image. |
387 |
|
388 |
Command line wins the metafile |
389 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
390 |
|
391 |
Let's compine the metafile with a command line attribute `user: admin` |
392 |
|
393 |
.. code-block:: console |
394 |
|
395 |
[kamaki]: image register -f 'Debian Base Delta' pithos:debian_base3.diskdump --metafile=debian_base3.diskdump.meta |
396 |
checksum: 3cb03556ec971f...e8dd6190443b560cb7 |
397 |
container-format: bare |
398 |
created-at: 2013-06-19 08:00:22 |
399 |
deleted-at: |
400 |
disk-format: diskdump |
401 |
id: 7h1rd-1m4g3-1d |
402 |
is-public: False |
403 |
location: pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump |
404 |
name: Debian Base Delta |
405 |
owner: s0m3-u53r-1d |
406 |
properties: |
407 |
OS: Linux |
408 |
USER: root |
409 |
size: 903471104 |
410 |
status: available |
411 |
updated-at: 2013-06-19 08:01:00 |
412 |
Metadata file uploaded as pithos:debian_base3.diskdump.meta (version 1377) |
413 |
[kamaki]: |
414 |
|
415 |
Although the property `OS` was read from the metafile, the property `USER` was |
416 |
set by the command line property to `admin`. |
417 |
|
418 |
.. note:: This feature allows the use of a metafile as a template for uploading |
419 |
multiple images with many common attributes but slight modifications per |
420 |
image |
421 |
|
422 |
Multiple metafile versions |
423 |
-------------------------- |
424 |
|
425 |
.. warning:: Make sure your container is set to auto, otherwise, there will be |
426 |
no object versions |
427 |
|
428 |
.. code-block:: console |
429 |
|
430 |
[kamaki]: file versioning get pithos |
431 |
x-container-policy-versioning: auto |
432 |
[kamaki]: |
433 |
|
434 |
To set versioning to auto |
435 |
|
436 |
.. code-block:: console |
437 |
|
438 |
[kamaki]: file versioning set auto pithos |
439 |
[kamaki]: |
440 |
|
441 |
In the above examples, the image was registered many times by overriding the |
442 |
metafile. It is possible to avoid writing a metafile, as well as accessing |
443 |
older versions of the file. |
444 |
|
445 |
Register the image without uploading a metafile |
446 |
|
447 |
.. code-block:: console |
448 |
|
449 |
[kamaki]: image register 'Debian Base Delta' pithos:debian_base3.diskdump --metafile=debian_base3.diskdump.meta --no-metafile-upload |
450 |
checksum: 3cb03556ec971f...e8dd6190443b560cb7 |
451 |
container-format: bare |
452 |
created-at: 2013-06-19 08:00:22 |
453 |
deleted-at: |
454 |
disk-format: diskdump |
455 |
id: 7h1rd-1m4g3-1d |
456 |
is-public: False |
457 |
location: pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump |
458 |
name: Debian Base Delta |
459 |
owner: s0m3-u53r-1d |
460 |
properties: |
461 |
OS: Linux |
462 |
USER: root |
463 |
size: 903471104 |
464 |
status: available |
465 |
updated-at: 2013-06-19 08:01:00 |
466 |
[kamaki]: |
467 |
|
468 |
Uploaded metafiles are kept in versions, thanks to Pithos+ versioning support |
469 |
|
470 |
.. code-block:: console |
471 |
|
472 |
[kamaki]: file versions pithos:debian_base3.diskdump.meta |
473 |
1352 |
474 |
created: 19-06-2013 11:00:22 |
475 |
1359 |
476 |
created: 19-06-2013 11:01:00 |
477 |
1377 |
478 |
created: 19-06-2013 11:34:37 |
479 |
[kamaki]: |
480 |
|
481 |
Consult the first version of the metafile |
482 |
|
483 |
.. code-block:: console |
484 |
|
485 |
[kamaki]: file cat --object-version=1352 pithos:debian_base3.diskdump.meta |
486 |
{ |
487 |
"status": "available", |
488 |
"name": "Debian Base Gama", |
489 |
"checksum": "3cb03556ec971f...e8dd6190443b560cb7", |
490 |
"id": "7h1rd-1m4g3-1d2", |
491 |
"updated-at": "2013-06-19 08:01:00", |
492 |
"created-at": "2013-06-19 08:00:22", |
493 |
"properties": {}, |
494 |
"location": "pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump", |
495 |
"is-public": "False", |
496 |
"owner": "s0m3-u53r-1d", |
497 |
"disk-format": "diskdump", |
498 |
"size": "903471104", |
499 |
"deleted-at": "", |
500 |
"container-format": "bare" |
501 |
} |
502 |
[kamaki]: |
503 |
|
504 |
Download the second version |
505 |
|
506 |
.. code-block:: console |
507 |
|
508 |
[kamaki]: file download --object-version=1359 pithos:debian_base3.diskdump.meta debian_base3.diskdump.meta.v1359 |
509 |
Downloading pithos:debian_base3.diskdump.meta --> /home/someuser/debian_base3.diskdump.meta.v1359 |
510 |
Done |
511 |
[kamaki]: |
512 |
|
513 |
Batch image upload |
514 |
------------------ |
515 |
|
516 |
Let a directory at /home/someuser/images with a variety of images needed to be |
517 |
uploaded and registered. |
518 |
|
519 |
Batch-upload the images |
520 |
|
521 |
.. code-block:: console |
522 |
|
523 |
[kamaki]: file upload -R images pithos |
524 |
mkdir pithos:images |
525 |
Uploading /home/someuser/images/debian.diskdump --> pithos:images/debian.diskdump |
526 |
Uploading /home/someuser/images/win8.diskdump --> pithos:images/win8.diskdump |
527 |
... |
528 |
Done |
529 |
[kamaki]: |
530 |
|
531 |
Make sure the images are uploaded to pithos:images/ remote directory object |
532 |
|
533 |
.. code-block:: console |
534 |
|
535 |
[kamaki]: file list pithos:images/ |
536 |
D images/ |
537 |
983MB images/debian.diskdump |
538 |
2.2GB images/win8.diskdump |
539 |
... |
540 |
[kamaki]: |
541 |
|
542 |
Use the host shell capabilities to streamline the registration, so exit kamaki |
543 |
|
544 |
.. code-block:: console |
545 |
|
546 |
[kamaki]: /exit |
547 |
|
548 |
The following is a bash script that attempts to register the already uploaded |
549 |
images: |
550 |
|
551 |
.. code-block:: bash |
552 |
|
553 |
#!/bin/bash |
554 |
|
555 |
userid=... # e.g., s0m3-u53r-1d |
556 |
container=... # e.g., pithos |
557 |
|
558 |
for path in images/*.diskdump; do |
559 |
location=$container:${path} |
560 |
kamaki image register $path $location |
561 |
done |
562 |
|
563 |
Let's use the script (enriched with a separator message) to batch-register the |
564 |
images (all images will be named after their relative paths). |
565 |
|
566 |
Also, let the registered images be public (accessible to all users for creating |
567 |
VMs) by adding the **- - public** flag argument when calling `image register`. |
568 |
|
569 |
.. code-block:: console |
570 |
|
571 |
$ for path in images/*.diskdump; do |
572 |
location=pithos:${path} |
573 |
echo "- - - Register ${path} - - -" |
574 |
kamaki image register $path $location --public |
575 |
done |
576 |
- - - Register images/debian.diskdump --- |
577 |
checksum: 3cb03556ec971f...e8dd6190443b560cb7 |
578 |
container-format: bare |
579 |
created-at: 2013-06-19 08:00:22 |
580 |
deleted-at: |
581 |
disk-format: diskdump |
582 |
id: d3b14n-1m4g3-1d |
583 |
is-public: False |
584 |
location: pithos://s0m3-u53r-1d/pithos/images/debian.diskdump |
585 |
name: images/debian.diskdump |
586 |
owner: s0m3-u53r-1d |
587 |
properties: |
588 |
size: 903471104 |
589 |
status: available |
590 |
updated-at: 2013-06-19 08:01:00 |
591 |
Metadata file uploaded as pithos:images/debian.diskdump.meta (version 4201) |
592 |
- - - Register images/win8.diskdump --- |
593 |
checksum: 4cb03556ec971f...e8dd6190443b560cb6 |
594 |
container-format: bare |
595 |
created-at: 2013-06-19 08:00:22 |
596 |
deleted-at: |
597 |
disk-format: diskdump |
598 |
id: w1nd0w5-1m4g3-1d |
599 |
is-public: False |
600 |
location: pithos://s0m3-u53r-1d/pithos/images/win8.diskdump |
601 |
name: images/win8.diskdump |
602 |
owner: s0m3-u53r-1d |
603 |
properties: |
604 |
size: 2103471104 |
605 |
status: available |
606 |
updated-at: 2013-06-19 08:01:00 |
607 |
Metadata file uploaded as pithos:images/debian.diskdump.meta (version 4301) |
608 |
... |
609 |
$ |
610 |
|
611 |
.. note:: All images can be re-registered, either individually or with a batch |
612 |
process. |
613 |
|
614 |
|