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

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



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2006-07-19 20:19:53

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

Log message:
	cluster create, and cluster remove (stop managing) bits

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/homebase_adapters.py.diff?cvsroot=cluster&r1=1.13&r2=1.14

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/07/14 16:00:26	1.2
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/07/19 20:19:53	1.3
@@ -14,12 +14,111 @@
 #then only display chooser if the current user has 
 #permissions on at least one. If the user is admin, show ALL clusters
 
-                          
+from homebase_adapters import nodeAuth, nodeUnauth                     
 
 CLUSTER_FOLDER_PATH = '/luci/systems/cluster/'
 
+def validatePost(request):
+	if int(request.form['pagetype']) != 6:
+		return
+
+	errors = list()
+	nodeList = list()
+	nodeHash = {}
+	rnodeHash = {}
+	oldNodeHash = {}
+	oldRnodeHash = {}
+	requestResults = {}
+
+ 	sessionData = request.SESSION.get('checkRet')
+	if sessionData and 'requestResults' in sessionData:
+		requestResults = sessionData['requestResults']
+		if 'nodeHash' in requestResults:
+			oldNodeHash = requestResults['nodeHash']
+		if 'rnodeHash' in requestResults:
+			oldRnodeHash = requestResults['rnodeHash']
+
+	if not 'clusterName' in request.form or not request.form['clusterName']:
+		return (False, {'errors': [ 'No cluster name was specified.' ] })
+	clusterName = request.form['clusterName']
+
+	try:
+		numStorage = int(request.form['numStorage'])
+	except:
+		return (False, { 'errors': ['Unknown number of systems entered'], 'requestResults': requestResults })
+
+	if numStorage < 2:
+		return (False, { 'errors': ['A cluster must contain at least two nodes'], 'requestResults': requestResults })
+
+	i = 0
+	while i < numStorage:
+		try:
+			sysData = request.form['__SYSTEM' + str(i)]
+			if not sysData or sysData[0] == '':
+				raise
+
+			if len(sysData) < 2 or sysData[1] == '':
+				errors.append('No password was specified for host \"' + sysData[0] + '\"')
+				raise
+		except:
+			i += 1
+			continue
+
+		if len(sysData) > 1:
+			node = nodeAuth(None, sysData[0], sysData[1])
+
+			if oldRnodeHash and node['ricci_host'] in oldRnodeHash:
+				oldNode = oldRnodeHash[node['ricci_host']]
+			elif oldNodeHash and node['host'] in nodeHash:
+				oldNode = oldNodeHash[node['host']]
+			else:
+				oldNode = None
+
+			if 'errors' in node:
+				errors.append(node['errors'])
+				node['errors'] = True
+
+			if node['host'] in nodeHash or node['ricci_host'] in rnodeHash:
+				node['errors'] = True
+				errors.append('You added the node \"' + node['host'] + '\" more than once')
+			else:
+				if oldNode and 'prev_auth' in oldNode:
+					node['prev_auth'] = oldNode['prev_auth']
+
+				nodeHash[node['host']] = node
+				rnodeHash[node['ricci_host']] = node
+				nodeList.append(node)
+		i += 1
+
+	if len(nodeList) < 2:
+		errors.append('A cluster must contain at least two nodes')
+
+	sfn = lambda x, y: \
+		x['cur_auth'] - y['cur_auth'] or (('errors' in y) - ('errors' in x))
+	nodeList.sort(sfn)
+
+	dfn = lambda x: not 'cur_auth' in x or x['cur_auth'] != True
+	cluster_properties = {
+		'clusterName': clusterName,
+		'nodeList': nodeList,
+		'nodeHash': nodeHash,
+		'rnodeHash': rnodeHash,
+		'isComplete': len(errors) < 1 and len(filter(dfn, nodeList)) == 0
+	}
+	return (len(errors) < 1, {'errors': errors, 'requestResults': cluster_properties })
+
 def createCluChooser(self, request, systems):
   dummynode = {}
+  
+  if request.REQUEST_METHOD == 'POST':
+    ret = validatePost(request)
+    try:
+		request.SESSION.set('checkRet', ret[1])
+    except:
+		request.SESSION.set('checkRet', {})
+  else:
+    try: request.SESSION.set('checkRet', {})
+    except: pass
 
   #First, see if a cluster is chosen, then 
   #check that the current user can access that system
@@ -39,6 +138,7 @@
   except KeyError, e:
     pagetype = "0"
 
+
   cldata = {}
   cldata['Title'] = "Cluster List"
   cldata['cfg_type'] = "clusters"
--- conga/luci/site/luci/Extensions/homebase_adapters.py	2006/07/18 19:26:03	1.13
+++ conga/luci/site/luci/Extensions/homebase_adapters.py	2006/07/19 20:19:53	1.14
@@ -174,8 +174,13 @@
 			systemName = host
 		node = { 'host': host, 'ricci_host': systemName, 'prev_auth': prevAuth, 'cur_auth': True }
 		cluster_info = rc.cluster_info()
