[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/luci/site/luci/Extensions homebase_adapt ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2006-06-22 03:58:41

Modified files:
	luci/site/luci/Extensions: homebase_adapters.py 

Log message:
	

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/homebase_adapters.py.diff?cvsroot=cluster&r1=1.4&r2=1.5

--- conga/luci/site/luci/Extensions/homebase_adapters.py	2006/06/08 19:56:35	1.4
+++ conga/luci/site/luci/Extensions/homebase_adapters.py	2006/06/22 03:58:41	1.5
@@ -4,9 +4,7 @@
 import os
 from AccessControl import getSecurityManager
 from ZPublisher import HTTPRequest
-import xml
 import xml.dom
-from xml.dom import minidom
 
 from ricci_defines import *
 from ricci_communicator import RicciCommunicator
@@ -35,6 +33,9 @@
 	errors = list()
 	messages = list()
 
+	sys.stdout = sys.stderr
+	print request.form
+
 	if '__SYSTEM' in request.form:
 		sysNames = request.form['__SYSTEM']
 		for i in sysNames:
@@ -110,6 +111,10 @@
 		return (False, {'errors': ['You didn\'t confirm the password'] })
 
 	user = request.form['newUserName']
+
+	if self.portal_membership.getMemberById(user):
+		return (False, {'errors': ['The user \"' + user + '\" already exists']})
+
 	passwd = request.form['newPassword']
 	pwconfirm = request.form['newPasswordConfirm']
 
@@ -136,7 +141,7 @@
 
 	# This should never fail
 	try:
-		numSystems = request.form['numSystems']
+		numStorage = request.form['numStorage']
 	except:
 		return (False, {'errors': ['Unknown number of systems entered']})
 
@@ -146,19 +151,23 @@
 
 	cclRet = createCluster(self, clusterName)
 	if cclRet:
-		return (False, {'errors': cclRet })
+		return (False, {'errors': [cclRet] })
 	else:
 		messages.append('Created cluster \"' + clusterName + '\" successfully')
 
 	i = 0
-	while i < numSystems:
+	while i < numStorage:
 		try:
 			sysData = request.form['__SYSTEM' + str(i)]
 		except:
 			break
 
 		if len(sysData) == 2 and sysData[0] != '' and sysData[1] != '':
-			csResult = createSystem(self, sysData[0], sysData[1])
+			try:
+				csResult = createClusterSystem(self, clusterName, sysData[0], sysData[1])
+			except string, e:
+				dialog_str = 'The system \"' + sysData[0] + '\" is a member of the cluster \"' + e + '\"\nDo you want to manage the whole cluster?'
+				return (True, {'dialog': dialog_str })
 			if csResult:
 				errors.append(csResult)
 			else:
@@ -177,12 +186,12 @@
 	messages = list()
 
 	try:
-		numSystems = request.form['numSystems']
+		numStorage = request.form['numStorage']
 	except:
 		return (False, {'errors': ['Unknown number of systems entered']})
 
 	i = 0
-	while i < numSystems:
+	while i < numStorage:
 		try:
 			sysData = request.form['__SYSTEM' + str(i)]
 		except:
@@ -220,7 +229,7 @@
 	userId = user.getUserId()
 
 	clusters = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/objectItems')()
-	if not request.form.__contains__('__CLUSTER'):
+	if not '__CLUSTER' in request.form:
 		for i in clusters:
 			try:
 				if user.has_role('View', i[1]):
@@ -261,7 +270,7 @@
 						errors.append('Failed to remove permission for ' + userId + ' for cluster ' + i[0])
 
 	storage = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/objectItems')()
-	if not request.form.__contains__('__STORAGE'):
+	if not '__SYSTEM' in request.form:
 		for i in storage:
 			try:
 				if user.has_role('View', i[1]):
@@ -277,7 +286,7 @@
 				errors.append('Failed to remove permission for ' + userId + ' for ' + i[0])
 	else:
 		for i in storage:
-			if i[0] in request.form['__STORAGE']:
+			if i[0] in request.form['__SYSTEM']:
 				try:
 					if not user.has_role('View', i[1]):
 						roles = list(i[1].get_local_roles_for_userid(userId))
@@ -338,37 +347,28 @@
 	return False
 
 def homebaseControlPost(self, request):
-	if 'ACTUAL_URL' in request:
+	if 'absoluteURL' in request.form:
+		url = request.form['absoluteURL']
+	elif 'ACTUAL_URL' in request:
 		url = request['ACTUAL_URL']
+	elif 'URL' in request:
+		url = request['URL']
 	else:
-		try:
-			url = request.form['absoluteURL']
-		except:
-			if 'URL' in request:
-				url = request['URL']
-			else:
-				url = '.'
+		url = '.'
 
-	try:
+	if 'pagetype' in request.form:
 		pagetype = request.form['pagetype']
-	except:
+	else:
 		return homebasePortal(self, request, '.', '0')
 
-	validatorFn = formValidators[int(request.form['pagetype']) - 1]
-	# Invalid request, send them to homebase
+	try:
+		validatorFn = formValidators[int(request.form['pagetype']) - 1]
+	except:
+		return homebasePortal(self, request, '.', '0')
 
 	ret = validatorFn(self, request)
-
 	request.SESSION.set('checkRet', ret[1])
-
-	if ret[0] == True:
-		# No errors occurred
-		return homebasePortal(self, request, url, pagetype, ret[1])
-
-		return homebasePortal(self, request, url, pagetype, ret[1])
-	else:
-		# Errors occurred
-		return homebasePortal(self, request, url, pagetype, ret[1])
+	return homebasePortal(self, request, url, pagetype, ret[1])
 
 def homebaseControl(self, request):
 	try:
@@ -380,23 +380,21 @@
 		return homebaseControlPost(self, request)
 
 	try:
-		url = request['URL']
+		url = request.form['absoluteURL']
 	except:
-		url = '.'
+		try:
+			url = request['URL']
+		except:
+			url = '.'
 
 	try:
 		pagetype = request.form['pagetype']
 	except:
 		pagetype = '0'
 
-	return homebasePortal(self, request,  url, pagetype)
+	return homebasePortal(self, request, url, pagetype)
 
 def homebasePortal(self, request=None, url=None, pagetype=None, params=None):
-#
-# The add user page
-#
-#	if params and 'dest' in params:
-#		pagetype = params['dest']
 	ret = {}
 	temp = list()
 	index = 0
@@ -471,17 +469,17 @@
 
 	try:
 		if (havePermRemStorage(self) and havePermRemCluster(self) and (getStorage(self) or getClusters(self))):
-			delSystem = {}
-			delSystem['Title'] = 'Remove a System'
-			delSystem['absolute_url'] = url + '?pagetype=' + HOMEBASE_DEL_SYSTEM
-			delSystem['Description'] = 'Remove a system'
+			remSystem = {}
+			remSystem['Title'] = 'Remove a System'
+			remSystem['absolute_url'] = url + '?pagetype=' + HOMEBASE_DEL_SYSTEM
+			remSystem['Description'] = 'Remove a system'
 			if pagetype == HOMEBASE_DEL_SYSTEM:
-				delSystem['currentItem'] = True
+				remSystem['currentItem'] = True
 				ret['curIndex'] = index
 			else:
-				delSystem['currentItem'] = False
+				remSystem['currentItem'] = False
 			index += 1
-			temp.append(delSystem)
+			temp.append(remSystem)
 	except: pass
 
 #
@@ -494,8 +492,8 @@
 			userPerm['absolute_url'] = url + '?pagetype=' + HOMEBASE_PERMS
 			userPerm['Description'] = 'Set permissions for users'
 			if pagetype == HOMEBASE_PERMS:
-#				if params and 'user' in params:
-#					userPerm['absolute_url'] += '&user=' + params['user']
+				if params and 'user' in params:
+					userPerm['curUser'] += params['user']
 				userPerm['currentItem'] = True
 				ret['curIndex'] = index
 			else:
@@ -510,13 +508,34 @@
 	ret['children'] = temp
 	return ret
 
+def getClusterSystems(self, clusterName):
+	if isAdmin(self):
+		return self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName + '/objectItems')()
+
+	try:
+		i = getSecurityManager().getUser()
+		if not i:
+			raise
+	except:
+		return None
+
+	csystems = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName + '/objectItems')()
+	if not csystems:
+		return None
+
+	allowedCSystems = list()
+	for c in csystems:
+		if i.has_role('View', c[1]):
+			allowedCSystems.append(c)
+	return (c)
+
 def getClusters(self):
 	if isAdmin(self):
 		return self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/objectItems')()
 	try:
 		i = getSecurityManager().getUser()
 		if not i:
