wip quotaholder client in backend
authorGeorgios D. Tsoukalas <gtsouk@cslab.ece.ntua.gr>
Wed, 12 Sep 2012 08:33:39 +0000 (11:33 +0300)
committerroot <gtsouk@cslab.ece.ntua.gr>
Fri, 9 Nov 2012 09:02:17 +0000 (11:02 +0200)
snf-pithos-app/pithos/api/settings.py
snf-pithos-app/pithos/api/util.py
snf-pithos-backend/pithos/backends/modular.py

index 7b78707..6731669 100644 (file)
@@ -45,6 +45,10 @@ BACKEND_QUOTA = getattr(
     settings, 'PITHOS_BACKEND_QUOTA', 50 * 1024 * 1024 * 1024)
 BACKEND_VERSIONING = getattr(settings, 'PITHOS_BACKEND_VERSIONING', 'auto')
 
+PITHOS_QUOTAHOLDER_URL = getattr(settings,
+                                'PITHOS_QUOTAHOLDER_URL',
+                                'http://127.0.0.1/api/quotaholder/v')
+
 # Update object checksums when using hashmaps.
 UPDATE_MD5 = getattr(settings, 'PITHOS_UPDATE_MD5', True)
 
index 117bb13..1f008c8 100644 (file)
@@ -61,6 +61,7 @@ from pithos.api.settings import (BACKEND_DB_MODULE, BACKEND_DB_CONNECTION,
                                  BACKEND_BLOCK_UMASK,
                                  BACKEND_QUEUE_MODULE, BACKEND_QUEUE_HOSTS,
                                  BACKEND_QUEUE_EXCHANGE,
+                                PITHOS_QUOTAHOLDER_URL,
                                  BACKEND_QUOTA, BACKEND_VERSIONING,
                                  AUTHENTICATION_URL, AUTHENTICATION_USERS,
                                  SERVICE_TOKEN, COOKIE_NAME)
@@ -858,7 +859,8 @@ def _get_backend():
                               block_umask=BACKEND_BLOCK_UMASK,
                               queue_module=BACKEND_QUEUE_MODULE,
                               queue_hosts=BACKEND_QUEUE_HOSTS,
-                              queue_exchange=BACKEND_QUEUE_EXCHANGE)
+                              queue_exchange=BACKEND_QUEUE_EXCHANGE,
+                             quotaholder_url=PITHOS_QUOTAHOLDER_URL)
     backend.default_policy['quota'] = BACKEND_QUOTA
     backend.default_policy['versioning'] = BACKEND_VERSIONING
     return backend
index 9ddb4e8..6ca9ee7 100644 (file)
@@ -39,6 +39,8 @@ import logging
 import hashlib
 import binascii
 
+from commissioning.clients.quotaholder import QuotaholderHTTP
+
 from base import DEFAULT_QUOTA, DEFAULT_VERSIONING, NotAllowedError, QuotaError, BaseBackend, \
     AccountExists, ContainerExists, AccountNotEmpty, ContainerNotEmpty, ItemNotExists, VersionNotExists
 
@@ -129,7 +131,7 @@ class ModularBackend(BaseBackend):
     def __init__(self, db_module=None, db_connection=None,
                  block_module=None, block_path=None, block_umask=None,
                  queue_module=None, queue_hosts=None,
-                 queue_exchange=None):
+                 queue_exchange=None, quotaholder_url=None):
         db_module = db_module or DEFAULT_DB_MODULE
         db_connection = db_connection or DEFAULT_DB_CONNECTION
         block_module = block_module or DEFAULT_BLOCK_MODULE
@@ -138,7 +140,7 @@ class ModularBackend(BaseBackend):
         #queue_module = queue_module or DEFAULT_QUEUE_MODULE
         #queue_hosts = queue_hosts or DEFAULT_QUEUE_HOSTS
         #queue_exchange = queue_exchange or DEFAULT_QUEUE_EXCHANGE
-               
+                
         self.hash_algorithm = 'sha256'
         self.block_size = 4 * 1024 * 1024  # 4MB
 
@@ -171,7 +173,7 @@ class ModularBackend(BaseBackend):
         if queue_module and queue_hosts:
             self.queue_module = load_module(queue_module)
             params = {'hosts': queue_hosts,
-                         'exchange': queue_exchange,
+                          'exchange': queue_exchange,
                       'client_id': QUEUE_CLIENT_ID}
             self.queue = self.queue_module.Queue(**params)
         else:
@@ -184,6 +186,8 @@ class ModularBackend(BaseBackend):
 
             self.queue = NoQueue()
 
+        self.quotaholder = QuotaholderHTTP('http://127.0.0.1/api/quotaholder/v')
+
     def close(self):
         self.wrapper.close()
         self.queue.close()
@@ -1233,19 +1237,22 @@ class ModularBackend(BaseBackend):
                                                  account, QUEUE_INSTANCE_ID, 'diskspace',
                                                  float(size), details))
 
+        serial = self.quotaholder.issue_provision()
+        self.serial.append(serial)
+
     def _report_object_change(self, user, account, path, details={}):
         details.update({'user': user})
         logger.debug("_report_object_change: %s %s %s %s", user,
                      account, path, details)
         self.messages.append((QUEUE_MESSAGE_KEY_PREFIX % ('object',),
-                                                 account, QUEUE_INSTANCE_ID, 'object', path, details))
+                                                  account, QUEUE_INSTANCE_ID, 'object', path, details))
 
     def _report_sharing_change(self, user, account, path, details={}):
         logger.debug("_report_permissions_change: %s %s %s %s",
                      user, account, path, details)
         details.update({'user': user})
         self.messages.append((QUEUE_MESSAGE_KEY_PREFIX % ('sharing',),
-                                                 account, QUEUE_INSTANCE_ID, 'sharing', path, details))
+                                                  account, QUEUE_INSTANCE_ID, 'sharing', path, details))
 
     # Policy functions.