Split file-quota semantics for account and contner
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 15 Apr 2013 11:11:46 +0000 (14:11 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 15 Apr 2013 11:11:46 +0000 (14:11 +0300)
kamaki file quota --> only for account
kamaki file quota <container> --> kamaki file containerlimit get [container]

Support #3541

docs/commands.rst
docs/man/kamaki.rst
kamaki/cli/commands/pithos.py
kamaki/clients/livetest/pithos.py
kamaki/clients/pithos/__init__.py
kamaki/clients/pithos/test.py

index 72e7b0e..9f1da72 100644 (file)
@@ -329,12 +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
     containerlimit:  Container size limit commands
-        set       :  Set copntainer data limit
+        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)
index 19888dd..7b30b14 100644 (file)
@@ -203,7 +203,8 @@ file commands
 * 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
+* 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)
index 7f0fd3e..fd6fb7f 100644 (file)
@@ -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,20 +1755,15 @@ class file_quota(_file_account_command):
 
     @errors.generic.all
     @errors.pithos.connection
-    @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_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, container=None):
-        super(self.__class__, self)._run()
-        self.container = container
+    def main(self, custom_uuid=None):
+        super(self.__class__, self)._run(custom_account=custom_uuid)
         self._run()
 
 
@@ -1776,12 +1773,35 @@ class file_containerlimit(_pithos_init):
 
 
 @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):
+        reply = self.client.get_container_limit(self.container)
+        if not self['in_bytes']:
+            for k in reply:
+                reply[k] = format_size(reply[k])
+        print_dict(pretty_keys(reply, '-'))
+
+    def main(self, container=None):
+        super(self.__class__, self)._run()
+        self.container = container
+        self._run()
+
+
+@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 containerlimit set 2.3GB mycontainer
-    Valide units: B, KiB (1024 B), KB (1000 B), MiB, MB, GiB, GB, TiB, TB
+    Valid units: B, KiB (1024 B), KB (1000 B), MiB, MB, GiB, GB, TiB, TB
     """
 
     @errors.generic.all
index 705b489..7d9101a 100644 (file)
@@ -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)
 
index 3372eaa..6b6021c 100644 (file)
@@ -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)
 
index b5c9a7c..60f93f0 100644 (file)
@@ -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)