Commit e6b39366 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Added store_delmenta (delete specific meta)

    In CLI:
        - store_delmeta for account, container, object

    In storage,pithos:
        - store_account_delmeta
        - store_container_delemeta
        - store_object_delmeta (is buggy, hope to fix it soon)
        - moved all *meta methods to pithos, as they are all implementation of the pithos API
parent ca6e2c63
......@@ -748,6 +748,21 @@ class store_setmeta(_store_account_command):
else:
self.client.set_object_meta(object, {metakey:metavalue})
@command(api='storage')
class store_delmeta(_store_account_command):
"""Delete an existing metadatum of account [, container [or object]]"""
def main(self, metakey, container=None, object=None):
super(store_delmeta, self).main()
if container is None:
self.client.delete_account_meta(metakey)
else:
self.client.container = container
if object is None:
self.client.delete_container_meta(metakey)
else:
self.client.delete_object_meta(metakey, object)
@command(api='storage')
class store_policy(_store_account_command):
"""Get policy for account [, container [or object]]"""
......
......@@ -93,8 +93,10 @@ class Client(object):
url = self.base_url + path
kwargs.setdefault('verify', False) # Disable certificate verification
print('HAVE WE BEEN OVER THIS? '+unicode(headers))
r = requests.request(method, url, headers=headers, data=data, **kwargs)
print('HAVE WE BEEN OVER THIS?')
req = r.request
sendlog.info('%s %s', req.method, req.url)
for key, val in req.headers.items():
......
......@@ -37,7 +37,7 @@ import os
from time import time
from .storage import StorageClient
from .utils import path4url, params4url, prefix_keys
from .utils import path4url, params4url, prefix_keys, filter_in, filter_out
def pithos_hash(block, blockhash):
......@@ -132,6 +132,11 @@ class PithosClient(StorageClient):
self.put(path, params=params, headers=headers, json=hashmap,
success=201)
def get_account_policy(self):
return filter_in(self.get_account_info(), 'X-Account-Policy-')
def get_account_meta(self):
return filter_in(self.get_account_info(), 'X-Account-Meta-')
def set_account_meta(self, metapairs):
assert(type(metapairs) is dict)
......@@ -140,6 +145,15 @@ class PithosClient(StorageClient):
meta = prefix_keys(metapairs, 'X-Account-Meta-')
self.post(path, meta=meta, success=202)
def get_container_policy(self, container):
return filter_in(self.get_container_info(container), 'X-Container-Policy-')
def get_container_meta(self, container):
return filter_in(self.get_container_info(container), 'X-Container-Meta-')
def get_container_object_meta(self, container):
return filter_in(self.get_container_info(container), 'X-Container-Object-Meta')
def set_container_meta(self, metapairs):
assert(type(metapairs) is dict)
self.assert_container()
......@@ -147,6 +161,20 @@ class PithosClient(StorageClient):
meta = prefix_keys(metapairs, 'X-Container-Meta-')
self.post(path, meta=meta, success=202)
def delete_container_meta(self, metakey):
headers = self.get_container_info(self.container)
new_headers = filter_out(headers, 'x-container-meta-'+metakey, exactMatch = True)
if len(new_headers) == len(headers):
raise ClientError('X-Container-Meta-%s not found' % metakey, 404)
path = path4url(self.account, self.container)
self.post(path, headers=new_headers, success = 202)
def replace_container_meta(self, metapairs):
self.assert_container()
path=path4url(self.account, self.container)
meta = prefix_keys(metapairs, 'X-Container-Meta-')
self.post(path, meta=meta, success=202)
def set_object_meta(self, object, metapairs):
assert(type(metapairs) is dict)
self.assert_container()
......
......@@ -32,7 +32,7 @@
# or implied, of GRNET S.A.
from . import Client, ClientError
from .utils import filter_dict_with_prefix, prefix_keys, path4url, params4url
from .utils import filter_in, filter_out, prefix_keys, path4url, params4url
class StorageClient(Client):
"""OpenStack Object Storage API 1.0 client"""
......@@ -59,17 +59,19 @@ class StorageClient(Client):
raise ClientError("No authorization")
return r.headers
def get_account_meta(self):
return filter_dict_with_prefix(self.get_account_info(), 'X-Account-Meta-')
def replace_account_meta(self, metapairs):
self.assert_account()
path = path4url(self.account)
meta = prefix_keys(metapairs, 'X-Account-Meta-')
self.post(path, meta=meta, success=202)
def get_account_policy(self):
return filter_dict_with_prefix(self.get_account_info(), 'X-Account-Policy-')
def delete_account_meta(self, metakey):
headers = self.get_account_info()
new_headers = filter_out(headers, 'X-Account-Meta-'+metakey, exactMatch = True)
if len(new_headers) == len(headers):
raise ClientError('X-Account-Meta-%s not found' % metakey, 404)
path = path4url(self.account)
self.post(path, headers=new_headers, success = 202)
def create_container(self, container):
self.assert_account()
......@@ -87,21 +89,6 @@ class StorageClient(Client):
reply = r.headers
return reply
def get_container_meta(self, container):
return filter_dict_with_prefix(self.get_container_info(container), 'X-Container-Meta-')
def get_container_object_meta(self, container):
return filter_dict_with_prefix(self.get_container_info(container), 'X-Container-Object-Meta')
def replace_container_meta(self, metapairs):
self.assert_container()
path=path4url(self.account, self.container)
meta = prefix_keys(metapairs, 'X-Container-Meta-')
self.post(path, meta=meta, success=202)
def get_container_policy(self, container):
return filter_dict_with_prefix(self.get_container_info(container), 'X-Container-Policy-')
def delete_container(self, container):
#Response codes
# Success 204
......@@ -143,7 +130,18 @@ class StorageClient(Client):
return r.headers
def get_object_meta(self, object):
return filter_dict_with_prefix(self.get_object_info(object), 'X-Object-Meta-')
return filter_in(self.get_object_info(object), 'X-Object-Meta-')
def delete_object_meta(self, metakey, object):
headers = self.get_object_info(object)
new_headers = filter_out(headers, 'X-Object-Meta-'+metakey, exactMatch = True)
if len(new_headers) == len(headers):
raise ClientError('X-Object-Meta-%s not found' % metakey, 404)
path = path4url(self.account, self.container, object)
print('HAVE WE BEEN OVER THIS?')
print(unicode(new_headers))
print('HAVE WE BEEN OVER THIS?')
self.post(path, headers=new_headers, success = 202)
def replace_object(self, metapairs):
self.assert_container()
......
......@@ -31,7 +31,14 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
def filter_dict_with_prefix(d, prefix):
def filter_out(d, prefix, exactMatch = False):
"""@return a dict that contains the entries of d that are NOT prefixed with prefic
"""
if exactMatch:
return {key:d[key] for key in d if not key.lower() == prefix.lower()}
return {key:d[key] for key in d if not key.lower().startswith(prefix.lower())}
def filter_in(d, prefix):
"""@return a dict that contains only the entries of d that are prefixed with prefic
"""
return {key:d[key] for key in d if key.lower().startswith(prefix.lower())}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment