[Checkins] SVN: gocept.zeoraid/branches/dirceu-addstoragetool/src/gocept/zeoraid/s Patch to allow to connect to a new storage using the client tool

Dirceu Pereira Tiegs dirceutiegs at gmail.com
Thu Jul 24 20:07:03 EDT 2008


Log message for revision 88804:
  Patch to allow to connect to a new storage using the client tool

Changed:
  U   gocept.zeoraid/branches/dirceu-addstoragetool/src/gocept/zeoraid/scripts/controller.py
  U   gocept.zeoraid/branches/dirceu-addstoragetool/src/gocept/zeoraid/storage.py

-=-
Modified: gocept.zeoraid/branches/dirceu-addstoragetool/src/gocept/zeoraid/scripts/controller.py
===================================================================
--- gocept.zeoraid/branches/dirceu-addstoragetool/src/gocept/zeoraid/scripts/controller.py	2008-07-25 00:04:58 UTC (rev 88803)
+++ gocept.zeoraid/branches/dirceu-addstoragetool/src/gocept/zeoraid/scripts/controller.py	2008-07-25 00:07:02 UTC (rev 88804)
@@ -33,6 +33,8 @@
 
     disable <storage> -- Disable a storage
 
+    add <ip:port:storage> -- Add a storage
+
 """
 
 import optparse
@@ -71,12 +73,18 @@
     def cmd_disable(self, storage):
         print self.raid.raid_disable(storage)
 
+    def cmd_add(self, storage):
+        try:
+            ip, port, storage = storage.split(':')
+            print self.raid.raid_add_storage(ip, port, storage)
+        except ValueError:
+            sys.exit("Usage: IP:PORT:STORAGE")
 
 def main(host="127.0.0.1", port=8100, storage="1"):
     usage = "usage: %prog [options] command [command-options]"
     description = ("Connect to a RAIDStorage on a ZEO server and perform "
                    "maintenance tasks. Available commands: status, details, "
-                   "recover <STORAGE>, disable <STORAGE>")
+                   "recover <STORAGE>, disable <STORAGE>, add <IP:PORT:STORAGE>")
 
     parser = optparse.OptionParser(usage=usage, description=description)
     parser.add_option("-S", "--storage", default=storage,

Modified: gocept.zeoraid/branches/dirceu-addstoragetool/src/gocept/zeoraid/storage.py
===================================================================
--- gocept.zeoraid/branches/dirceu-addstoragetool/src/gocept/zeoraid/storage.py	2008-07-25 00:04:58 UTC (rev 88803)
+++ gocept.zeoraid/branches/dirceu-addstoragetool/src/gocept/zeoraid/storage.py	2008-07-25 00:07:02 UTC (rev 88804)
@@ -32,6 +32,7 @@
 import transaction
 import transaction.interfaces
 import ZODB.blob
+import ZODB.config
 
 import gocept.zeoraid.interfaces
 import gocept.zeoraid.recovery
@@ -55,6 +56,20 @@
     return check_writable
 
 
+class ZEOOpener(object):
+
+    def __init__(self, ip, port, name):
+        self.ip = ip
+        self.name = name
+        self.port = port
+
+    def open(self, **kwargs):
+        return ZODB.config.storageFromString("""<zeoclient>
+            server %s:%s
+            storage %s
+        </zeoclient>""" % (self.ip, self.port, self.name))
+
+
 class RAIDStorage(object):
     """The RAID storage is a drop-in replacement for the client storages that
     are configured.
@@ -524,7 +539,8 @@
     def getExtensionMethods(self):
         # This method isn't officially part of the interface but it is supported.
         methods = dict.fromkeys(
-            ['raid_recover', 'raid_status', 'raid_disable', 'raid_details'])
+            ['raid_recover', 'raid_status', 'raid_disable', 'raid_details',
+            'raid_add_storage'])
         return methods
 
     # IRAIDStorage
@@ -560,6 +576,13 @@
         t.start()
         return 'recovering %r' % (name,)
 
+    def raid_add_storage(self, ip, port, name):
+        self.openers[name] = ZEOOpener(ip, port, name)
+        self._open_storage(name)
+        self.storages_degraded.append(name)
+        self.raid_recover(name)
+        return 'added %s:%s:%s' % (ip, port, name)
+
     # internal
 
     def _open_storage(self, name):



More information about the Checkins mailing list