-			return None
+			raise
 	except:
 		return None
 
@@ -554,6 +573,12 @@
 
 def createSystem(self, host, passwd):
 	try:
+		exists = self.restrictedTraverse(PLONE_ROOT +'/systems/storage/' + host)
+		return 'Storage system \"' +  host + '\" is already managed.'
+	except:
+		pass
+
+	try:
 		rc = RicciCommunicator(host)
 	except:
 		return 'Unable to establish a connection to the ricci agent on \"' + host + '\"'
@@ -588,6 +613,16 @@
 	except:
 		return 'Unable to set permissions on new system \"' + host + '\"'
 
+#	sys.stdout = sys.stderr
+#	cluster_info = rc.cluster_info()
+#	if cluster_info[0] != '':
+#		cluConf = getClusterConf(rc)
+#		if cluConf:
+#			print cluConf.toxml()
+#			nodeList = getClusterConfNodes(cluConf)
+#			sys.stdout = sys.stderr
+#			print "other nodes in",cluster_info[0],"::",nodeList
+
 def createCluster(self, clusterName):
 	try:
 		clusters = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/')
@@ -625,22 +660,27 @@
 	if i != True:
 		return 'Authentication for host \"' + host + '\" failed'
 
+	cluster_info = rc.cluster_info()
+	if len(cluster_info) > 0 and cluster_info[0] != '' and  cluster_info[0] != cluster:
+		return 'The host \"' + host + '\" is already a member of the cluster \"' + cluster_info[0] + '\"'
+
 	try:
