Add a purge command
authorGiorgos Verigakis <verigak@gmail.com>
Fri, 23 Mar 2012 13:50:03 +0000 (15:50 +0200)
committerGiorgos Verigakis <verigak@gmail.com>
Wed, 9 May 2012 10:18:47 +0000 (13:18 +0300)
kamaki/cli.py
kamaki/clients/pithos.py

index 43cbe39..842ffa2 100755 (executable)
@@ -712,8 +712,7 @@ class store_create(_store_account_command):
     """Create a container"""
     
     def main(self, container):
-        if self.options.account:
-            self.client.account = self.options.account
+        super(store_create, self).main()
         self.client.create_container(container)
 
 
@@ -722,8 +721,7 @@ class store_container(_store_account_command):
     """Get container info"""
     
     def main(self, container):
-        if self.options.account:
-            self.client.account = self.options.account
+        super(store_container, self).main()
         reply = self.client.get_container_meta(container)
         print_dict(reply)
 
@@ -801,6 +799,15 @@ class store_delete(_store_container_command):
         self.client.delete_object(path)
 
 
+@command(api='storage')
+class store_purge(_store_account_command):
+    """Purge a container"""
+    
+    def main(self, container):
+        super(store_purge, self).main()
+        self.client.purge_container(container)
+
+
 @command(api='astakos')
 class astakos_authenticate(object):
     """Authenticate a user"""
index e12f0ea..177487a 100644 (file)
@@ -34,6 +34,8 @@
 import hashlib
 import os
 
+from time import time
+
 from ..utils import OrderedDict
 
 from .storage import StorageClient
@@ -47,7 +49,14 @@ def pithos_hash(block, blockhash):
 
 class PithosClient(StorageClient):
     """GRNet Pithos API client"""
-    
+
+    def purge_container(self, container):
+        self.assert_account()
+
+        path = '/%s/%s' % (self.account, container)
+        params = {'until': int(time())}
+        self.delete(path, params=params, success=204)
+
     def put_block(self, data, hash):
         path = '/%s/%s' % (self.account, self.container)
         params = {'update': ''}