+ """Set new quota for account or container
+ By default, quota is set in bytes
+ Users may specify a different unit, e.g:
+ /store setquota 2.3GB mycontainer
+ Accepted units: B, KiB (1024 B), KB (1000 B), MiB, MB, GiB, GB, TiB, TB
+ """
+
+ def _calculate_quota(self, user_input):
+ quota = 0
+ try:
+ quota = 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]
+ format = user_input[index:]
+ try:
+ return to_bytes(quota, format)
+ except Exception as qe:
+ raiseCLIError(qe,
+ 'Failed to convert %s to bytes' % user_input,
+ details=['Syntax: setquota <quota>[format] [container]',
+ 'e.g.: setquota 2.3GB mycontainer',
+ 'Acceptable formats:',
+ '(*1024): B, KiB, MiB, GiB, TiB',
+ '(*1000): B, KB, MB, GB, TB'])
+ return quota