-		ssystem = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + cluster)
+		exists = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + cluster + '/' + host)
+		if exists:
+			return None
 	except:
-		return 'Unable to create storage system \"' + host + '\" for cluster \"' + cluster + '\"'
+		pass
 
 	try:
-		ssystem.manage_addFolder(host, '__luci__:system')
-		newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
+		ssystem = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + cluster)
 	except:
-		return 'Unable to create storage system \"' + host + '\" for cluster \"' + cluster + '\"'
+		return 'Unable to create storage system \"' + host + '\" for cluster \"' + cluster + '\": Cannot find cluster'
 
 	try:
-		newSystem.manage_acquiredPermissions([])
-		newSystem.manage_role('View', ['Access contents information','View'])
+		ssystem.manage_addFolder(host, '__luci__:csystem:' + cluster)
+		newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + cluster + '/' + host)
 	except:
-		return 'Unable to set permissions on new system \"' + host + '\" for cluster \"' + cluster + '\"'
+		return 'Unable to create storage system \"' + host + '\" for cluster \"' + cluster + '\"'
 
 	try:
 		ssystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/')
@@ -649,7 +689,13 @@
 
 	try:
 		ssystem.manage_addFolder(host, '__luci__:system')
+	except:
+		pass
+
+	try:
 		newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
+		if not newSystem:
+			raise
 	except:
 		return 'Unable to create storage system \"' + host + '\"'
 
@@ -660,16 +706,38 @@
 		return 'Unable to set permissions on new storage system \"' + host + '\"'
 
 def delSystem(self, systemName):
