]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Refactoring to make backend configuration accessible from outside Client. refs #1971
authorDaira Hopwood <david-sarah@jacaranda.org>
Fri, 17 May 2013 16:39:20 +0000 (17:39 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Fri, 17 Apr 2015 21:31:40 +0000 (22:31 +0100)
Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
src/allmydata/client.py

index 9f56a7d11ee1bdba7ecffe216d2c7106496aaa91..6218d5b9c8ab0dd7a70f7690400a95099f9b4fcc 100644 (file)
@@ -262,16 +262,14 @@ class Client(node.Node, pollmixin.PollMixin):
             self.write_config("permutation-seed", seed+"\n")
         return seed.strip()
 
-    def init_storage(self):
-        self.accountant = None
-        # Should we run a storage server (and publish it for others to use)?
-        if not self.get_config("storage", "enabled", True, boolean=True):
-            return
+    @classmethod
+    def configure_backend(cls, config):
+        """This is also called directly by the implementation of 'tahoe admin create-container'."""
 
-        storedir = os.path.join(self.basedir, self.STOREDIR)
+        storedir = os.path.join(config.basedir, cls.STOREDIR)
 
         # What sort of backend?
-        backendtype = self.get_config("storage", "backend", "disk")
+        backendtype = config.get_config("storage", "backend", "disk")
         if backendtype == "s3":
             backendtype = "cloud.s3"
         backendprefix = backendtype.partition('.')[0]
@@ -285,9 +283,18 @@ class Client(node.Node, pollmixin.PollMixin):
 
         if backendprefix not in backend_configurators:
             raise InvalidValueError("%s is not supported; it must start with one of %s"
-                                    % (quote_output("[storage]backend = " + backendtype), backend_configurators.keys()) )
+                                    % (quote_output("[storage]backend = " + backendtype),
+                                    backend_configurators.keys()) )
+
+        return (backend_configurators[backendprefix](storedir, config), storedir)
+
+    def init_storage(self):
+        self.accountant = None
+        # Should we run a storage server (and publish it for others to use)?
+        if not self.get_config("storage", "enabled", True, boolean=True):
+            return
 
-        backend = backend_configurators[backendprefix](storedir, self)
+        (backend, storedir) = self.configure_backend(self)
 
         if self.get_config("storage", "debug_discard", False, boolean=True):
             raise OldConfigOptionError("[storage]debug_discard = True is no longer supported.")