All of lore.kernel.org
 help / color / mirror / Atom feed
From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/luci/utils luci_admin
Date: 16 Jun 2006 23:19:59 -0000	[thread overview]
Message-ID: <20060616231959.27794.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2006-06-16 23:19:59

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.11&r2=1.12

--- conga/luci/utils/luci_admin	2006/06/16 19:35:33	1.11
+++ conga/luci/utils/luci_admin	2006/06/16 23:19:58	1.12
@@ -118,7 +118,7 @@
 		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.')
+		sys.stderr.write('Your Luci installation appears to be corrupt.')
 		return -1
 
 	userList = node.getElementsByTagName('userList')
@@ -127,6 +127,10 @@
 		return -1
 
 	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
+	
 	for u in userList:
 		id = u.getAttribute('id')
 		if not id:
@@ -164,7 +168,8 @@
 				return -1
 
 			verbose.write('Added user \"' + id + '\"\n')
-		#transaction.commit()
+		transaction.commit()
+
 
 	try:
 		x = app.unrestrictedTraverse('/luci/systems/storage')
@@ -180,14 +185,20 @@
 		sys.write.stderr('No storage systems to add')
 	else:
 		systemList = systemList[0].getElementsByTagName('system')
+		if len(systemList) < 1:
+			sys.write.stderr('No storage systems to add')
 
 	for s in systemList:
 		id = s.getAttribute('id')
 		if not id:
-			sys.stderr.write('Missing ID for storage system')
-			continue
+			sys.stderr.write('Missing ID for storage system. Your backup may be corrupt.\n')
+			transaction.abort()
+			return -1
 		id = str(id)
-		title = str(s.getAttribute('title'))
+		try:
+			title = str(s.getAttribute('title'))
+		except:
+			title = '__luci__:system'
 
 		x.manage_addFolder(id, title)
 		try:
@@ -201,18 +212,21 @@
 
 		userPerms = s.getElementsByTagName('permList')
 		if not userPerms or len(userPerms) < 1:
+			verbose.write('Added storage system \"' + id + '\"\n')
 			continue
 		userPerms = userPerms[0].getElementsByTagName('ref')
 		for i in userPerms:
-			if i.nodeType != xml.dom.Node.ELEMENT_NODE:
-				continue
 			newuser = i.getAttribute('name')
 			if not newuser:
 				continue
-			new_system.manage_setLocalRoles(newuser, ['View'])
+			try:
+				new_system.manage_setLocalRoles(newuser, ['View'])
+				verbose.write('Added view permission to storage system \"' + id + '\" for \"' + newuser + '\"\n')
+			except:
+				sys.stderr.write('An error occurred while restoring permission for storage system \"' + id + '\" for user \"' + newuser + '\"\n')
 
 		verbose.write('Added storage system \"' + id + '\"\n')
-		#transaction.commit()
+		transaction.commit()
 
 	try:
 		x = app.unrestrictedTraverse('/luci/systems/cluster')
@@ -222,14 +236,28 @@
 		sys.stderr.write('Cannot find the Luci cluster directory. Your Luci installation may be corrupt.')
 		transaction.abort()
 		return -1
-	clusterList = node.getElementsByTagName('cluster')
+
+	clusterList = node.getElementsByTagName('clusterList')
+	if not clusterList or len(clusterList) < 1:
+		verbose('No clusters to add')
+	else:
+		clusterList = clusterList[0].getElementsByTagName('cluster')
+		if len(clusterList) < 1:
+			verbose('No clusters to add')
+
 	for c in clusterList:
 		id = c.getAttribute('id')
 		if not id:
 			sys.stderr.write('Cluster element is missing id\n')
-			continue
+			transaction.abort()
+			return -1
 		id = str(id)
-		title = str(c.getAttribute('title'))
+
+		title = c.getAttribute('title')
+		if not title:
+			title = '__luci__:cluster'
+		else:
+			title = str(title)
 
 		try:
 			x.manage_addFolder(id, title)