-		if not cluster_info or cluster_info[0] != cluster:
-			node['errors'] = 'Node ' + host + ' is reporting it is not a member of cluster \"' + cluster + '\"'
+		if not cluster or not cluster_info or cluster_info[0] != cluster:
+			if cluster:
+				node['errors'] = 'Node \"' + host + '\" is reporting it is not a member of cluster \"' + cluster + '\"'
+				if cluster_info[0]:
+					node['errors'] += ' and that it is a member of cluster \"' + cluster_info[0] + '\"'
+			else:
+				node['errors'] = 'Node \"' + host + '\" reports it is a member of cluster \"' + cluster_info[0] + '\"'
 		return node
 
 	error = 'Unable to authenticate to the ricci agent on \"' + host + '\"'
@@ -563,21 +568,20 @@
 	except:
 		sessionData = None
 
-
 	if 'ACTUAL_URL' in request:
 		url = request['ACTUAL_URL']
 	else:
 		url = '.'
 
 	if 'pagetype' in request.form:
-		pagetype = request.form['pagetype']
+		pagetype = int(request.form['pagetype'])
 	else:
 		try: request.SESSION.set('checkRet', {})
 		except: pass
 		return homebasePortal(self, request, '.', '0')
 
 	try:
-		validatorFn = formValidators[int(request.form['pagetype']) - 1]
+		validatorFn = formValidators[pagetype - 1]
 	except:
 		try: request.SESSION.set('checkRet', {})
 		except: pass
@@ -887,6 +891,12 @@
 	except:
 		return 'Unable to set permissions on new system \"' + host + '\"'
 
+def abortManageCluster(self):
+	try:
+		sessionData = request.SESSION.get('checkRet')
+		nodeUnauth(sessionData['requestResults']['nodeList'])
+	except: pass
+
 def manageCluster(self, clusterName, nodeList):
 	clusterName = str(clusterName)
 
@@ -920,11 +930,6 @@
 		except: pass
 		return 'Unable to set permissions on new cluster \"' + clusterName + '\"-- Cluster creation failed'
 
-	try:
-		ssystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/')
-	except:
-		ssystem = None
-
 	for i in nodeList:
 		if 'ricci_host' in i:
 			host = str(i['ricci_host'])
@@ -938,25 +943,39 @@
 				raise 'not there'
 			newSystem.manage_acquiredPermissions([])
 			newSystem.manage_role('View', [ 'Access contents information' , 'View' ])
-		except Exception, e:
+		except:
 			nodeUnauth(nodeList)
 			try: clusters.manage_delObjects([clusterName])
 			except: pass
 			return 'Unable to create cluster node \"' + host + '\" for cluster \"' + clusterName + '\" -- Cluster creation failed."'
 
-		if ssystem:
-			try:
-				# It's already there, as a storage system, no problem.
-				exists = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
-				continue
-			except: pass
+	try:
+		ssystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/')
+		if not ssystem:
+			raise
+	except:
+		return
 
-			try:
-				ssystem.manage_addFolder(host, '__luci__:system')
-				newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
-				newSystem.manage_acquiredPermissions([])
-				newSystem.manage_role('View', [ 'Access contents information' , 'View' ])
-			except: pass
+	# Only add storage systems if the cluster and cluster node DB
+	# objects were added successfully.
+	for i in nodeList:
+		if 'ricci_host' in i:
+			host = str(i['ricci_host'])
+		else:
+			host = str(i['host'])
+
+		try:
+			# It's already there, as a storage system, no problem.
+			exists = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
+			continue
+		except: pass
+
+		try:
+			ssystem.manage_addFolder(host, '__luci__:system')
+			newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + host)
+			newSystem.manage_acquiredPermissions([])
+			newSystem.manage_role('View', [ 'Access contents information' , 'View' ])
+		except: pass
 
 def delSystem(self, systemName):
 	try:
@@ -964,28 +983,25 @@
 	except:
 		return 'Unable to find storage system \"' + systemName + '\"'
 
-	rc = RicciCommunicator(systemName)
-	cluster_info = rc.cluster_info()
-
 	try:
-		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
+		rc = RicciCommunicator(systemName)
+		if not rc:
+			raise
+	except:
+		return 'Unable to connect to the ricci agent on \"' + systemName + '\" to unauthenticate'
 
-	if len(cluster_info) > 0 and cluster_info[0] != '':
+	# Only unauthenticate if the system isn't a member of
+	# a managed cluster.
+	cluster_info = rc.cluster_info()
+	if not cluster_info[0]:
+		try: rc.unauth()
+		except: pass
+	else:
 		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
+			newSystem = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + cluster_info[0] + '/' + rc.system_name())
 		except:
-			return 'Unable to delete cluster storage system \"' + systemName + '\"'
+			try: rc.unauth()
+			except: pass
 
 	try:
 		ssystem.manage_delObjects([systemName])
@@ -1007,8 +1023,7 @@
 	except:
 		return 'Unable to delete cluster \"' + clusterName + '\"'
 
-def delClusterSystem(self, clusterName, systemName):
-	cluster = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName)
+def delClusterSystem(self, cluster, systemName):
 	try:
 		if not self.restrictedTraverse(PLONE_ROOT + '/systems/storage/' + systemName):
 			raise
@@ -1029,10 +1044,9 @@
 	errors = ''
 	for i in csystems:
 		try:
-			cluster.manage_delObjects([i])
-			delClusterSystem(i)
+			delClusterSystem(self, cluster, i[0])
 		except:
-			errors += 'Unable to delete the cluster system \"' + i + '\"\n'
+			errors += 'Unable to delete the cluster system \"' + i[0] + '\"\n'
 
 	return errors
 


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