Pithos level extentions added
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 16 Jul 2012 09:00:57 +0000 (12:00 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 16 Jul 2012 09:00:57 +0000 (12:00 +0300)
get_account_info now supports until parameter, and if-(un)modified-since headers
in request

kamaki/clients/pithos.py

index 83dd736..e75ba14 100644 (file)
@@ -141,6 +141,25 @@ class PithosClient(StorageClient):
         self.set_header('X-Account-Group-'+group, '')
         r = self.post(path, success=202)
 
         self.set_header('X-Account-Group-'+group, '')
         r = self.post(path, success=202)
 
+    def get_account_info(self, until = None, if_modified_since=None, if_unmodified_since=None):
+        """ @param until (string): optional timestamp
+            @param if_modified_since (string): Retrieve if account has changed since provided timestamp
+            @param if_unmodified_since (string): Retrieve if account has not changed since provided timestamp
+        """
+        self.assert_account()
+        path = path4url(self.account)
+
+        path += '' if until is None else params4url({'until':until})
+        if if_modified_since is not None:
+            self.set_header('If-Modified-Since', if_modified_since)
+        if if_modified_since is not None:
+            self.set_header('If-Unmodified-Since', if_unmodified_since)
+
+        r = self.head(path, success=(204, 401))
+        if r.status_code == 401:
+            raise ClientError("No authorization")
+        return r.headers
+
     def get_account_quota(self):
         return filter_in(self.get_account_info(), 'X-Account-Policy-Quota', exactMatch = True)
 
     def get_account_quota(self):
         return filter_in(self.get_account_info(), 'X-Account-Policy-Quota', exactMatch = True)