@@ -241,49 +269,65 @@
 			transaction.abort()
 			return -1
 
+		viewperm = list()
+
 		userPerms = c.getElementsByTagName('permList')
-		if not userPerms or len(userPerms) < 1:
-			continue
-		userPerms = userPerms[0].getElementsByTagName('ref')
-		for i in userPerms:
-			if i.nodeType != xml.dom.Node.ELEMENT_NODE:
-				continue
-			newuser = i.getAttribute('name')
-			if not newuser:
-				continue
-			new_cluster.manage_setLocalRoles(newuser, ['View'])
+		if userPerms and len(userPerms) > 0:
+			userPerms = userPerms[0].getElementsByTagName('ref')
+			for i in userPerms:
+				newuser = i.getAttribute('name')
+				if not newuser:
+					continue
+				newuser = str(newuser)
 
-		clusterSystems = c.getElementsByTagName('systemsList')
+				try:
+					new_cluster.manage_setLocalRoles(newuser, ['View'])
+					verbose.write('Added view permission to cluster \"' + id + '\" for \"' + newuser + '\"\n')
+				except:
+					sys.stderr.write('An error occurred while restoring permission for cluster \"' + id + '\" for user \"' + newuser + '\"\n')
+				viewperm.append(newuser)
+
+		clusterSystems = c.getElementsByTagName('csystemList')
 		if not clusterSystems or len(clusterSystems) < 1:
 			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('Storage system missing name for cluster \"' + id + '\"\n')
-				continue
-			newsys = str(newsys)
-			stitle = i.getAttribute('title')
-			if stitle:
-				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()
+		else:
+			clusterSystems = clusterSystems[0].getElementsByTagName('csystem')
+			for i in clusterSystems:
+				newsys = i.getAttribute('id')
+				if not newsys:
+					sys.stderr.write('Storage system missing name for cluster \"' + id + '\"\n')
+					continue
+				newsys = str(newsys)
+				stitle = i.getAttribute('title')
+				if not stitle:
+					stitle = '__luci__:csystem:' + id
+				else:
+					stitle = str(stitle)
+
+				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 + '\"\n')
+					transaction.abort()
+					return -1
+				transaction.commit()
+
+				try:
+					for i in viewperm:
+						newcs.manage_setLocalRoles(i, ['View'])
+						verbose.write('Added view permission to cluster system \"' + newsys + '\" for \"' + i + '\"\n')
+				except:
+					sys.stderr.write('An error occurred while restoring permissions for cluster system \"' + newsys + '\" in cluster \"' + id + '\" for user \"' + i + '\"\n')
+					transaction.abort()
+					return -1
+				verbose.write('Added storage system \"' + newsys + '\" for cluster \"' + id + '\"\n')
+		verbose.write('Added cluster \"' + id + '\"\n')
+		transaction.commit()
 
-	#transaction.commit()
-	transaction.abort()
+	transaction.commit()
 	conn.close()
 	db.pack()
 	db.close()
@@ -328,7 +372,7 @@
 		conn = db.open()
 	except:
 		stderr.write('Unable to open the luci database \"' + dbfn + '\"\n')
-		sys.exit(1)
+		return -1
 
 	systems = {}
 	clusters = {}
@@ -339,14 +383,6 @@
 	else:
 		backupfn = LUCI_BACKUP_PATH
 
-	# TODO: this needs to backup the backup, if any, and should
-	# write to a tempfile, then rename.
-	try:
-		f = file(backupfn, 'w')
-	except:
-		sys.stderr.write('Unable to open \"' + backupfn + '\" to write backup.\n')
-		sys.exit(1)
-
 	# To suppress some useless zope error messages.
 	sys.stderr = null
 
@@ -374,27 +410,38 @@
 		dict = obj.__dict__
 
 		if obj_class == 'OFS.Folder.Folder':
