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
ea36496d
Commit
ea36496d
authored
Mar 04, 2014
by
Stavros Sachtouris
Browse files
Add lists of expected headers in Client classes
parent
85015403
Changes
4
Hide whitespace changes
Inline
Side-by-side
kamaki/clients/__init__.py
View file @
ea36496d
...
...
@@ -127,11 +127,10 @@ class RequestManager(Logged):
url
+=
'%s%s%s'
%
(
delim
,
key
,
(
'=%s'
%
val
)
if
val
else
''
)
delim
=
'&'
parsed
=
urlparse
(
url
)
self
.
url
=
_encode
(
u
'%s'
%
url
)
self
.
path
=
_encode
((
u
'%s'
%
parsed
.
path
)
if
parsed
.
path
else
'/'
)
if
parsed
.
query
:
self
.
path
+=
'?%s'
%
parsed
.
query
return
(
_encode
(
parsed
.
scheme
),
_encode
(
parsed
.
netloc
))
self
.
url
=
'%s'
%
url
self
.
path
=
((
'%s'
%
parsed
.
path
)
if
parsed
.
path
else
'/'
)
+
(
'?%s'
%
parsed
.
query
if
parsed
.
query
else
''
)
return
(
parsed
.
scheme
,
parsed
.
netloc
)
def
__init__
(
self
,
method
,
url
,
path
,
...
...
@@ -177,7 +176,7 @@ class RequestManager(Logged):
self
.
dump_log
()
conn
.
request
(
method
=
self
.
method
.
upper
(),
url
=
(
'%s'
%
self
.
path
)
or
''
,
url
=
self
.
path
.
encode
(
'utf-8'
)
,
headers
=
self
.
headers
,
body
=
self
.
data
)
sendlog
.
info
(
''
)
...
...
@@ -253,12 +252,8 @@ class ResponseManager(Logged):
r_headers
=
r
.
getheaders
()
enc_headers
=
self
.
_get_headers_to_decode
(
r_headers
)
for
k
,
v
in
r_headers
:
if
k
.
lower
in
(
'x-auth-token'
,
)
and
(
not
self
.
LOG_TOKEN
):
self
.
_token
,
v
=
v
,
'...'
elif
k
.
lower
()
in
enc_headers
:
v
=
unquote
(
v
).
decode
(
'utf-8'
)
self
.
_headers
[
k
]
=
v
self
.
_headers
[
k
]
=
unquote
(
v
).
decode
(
'utf-8'
)
if
(
k
.
lower
())
in
enc_headers
else
v
recvlog
.
info
(
' %s: %s%s'
%
(
k
,
v
,
plog
))
self
.
_content
=
r
.
read
()
recvlog
.
info
(
'data size: %s%s'
%
(
...
...
@@ -344,9 +339,7 @@ class SilentEvent(Thread):
"""Thread-run method(*args, **kwargs)"""
def
__init__
(
self
,
method
,
*
args
,
**
kwargs
):
super
(
self
.
__class__
,
self
).
__init__
()
self
.
method
=
method
self
.
args
=
args
self
.
kwargs
=
kwargs
self
.
method
,
self
.
args
,
self
.
kwargs
=
method
,
args
,
kwargs
@
property
def
exception
(
self
):
...
...
@@ -380,7 +373,8 @@ class Client(Logged):
self
.
token
=
token
self
.
headers
,
self
.
params
=
dict
(),
dict
()
self
.
poolsize
=
None
self
.
headers_to_decode
,
self
.
header_prefices
=
[],
[]
self
.
response_headers
=
[]
self
.
response_header_prefices
=
[]
def
_init_thread_limit
(
self
,
limit
=
1
):
assert
isinstance
(
limit
,
int
)
and
limit
>
0
,
'Thread limit not a +int'
...
...
@@ -490,7 +484,6 @@ class Client(Logged):
headers
.
setdefault
(
'Content-Type'
,
'application/json'
)
if
data
:
headers
.
setdefault
(
'Content-Length'
,
'%s'
%
len
(
data
))
plog
=
(
'
\t
[%s]'
%
self
)
if
self
.
LOG_PID
else
''
sendlog
.
debug
(
'
\n\n
CMT %s@%s%s'
,
method
,
self
.
base_url
,
plog
)
req
=
RequestManager
(
...
...
@@ -501,8 +494,8 @@ class Client(Logged):
req
,
poolsize
=
self
.
poolsize
,
connection_retry_limit
=
self
.
CONNECTION_RETRY_LIMIT
)
r
.
headers_to_decode
=
self
.
headers_to_decode
r
.
header_prefices
=
self
.
header_prefices
r
.
headers_to_decode
=
self
.
response_headers
r
.
header_prefices
=
self
.
response_
header_prefices
r
.
LOG_TOKEN
,
r
.
LOG_DATA
,
r
.
LOG_PID
=
(
self
.
LOG_TOKEN
,
self
.
LOG_DATA
,
self
.
LOG_PID
)
r
.
_token
=
headers
[
'X-Auth-Token'
]
...
...
kamaki/clients/image/__init__.py
View file @
ea36496d
...
...
@@ -57,6 +57,7 @@ class ImageClient(Client):
def
__init__
(
self
,
base_url
,
token
):
super
(
ImageClient
,
self
).
__init__
(
base_url
,
token
)
self
.
response_header_prefices
=
[
'X-Image-'
,
]
def
list_public
(
self
,
detail
=
False
,
filters
=
{},
order
=
''
):
"""
...
...
@@ -70,7 +71,7 @@ class ImageClient(Client):
:returns: (list) id,name + full image info if detail
"""
path
=
path4url
(
'images'
,
'detail'
)
if
detail
else
(
path4url
(
'images'
)
+
'/'
)
'%s/'
%
path4url
(
'images'
))
async_params
=
{}
if
isinstance
(
filters
,
dict
):
...
...
@@ -115,7 +116,7 @@ class ImageClient(Client):
:returns: (dict) metadata of the created image
"""
path
=
path4url
(
'images'
)
+
'/'
path
=
'%s/'
%
path4url
(
'images'
)
self
.
set_header
(
'X-Image-Meta-Name'
,
name
)
location
=
location
if
(
isinstance
(
location
,
str
)
or
isinstance
(
location
,
unicode
))
else
(
...
...
kamaki/clients/pithos/__init__.py
View file @
ea36496d
...
...
@@ -466,10 +466,7 @@ class PithosClient(PithosRestClient):
sendlog
.
info
(
'%s blocks missing'
%
len
(
missing
))
num_of_blocks
=
len
(
missing
)
missing
=
self
.
_upload_missing_blocks
(
missing
,
hmap
,
f
,
upload_gen
)
missing
,
hmap
,
f
,
upload_gen
)
if
missing
:
if
num_of_blocks
==
len
(
missing
):
retries
-=
1
...
...
kamaki/clients/pithos/rest_api.py
View file @
ea36496d
...
...
@@ -60,6 +60,8 @@ class PithosRestClient(StorageClient):
:returns: ConnectionResponse
"""
self
.
response_headers
=
[
'Last-Modified'
,
]
self
.
response_header_prefices
=
[
'X-Account-'
,
]
self
.
_assert_account
()
path
=
path4url
(
self
.
account
)
...
...
@@ -111,6 +113,8 @@ class PithosRestClient(StorageClient):
:returns: ConnectionResponse
"""
self
.
_assert_account
()
self
.
response_headers
=
[
'Last-Modified'
,
]
self
.
response_header_prefices
=
[
'X-Account-'
,
]
self
.
set_param
(
'limit'
,
limit
,
iff
=
limit
)
self
.
set_param
(
'marker'
,
marker
,
iff
=
marker
)
...
...
@@ -156,7 +160,6 @@ class PithosRestClient(StorageClient):
:returns: ConnectionResponse
"""
self
.
_assert_account
()
self
.
set_param
(
'update'
,
''
,
iff
=
update
)
...
...
@@ -201,8 +204,9 @@ class PithosRestClient(StorageClient):
:returns: ConnectionResponse
"""
self
.
_assert_container
()
self
.
response_headers
=
[
'Last-Modified'
,
]
self
.
response_header_prefices
=
[
'X-Container-'
,
]
self
.
set_param
(
'until'
,
until
,
iff
=
until
)
...
...
@@ -269,6 +273,8 @@ class PithosRestClient(StorageClient):
"""
self
.
_assert_container
()
self
.
response_headers
=
[
'Last-Modified'
,
]
self
.
response_header_prefices
=
[
'X-Container-'
,
]
self
.
set_param
(
'limit'
,
limit
,
iff
=
limit
)
self
.
set_param
(
'marker'
,
marker
,
iff
=
marker
)
...
...
@@ -431,8 +437,16 @@ class PithosRestClient(StorageClient):
:returns: ConnectionResponse
"""
self
.
_assert_container
()
self
.
response_headers
=
[
'ETag'
,
'Content-Length'
,
'Content-Type'
,
'Last-Modified'
,
'Content-Encoding'
,
'Content-Disposition'
,
]
self
.
response_header_prefices
=
[
'X-Object-'
,
]
self
.
set_param
(
'version'
,
version
,
iff
=
version
)
...
...
@@ -487,8 +501,17 @@ class PithosRestClient(StorageClient):
:returns: ConnectionResponse
"""
self
.
_assert_container
()
self
.
response_headers
=
[
'ETag'
,
'Content-Length'
,
'Content-Type'
,
'Last-Modified'
,
'Content-Encoding'
,
'Content-Disposition'
,
'Content-Range'
,
]
self
.
response_header_prefices
=
[
'X-Object-'
,
]
self
.
set_param
(
'format'
,
format
,
iff
=
format
)
self
.
set_param
(
'hashmap'
,
hashmap
,
iff
=
hashmap
)
...
...
@@ -582,8 +605,8 @@ class PithosRestClient(StorageClient):
:returns: ConnectionResponse
"""
self
.
_assert_container
()
self
.
response_headers
=
[
'ETag'
,
'X-Object-Version'
]
self
.
set_param
(
'format'
,
format
,
iff
=
format
)
self
.
set_param
(
'hashmap'
,
hashmap
,
iff
=
hashmap
)
...
...
@@ -679,8 +702,18 @@ class PithosRestClient(StorageClient):
:returns: ConnectionResponse
"""
self
.
_assert_container
()
self
.
response_headers
=
[
'If-Match'
,
'If-None-Match'
,
'Destination'
,
'Destination-Account'
,
'Content-Type'
,
'Content-Encoding'
,
'Content-Disposition'
,
'X-Source-Version'
,
]
self
.
response_header_prefices
=
[
'X-Object-'
,
]
self
.
set_param
(
'format'
,
format
,
iff
=
format
)
self
.
set_param
(
'ignore_content_type'
,
iff
=
ignore_content_type
)
...
...
@@ -767,8 +800,18 @@ class PithosRestClient(StorageClient):
:returns: ConnectionResponse
"""
self
.
_assert_container
()
self
.
response_headers
=
[
'If-Match'
,
'If-None-Match'
,
'Destination'
,
'Destination-Account'
,
'Content-Type'
,
'Content-Encoding'
,
'Content-Disposition'
,
'X-Source-Version'
,
]
self
.
response_header_prefices
=
[
'X-Object-'
,
]
self
.
set_param
(
'format'
,
format
,
iff
=
format
)
self
.
set_param
(
'ignore_content_type'
,
iff
=
ignore_content_type
)
...
...
@@ -866,8 +909,8 @@ class PithosRestClient(StorageClient):
:returns: ConnectionResponse
"""
self
.
_assert_container
()
self
.
response_headers
=
[
'ETag'
,
'X-Object-Version'
]
self
.
set_param
(
'format'
,
format
,
iff
=
format
)
self
.
set_param
(
'update'
,
''
,
iff
=
update
)
...
...
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