Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
kamaki
Commits
eed12505
Commit
eed12505
authored
Jul 30, 2013
by
Stavros Sachtouris
Browse files
Merge branch 'feature-image-register-args' into develop
parents
b773795c
f2ea1314
Changes
4
Hide whitespace changes
Inline
Side-by-side
docs/collection_of_examples/imageregister.rst
View file @
eed12505
...
...
@@ -14,6 +14,8 @@ The image location format::
pithos://s0m3-u53r-1d/pithos/debian_base3.diskdump
The crussial element in an image location is the container (e.g. `pithos`) and
the image object path (e.g. `debian_base3.diskdump`).
Register an image
-----------------
...
...
@@ -34,7 +36,7 @@ Register the image object with the name 'Debian Base Alpha'
.. code-block:: console
[kamaki]: image register 'Debian Base Alpha' pithos:
//s0m3-u53r-1d/pithos/
debian_base3.diskdump
[kamaki]: image register 'Debian Base Alpha' pithos:debian_base3.diskdump
checksum: 3cb03556ec971f...e8dd6190443b560cb7
container-format: bare
created-at: 2013-06-19 08:00:22
...
...
@@ -52,7 +54,7 @@ Register the image object with the name 'Debian Base Alpha'
Metadata file uploaded as pithos:debian_base3.diskdump.meta (version 1352)
[kamaki]:
.. note:: The `image register` command automatically create a meta file and
.. note:: The `image register` command automatically create
s
a meta file and
uploads it to the same location as the image. The meta file can be
downloaded and reused for more image registrations.
...
...
@@ -157,7 +159,7 @@ Attempt to register with properties
.. code-block:: console
[kamaki]: image register 'Debian Base Gama' pithos:
//s0m3-u53r-1d/pithos/
debian_base3.diskdump -p OS=Linux -p user=someuser
[kamaki]: image register 'Debian Base Gama' pithos:debian_base3.diskdump -p OS=Linux -p user=someuser
Metadata file pithos:debian_base3.diskdump.meta already exists
[kamaki]:
...
...
@@ -165,7 +167,7 @@ It's true that the metafile is already there, but we can override it (**-f**)
.. code-block:: console
[kamaki]: image register -f 'Debian Base Gama' pithos:
//s0m3-u53r-1d/pithos/
debian_base3.diskdump -p OS=Linux -p user=someuser
[kamaki]: image register -f 'Debian Base Gama' pithos:debian_base3.diskdump -p OS=Linux -p user=someuser
[kamaki]:
Register with a meta file
...
...
@@ -218,7 +220,7 @@ Register the image (don't forget the -f parameter, to override the metafile).
.. code-block:: console
[kamaki]: image register -f 'Debian Base Delta' pithos:
//s0m3-u53r-1d/pithos/
debian_base3.diskdump --metafile=debian_base3.diskdump.meta
[kamaki]: image register -f 'Debian Base Delta' pithos:debian_base3.diskdump --metafile=debian_base3.diskdump.meta
checksum: 3cb03556ec971f...e8dd6190443b560cb7
container-format: bare
created-at: 2013-06-19 08:00:22
...
...
@@ -272,7 +274,7 @@ Let's compine the metafile with a command line attribute `user: admin`
.. code-block:: console
[kamaki]: image register -f 'Debian Base Delta' pithos:
//s0m3-u53r-1d/pithos/
debian_base3.diskdump --metafile=debian_base3.diskdump.meta
[kamaki]: image register -f 'Debian Base Delta' pithos:debian_base3.diskdump --metafile=debian_base3.diskdump.meta
checksum: 3cb03556ec971f...e8dd6190443b560cb7
container-format: bare
created-at: 2013-06-19 08:00:22
...
...
@@ -326,7 +328,7 @@ Register the image without uploading a metafile
.. code-block:: console
[kamaki]: image register 'Debian Base Delta' pithos:
//s0m3-u53r-1d/pithos/
debian_base3.diskdump --metafile=debian_base3.diskdump.meta --no-metafile-upload
[kamaki]: image register 'Debian Base Delta' pithos:debian_base3.diskdump --metafile=debian_base3.diskdump.meta --no-metafile-upload
checksum: 3cb03556ec971f...e8dd6190443b560cb7
container-format: bare
created-at: 2013-06-19 08:00:22
...
...
@@ -436,7 +438,7 @@ images:
container=... # e.g. pithos
for path in images/*.diskdump; do
location=
pithos://$userid/
$container
/
${path}
location=$container
:
${path}
kamaki image register $path $location
done
...
...
@@ -449,7 +451,7 @@ VMs) by adding the **--public** flag argument when calling `image register`.
.. code-block:: console
$ for path in images/*.diskdump; do
location=pithos:
//s0m3-u53r-1d/pithos/
${path}
location=pithos:${path}
echo "- - - Register ${path} - - -"
kamaki image register $path $location --public
done
...
...
kamaki/cli/commands/image.py
View file @
eed12505
...
...
@@ -153,9 +153,9 @@ def _load_image_meta(filepath):
def
_validate_image_location
(
location
):
"""
:param location: (str) pithos://<user-id>/<container>/<img
-fil
e-path>
:param location: (str) pithos://<user-id>/<container>/<im
a
ge-path>
:returns: (<user-id>, <container>, <img
-fil
e-path>)
:returns: (<user-id>, <container>, <im
a
ge-path>)
:raises AssertionError: if location is invalid
"""
...
...
@@ -305,7 +305,10 @@ class image_register(_init_image, _optional_json):
no_metafile_upload
=
FlagArgument
(
'Do not store metadata in remote meta file'
,
(
'--no-metafile-upload'
)),
container
=
ValueArgument
(
'Pithos+ container containing the image file'
,
(
'-C'
,
'--container'
)),
uuid
=
ValueArgument
(
'Custom user uuid'
,
'--uuid'
)
)
def
_get_user_id
(
self
):
...
...
@@ -379,7 +382,7 @@ class image_register(_init_image, _optional_json):
importance
=
2
,
details
=
[
'An image location is needed. Image location format:'
,
' pithos://<user-id>/<container>/<path>'
,
' an image file at the above location must exist.'
'
where
an image file at the above location must exist.'
]
+
howto_image_file
)
try
:
return
_validate_image_location
(
location
)
...
...
@@ -391,11 +394,29 @@ class image_register(_init_image, _optional_json):
' pithos://<user-id>/<container>/<img-file-path>'
]
+
howto_image_file
)
def
_mine_location
(
self
,
container_path
):
uuid
=
self
[
'uuid'
]
or
self
.
_get_user_id
()
if
self
[
'container'
]:
return
uuid
,
self
[
'container'
],
container_path
container
,
sep
,
path
=
container_path
.
partition
(
':'
)
if
not
(
bool
(
container
)
and
bool
(
path
)):
raiseCLIError
(
'Incorrect container-path format'
,
importance
=
1
,
details
=
[
'Use : to seperate container form path'
,
' <container>:<image-path>'
,
'OR'
,
'Use -C to specifiy a container'
,
' -C <container> <image-path>'
]
+
howto_image_file
)
return
uuid
,
container
,
path
@
errors
.
generic
.
all
@
errors
.
plankton
.
connection
def
_run
(
self
,
name
,
location
):
(
params
,
properties
,
location
)
=
self
.
_load_params_from_file
(
location
)
uuid
,
container
,
img_path
=
self
.
_validate_location
(
location
)
def
_run
(
self
,
name
,
uuid
,
container
,
img_path
):
location
=
'pithos://%s/%s/%s'
%
(
uuid
,
container
,
img_path
)
(
params
,
properties
,
new_loc
)
=
self
.
_load_params_from_file
(
location
)
if
location
!=
new_loc
:
uuid
,
container
,
img_path
=
self
.
_validate_location
(
new_loc
)
self
.
_load_params_from_args
(
params
,
properties
)
pclient
=
self
.
_get_pithos_client
(
container
)
...
...
@@ -440,9 +461,9 @@ class image_register(_init_image, _optional_json):
print
(
'Metadata file uploaded as %s:%s (version %s)'
%
(
container
,
meta_path
,
meta_headers
[
'x-object-version'
]))
def
main
(
self
,
name
,
location
):
def
main
(
self
,
name
,
container___image_path
):
super
(
self
.
__class__
,
self
).
_run
()
self
.
_run
(
name
,
location
)
self
.
_run
(
name
,
*
self
.
_mine_location
(
container___image_path
)
)
@
command
(
image_cmds
)
...
...
kamaki/clients/image/__init__.py
View file @
eed12505
...
...
@@ -103,7 +103,9 @@ class ImageClient(Client):
:param name: (str)
:param location: (str) pithos://<account>/<container>/<path>
:param location: (str or iterable) if iterable, then
(user_uuid, container, image_path) else if string
pithos://<user_uuid>/<container>/<image object>
:param params: (dict) image metadata (X-Image-Meta) can be id, store,
disc_format, container_format, size, checksum, is_public, owner
...
...
@@ -114,6 +116,9 @@ class ImageClient(Client):
"""
path
=
path4url
(
'images'
)
+
'/'
self
.
set_header
(
'X-Image-Meta-Name'
,
name
)
location
=
location
if
(
isinstance
(
location
,
str
)
or
isinstance
(
location
,
unicode
))
else
(
'pithos://%s'
%
'/'
.
join
(
location
))
self
.
set_header
(
'X-Image-Meta-Location'
,
location
)
async_headers
=
{}
...
...
kamaki/clients/image/test.py
View file @
eed12505
...
...
@@ -224,8 +224,7 @@ class ImageClient(TestCase):
props
[
'%s%s'
%
(
proprfx
,
args
[
i
])]
=
k
async_headers
.
update
(
props
)
r
=
self
.
client
.
register
(
img0_name
,
img0_location
,
params
=
params
,
properties
=
props
)
img0_name
,
img0_location
,
params
=
params
,
properties
=
props
)
expectedict
=
dict
(
example_image_headers
)
expectedict
.
pop
(
'extraheaders'
)
from
kamaki.clients.image
import
_format_image_headers
...
...
@@ -236,6 +235,13 @@ class ImageClient(TestCase):
self
.
assertEqual
(
SH
.
mock_calls
[
-
2
:],
[
call
(
'X-Image-Meta-Name'
,
img0_name
),
call
(
'X-Image-Meta-Location'
,
img0_location
)])
img1_location
=
(
'some_uuid'
,
'some_container'
,
'some/path'
)
r
=
self
.
client
.
register
(
img0_name
,
img1_location
,
params
=
params
,
properties
=
props
)
img1_location
=
'pithos://%s'
%
'/'
.
join
(
img1_location
)
self
.
assertEqual
(
SH
.
mock_calls
[
-
2
:],
[
call
(
'X-Image-Meta-Name'
,
img0_name
),
call
(
'X-Image-Meta-Location'
,
img1_location
)])
@
patch
(
'%s.delete'
%
image_pkg
)
def
test_unregister
(
self
,
delete
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment