Revision 326a79b9 kamaki/cli/commands/pithos.py
b/kamaki/cli/commands/pithos.py | ||
---|---|---|
1771 | 1771 |
|
1772 | 1772 |
|
1773 | 1773 |
@command(pithos_cmds) |
1774 |
class file_setquota(_file_account_command): |
|
1775 |
"""Set new quota for account or container |
|
1776 |
By default, quota is set in bytes |
|
1774 |
class file_containerlimit(_pithos_init): |
|
1775 |
"""Container size limit commands""" |
|
1776 |
|
|
1777 |
|
|
1778 |
@command(pithos_cmds) |
|
1779 |
class file_containerlimit_set(_file_account_command): |
|
1780 |
"""Set new storage limit for a container |
|
1781 |
By default, the limit is set in bytes |
|
1777 | 1782 |
Users may specify a different unit, e.g: |
1778 |
/file setquota 2.3GB mycontainer
|
|
1779 |
Accepted units: B, KiB (1024 B), KB (1000 B), MiB, MB, GiB, GB, TiB, TB
|
|
1783 |
/file containerlimit set 2.3GB mycontainer
|
|
1784 |
Valide units: B, KiB (1024 B), KB (1000 B), MiB, MB, GiB, GB, TiB, TB
|
|
1780 | 1785 |
""" |
1781 | 1786 |
|
1782 | 1787 |
@errors.generic.all |
1783 |
def _calculate_quota(self, user_input):
|
|
1784 |
quota = 0
|
|
1788 |
def _calculate_limit(self, user_input):
|
|
1789 |
limit = 0
|
|
1785 | 1790 |
try: |
1786 |
quota = int(user_input)
|
|
1791 |
limit = int(user_input)
|
|
1787 | 1792 |
except ValueError: |
1788 | 1793 |
index = 0 |
1789 | 1794 |
digits = [str(num) for num in range(0, 10)] + ['.'] |
1790 | 1795 |
while user_input[index] in digits: |
1791 | 1796 |
index += 1 |
1792 |
quota = user_input[:index]
|
|
1797 |
limit = user_input[:index]
|
|
1793 | 1798 |
format = user_input[index:] |
1794 | 1799 |
try: |
1795 |
return to_bytes(quota, format)
|
|
1800 |
return to_bytes(limit, format)
|
|
1796 | 1801 |
except Exception as qe: |
1797 | 1802 |
msg = 'Failed to convert %s to bytes' % user_input, |
1798 | 1803 |
raiseCLIError(qe, msg, details=[ |
1799 |
'Syntax: setquota <quota>[format] [container]',
|
|
1800 |
'e.g.: setquota 2.3GB mycontainer',
|
|
1801 |
'Acceptable formats:',
|
|
1804 |
'Syntax: containerlimit set <limit>[format] [container]',
|
|
1805 |
'e.g.: containerlimit set 2.3GB mycontainer',
|
|
1806 |
'Valid formats:',
|
|
1802 | 1807 |
'(*1024): B, KiB, MiB, GiB, TiB', |
1803 | 1808 |
'(*1000): B, KB, MB, GB, TB']) |
1804 |
return quota
|
|
1809 |
return limit
|
|
1805 | 1810 |
|
1806 | 1811 |
@errors.generic.all |
1807 | 1812 |
@errors.pithos.connection |
1808 | 1813 |
@errors.pithos.container |
1809 |
def _run(self, quota):
|
|
1814 |
def _run(self, limit):
|
|
1810 | 1815 |
if self.container: |
1811 | 1816 |
self.client.container = self.container |
1812 |
self.client.set_container_quota(quota) |
|
1813 |
else: |
|
1814 |
self.client.set_account_quota(quota) |
|
1817 |
self.client.set_container_limit(limit) |
|
1815 | 1818 |
|
1816 |
def main(self, quota, container=None):
|
|
1819 |
def main(self, limit, container=None):
|
|
1817 | 1820 |
super(self.__class__, self)._run() |
1818 |
quota = self._calculate_quota(quota)
|
|
1821 |
limit = self._calculate_limit(limit)
|
|
1819 | 1822 |
self.container = container |
1820 |
self._run(quota)
|
|
1823 |
self._run(limit)
|
|
1821 | 1824 |
|
1822 | 1825 |
|
1823 | 1826 |
@command(pithos_cmds) |
Also available in: Unified diff