[Cluster-devel] conga/luci/utils luci_admin

rmccabe at sourceware.org rmccabe at sourceware.org
Fri Jun 16 17:44:17 UTC 2006


CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2006-06-16 17:44:17

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.8&r2=1.9

--- conga/luci/utils/luci_admin	2006/06/16 05:35:22	1.8
+++ conga/luci/utils/luci_admin	2006/06/16 17:44:17	1.9
@@ -74,45 +74,50 @@
 	try:
 		node = xml.dom.minidom.parse(backupfn)
 	except:
-		stderr.write('Unable to open the luci backup file \"' + backupfn + '\"\n')
+		stderr.write('Unable to open the luci backup file \"'+ backupfn +'\"\n')
 		sys.exit(1)
 
-	if node.firstChild.nodeName != 'luci':
-		'The backup file \"' + backupfn + '\" is not in the expected format (expected <luci>)\n'
+	node = node.getElementsByName('luci')
+	if not node:
+		sys.stderr.write('Backup file is missing the \'luci\' tag\n')
 		sys.exit(1)
 
-	if not node.getElementsByTagName('backupData'):
-		'The backup file \"' + backupfn + '\" is not in the expected format (expected <luci>)\n'
+	node = node.getElementsByName('backupData')
+	if not node:
+		sys.stderr.write('Backup file is missing the \'backupData\' tag\n')
 		sys.exit(1)
 
 	tempuser = AccessControl.User.UnrestrictedUser('admin', '',
 				('manage','Manager', 'Owner', 'View', 'Authenticated'), [])
+
 	newSecurityManager(None, tempuser)
 
 	app = conn.root()['Application']
 	AppInitializer(app).initialize()
 
 	portal_mem = app.unrestrictedTraverse('/luci/portal_membership')
+
 	userList = node.getElementsByTagName('user')
 	for u in userList:
 		id = u.getAttribute('id')
 		if not id:
-			sys.stderr.write('Missing ID for user')
+			sys.stderr.write('Missing ID for user\n')
 			continue
 		id = str(id)
 
 		passwd = u.getAttribute('passwd')
 		if not passwd:
-			sys.stderr.write('Missing password for user \"' + id + '\"')
+			sys.stderr.write('Missing password for user \"' + id + '\"\n')
 			continue
 		passwd = str(passwd)
 
-		email = u.getAttribute('email')
-		if not email:
-			email = id + '@luci.example.org'
-		else:
-			email = str(email)
 		if id != 'admin':
+			email = u.getAttribute('email')
+			if not email:
+				email = id + '@luci.example.org'
+			else:
+				email = str(email)
+
 			props = {
 				'username': id,
 				'roles': [ 'Member' ],
@@ -126,22 +131,37 @@
 			member = portal_mem.getMemberById(id)
 			if not member:
 				transaction.abort()
-				sys.stderr.write('Error adding user \"' + id + '\"')
-			#transaction.commit()
+				sys.stderr.write('Error adding user \"' + id + '\"\n')
+		#transaction.commit()
 
 	x = app.unrestrictedTraverse('/luci/systems/storage')
-	systemList = node.getElementsByTagName('system')
+	systemList = node.getElementsByTagName('systemList')
+	if not systemList:
+		sys.write.stderr('No storage systems to add')
+	else:
+		systemList = systemList.getElementsByTagName('system')
 	for s in systemList:
 		id = s.getAttribute('id')
 		if not id:
+			sys.stderr.write('Missing ID for storage system')
 			continue
 		id = str(id)
 		title = str(s.getAttribute('title'))
 
 		x.manage_addFolder(id)
-		new_system = app.unrestrictedTraverse('/luci/systems/storage/' + id)
+		try:
+			new_system = app.unrestrictedTraverse('/luci/systems/storage/' + id)
+			if not new_system:
+				raise
+		except:
+			sys.stderr.write('Unable to add system \"' + id + '\"\n')
+			transaction.abort()
+			sys.exit(1)
 
-		userPerms = s.getElementsByTagName('permList')[0].childNodes
+		userPerms = s.getElementsByTagName('permList')
+		if not userPerms:
+			continue
+		userPerms = userPerms.getElementsByTagName('ref')
 		for i in userPerms:
 			if i.nodeType != xml.dom.Node.ELEMENT_NODE:
 				continue
@@ -149,7 +169,6 @@
 			if not newuser:
 				continue
 			new_system.setLocalRoles(newuser, ['View'])
-
 		#transaction.commit()
 
 	x = app.unrestrictedTraverse('/luci/systems/cluster')
@@ -157,17 +176,24 @@
 	for c in clusterList:
 		id = c.getAttribute('id')
 		if not id:
+			sys.stderr.write('Cluster element is missing id\n')
 			continue
 		id = str(id)
 		title = str(c.getAttribute('title'))
 
-		new_cluster = app.unrestrictedTraverse('/luci/systems/cluster/' + id)
-		if not new_cluster:
-			print 'error adding cluster',id
+		try:
+			new_cluster = app.unrestrictedTraverse('/luci/systems/cluster/'+ id)
+			if not new_cluster:
+				raise
+		except:
+			sys.stderr.write('Error adding cluster \"' + id + '\"\n')
 			tranaction.abort()
 			sys.exit(1)
 
-		userPerms = c.getElementsByTagName('permList')[0].childNodes
+		userPerms = c.getElementsByTagName('permList')
+		if not userPerms:
+			continue
+		userPerms = userPerms.getElementsByTagName('ref')
 		for i in userPerms:
 			if i.nodeType != xml.dom.Node.ELEMENT_NODE:
 				continue
@@ -176,15 +202,19 @@
 				continue
 			new_cluster.setLocalRoles(newuser, ['View'])
 
-		clusterSystems = c.getElementsByTagName('systemsList')[0].childNodes
+		clusterSystems = c.getElementsByTagName('systemsList')
+		if not clusterSystems:
+			sys.stderr.write('No cluster storage systems to add\n')
+			continue
+		clusterSystems = clusterSystems.getElementsByTagName('ref')
 		for i in clusterSystems:
-			if i.nodeType != xml.dom.Node.ELEMENT_NODE:
-				continue
 			newsys = i.getAttribute('name')
 			if not newsys:
+				sys.stderr.write('Cluster system element missing name tag\n')
 				continue
 			newsys = str(newsys)
 			x.manage_addFolder(newsys)
+		#transaction.commit()
 
 	transaction.abort()
 	conn.close()




More information about the Cluster-devel mailing list