-	# should rikki revoke certs?
 	try:
 		ssystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/')
 	except:
 		return 'Unable to find storage system \"' + systemName + '\"'
 
+	rc = RicciCommunicator(systemName)
+	cluster_info = rc.cluster_info()
+
 	try:
-		ssystem.manage_delObjects([systemName])
-	except:
-		return 'Unable to delete storage system \"' + systemName + '\"'
+		rc.unauth()
+	except Exception, e:
+		e = str(e)
+		if str(e) != '5':
+			# If it's simply a case where we're not authed in the first
+			# place, an attempt to unauthorize failing isn't a problem.
+			return 'Unable to unauthenticate to storage system \"' + systemName + '\"'
+		pass
+
+	if len(cluster_info) > 0 and cluster_info[0] != '':
+		try:
+			delClusterSystem(self, str(cluster_info[0]), systemName)
+		except KeyError:
+			# The cluster may have been deleted, but the system
+			# may still exist in the storage dir.
+			pass
+		except:
+			return 'Unable to delete cluster storage system \"' + systemName + '\"'
+
+		try:
+			ssystem.manage_delObjects([systemName])
+		except:
+			return 'Unable to delete storage system \"' + systemName + '\"'
 
 def delCluster(self, clusterName):
 	try:
@@ -681,7 +749,29 @@
 		clusters.manage_delObjects([clusterName])
 	except:
 		return 'Unable to delete cluster \"' + clusterName + '\"'
-	
+
+def delClusterSystem(self, clusterName, systemName):
+	cluster = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName)
+	cluster.manage_delObjects([systemName])
+
+def delClusterSystems(self, clusterName):
+	try:
+		cluster = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName)
+		csystems = getClusterSystems(self, clusterName)
+	except:
+		return 'Unable to find any systems for cluster \"' + clusterName + '\"'
+
+	errors = ''
+	for i in csystems:
+		try:
+			delSystem(i)
+			cluster.manage_delObjects([i])
+			delClusterSystem(i)
+		except:
+			errors += 'Unable to delete the cluster system \"' + i + '\"\n'
+
+	return errors
+
 def getDefaultUser(self):
 	try:
 		return self.portal_membership.listMembers()[0].getUserName()
@@ -732,7 +822,7 @@
 	return isAdmin(self) 
 
 def getClusterConf(rc):
-	doc = minidom.Document()
+	doc = xml.dom.minidom.Document()
 	batch = doc.createElement('batch')
 	module = doc.createElement('module')
 	module.setAttribute('name', 'cluster')
@@ -743,8 +833,12 @@
 	request.appendChild(call)
 	module.appendChild(request)
 	batch.appendChild(module)
+
 	ret = rc.process_batch(batch)
 
+	if not ret:
+		return None
+
 	cur = ret
 	while len(cur.childNodes) > 0:
 		for i in cur.childNodes:
@@ -753,10 +847,9 @@
 					return i.childNodes[1].cloneNode(True)
 				else:
 					cur = i
-		
 	return None
 
-def getClusterNodes(clusterConfDom):
+def getClusterConfNodes(clusterConfDom):
 	cur = clusterConfDom
 	clusterNodes = list()
 
@@ -768,3 +861,25 @@
 					clusterNodes.append(i.getAttribute('name'))
 			return clusterNodes
 	return clusterNodes
+
+def getSystems(self):
+	storage = getStorage(self)
+	clusters = getClusters(self)
+	storageList = None
+	ret = [{}, None]
+	zeroindex = lambda i: i[0]
+
+	if storage and len(storage) > 0:
+		storageList = map(zeroindex, storage)
+
+	for i in clusters:
+		cSystems = map(zeroindex, getClusterSystems(self, i[0]))
+		for c in cSystems:
+			try:
+				del storageList[storageList.index(c)]
+			except ValueError: pass
+		ret[0][i[0]] = cSystems
+
+	if storageList:
+		ret[1] = storageList
+	return ret


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]