Revision d5832d3b
b/kamaki/cli.py | ||
---|---|---|
749 | 749 |
self.client.set_object_meta(object, {metakey:metavalue}) |
750 | 750 |
|
751 | 751 |
@command(api='storage') |
752 |
class store_delmeta(_store_account_command): |
|
753 |
"""Delete an existing metadatum of account [, container [or object]]""" |
|
754 |
|
|
755 |
def main(self, metakey, container=None, object=None): |
|
756 |
super(store_delmeta, self).main() |
|
757 |
if container is None: |
|
758 |
self.client.delete_account_meta(metakey) |
|
759 |
else: |
|
760 |
self.client.container = container |
|
761 |
if object is None: |
|
762 |
self.client.delete_container_meta(metakey) |
|
763 |
else: |
|
764 |
self.client.delete_object_meta(metakey, object) |
|
765 |
|
|
766 |
@command(api='storage') |
|
752 | 767 |
class store_policy(_store_account_command): |
753 | 768 |
"""Get policy for account [, container [or object]]""" |
754 | 769 |
|
b/kamaki/clients/__init__.py | ||
---|---|---|
93 | 93 |
|
94 | 94 |
url = self.base_url + path |
95 | 95 |
kwargs.setdefault('verify', False) # Disable certificate verification |
96 |
print('HAVE WE BEEN OVER THIS? '+unicode(headers)) |
|
96 | 97 |
r = requests.request(method, url, headers=headers, data=data, **kwargs) |
97 | 98 |
|
99 |
print('HAVE WE BEEN OVER THIS?') |
|
98 | 100 |
req = r.request |
99 | 101 |
sendlog.info('%s %s', req.method, req.url) |
100 | 102 |
for key, val in req.headers.items(): |
b/kamaki/clients/pithos.py | ||
---|---|---|
37 | 37 |
from time import time |
38 | 38 |
|
39 | 39 |
from .storage import StorageClient |
40 |
from .utils import path4url, params4url, prefix_keys |
|
40 |
from .utils import path4url, params4url, prefix_keys, filter_in, filter_out
|
|
41 | 41 |
|
42 | 42 |
|
43 | 43 |
def pithos_hash(block, blockhash): |
... | ... | |
132 | 132 |
self.put(path, params=params, headers=headers, json=hashmap, |
133 | 133 |
success=201) |
134 | 134 |
|
135 |
def get_account_policy(self): |
|
136 |
return filter_in(self.get_account_info(), 'X-Account-Policy-') |
|
137 |
|
|
138 |
def get_account_meta(self): |
|
139 |
return filter_in(self.get_account_info(), 'X-Account-Meta-') |
|
135 | 140 |
|
136 | 141 |
def set_account_meta(self, metapairs): |
137 | 142 |
assert(type(metapairs) is dict) |
... | ... | |
140 | 145 |
meta = prefix_keys(metapairs, 'X-Account-Meta-') |
141 | 146 |
self.post(path, meta=meta, success=202) |
142 | 147 |
|
148 |
def get_container_policy(self, container): |
|
149 |
return filter_in(self.get_container_info(container), 'X-Container-Policy-') |
|
150 |
|
|
151 |
def get_container_meta(self, container): |
|
152 |
return filter_in(self.get_container_info(container), 'X-Container-Meta-') |
|
153 |
|
|
154 |
def get_container_object_meta(self, container): |
|
155 |
return filter_in(self.get_container_info(container), 'X-Container-Object-Meta') |
|
156 |
|
|
143 | 157 |
def set_container_meta(self, metapairs): |
144 | 158 |
assert(type(metapairs) is dict) |
145 | 159 |
self.assert_container() |
... | ... | |
147 | 161 |
meta = prefix_keys(metapairs, 'X-Container-Meta-') |
148 | 162 |
self.post(path, meta=meta, success=202) |
149 | 163 |
|
164 |
def delete_container_meta(self, metakey): |
|
165 |
headers = self.get_container_info(self.container) |
|
166 |
new_headers = filter_out(headers, 'x-container-meta-'+metakey, exactMatch = True) |
|
167 |
if len(new_headers) == len(headers): |
|
168 |
raise ClientError('X-Container-Meta-%s not found' % metakey, 404) |
|
169 |
path = path4url(self.account, self.container) |
|
170 |
self.post(path, headers=new_headers, success = 202) |
|
171 |
|
|
172 |
def replace_container_meta(self, metapairs): |
|
173 |
self.assert_container() |
|
174 |
path=path4url(self.account, self.container) |
|
175 |
meta = prefix_keys(metapairs, 'X-Container-Meta-') |
|
176 |
self.post(path, meta=meta, success=202) |
|
177 |
|
|
150 | 178 |
def set_object_meta(self, object, metapairs): |
151 | 179 |
assert(type(metapairs) is dict) |
152 | 180 |
self.assert_container() |
b/kamaki/clients/storage.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from . import Client, ClientError |
35 |
from .utils import filter_dict_with_prefix, prefix_keys, path4url, params4url
|
|
35 |
from .utils import filter_in, filter_out, prefix_keys, path4url, params4url
|
|
36 | 36 |
|
37 | 37 |
class StorageClient(Client): |
38 | 38 |
"""OpenStack Object Storage API 1.0 client""" |
... | ... | |
59 | 59 |
raise ClientError("No authorization") |
60 | 60 |
return r.headers |
61 | 61 |
|
62 |
def get_account_meta(self): |
|
63 |
return filter_dict_with_prefix(self.get_account_info(), 'X-Account-Meta-') |
|
64 |
|
|
65 | 62 |
def replace_account_meta(self, metapairs): |
66 | 63 |
self.assert_account() |
67 | 64 |
path = path4url(self.account) |
68 | 65 |
meta = prefix_keys(metapairs, 'X-Account-Meta-') |
69 | 66 |
self.post(path, meta=meta, success=202) |
70 | 67 |
|
71 |
def get_account_policy(self): |
|
72 |
return filter_dict_with_prefix(self.get_account_info(), 'X-Account-Policy-') |
|
68 |
def delete_account_meta(self, metakey): |
|
69 |
headers = self.get_account_info() |
|
70 |
new_headers = filter_out(headers, 'X-Account-Meta-'+metakey, exactMatch = True) |
|
71 |
if len(new_headers) == len(headers): |
|
72 |
raise ClientError('X-Account-Meta-%s not found' % metakey, 404) |
|
73 |
path = path4url(self.account) |
|
74 |
self.post(path, headers=new_headers, success = 202) |
|
73 | 75 |
|
74 | 76 |
def create_container(self, container): |
75 | 77 |
self.assert_account() |
... | ... | |
87 | 89 |
reply = r.headers |
88 | 90 |
return reply |
89 | 91 |
|
90 |
def get_container_meta(self, container): |
|
91 |
return filter_dict_with_prefix(self.get_container_info(container), 'X-Container-Meta-') |
|
92 |
|
|
93 |
def get_container_object_meta(self, container): |
|
94 |
return filter_dict_with_prefix(self.get_container_info(container), 'X-Container-Object-Meta') |
|
95 |
|
|
96 |
def replace_container_meta(self, metapairs): |
|
97 |
self.assert_container() |
|
98 |
path=path4url(self.account, self.container) |
|
99 |
meta = prefix_keys(metapairs, 'X-Container-Meta-') |
|
100 |
self.post(path, meta=meta, success=202) |
|
101 |
|
|
102 |
def get_container_policy(self, container): |
|
103 |
return filter_dict_with_prefix(self.get_container_info(container), 'X-Container-Policy-') |
|
104 |
|
|
105 | 92 |
def delete_container(self, container): |
106 | 93 |
#Response codes |
107 | 94 |
# Success 204 |
... | ... | |
143 | 130 |
return r.headers |
144 | 131 |
|
145 | 132 |
def get_object_meta(self, object): |
146 |
return filter_dict_with_prefix(self.get_object_info(object), 'X-Object-Meta-') |
|
133 |
return filter_in(self.get_object_info(object), 'X-Object-Meta-') |
|
134 |
|
|
135 |
def delete_object_meta(self, metakey, object): |
|
136 |
headers = self.get_object_info(object) |
|
137 |
new_headers = filter_out(headers, 'X-Object-Meta-'+metakey, exactMatch = True) |
|
138 |
if len(new_headers) == len(headers): |
|
139 |
raise ClientError('X-Object-Meta-%s not found' % metakey, 404) |
|
140 |
path = path4url(self.account, self.container, object) |
|
141 |
print('HAVE WE BEEN OVER THIS?') |
|
142 |
print(unicode(new_headers)) |
|
143 |
print('HAVE WE BEEN OVER THIS?') |
|
144 |
self.post(path, headers=new_headers, success = 202) |
|
147 | 145 |
|
148 | 146 |
def replace_object(self, metapairs): |
149 | 147 |
self.assert_container() |
b/kamaki/clients/utils.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
def filter_dict_with_prefix(d, prefix): |
|
34 |
def filter_out(d, prefix, exactMatch = False): |
|
35 |
"""@return a dict that contains the entries of d that are NOT prefixed with prefic |
|
36 |
""" |
|
37 |
if exactMatch: |
|
38 |
return {key:d[key] for key in d if not key.lower() == prefix.lower()} |
|
39 |
return {key:d[key] for key in d if not key.lower().startswith(prefix.lower())} |
|
40 |
|
|
41 |
def filter_in(d, prefix): |
|
35 | 42 |
"""@return a dict that contains only the entries of d that are prefixed with prefic |
36 | 43 |
""" |
37 | 44 |
return {key:d[key] for key in d if key.lower().startswith(prefix.lower())} |
Also available in: Unified diff