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
7b6e977c
Commit
7b6e977c
authored
Apr 11, 2013
by
Stavros Sachtouris
Browse files
Return image details as headers, in image register
Feature #3512
parent
47195121
Changes
4
Hide whitespace changes
Inline
Side-by-side
kamaki/cli/commands/image_cli.py
View file @
7b6e977c
...
...
@@ -202,7 +202,8 @@ class image_register(_init_image):
if
self
[
'update'
]:
self
.
client
.
reregister
(
location
,
name
,
params
,
properties
)
else
:
self
.
client
.
register
(
name
,
location
,
params
,
properties
)
r
=
self
.
client
.
register
(
name
,
location
,
params
,
properties
)
print_dict
(
r
)
def
main
(
self
,
name
,
location
):
super
(
self
.
__class__
,
self
).
_run
()
...
...
kamaki/clients/image/__init__.py
View file @
7b6e977c
...
...
@@ -32,7 +32,7 @@
# or implied, of GRNET S.A.
from
kamaki.clients
import
Client
,
ClientError
from
kamaki.clients.utils
import
path4url
from
kamaki.clients.utils
import
path4url
,
filter_in
class
ImageClient
(
Client
):
...
...
@@ -109,6 +109,8 @@ class ImageClient(Client):
disc_format, container_format, size, checksum, is_public, owner
:param properties: (dict) image properties (X-Image-Meta-Property)
:returns: (dict) details of the created image
"""
path
=
path4url
(
'images'
)
+
'/'
self
.
set_header
(
'X-Image-Meta-Name'
,
name
)
...
...
@@ -124,7 +126,8 @@ class ImageClient(Client):
for
key
,
val
in
properties
.
items
():
async_headers
[
'x-image-meta-property-%s'
%
key
]
=
val
self
.
post
(
path
,
success
=
200
,
async_headers
=
async_headers
)
r
=
self
.
post
(
path
,
success
=
200
,
async_headers
=
async_headers
)
return
filter_in
(
r
.
headers
,
'X-Image-'
)
def
list_members
(
self
,
image_id
):
"""
...
...
kamaki/clients/image/test.py
View file @
7b6e977c
...
...
@@ -35,6 +35,22 @@ from mock import patch, call
from
unittest
import
TestCase
from
itertools
import
product
example_image_headers
=
{
'x-image-meta-id'
:
'3edd4d15-41b4-4a39-9601-015ef56b3bb3'
,
'x-image-meta-checksum'
:
'df23837c30889252c0aed80b6f770a53a86'
,
'x-image-meta-container-format'
:
'bare'
,
'x-image-meta-location'
:
'pithos://a13528163db/con/obj_13.0'
,
'x-image-meta-disk-format'
:
'diskdump'
,
'x-image-meta-is-public'
:
'True'
,
'x-image-meta-status'
:
'available'
,
'x-image-meta-deleted-at'
:
''
,
'x-image-meta-updated-at'
:
'2013-04-11 15:22:39'
,
'x-image-meta-created-at'
:
'2013-04-11 15:22:37'
,
'x-image-meta-owner'
:
'a13529bb3c3db'
,
'x-image-meta-size'
:
'1073741824'
,
'x-image-meta-name'
:
'img_1365686546.0'
,
'extraheaders'
:
'should be ignored'
}
example_images
=
[
{
"status"
:
"available"
,
...
...
@@ -185,6 +201,7 @@ class ImageClient(TestCase):
@
patch
(
'%s.post'
%
image_pkg
,
return_value
=
FR
())
def
test_register
(
self
,
post
,
SH
):
img0
=
example_images_detailed
[
0
]
FR
.
headers
=
example_image_headers
img0_location
=
img0
[
'location'
]
img0_name
=
'A new img0 name'
prfx
=
'x-image-meta-'
...
...
@@ -206,9 +223,12 @@ class ImageClient(TestCase):
async_headers
[
'%s%s'
%
(
prfx
,
k
)]
=
args
[
i
]
props
[
'%s%s'
%
(
proprfx
,
args
[
i
])]
=
k
async_headers
.
update
(
props
)
self
.
client
.
register
(
r
=
self
.
client
.
register
(
img0_name
,
img0_location
,
params
=
params
,
properties
=
props
)
expectedict
=
dict
(
example_image_headers
)
expectedict
.
pop
(
'extraheaders'
)
self
.
assert_dicts_are_equal
(
expectedict
,
r
)
self
.
assertEqual
(
post
.
mock_calls
[
-
1
],
call
(
'/images/'
,
async_headers
=
async_headers
,
success
=
200
))
...
...
kamaki/clients/livetest/image.py
View file @
7b6e977c
...
...
@@ -39,6 +39,12 @@ from kamaki.clients.image import ImageClient
from
kamaki.clients
import
ClientError
IMGMETA
=
set
([
'id'
,
'name'
,
'checksum'
,
'container-format'
,
'location'
,
'disk-format'
,
'is-public'
,
'status'
,
'deleted-at'
,
'updated-at'
,
'created-at'
,
'owner'
,
'size'
])
class
Image
(
livetest
.
Generic
):
def
setUp
(
self
):
self
.
now
=
time
.
mktime
(
time
.
gmtime
())
...
...
@@ -49,6 +55,7 @@ class Image(livetest.Generic):
cyclades_url
=
self
[
'compute'
,
'url'
]
self
.
cyclades
=
CycladesClient
(
cyclades_url
,
self
[
'token'
])
self
.
_imglist
=
{}
self
.
_imgdetails
=
{}
def
test_000
(
self
):
self
.
_prepare_img
()
...
...
@@ -73,12 +80,13 @@ class Image(livetest.Generic):
print
(
'
\t
- ok'
)
f
.
close
()
self
.
client
.
register
(
r
=
self
.
client
.
register
(
self
.
imgname
,
self
.
location
,
params
=
dict
(
is_public
=
True
))
img
=
self
.
_get_img_by_name
(
self
.
imgname
)
self
.
_imglist
[
self
.
imgname
]
=
img
self
.
_imglist
[
self
.
imgname
]
=
dict
(
name
=
r
[
'x-image-meta-name'
],
id
=
r
[
'x-image-meta-id'
])
self
.
_imgdetails
[
self
.
imgname
]
=
r
def
tearDown
(
self
):
for
img
in
self
.
_imglist
.
values
():
...
...
@@ -200,6 +208,9 @@ class Image(livetest.Generic):
self
.
assertTrue
(
self
.
_imglist
)
for
img
in
self
.
_imglist
.
values
():
self
.
assertTrue
(
img
is
not
None
)
r
=
set
(
self
.
_imgdetails
[
img
[
'name'
]].
keys
())
self
.
assertTrue
(
r
.
issubset
([
'x-image-meta-%s'
%
k
for
k
in
IMGMETA
]))
def
test_set_members
(
self
):
"""Test set_members"""
...
...
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