-			if not 'title' in dict or dict['title'][0:9] != '__luci__:':
+			if not 'title' in dict or not dict['title'] or dict['title'][0:9] != '__luci__:':
 				if next_oid is None: break
 				else: 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']]
+				if not dict['id'] in clusters:
+					clusters[dict['id']] = {
+						'id': dict['id'],
+						'title': dict['title'],
+						'permList': [],
+						'csystemList': {}
+					}
+					cur = clusters[dict['id']]
+				else:
+					cur = clusters[dict['id']]
+					cur['id'] = dict['id']
+					cur['title'] = dict['title']
 			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'])
+				if not clusterName in clusters:
+					clusters[clusterName] = {
+						'id': clusterName,
+						'csystemList': {},
+						'permList': []
+					}
+				clusters[clusterName]['csystemList'][dict['id']] = {
+					'id': dict['id'],
+					'title': '__luci__:csystem:' + clusterName,
+				}
 			elif title[1] == 'system':
 				systems[dict['id']] = {
 					'id': dict['id'],
@@ -407,7 +454,7 @@
 				if next_oid is None: break
 				else: continue
 
-			if cur:
+			if cur and '__ac_local_roles__' in dict:
 				roles = dict['__ac_local_roles__']
 				for i in roles:
 					if not i in users:
@@ -446,7 +493,6 @@
 			break
 
 	sys.stderr = orig_stderr
-	null.close()
 	conn.close()
 	db.close()
 	fs.close()
@@ -459,9 +505,9 @@
 		del users[i]
 
 	backup = {
+		'userList': users,
 		'systemList': systems,
-		'clusterList': clusters,
-		'userList': users
+		'clusterList': clusters
 	}
 
 	doc = xml.dom.minidom.Document()
@@ -485,7 +531,7 @@
 		certfile.close()
 	except False:
 		sys.stderr.write('Unable to read ' + SSL_PRIVKEY_PATH + '\n')
-		sys.exit(1)
+		return -1
 
 	try:
 		certfile = file(SSL_PUBKEY_PATH, 'rb')
@@ -503,7 +549,7 @@
 		certfile.close()
 	except:
 		sys.stderr.write('Unable to read ' + SSL_PUBKEY_PATH + '\n')
-		sys.exit(1)
+		return -1
 
 	try:
 		certfile = file(SSL_KEYCONFIG_PATH, 'rb')
@@ -523,6 +569,15 @@
 		sys.stderr.write('Unable to read ' + SSL_KEYCONFIG_PATH + '\n')
 
 	luciData.appendChild(dataNode)
+
+	# TODO: this needs to backup the backup, if any, and should
+	# write to a tempfile, then rename.
+	try:
+		f = file(backupfn, 'w')
+	except:
+		sys.stderr.write('Unable to open \"' + backupfn + '\" to write backup.\n')
+		return -1
+
 	f.write(doc.toprettyxml())
 	f.flush()
 	f.close()
@@ -735,16 +790,22 @@
         sys.exit(1)
         pass
     
-    print 'Backing up Luci server'
-    luci_backup(argv[2:])
-    
+    print 'Backing up the Luci server...'
+
+    if luci_backup(argv[2:]):
+        sys.write.stderr('The Luci backup failed.\n')
+        sys.exit(1)
+    print 'Backup was successful. The backup file is',LUCI_BACKUP_PATH
     return
 
 
 def restore(argv):
-    print 'Restoring Luci server'
+    print 'Restoring the Luci server...'
     
-    luci_restore(argv[2:])
+    if luci_restore(argv[2:]):
+        print 'The Luci restore failed. Try reinstalling Luci, then restoring again.'
+        sys.exit(1)
+
     restart_message()
     
     return



             reply	other threads:[~2006-06-16 23:19 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-16 23:19 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 19:35 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=20060616231959.27794.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.