[Cluster-devel] conga/luci/utils luci_admin
rmccabe at sourceware.org
rmccabe at sourceware.org
Tue Jun 13 17:36:20 UTC 2006
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2006-06-13 17:36:20
Modified files:
luci/utils : luci_admin
Log message:
new backup
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/utils/luci_admin.diff?cvsroot=cluster&r1=1.4&r2=1.5
--- conga/luci/utils/luci_admin 2006/06/06 21:05:43 1.4
+++ conga/luci/utils/luci_admin 2006/06/13 17:36:20 1.5
@@ -12,17 +12,10 @@
from sys import stderr, argv
from ZODB.FileStorage import FileStorage
from ZODB.DB import DB
-from ZODB.serialize import referencesf
-from ZODB.ExportImport import *
-from ZODB.FileStorage.format import *
-from ZODB.Connection import *
-from OFS.ZDOM import *
-import OFS
-from OFS.XMLExportImport import *
-from Products.ZODBMountPoint import MountedObject
-
-
-
+import xml
+import xml.dom
+from xml.dom import minidom
+import types
LUCI_USER='zope'
@@ -39,6 +32,34 @@
print "TODO: implement me"
return 1
+# This function's ability to work is dependent
+# upon the structure of @dict
+def dataToXML(doc, dict, tltag):
+ node = doc.createElement(tltag)
+ for i in dict:
+ if isinstance(dict[i], types.DictType):
+ if i[-4:] == 'List':
+ tagname = i
+ else:
+ tagname = tltag[:-4]
+ temp = dataToXML(doc, dict[i], tagname)
+ node.appendChild(temp)
+ elif isinstance(dict[i], types.StringType) or isinstance(dict[i], types.IntType):
+ temp = doc.createElement('item')
+ temp.setAttribute('key', i)
+ temp.setAttribute('value', str(dict[i]))
+ node.appendChild(temp.cloneNode(True))
+ elif isinstance(dict[i], types.ListType):
+ if len(dict[i]) < 1:
+ continue
+ temp = doc.createElement(i)
+ for x in dict[i]:
+ t = doc.createElement('ref')
+ t.setAttribute('name', x)
+ temp.appendChild(t.cloneNode(True))
+ node.appendChild(temp.cloneNode(True))
+ return node.cloneNode(True)
+
def luci_backup(argv):
if len(argv) > 0:
dbfn = argv[0]
@@ -54,6 +75,10 @@
stderr.write('Unable to open the luci database \"' + dbfn + '\"\n')
sys.exit(1)
+ systems = {}
+ clusters = {}
+ users = {}
+
examine_classes = [ 'OFS.Folder.Folder',
'AccessControl.User.User',
'Products.CMFCore.MemberDataTool.MemberData' ]
@@ -78,7 +103,6 @@
sys.stderr = null
f.write('<?xml version="1.0"?>\n')
- f.write('<ZopeData>\n')
next_oid = None
while True:
@@ -87,81 +111,137 @@
try:
obj = conn.get(oid)
obj_class = str(type(obj)).split('\'')[1]
+ except:
+ continue
- if obj_class in examine_classes:
- conn.setstate(obj)
- if obj_class == 'OFS.Folder.Folder':
- if obj.__dict__['title'].split(':')[0] != '__luci__':
- raise
- elif obj_class == 'AccessControl.User.User':
- if not 'name' in obj.__dict__ or not '__' in obj.__dict__ or obj.__dict__['__'][0] != '{':
- raise
- elif obj_class == 'Products.CMFCore.MemberDataTool.MemberData':
- if not 'id' in obj.__dict__:
- raise
-
- # This better not fail.
- try:
- pickle, serial = conn._storage.load(oid, conn._version)
- referencesf(pickle, [oid])
- f.write(OFS.XMLExportImport.XMLrecord(oid, len(pickle), pickle))
- except:
- sys.stderr = temp
- sys.stderr.write('An error occurred while backing up the luci database.')
- sys.exit(1)
-
- # Anything that is caught here will have been raised by something
- # we don't care about.
- except: pass
+ if not obj_class in examine_classes:
+ continue
+ try:
+ conn.setstate(obj)
+ dict = obj.__dict__
+ except:
+ continue
+
+ if obj_class == 'OFS.Folder.Folder':
+ if not 'title' in dict or dict['title'][0:9] != '__luci__:':
+ continue
+ title = dict['title'].split(':')
+ cur = None
+
+ if title[1] == 'cluster':
+ clusters[dict['id']] = {
+ 'id': dict['id'],
+ 'title': dict['title'],
+ 'permList': [],
+ 'systemsList:': []
+ }
+ cur = clusters[dict['id']]
+ elif title[1] == 'csystem':
+ if len(title) > 2:
+ clusterName = title[2]
+ else:
+ parent = obj.parentNode()
+ clusterName = parent.__dict__['id']
+ clusters[clusterName]['systemsList'].append(dict['id'])
+ elif title[1] == 'system':
+ systems[dict['id']] = {
+ 'id': dict['id'],
+ 'title': dict['title'],
+ 'permList': []
+ }
+ cur = systems[dict['id']]
+ else:
+ # we don't care
+ continue
+
+ if cur:
+ roles = dict['__ac_local_roles__']
+ for i in roles:
+ if not i in users:
+ users[i] = { 'id': i }
+ if 'View' in roles[i]:
+ cur['permList'].append(i)
+ elif obj_class == 'AccessControl.User.User':
+ if not dict['name'] in users:
+ users[dict['name']] = {}
+ cur_user = users[dict['name']]
+ cur_user['name'] = dict['name']
+ cur_user['passwd'] = dict['__']
+ elif obj_class == 'Products.CMFCore.MemberDataTool.MemberData':
+ if not 'id' in dict:
+ continue
+ if not dict['id'] in users:
+ users[dict['id']] = {}
+ cur_user = users[dict['id']]
+ for i in dict:
+ cur_user[i] = dict[i]
if next_oid is None:
break
-
sys.stderr = temp
- f.write('</ZopeData>\n\n')
- f.flush()
- f.write('<CertificateData>\n\t<list>\n')
+ backup = {'systemList': systems, 'cluterList': clusters, 'userList': users }
+ doc = xml.dom.minidom.Document()
+ dataNode = dataToXML(doc, backup, 'backupData')
+
try:
certfile = file(SSL_PRIVKEY_PATH, 'rb')
output = certfile.read()
+
# should be at least some length greater than one
# TODO: find out what the min length of a valid keyfile is.
if len(output) < 1:
raise
- except:
+
+ certNode = doc.createElement('Certificate')
+ certNode.setAttribute('name', SSL_PRIVKEY_PATH)
+ certNode.setAttribute('data', output)
+ dataNode.appendChild(certNode.cloneNode(True))
+ certfile.close()
+ except False:
sys.stderr.write('Unable to read ' + SSL_PRIVKEY_PATH + '\n')
sys.exit(1)
- f.write('\t\t<tuple>\n\t\t\t<name=\"' + SSL_PRIVKEY_PATH + '\" />\n\t\t\t<data=\"' + output + '\" />\n\t\t</tuple>\n')
try:
certfile = file(SSL_PUBKEY_PATH, 'rb')
output = certfile.read()
+
# should be at least some length greater than one
# TODO: find out what the min length of a valid keyfile is.
if len(output) < 1:
raise
+
+ certNode = doc.createElement('Certificate')
+ certNode.setAttribute('name', SSL_PUBKEY_PATH)
+ certNode.setAttribute('data', output)
+ dataNode.appendChild(certNode.cloneNode(True))
+ certfile.close()
except:
sys.stderr.write('Unable to read ' + SSL_PUBKEY_PATH + '\n')
sys.exit(1)
- f.write('\t\t<tuple>\n\t\t\t<name=\"' + SSL_PUBKEY_PATH + '\" />\n\t\t\t<data=\"' + output + '\" />\n\t\t</tuple>\n')
try:
certfile = file(SSL_KEYCONFIG_PATH, 'rb')
output = certfile.read()
+
# should be at least some length greater than one
# TODO: find out what the min length of a valid key conf is.
if len(output) < 1:
raise
+
+ certNode = document.createElement('CertificateConfig')
+ certNode.setAttribute('name', SSL_KEYCONFIG_PATH)
+ certNode.setAttribute('data', output)
+ dataNode.appendChild(certNode.cloneNode(TRUE))
+ certfile.close()
except:
sys.stderr.write('Unable to read ' + SSL_KEYCONFIG_PATH + '\n')
- f.write('\t\t<tuple>\n\t\t\t<name=\"' + SSL_KEYCONFIG_PATH + '\" />\n\t\t\t<data=\"' + output + '\" />\n\t\t</tuple>\n')
- f.write('\t</list>\n</CertificateData>\n')
+ f.write(dataNode.toprettyxml())
+ f.flush()
f.close()
-
def _execWithCaptureErrorStatus(command, argv, searchPath = 0, root = '/', stdin = 0, catchfd = 1, catcherrfd = 2, closefd = -1):
if not os.access (root + command, os.X_OK):
raise RuntimeError, command + " can not be run"
More information about the Cluster-devel
mailing list