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