[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-10-20 21:59:54

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

Log message:
	more logging for debug

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

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/10/18 23:12:31	1.122
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/10/20 21:59:54	1.123
@@ -2594,13 +2594,21 @@
 	except:
 		return "Unable to resolve node name %s to retrieve logging information" % nodename_resolved
 
+	if not rc.authed():
+		try:
+			snode = getStorageNode(self, nodename)
+			setNodeFlag(snode, CLUSTER_NODE_NEED_AUTH)
+		except:
+			pass
+		return "Luci is not authenticated to node %s. Please reauthenticate first." % nodename
+
 	return getNodeLogs(rc)
 
 def processXenVM(self, req):
   model = req.SESSION.get('model')
   isNew = False
   try:
-    xenvmname = req	['servicename']
+    xenvmname = req['servicename']
   except KeyError, e:
     isNew = True
   
@@ -2623,14 +2631,27 @@
     
 
 def getXenVMInfo(self, model, request):
-  try:
-    xenvmname = request['servicename']
-  except KeyError, e:
-    return {}
-  
-  xenvm = model.retrieveXenVMsByName(xenvmname)
-  map = xenvm.getAttributes()
-  return map
+	try:
+		xenvmname = request['servicename']
+	except KeyError, e:
+		try:
+			xenvmname = request.form['servicename']
+		except:
+			luci_log.debug_verbose('servicename is missing from request')
+			return {}
+	except:
+		luci_log.debug_verbose('servicename is missing from request')
+		return {}
+
+	try:  
+		xenvm = model.retrieveXenVMsByName(xenvmname)
+	except:
+		luci_log.debug('An error occurred while attempting to get VM %s' \
+			% xenvmname)
+		return {}
+
+	map = xenvm.getAttributes()
+	return map
 
 def isClusterBusy(self, req):
   items = None
@@ -2661,9 +2682,10 @@
 
   try:
     items = clusterfolder.objectItems('ManagedSystem')
-    if len(items) == 0:
+    if not items or len(items) < 1:
       return map  #This returns an empty map, and should indicate not busy
   except:
+    luci_log.debug('An error occurred while looking for cluster %s flags' % cluname)
     return map
     
   map['busy'] = "true"
@@ -2760,7 +2782,10 @@
           node_report['statusmessage'] = "Node created successfully" + REDIRECT_MSG
           node_report['statusindex'] = creation_status
           nodereports.append(node_report)
-          clusterfolder.manage_delObjects(item[0])
+          try:
+              clusterfolder.manage_delObjects(item[0])
+          except Exception, e:
+              luci_log.info('Unable to delete %s: %s' % (item[0], str(e)))
           continue
         else:
           map['busy'] = "true"
@@ -2783,13 +2808,17 @@
       if finished == True:
         node_report['desc'] = item[1].getProperty(FLAG_DESC) + REDIRECT_MSG
         nodereports.append(node_report)
-        clusterfolder.manage_delObjects(item[0])
+        try:
+            clusterfolder.manage_delObjects(item[0])
+        except Exception, e:
+            luci_log.info('Unable to delete %s: %s' % (item[0], str(e)))
       else:
         node_report = {}
         map['busy'] = "true"
         isBusy = True
         node_report['desc'] = item[1].getProperty(FLAG_DESC)
         nodereports.append(node_report)
+
   if isBusy:
     part1 = req['ACTUAL_URL']
     part2 = req['QUERY_STRING']
@@ -2809,12 +2838,14 @@
 
 def getClusterOS(self, rc):
 	map = {}
+
 	try:
 		os_str = resolveOSType(rc.os())
 		map['os'] = os_str
 		map['isVirtualized'] = rc.dom0()
 	except:
 		# default to rhel5 if something crazy happened.
+		luci_log.debug('An error occurred while attempting to get OS/Virt info for %s -- defaulting to rhel5/False' % rc.hostname())
 		map['os'] = 'rhel5'
 		map['isVirtualized'] = False
 	return map
@@ -2829,8 +2860,10 @@
 		try:
 			cluname = request.form['clustername']
 		except:
+			luci_log.debug_verbose('getResourcesInfo missing cluster name')
 			return resList
 	except:
+		luci_log.debug_verbose('getResourcesInfo missing cluster name')
 		return resList
 
 	for item in modelb.getResources():
@@ -2850,8 +2883,10 @@
 		try:
 			name = request.form['resourcename']
 		except:
+			luci_log.debug_verbose('getResourceInfo missing res name')
 			return {}
 	except:
+		luci_log.debug_verbose('getResourceInfo missing res name')
 		return {}
 
 	try:
@@ -2860,19 +2895,22 @@
 		try:
 			cluname = request.form['clustername']
 		except:
+			luci_log.debug_verbose('getResourceInfo missing cluster name')
 			return {}
 	except:
+		luci_log.debug_verbose('getResourceInfo missing cluster name')
 		return {}
 
 	try:
 		baseurl = request['URL']
 	except:
+		luci_log.debug_verbose('getResourceInfo missing URL')
 		return {}
 
 	for res in modelb.getResources():
 		if res.getName() == name:
-			resMap = {}
 			try:
+				resMap = {}
 				resMap['name'] = res.getName()
 				resMap['type'] = res.resource_type
 				resMap['tag_name'] = res.TAG_NAME
@@ -2880,7 +2918,7 @@
 				resMap['cfgurl'] = baseurl + "?" + "clustername=" + cluname + "&resourcename=" + res.getName() + "&pagetype=" + RESOURCE_CONFIG
 				return resMap
 			except:
-				return {}
+				continue
 
 def delResource(self, rc, request):
 	errstr = 'An error occurred in while attempting to set the cluster.conf'
@@ -2888,11 +2926,19 @@
 	try:
 		modelb = request.SESSION.get('model')
 	except:
+		luci_log.debug_verbose('delResource unable to extract model from SESSION')
 		return errstr
 
 	try:
 		name = request['resourcename']
 	except KeyError, e:
+		try:
+			name = request.form['resourcename']
+		except:
+			luci_log.debug_verbose('delResource missing resname %s' % str(e))
+			return errstr + ': ' + str(e)
+	except:
+		luci_log.debug_verbose('delResource missing resname')
 		return errstr + ': ' + str(e)
 
 	try:
@@ -2901,6 +2947,7 @@
 		try:
 			clustername = request.form['clustername']
 		except:
+			luci_log.debug_verbose('delResource missing cluster name')
 			return errstr + ': could not determine the cluster name.'
 
 	try:
@@ -2921,6 +2968,7 @@
 			break
 
 	if not found:
+		luci_log.debug_verbose('delresource cant find res %s' % name)
 		return errstr + ': the specified resource was not found.'
 
 	try:
@@ -2928,10 +2976,12 @@
 		if not conf:
 			raise
 	except:
+		luci_log.debug_verbose('exportModelAsString failed')
 		return errstr
 
 	batch_number, result = setClusterConf(str(conf))
 	if batch_number is None or result is None:
+		luci_log.debug_verbose('missing batch and/or result from setClusterConf')
 		return errstr
 
 	modelstr = ""
@@ -2939,13 +2989,20 @@
 	clusterfolder = self.restrictedTraverse(path)
 	batch_id = str(batch_number)
 	objname = str(ragent) + '____flag'
-	clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
-	#Now we need to annotate the new DB object
 	objpath = str(path + '/' + objname)
-	flag = self.restrictedTraverse(objpath)
-	flag.manage_addProperty(BATCH_ID, batch_id, "string")
-	flag.manage_addProperty(TASKTYPE, RESOURCE_REMOVE, "string")
-	flag.manage_addProperty(FLAG_DESC, "Removing Resource \'" + request['resourcename'] + "\'", "string")
+
+	try:
+		clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
+		#Now we need to annotate the new DB object
+		flag = self.restrictedTraverse(objpath)
+		flag.manage_addProperty(BATCH_ID, batch_id, "string")
+		flag.manage_addProperty(TASKTYPE, RESOURCE_REMOVE, "string")
+		flag.manage_addProperty(FLAG_DESC, "Removing Resource \'" + request['resourcename'] + "\'", "string")
+	except Exception, e:
+		luci_log.debug('An error occurred while setting flag %s: %s' \
+			% (objname, str(e)))
+	except:
+		luci_log.debug('An error occurred while setting flag %s' % objname)
 
 	response = request.RESPONSE
 	response.redirect(request['HTTP_REFERER'] + "&busyfirst=true")
@@ -2953,8 +3010,8 @@
 def addIp(request, form=None):
 	if form is None:
 		form = request.form
-	modelb = request.SESSION.get('model')
 
+	modelb = request.SESSION.get('model')
 	if not modelb or not form:
 		return None
 
@@ -3069,6 +3126,7 @@
 def addGfs(request, form=None):
 	if form is None:
 		form = request.form
+
 	modelb = request.SESSION.get('model')
 	if not modelb:
 		return None
@@ -3079,13 +3137,21 @@
 			if not oldname:
 				raise KeyError('oldname is blank.')
 			res = getResourceForEdit(modelb, oldname)
+			if not res:
+				luci_log.debug('resource %s was not found for editing' % oldname)
+				return None
 		except KeyError, e:
+			luci_log.debug('resource %s was not found for editing: %s' \
+				% (oldname, str(e)))
 			return None
 	else:
-		res = apply(Clusterfs)
-
-	if not res:
-		return None
+		try:
+			res = apply(Clusterfs)
+			if not res:
+				raise
+		except:
+			luci_log.debug('Error creating node Clusterfs resource')
+			return None
 
 	# XXX: sanity check these fields
 	try:
@@ -3094,30 +3160,35 @@
 			raise
 		res.attr_hash['name'] = name
 	except:
+		luci_log.debug_verbose('name is missing in clusterfs res')
 		return None
 
 	try:
 		mountpoint = form['mountpoint'].strip()
 		res.attr_hash['mountpoint'] = mountpoint
 	except:
+		luci_log.debug_verbose('mountpoint is missing in clusterfs res')
 		return None
 
 	try:
 		device = form['device'].strip()
 		res.attr_hash['device'] = device
 	except:
+		luci_log.debug_verbose('device is missing in clusterfs res')
 		return None
 
 	try:
 		options = form['options'].strip()
 		res.attr_hash['options'] = options
 	except:
+		luci_log.debug_verbose('options is missing in clusterfs res')
 		return None
 
 	try:
 		fsid = form['fsid'].strip()
 		res.attr_hash['fsid'] = fsid
 	except:
+		luci_log.debug_verbose('fsid is missing in clusterfs res')
 		return None
 
 	if form.has_key('forceunmount'):
@@ -3373,16 +3444,20 @@
 	try:
 		mb_nodes = modelb.getNodes()
 		if not mb_nodes or not len(mb_nodes):
-			raise
-	except:
-		return 'Unable to find cluster nodes for ' + clusterName
+			raise Exception, 'node list is empty'
+	except Exception, e:
+		luci_log.debug_verbose('no model builder nodes found for %s: %s' \
+				% (str(e), clusterName))
+		return 'Unable to find cluster nodes for %s' % clusterName
 
 	try:
 		cluster_node = self.restrictedTraverse(PLONE_ROOT + '/systems/cluster/' + clusterName)
 		if not cluster_node:
-			raise
-	except:
-		return 'Unable to find an entry for ' + clusterName + ' in the Luci database.'
+			raise Exception, 'cluster node is none'
+	except Exception, e:
+		luci_log.debug('cant find cluster node for %s: %s'
+			% (clusterName, str(e)))
+		return 'Unable to find an entry for %s in the Luci database.' % clusterName
 
 	try:
 		db_nodes = map(lambda x: x[0], cluster_node.objectItems('Folder'))
@@ -3469,9 +3544,11 @@
 	try:
 		ragent = rc.hostname()
 		if not ragent:
+			luci_log.debug('missing hostname')
 			raise
 		batch_number, result = setClusterConf(str(conf))
 		if batch_number is None or result is None:
+			luci_log.debug('missing batch_number or result')
 			raise
 	except:
 		return "Some error occured in setClusterConf\n"
@@ -3480,17 +3557,24 @@
 	clusterfolder = self.restrictedTraverse(path)
 	batch_id = str(batch_number)
 	objname = str(ragent + '____flag')
-	clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
-	#Now we need to annotate the new DB object
 	objpath = str(path + '/' + objname)
-	flag = self.restrictedTraverse(objpath)
-	flag.manage_addProperty(BATCH_ID, batch_id, "string")
-	flag.manage_addProperty(TASKTYPE, RESOURCE_ADD, "string")
 
-	if type != 'ip':
-		flag.manage_addProperty(FLAG_DESC, "Creating New Resource \'" + request.form['resourceName'] + "\'", "string")
-	else:
-		flag.manage_addProperty(FLAG_DESC, "Creating New Resource \'" + res.attr_hash['address'] + "\'", "string")
+	try:
+		clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
+		#Now we need to annotate the new DB object
+		flag = self.restrictedTraverse(objpath)
+		flag.manage_addProperty(BATCH_ID, batch_id, "string")
+		flag.manage_addProperty(TASKTYPE, RESOURCE_ADD, "string")
+
+		if type != 'ip':
+			flag.manage_addProperty(FLAG_DESC, "Creating New Resource \'" + request.form['resourceName'] + "\'", "string")
+		else:
+			flag.manage_addProperty(FLAG_DESC, "Creating New Resource \'" + res.attr_hash['address'] + "\'", "string")
+	except Exception, e:
+		try:
+			luci_log.info('Unable to create flag %s: %s' % (objpath, str(e)))
+		except:
+			pass
 
 	response = request.RESPONSE
 	response.redirect(request['HTTP_REFERER'] + "&busyfirst=true")
@@ -3503,24 +3587,33 @@
 		if res.getName() == name:
 			resPtr.removeChild(res)
 			return res
+
+	luci_log.debug_verbose('unable to find resource \"%s\"' % name)
 	raise KeyError, name
 
 def appendModel(request, model):
 	try:
 		request.SESSION.set('model', model)
 	except:
-		pass
-
-	return False
+		luci_log.debug_verbose('Appending model to request failed')
+		return False
 
 def resolve_nodename(self, clustername, nodename):
-	path = CLUSTER_FOLDER_PATH + clustername
-	clusterfolder = self.restrictedTraverse(path)
-	objs = clusterfolder.objectItems('Folder')
+	path = str(CLUSTER_FOLDER_PATH + clustername)
+
+	try:
+		clusterfolder = self.restrictedTraverse(path)
+		objs = clusterfolder.objectItems('Folder')
+	except Exception, e:
+		luci_log.info('resolve_nodename failed for %s/%s: %s' \
+			% (nodename, clustername, str(e)))
+
 	for obj in objs:
 		if obj[0].find(nodename) != (-1):
 			return obj[0]
-	raise
+
+	luci_log.info('resolve_nodename failed for %s/%s' % (nodename, clustername))
+	return None
 
 def noNodeFlagsPresent(self, nodefolder, flagname, hostname):
 	try:
@@ -3536,15 +3629,26 @@
 		#a flag already exists... try to delete it
 		try:
 			rc = RicciCommunicator(hostname)
-		except:
-			luci_log.info('Unable to connect to the ricci daemon on host ' + hostname)
+		except RicciError, e:
+			luci_log.info('Unable to connect to the ricci daemon: %s' % str(e))
 			return False
 
+		if not rc.authed():
+			try:
+				snode = getStorageNode(self, hostname)
+				setNodeFlag(snode, CLUSTER_NODE_NEED_AUTH)
+			except:
+				pass
+			luci_log.info('Node %s is not authenticated' % item[0])
+			return None
+
 		finished = checkBatch(rc, item[1].getProperty(BATCH_ID))
 		if finished == True:
 			try:
 				nodefolder.manage_delObjects(item[0])
-			except:
+			except Exception, e:
+				luci_log.info('manage_delObjects for %s failed: %s' \
+					% (item[0], str(e)))
 				return False
 			return True
 		else:
@@ -3552,8 +3656,22 @@
 			return False
 	return True
 
-def getModelBuilder(rc,isVirtualized):
-	cluster_conf_node = getClusterConf(rc)
-	modelb = ModelBuilder(0, None, None, cluster_conf_node)
+def getModelBuilder(rc, isVirtualized):
+	try:
+		cluster_conf_node = getClusterConf(rc)
+		if not cluster_conf_node:
+			raise;
+	except:
+		luci_log.debug('unable to get cluster_conf_node in getModelBuilder')
+		return None
+
+	try:
+		modelb = ModelBuilder(0, None, None, cluster_conf_node)
+	except Exception, e:
+		try:
+			luci_log.debug('An error occurred while trying to get modelb for conf \"%s\": %s' % (cluster_conf_node.toxml(), str(e)))
+		except:
+			pass
+
 	modelb.setIsVirtualized(isVirtualized)
 	return modelb


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