From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/luci/utils luci_admin
Date: 16 Jun 2006 19:35:33 -0000 [thread overview]
Message-ID: <20060616193533.15989.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2006-06-16 19:35:33
Modified files:
luci/utils : luci_admin
Log message:
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/utils/luci_admin.diff?cvsroot=cluster&r1=1.10&r2=1.11
--- conga/luci/utils/luci_admin 2006/06/16 18:17:24 1.10
+++ conga/luci/utils/luci_admin 2006/06/16 19:35:33 1.11
@@ -33,6 +33,8 @@
import Products.CMFCore.MemberDataTool
import transaction
+LUCI_INIT_DEBUG = 0
+
LUCI_USER='luci'
LUCI_GROUP='luci'
@@ -50,6 +52,14 @@
'Products.CMFCore.MemberDataTool.MemberData'
]
+null = file('/dev/null', 'rwb+', 0)
+
+if LUCI_INIT_DEBUG:
+ verbose = sys.stderr
+else:
+ verbose = null
+orig_stderr = sys.stderr
+
def luci_restore(argv):
if len(argv) > 0:
dbfn = argv[0]
@@ -67,40 +77,56 @@
db.pack()
conn = db.open()
except:
- stderr.write('Unable to open the luci database \"' + dbfn + '\"\n')
- sys.exit(1)
+ stderr.write('Unable to open the Luci database \"' + dbfn + '\"\n')
+ return -1
try:
node = xml.dom.minidom.parse(backupfn)
except:
- stderr.write('Unable to open the luci backup file \"'+ backupfn +'\"\n')
- sys.exit(1)
+ stderr.write('Unable to open the Luci backup file \"'+ backupfn +'\"\n')
+ return -1
node = node.getElementsByTagName('luci')
if not node or len(node) < 1:
sys.stderr.write('Backup file is missing the \'luci\' tag\n')
- sys.exit(1)
+ return -1
node = node[0].getElementsByTagName('backupData')
if not node or len(node) < 1:
sys.stderr.write('Backup file is missing the \'backupData\' tag\n')
- sys.exit(1)
+ return -1
node = node[0]
- tempuser = AccessControl.User.UnrestrictedUser('admin', '',
- ('manage','Manager', 'Owner', 'View', 'Authenticated'), [])
+ try:
+ sys.stderr = null
+ tempuser = AccessControl.User.UnrestrictedUser('admin', '',
+ ('manage','Manager', 'Owner', 'View', 'Authenticated'), [])
- newSecurityManager(None, tempuser)
+ newSecurityManager(None, tempuser)
- app = conn.root()['Application']
- AppInitializer(app).initialize()
+ app = conn.root()['Application']
+ AppInitializer(app).initialize()
+ sys.stderr = orig_stderr
+ except:
+ sys.stderr = orig_stderr
+ sys.stderr.write('An error occurred while initializing the Luci installation for restoration from backup\n')
+ return -1
- portal_mem = app.unrestrictedTraverse('/luci/portal_membership')
- portal_reg = app.unrestrictedTraverse('/luci/portal_registration')
+ try:
+ portal_mem = app.unrestrictedTraverse('/luci/portal_membership')
+ portal_reg = app.unrestrictedTraverse('/luci/portal_registration')
+ if not portal_mem or not portal_reg:
+ raise
+ except:
+ sys.stderr.write('Your Luci installation appears to be corrupt. Please reinstall, then try to restore again.')
+ return -1
userList = node.getElementsByTagName('userList')
- if userList and len(userList) > 0:
- userList = userList[0].getElementsByTagName('user')
+ if not userList or len(userList) < 1:
+ sys.stderr.write('Your backup file contains no users. At the very least, the admin user must exist. Please check that your backup file is not corrupt.\n')
+ return -1
+
+ userList = userList[0].getElementsByTagName('user')
for u in userList:
id = u.getAttribute('id')
if not id:
@@ -134,10 +160,21 @@
member = portal_mem.getMemberById(id)
if not member:
transaction.abort()
- sys.stderr.write('Error adding user \"' + id + '\"\n')
+ sys.stderr.write('An error occurred while restoring the user \"' + id + '\"\n')
+ return -1
+
+ verbose.write('Added user \"' + id + '\"\n')
#transaction.commit()
- x = app.unrestrictedTraverse('/luci/systems/storage')
+ try:
+ x = app.unrestrictedTraverse('/luci/systems/storage')
+ if not x:
+ raise
+ except:
+ sys.stderr.write('Cannot find the Luci storage systems directory. Your Luci installation may be corrupt.')
+ transaction.abort()
+ return -1
+
systemList = node.getElementsByTagName('systemList')
if not systemList or len(systemList) < 1:
sys.write.stderr('No storage systems to add')
@@ -158,9 +195,9 @@
if not new_system:
raise
except:
- sys.stderr.write('Unable to add system \"' + id + '\"\n')
+ sys.stderr.write('An error occurred while restoring storage system \"' + id + '\"\n')
transaction.abort()
- sys.exit(1)
+ return -1
userPerms = s.getElementsByTagName('permList')
if not userPerms or len(userPerms) < 1:
@@ -173,9 +210,18 @@
if not newuser:
continue
new_system.manage_setLocalRoles(newuser, ['View'])
+
+ verbose.write('Added storage system \"' + id + '\"\n')
#transaction.commit()
- x = app.unrestrictedTraverse('/luci/systems/cluster')
+ try:
+ x = app.unrestrictedTraverse('/luci/systems/cluster')
+ if not x:
+ raise
+ except:
+ sys.stderr.write('Cannot find the Luci cluster directory. Your Luci installation may be corrupt.')
+ transaction.abort()
+ return -1
clusterList = node.getElementsByTagName('cluster')
for c in clusterList:
id = c.getAttribute('id')
@@ -191,9 +237,9 @@
if not new_cluster:
raise
except:
- sys.stderr.write('Error adding cluster \"' + id + '\"\n')
+ sys.stderr.write('An error occurred while restoring the cluster \"' + id + '\"\n')
transaction.abort()
- sys.exit(1)
+ return -1
userPerms = c.getElementsByTagName('permList')
if not userPerms or len(userPerms) < 1:
@@ -209,13 +255,13 @@
clusterSystems = c.getElementsByTagName('systemsList')
if not clusterSystems or len(clusterSystems) < 1:
- sys.stderr.write('No cluster storage systems to add\n')
+ verbose.write('Cluster \"' + id + '\" has no storage systems\n')
continue
clusterSystems = clusterSystems[0].getElementsByTagName('ref')
for i in clusterSystems:
newsys = i.getAttribute('name')
if not newsys:
- sys.stderr.write('Cluster system element missing name tag\n')
+ sys.stderr.write('Storage system missing name for cluster \"' + id + '\"\n')
continue
newsys = str(newsys)
stitle = i.getAttribute('title')
@@ -223,15 +269,26 @@
stitle = str(stitle)
else:
stitle = None
+ try:
x.manage_addFolder(newsys, stitle)
-
+ newcs = app.unrestrictedTraverse('/luci/systems/cluster/' + id + '/' + newsys)
+ if not newcs:
+ raise
+ except:
+ sys.stderr.write('An error occurred while restoring the storage system \"' + newsys + '\" for cluster \"' + id + '\"')
+ transaction.abort()
+ return -1
+ verbose.write('Added storage system \"' + newsys + '\" for cluster \"' + id)
+ verbose.write('Added cluster\"' + id + '\"')
#transaction.commit()
+ #transaction.commit()
transaction.abort()
conn.close()
db.pack()
db.close()
fs.close()
+ return 0
# This function's ability to work is dependent
# upon the structure of @dict
@@ -290,39 +347,36 @@
sys.stderr.write('Unable to open \"' + backupfn + '\" to write backup.\n')
sys.exit(1)
- # To suppress some meaningless zope errors upon unpickling certain
- # kinds of objects.
- temp = sys.stderr
- null = file('/dev/null')
+ # To suppress some useless zope error messages.
+ sys.stderr = null
next_oid = None
while True:
oid, tid, data, next_oid = fs.record_iternext(next_oid)
- sys.stderr = null
try:
obj = conn.get(oid)
obj_class = str(type(obj)).split('\'')[1]
except:
- continue
- sys.stderr = temp
+ if next_oid is None: break
+ else: continue
if not obj_class in examine_classes:
- continue
+ if next_oid is None: break
+ else: continue
- # for some reason, when stderr is dumped to /dev/null
- # something goes wrong here, which is why it's set and restored
- # inside the loop.
try:
conn.setstate(obj)
except:
- continue
+ if next_oid is None: break
+ else: continue
dict = obj.__dict__
if obj_class == 'OFS.Folder.Folder':
if not 'title' in dict or dict['title'][0:9] != '__luci__:':
- continue
+ if next_oid is None: break
+ else: continue
title = dict['title'].split(':')
cur = None
@@ -350,7 +404,8 @@
cur = systems[dict['id']]
else:
# we don't care
- continue
+ if next_oid is None: break
+ else: continue
if cur:
roles = dict['__ac_local_roles__']
@@ -373,7 +428,8 @@
cur_user['passwd'] = dict['__']
elif obj_class == 'Products.CMFCore.MemberDataTool.MemberData':
if not 'id' in dict and not 'name' in dict:
- continue
+ if next_oid is None: break
+ else: continue
try:
cur_user = users[dict['id']]
@@ -388,7 +444,8 @@
cur_user[i] = dict[i]
if next_oid is None:
break
- sys.stderr = temp
+
+ sys.stderr = orig_stderr
null.close()
conn.close()
db.close()
@@ -411,7 +468,7 @@
luciData = doc.createElement('luci')
doc.appendChild(luciData)
dataNode = dataToXML(doc, backup, 'backupData')
-
+
try:
certfile = file(SSL_PRIVKEY_PATH, 'rb')
output = certfile.read()
next reply other threads:[~2006-06-16 19:35 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-16 19:35 rmccabe [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-03-25 20:14 [Cluster-devel] conga/luci/utils luci_admin rmccabe
2007-09-19 5:17 rmccabe
2007-08-10 18:36 rmccabe
2007-08-10 18:33 rmccabe
2007-08-10 18:32 rmccabe
2007-08-07 20:22 rmccabe
2006-10-13 6:56 kupcevic
2006-08-18 18:03 rmccabe
2006-08-04 19:19 rmccabe
2006-08-04 18:37 rmccabe
2006-08-03 22:58 kupcevic
2006-08-03 21:19 rmccabe
2006-08-03 21:11 rmccabe
2006-08-03 16:32 rmccabe
2006-08-03 15:55 rmccabe
2006-08-03 12:26 rmccabe
2006-08-03 3:58 rmccabe
2006-08-03 3:30 rmccabe
2006-08-02 23:29 rmccabe
2006-08-02 20:52 rmccabe
2006-08-02 20:45 rmccabe
2006-07-26 1:17 rmccabe
2006-07-25 22:36 rmccabe
2006-07-11 18:46 rmccabe
2006-07-11 14:51 rmccabe
2006-06-29 18:04 rmccabe
2006-06-29 17:51 rmccabe
2006-06-27 19:50 rmccabe
2006-06-27 19:40 rmccabe
2006-06-27 18:19 rmccabe
2006-06-26 22:30 rmccabe
2006-06-26 20:01 rmccabe
2006-06-21 23:06 rmccabe
2006-06-21 17:41 rmccabe
2006-06-21 17:06 rmccabe
2006-06-18 15:02 rmccabe
2006-06-18 12:50 rmccabe
2006-06-18 3:26 rmccabe
2006-06-16 23:19 rmccabe
2006-06-16 18:17 rmccabe
2006-06-16 17:44 rmccabe
2006-06-16 5:35 rmccabe
2006-06-13 18:42 rmccabe
2006-06-13 17:36 rmccabe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060616193533.15989.qmail@sourceware.org \
--to=rmccabe@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).