[Checkins] SVN: gocept.zeoraid/trunk/ Extend management script to
allow use as `console_script`
Christian Theune
ct at gocept.com
Thu Mar 27 08:23:07 EDT 2008
Log message for revision 84961:
Extend management script to allow use as `console_script`
Changed:
U gocept.zeoraid/trunk/base.cfg
U gocept.zeoraid/trunk/setup.py
A gocept.zeoraid/trunk/src/gocept/zeoraid/scripts/__init__.py
U gocept.zeoraid/trunk/src/gocept/zeoraid/scripts/controller.py
-=-
Modified: gocept.zeoraid/trunk/base.cfg
===================================================================
--- gocept.zeoraid/trunk/base.cfg 2008-03-27 10:33:46 UTC (rev 84960)
+++ gocept.zeoraid/trunk/base.cfg 2008-03-27 12:23:06 UTC (rev 84961)
@@ -1,6 +1,6 @@
[buildout]
develop = . externals/ZODB
-parts = zodbscripts test client server1 server2 zeoraid
+parts = zodbscripts test client server1 server2 zeo
find-links = http://download.zope.org/distribution/
@@ -36,7 +36,7 @@
path ${storage2:path}
</filestorage>
-[zeoraid]
+[zeo]
recipe = zc.zodbrecipes:server
eggs = gocept.zeoraid
zeo.conf =
Modified: gocept.zeoraid/trunk/setup.py
===================================================================
--- gocept.zeoraid/trunk/setup.py 2008-03-27 10:33:46 UTC (rev 84960)
+++ gocept.zeoraid/trunk/setup.py 2008-03-27 12:23:06 UTC (rev 84961)
@@ -19,7 +19,7 @@
name = "gocept.zeoraid"
setup(
name = name,
- version = "dev",
+ version = "1.0a1",
author = "Christian Theune",
author_email = "ct at gocept.com",
description = "A ZODB storage for replication using RAID techniques.",
@@ -39,8 +39,11 @@
extras_require = {
'recipe': ['zc.buildout']
},
- entry_points = {
- 'zc.buildout': [
- 'default = %s.recipe:Recipe [recipe]' % name,
- ]},
+ entry_points = """
+ [zc.buildout]
+ default = %s.recipe:Recipe [recipe]
+
+ [console_scripts]
+ zeoraid = gocept.zeoraid.scripts.controller:main
+ """ % name,
)
Added: gocept.zeoraid/trunk/src/gocept/zeoraid/scripts/__init__.py
===================================================================
--- gocept.zeoraid/trunk/src/gocept/zeoraid/scripts/__init__.py (rev 0)
+++ gocept.zeoraid/trunk/src/gocept/zeoraid/scripts/__init__.py 2008-03-27 12:23:06 UTC (rev 84961)
@@ -0,0 +1 @@
+# Make this a Python package
Property changes on: gocept.zeoraid/trunk/src/gocept/zeoraid/scripts/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: gocept.zeoraid/trunk/src/gocept/zeoraid/scripts/controller.py
===================================================================
--- gocept.zeoraid/trunk/src/gocept/zeoraid/scripts/controller.py 2008-03-27 10:33:46 UTC (rev 84960)
+++ gocept.zeoraid/trunk/src/gocept/zeoraid/scripts/controller.py 2008-03-27 12:23:06 UTC (rev 84961)
@@ -12,55 +12,91 @@
#
##############################################################################
"""The management utility for gocept.zeoraid.
-"""
-import sys
+Usage: controller.py [options] <command> [command_options]
-import ZEO.zrpc.client
+Options:
-import logging
-logging.getLogger().addHandler(logging.StreamHandler())
+ -p port -- port to connect to (default is 8100)
-class RAIDManager(object):
+ -h host -- host to connect to (default is 127.0.0.1)
- def __init__(self):
- self.manager = ZEO.zrpc.client.ConnectionManager(('127.0.0.1', 8100), self)
- self.manager.connect(True)
+ -S name -- storage name (default is '1')
- def testConnection(self, connection):
- # This is a preferred connection
- return 1
+Commands:
- def notifyConnected(self, connection):
- self.connection = connection
- self.connection.call('register', '1', True)
+ status -- Print short status information
- def status(self):
- return self.connection.call('raid_status')
+ details -- Print detailed status information
- def recover(self, storage):
- return self.connection.call('raid_recover', storage)
+ recover <storage> -- Start recovery for a storage
- def disable(self, storage):
- return self.connection.call('raid_disable', storage)
+ disable <storage> -- Disable a storage
- def details(self):
- return self.connection.call('raid_details')
+"""
-if __name__ == '__main__':
- m = RAIDManager()
+import optparse
+import sys
- if sys.argv[1] == 'status':
- print m.status()
- elif sys.argv[1] == 'details':
- ok, recovering, failed = m.details()
+import ZEO.ClientStorage
+
+import logging
+
+
+class RAIDManager(object):
+
+ def __init__(self, host, port, storage):
+ self.host = host
+ self.port = port
+ self.storage = storage
+
+ self.raid = ZEO.ClientStorage.ClientStorage(
+ (self.host, self.port), storage=self.storage, wait=1, read_only=1)
+
+ def cmd_status(self):
+ print self.raid.raid_status()
+
+ def cmd_details(self):
+ ok, recovering, failed = self.raid.raid_details()
print "RAID status:"
- print "\t", m.status()
+ print "\t", self.raid.raid_status()
print "Storage status:"
print "\toptimal\t\t", ok
print "\trecovering\t", recovering
print "\tfailed\t\t", failed
- elif sys.argv[1] == 'disable':
- print m.disable(sys.argv[2])
- elif sys.argv[1] == 'recover':
- print m.recover(sys.argv[2])
+
+ def cmd_recover(self, storage):
+ print self.raid.raid_recover(storage)
+
+ def cmd_disable(self, storage):
+ print self.raid.raid_disable(storage)
+
+
+def main():
+ 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>")
+
+ parser = optparse.OptionParser(usage=usage, description=description)
+ parser.add_option("-S", "--storage", default="1",
+ help="Use STORAGE on ZEO server. Default: %default")
+ parser.add_option("-H", "--host", default="127.0.0.1",
+ help="Connect to HOST. Default: %default")
+ parser.add_option("-p", "--port", type="int", default=8100,
+ help="Connect to PORT. Default: %default")
+ options, args = parser.parse_args()
+
+ if not args:
+ parser.error("no command given")
+
+ command, subargs = args[0], args[1:]
+
+ logging.getLogger().addHandler(logging.StreamHandler())
+ m = RAIDManager(options.host, options.port, options.storage)
+ command = getattr(m, 'cmd_%s' % command)
+ command(*subargs)
+
+
+if __name__ == '__main__':
+ main()
More information about the Checkins
mailing list