Commit 067c3661 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis Committed by Stavros Sachtouris
Browse files

Adapt Pithos-related commands for new projects

- Add optional argument --project in command "file create"
- Add command "file reassign"
parent 82c4d59b
......@@ -1545,7 +1545,8 @@ class container_create(_pithos_account):
'set container versioning (auto/none)', '--versioning'),
limit=IntArgument('set default container limit', '--limit'),
meta=KeyValueArgument(
'set container metadata (can be repeated)', '--meta')
'set container metadata (can be repeated)', '--meta'),
project=ValueArgument('assign the container to project', '--project'),
)
@errors.generic.all
......@@ -1557,6 +1558,7 @@ class container_create(_pithos_account):
container=container,
sizelimit=self['limit'],
versioning=self['versioning'],
project=self['project'],
metadata=self['meta'],
success=(201, ))
except ClientError as ce:
......@@ -1624,6 +1626,25 @@ class container_empty(_pithos_account):
self._run(container)
@command(container_cmds)
class container_reassign(_pithos_account, _optional_output_cmd):
"""Assign a container to a different project
"""
@errors.generic.all
@errors.pithos.connection
@errors.pithos.container
def _run(self, project):
if self.container:
self.client.container = self.container
self._optional_output(self.client.reassign_container(project))
def main(self, container, project):
super(self.__class__, self)._run()
self.container = container
self._run(project)
@command(sharer_cmds)
class sharer_list(_pithos_account, _optional_json):
"""List accounts who share file objects with current user"""
......
......@@ -108,7 +108,7 @@ class PithosClient(PithosRestClient):
def create_container(
self,
container=None, sizelimit=None, versioning=None, metadata=None,
**kwargs):
project=None, **kwargs):
"""
:param container: (str) if not given, self.container is used instead
......@@ -126,7 +126,7 @@ class PithosClient(PithosRestClient):
self.container = container or cnt_back_up
r = self.container_put(
quota=sizelimit, versioning=versioning, metadata=metadata,
**kwargs)
project=project, **kwargs)
return r.headers
finally:
self.container = cnt_back_up
......@@ -1551,3 +1551,7 @@ class PithosClient(PithosRestClient):
self._assert_container()
r = self.object_get(obj, format='json', version='list')
return r.json['versions']
def reassign_container(self, project):
r = self.container_post(project=project)
return r.headers
......@@ -292,7 +292,7 @@ class PithosRestClient(StorageClient):
def container_put(
self,
quota=None, versioning=None, metadata=None,
quota=None, versioning=None, project=None, metadata=None,
*args, **kwargs):
""" Full Pithos+ PUT at container level
......@@ -311,6 +311,9 @@ class PithosRestClient(StorageClient):
self.set_header('X-Container-Policy-Quota', quota)
self.set_header('X-Container-Policy-Versioning', versioning)
if project:
self.set_header('X-Container-Policy-project', project)
if metadata:
for metaname, metaval in metadata.items():
self.set_header('X-Container-Meta-' + metaname, metaval)
......@@ -325,6 +328,7 @@ class PithosRestClient(StorageClient):
format='json',
quota=None,
versioning=None,
project=None,
metadata=None,
content_type=None,
content_length=None,
......@@ -362,6 +366,9 @@ class PithosRestClient(StorageClient):
self.set_header('X-Container-Policy-Quota', quota)
self.set_header('X-Container-Policy-Versioning', versioning)
if project:
self.set_header('X-Container-Policy-project', project)
if metadata:
for metaname, metaval in metadata.items():
self.set_header('X-Container-Meta-' + metaname, metaval)
......
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