Commit 7515b22e authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Merge branch 'feature-containerlimit' into develop

parents f2477d6a 3ed6dbde
......@@ -329,11 +329,13 @@ file (Storage/Pithos+)
permissions : Get object read/write permissions
publish : Publish an object
purge : Purge a container
quota : Get quota for account [or container]
quota : Get quota for account
setgroup : Create/update a new user group
setmeta : Set a new metadatum for account [, container [or object]]
setpermissions: Set sharing permissions
setquota : Set new quota (in KB) for account [or container]
containerlimit: Container size limit commands
set : Set container data limit
get : Get container data limit
setversioning : Set new versioning (auto, none) for account [or container]
sharers : List the accounts that share objects with default account
touch : Create an empty object (file)
......
......@@ -178,40 +178,41 @@ network commands
file commands
**************
* append Append local file to (existing) remote object
* cat Print remote file contents to console
* copy Copy an object from container to (another) container
* create Create a container
* delete Delete a container [or an object]
* delgroup Delete a user group
* delmeta Delete metadata from account, container or object
* delpermissions Delete all permissions set on object
* download Download remote object as local file
* group Get groups and group members
* hashmap Get the hash-map of an object
* info Get detailed info for account, containers or objects
* list List containers, object trees or objects in a directory
* manifest Create a remote file of uploaded parts by manifestation
* meta Get metadata for account, containers or objects
* mkdir Create a directory
* move Copy an object
* overwrite Overwrite part (from start to end) of a remote file
* permissions Get read and write permissions of an object
* publish Publish the object and print the public url
* purge Delete a container and release related data blocks
* quota Get quota (in KB) for account or container
* setgroup Set a user group
* setmeta Set a piece of metadata for account, container or object
* setpermissions Set permissions for an object
* setquota Set new quota (in KB) for account or container
* setversioning Set versioning mode (auto, none) for account or container
* sharers List the accounts that share objects with current user
* touch Create an empty object (file)
* truncate Truncate remote file up to a size
* unpublish Unpublish an object
* upload Upload a file
* versioning Get versioning for account or container
* versions Get the list of object versions
* append Append local file to (existing) remote object
* cat Print remote file contents to console
* copy Copy an object from container to (another) container
* create Create a container
* delete Delete a container [or an object]
* delgroup Delete a user group
* delmeta Delete metadata from account, container or object
* delpermissions Delete all permissions set on object
* download Download remote object as local file
* group Get groups and group members
* hashmap Get the hash-map of an object
* info Get detailed info for account, containers or objects
* list List containers, object trees or objects in a directory
* manifest Create a remote file of uploaded parts by manifestation
* meta Get metadata for account, containers or objects
* mkdir Create a directory
* move Copy an object
* overwrite Overwrite part (from start to end) of a remote file
* permissions Get read and write permissions of an object
* publish Publish the object and print the public url
* purge Delete a container and release related data blocks
* quota Get quota (in KB) for account or container
* setgroup Set a user group
* setmeta Set a piece of metadata for account, container or object
* setpermissions Set permissions for an object
* containerlimit set Set new limit for container
* containerlimit get Get container limit
* setversioning Set versioning mode (auto, none) for account or container
* sharers List the accounts that share objects with current user
* touch Create an empty object (file)
* truncate Truncate remote file up to a size
* unpublish Unpublish an object
* upload Upload a file
* versioning Get versioning for account or container
* versions Get the list of object versions
test commands (hidden)
......
......@@ -198,9 +198,11 @@ class _file_account_command(_pithos_init):
'Set user account (not permanent)',
('-A', '--account'))
def _run(self):
def _run(self, custom_account=None):
super(_file_account_command, self)._run()
if self['account']:
if custom_account:
self.client.account = custom_account
elif self['account']:
self.client.account = self['account']
@errors.generic.all
......@@ -484,7 +486,7 @@ class file_create(_file_container_command):
versioning=ValueArgument(
'set container versioning (auto/none)',
'--versioning'),
quota=IntArgument('set default container quota', '--quota'),
limit=IntArgument('set default container limit', '--limit'),
meta=KeyValueArgument(
'set container metadata (can be repeated)',
'--meta')
......@@ -495,7 +497,7 @@ class file_create(_file_container_command):
@errors.pithos.container
def _run(self):
self.client.container_put(
quota=self['quota'],
limit=self['limit'],
versioning=self['versioning'],
metadata=self['meta'])
......@@ -1745,7 +1747,7 @@ class file_delmeta(_file_container_command):
@command(pithos_cmds)
class file_quota(_file_account_command):
"""Get quota for account or container"""
"""Get account quota"""
arguments = dict(
in_bytes=FlagArgument('Show result in bytes', ('-b', '--bytes'))
......@@ -1753,12 +1755,35 @@ class file_quota(_file_account_command):
@errors.generic.all
@errors.pithos.connection
def _run(self):
reply = self.client.get_account_quota()
if not self['in_bytes']:
for k in reply:
reply[k] = format_size(reply[k])
print_dict(pretty_keys(reply, '-'))
def main(self, custom_uuid=None):
super(self.__class__, self)._run(custom_account=custom_uuid)
self._run()
@command(pithos_cmds)
class file_containerlimit(_pithos_init):
"""Container size limit commands"""
@command(pithos_cmds)
class file_containerlimit_get(_file_container_command):
"""Get container size limit"""
arguments = dict(
in_bytes=FlagArgument('Show result in bytes', ('-b', '--bytes'))
)
@errors.generic.all
@errors.pithos.container
def _run(self):
if self.container:
reply = self.client.get_container_quota(self.container)
else:
reply = self.client.get_account_quota()
reply = self.client.get_container_limit(self.container)
if not self['in_bytes']:
for k in reply:
reply[k] = format_size(reply[k])
......@@ -1771,53 +1796,51 @@ class file_quota(_file_account_command):
@command(pithos_cmds)
class file_setquota(_file_account_command):
"""Set new quota for account or container
By default, quota is set in bytes
class file_containerlimit_set(_file_account_command):
"""Set new storage limit for a container
By default, the limit is set in bytes
Users may specify a different unit, e.g:
/file setquota 2.3GB mycontainer
Accepted units: B, KiB (1024 B), KB (1000 B), MiB, MB, GiB, GB, TiB, TB
/file containerlimit set 2.3GB mycontainer
Valid units: B, KiB (1024 B), KB (1000 B), MiB, MB, GiB, GB, TiB, TB
"""
@errors.generic.all
def _calculate_quota(self, user_input):
quota = 0
def _calculate_limit(self, user_input):
limit = 0
try:
quota = int(user_input)
limit = int(user_input)
except ValueError:
index = 0
digits = [str(num) for num in range(0, 10)] + ['.']
while user_input[index] in digits:
index += 1
quota = user_input[:index]
limit = user_input[:index]
format = user_input[index:]
try:
return to_bytes(quota, format)
return to_bytes(limit, format)
except Exception as qe:
msg = 'Failed to convert %s to bytes' % user_input,
raiseCLIError(qe, msg, details=[
'Syntax: setquota <quota>[format] [container]',
'e.g.: setquota 2.3GB mycontainer',
'Acceptable formats:',
'Syntax: containerlimit set <limit>[format] [container]',
'e.g.: containerlimit set 2.3GB mycontainer',
'Valid formats:',
'(*1024): B, KiB, MiB, GiB, TiB',
'(*1000): B, KB, MB, GB, TB'])
return quota
return limit
@errors.generic.all
@errors.pithos.connection
@errors.pithos.container
def _run(self, quota):
def _run(self, limit):
if self.container:
self.client.container = self.container
self.client.set_container_quota(quota)
else:
self.client.set_account_quota(quota)
self.client.set_container_limit(limit)
def main(self, quota, container=None):
def main(self, limit, container=None):
super(self.__class__, self)._run()
quota = self._calculate_quota(quota)
limit = self._calculate_limit(limit)
self.container = container
self._run(quota)
self._run(limit)
@command(pithos_cmds)
......
......@@ -286,8 +286,8 @@ class Pithos(livetest.Generic):
you don't have permissions to modify those at account level
"""
newquota = 1000000
self.client.set_account_quota(newquota)
#newquota = 1000000
#self.client.set_account_quota(newquota)
#r = self.client.get_account_info()
#print(unicode(r))
#r = self.client.get_account_quota()
......@@ -396,14 +396,14 @@ class Pithos(livetest.Generic):
r = self.client.container_put()
self.assertEqual(r.status_code, 202)
r = self.client.get_container_quota(self.client.container)
r = self.client.get_container_limit(self.client.container)
cquota = r.values()[0]
newquota = 2 * int(cquota)
r = self.client.container_put(quota=newquota)
self.assertEqual(r.status_code, 202)
r = self.client.get_container_quota(self.client.container)
r = self.client.get_container_limit(self.client.container)
xquota = int(r.values()[0])
self.assertEqual(newquota, xquota)
......@@ -468,15 +468,15 @@ class Pithos(livetest.Generic):
self.assertEqual(r['x-container-meta-m2'], 'v2a')
"""check quota"""
r = self.client.get_container_quota(self.client.container)
r = self.client.get_container_limit(self.client.container)
cquota = r.values()[0]
newquota = 2 * int(cquota)
r = self.client.set_container_quota(newquota)
r = self.client.get_container_quota(self.client.container)
r = self.client.set_container_limit(newquota)
r = self.client.get_container_limit(self.client.container)
xquota = int(r.values()[0])
self.assertEqual(newquota, xquota)
r = self.client.set_container_quota(cquota)
r = self.client.get_container_quota(self.client.container)
r = self.client.set_container_limit(cquota)
r = self.client.get_container_limit(self.client.container)
xquota = r.values()[0]
self.assertEqual(cquota, xquota)
......
......@@ -716,11 +716,13 @@ class PithosClient(PithosRestClient):
"""
self.account_post(update=True, metadata={metakey: ''})
"""
def set_account_quota(self, quota):
"""
""
:param quota: (int)
"""
""
self.account_post(update=True, quota=quota)
"""
def set_account_versioning(self, versioning):
"""
......@@ -774,7 +776,7 @@ class PithosClient(PithosRestClient):
finally:
self.container = cnt_back_up
def get_container_quota(self, container=None):
def get_container_limit(self, container=None):
"""
:param container: (str)
......@@ -837,11 +839,11 @@ class PithosClient(PithosRestClient):
"""
self.container_post(update=True, metadata={metakey: ''})
def set_container_quota(self, quota):
def set_container_limit(self, limit):
"""
:param quota: (int)
:param limit: (int)
"""
self.container_post(update=True, quota=quota)
self.container_post(update=True, quota=limit)
def set_container_versioning(self, versioning):
"""
......
......@@ -1277,11 +1277,13 @@ class PithosClient(TestCase):
self.client.set_account_meta(metas)
post.assert_called_once_with(update=True, metadata=metas)
"""
@patch('%s.account_post' % pithos_pkg, return_value=FR())
def test_set_account_quota(self, post):
qu = 1024
self.client.set_account_quota(qu)
post.assert_called_once_with(update=True, quota=qu)
"""
@patch('%s.account_post' % pithos_pkg, return_value=FR())
def test_set_account_versioning(self, post):
......@@ -1314,12 +1316,12 @@ class PithosClient(TestCase):
self.assertEqual(bu_cnt, self.client.container)
@patch('%s.get_container_info' % pithos_pkg, return_value=container_info)
def test_get_container_quota(self, GCI):
def test_get_container_limit(self, GCI):
key = 'x-container-policy-quota'
cont = 'c0n7-417'
bu_cnt = self.client.container
for container in (None, cont):
r = self.client.get_container_quota(container=container)
r = self.client.get_container_limit(container=container)
self.assertEqual(r[key], container_info[key])
self.assertEqual(GCI.mock_calls[-1], call())
self.assertEqual(bu_cnt, self.client.container)
......@@ -1370,9 +1372,9 @@ class PithosClient(TestCase):
AP.assert_called_once_with(update=True, metadata={'somekey': ''})
@patch('%s.container_post' % pithos_pkg, return_value=FR())
def test_set_container_quota(self, post):
def test_set_container_limit(self, post):
qu = 1024
self.client.set_container_quota(qu)
self.client.set_container_limit(qu)
post.assert_called_once_with(update=True, quota=qu)
@patch('%s.container_post' % pithos_pkg, return_value=FR())
......
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