Commit 326a79b9 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Rename file setquota to file containerlimit set

Also, do not allow user to set account quota
parent f2477d6a
......@@ -333,7 +333,8 @@ file (Storage/Pithos+)
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 copntainer 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,40 @@ 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 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
test commands (hidden)
......
......@@ -1771,53 +1771,56 @@ 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(_pithos_init):
"""Container size limit commands"""
@command(pithos_cmds)
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
Valide 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)
......
......@@ -837,11 +837,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):
"""
......
......@@ -1370,9 +1370,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