All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cluster-devel] conga/luci/site/luci/Extensions conga_constant ...
@ 2007-06-08 18:26 rmccabe
  0 siblings, 0 replies; 3+ messages in thread
From: rmccabe @ 2007-06-08 18:26 UTC (permalink / raw)
  To: cluster-devel.redhat.com

CVSROOT:	/cvs/cluster
Module name:	conga
Branch: 	EXPERIMENTAL
Changes by:	rmccabe at sourceware.org	2007-06-08 18:26:15

Modified files:
	luci/site/luci/Extensions: conga_constants.py 
	                           ricci_communicator.py LuciSyslog.py 

Log message:
	Groundwork and part of the fix for 227852

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/conga_constants.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.39.2.8&r2=1.39.2.9
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ricci_communicator.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.25.2.6&r2=1.25.2.7
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/LuciSyslog.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.11.4.3&r2=1.11.4.4

--- conga/luci/site/luci/Extensions/conga_constants.py	2007/06/07 06:41:05	1.39.2.8
+++ conga/luci/site/luci/Extensions/conga_constants.py	2007/06/08 18:26:14	1.39.2.9
@@ -147,4 +147,5 @@
 # to >= 2 to get full debugging output in syslog (LOG_DAEMON/LOG_DEBUG).
 
 LUCI_DEBUG_MODE			= False
+LUCI_DEBUG_NET			= False
 LUCI_DEBUG_VERBOSITY	= 0
--- conga/luci/site/luci/Extensions/ricci_communicator.py	2007/06/01 23:18:16	1.25.2.6
+++ conga/luci/site/luci/Extensions/ricci_communicator.py	2007/06/08 18:26:15	1.25.2.7
@@ -10,7 +10,7 @@
 from xml.dom import minidom
 from LuciSyslog import get_logger
 from conga_ssl import SSLSocket
-from conga_constants import LUCI_DEBUG_MODE
+from conga_constants import LUCI_DEBUG_MODE, LUCI_DEBUG_NET
 
 CERTS_DIR_PATH = '/var/lib/luci/var/certs/'
 luci_log = get_logger()
@@ -37,22 +37,23 @@
 								self.__timeout_init)
 			if enforce_trust:
 				if not self.ss.trusted():
+					luci_log.info('The SSL certificate for host "%s" is not trusted. Aborting connection attempt.' % self.__hostname)
 					raise RicciError, 'ricci\'s certificate is not trusted'
 		except Exception, e:
-			raise RicciError, 'Error setting up SSL for connection to %s: %s' \
-				% (self.__hostname, str(e))
-		except:
-			raise RicciError, 'Error setting up SSL for connection to %s' \
-				% self.__hostname
+			errmsg = 'Unable to establish an SSL connection to %s:%d: %s' \
+						% ((self.__hostname, self.__port, str(e)))
+			luci_log.info(errmsg)
+			raise RicciError, errmsg
 
 		# receive ricci header
 		hello = self.__receive(self.__timeout_init)
 		try:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:init0: recv header from %s: \"%s\"' \
+			if LUCI_DEBUG_NET is True:
+				luci_log.debug_net('RC:init0: recv header from %s: \"%s\"' \
 					% (self.__hostname, hello.toxml()))
 		except:
-			pass
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('RC:init0: error receiving header from %s: %r %s' % (self.__hostname, e, str(e)))
 
 		self.__authed = hello.firstChild.getAttribute('authenticated') == 'true'
 		self.__cluname = hello.firstChild.getAttribute('clustername')
@@ -62,43 +63,47 @@
 		self.__dom0 = hello.firstChild.getAttribute('xen_host') == 'true'
 
 	def hostname(self):
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:hostname: [auth %d] hostname = %s' \
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net('RC:hostname: [auth %d] hostname = %s' \
 				% (self.__authed, self.__hostname))
 		return self.__hostname
 
 	def authed(self):
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:authed: reported authed = %d for %s' \
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net('RC:authed: reported authed = %d for %s' \
 				% (self.__authed, self.__hostname))
 		return self.__authed
 
 	def system_name(self):
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:system_name: [auth %d] system_name = %s for %s' % (self.__authed, self.__reported_hostname, self.__hostname))
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net('RC:SN: [auth %d] system_name = %s for %s' \
+				% (self.__authed, self.__reported_hostname, self.__hostname))
 		return self.__reported_hostname
 
 	def cluster_info(self):
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:cluster_info: [auth %d] reported cluster_info = (%s,%s) for %s' % (self.__authed, self.__cluname, self.__clualias, self.__hostname))
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net('RC:CI: [auth %d] (%s,%s) for %s' \
+				% (	self.__authed, self.__cluname,
+					self.__clualias, self.__hostname))
+
 		return (self.__cluname, self.__clualias)
 
 	def os(self):
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:os: [auth %d] reported os = %s for %s' \
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net('RC:OS: [auth %d] reported os = %s for %s' \
 				% (self.__authed, self.__os, self.__hostname))
 		return self.__os
 
 	def dom0(self):
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:dom0: [auth %d] dom0 = %s for %s' \
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net('RC:DOM0: [auth %d] dom0 = %s for %s' \
 				% (self.__authed, self.__dom0, self.__hostname))
 		return self.__dom0
 
 	def fingerprint(self):
 		fp = self.ss.peer_fingerprint()
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:fp: [auth %d] fp for %s = %s' \
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net('RC:fp: [auth %d] fp for %s = %s' \
 				% (self.__authed, self.__hostname, fp))
 		return fp
 
@@ -114,7 +119,7 @@
 	def auth(self, password):
 		if self.authed():
 			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:auth0: already authenticated to %s' \
+				luci_log.debug_verbose('RC:AUTH0: already authenticated to %s' \
 					% self.__hostname)
 			return True
 
@@ -138,11 +143,13 @@
 				self.__reported_hostname = resp.firstChild.getAttribute('hostname')
 				self.__os = resp.firstChild.getAttribute('os')
 				self.__dom0 = resp.firstChild.getAttribute('xen_host') == 'true'
-			except:
-				pass
+			except Exception, e:
+				if LUCI_DEBUG_MODE is True:
+					luci_log.debug_verbose('RC:AUTH1: %r %s for %s' \
+						% (e, str(e), self.__hostname))
 
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:auth1: auth call returning %d' \
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net('RC:auth1: auth call returning %d' \
 				% self.__authed)
 		return self.__authed
 
@@ -155,14 +162,10 @@
 		self.__send(doc, self.__timeout_auth)
 		resp = self.__receive(self.__timeout_auth)
 
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:unauth0: unauthenticate %s' \
-				% self.__hostname)
-
 		try:
 			ret = resp.firstChild.getAttribute('success')
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:unauth1: unauthenticate %s for %s' \
+			if LUCI_DEBUG_NET is True:
+				luci_log.debug_net('RC:UNAUTH0: unauthenticate %s for %s' \
 					% (ret, self.__hostname))
 			if ret != '0':
 				raise Exception, 'Invalid response'
@@ -172,36 +175,36 @@
 			except:
 				pass
 		except:
-			errstr = 'Error authenticating to host %s: %s' \
+			errstr = 'Error authenticating host %s: %s' \
 						% (self.__hostname, str(ret))
-
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:unauth2: %s' % errstr)
+			luci_log.info(errstr)
 			raise RicciError, errstr
 		return True
 
-
 	def process_batch(self, batch_xml, async=False):
-		if LUCI_DEBUG_MODE is True:
-			try:
-				luci_log.debug_verbose('RC:PB0: [auth=%d] to %s for batch %s [async=%d]' % (self.__authed, self.__hostname, batch_xml.toxml(), async))
-			except:
-				pass
+		try:
+			if LUCI_DEBUG_NET is True:
+				luci_log.debug_net_priv('RC:PB0: [auth=%d] to %s for batch %s [async=%d]' % (self.__authed, self.__hostname, batch_xml.toxml(), async))
+		except:
+			pass
 
 		if not self.authed():
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('RC:PB1: not authenticated to %s' \
+					% self.__hostname)
 			raise RicciError, 'not authenticated to host %s' % self.__hostname
 
 		# construct request
 		doc = minidom.Document()
-		ricci = doc.createElement("ricci")
-		ricci.setAttribute("version", "1.0")
-		ricci.setAttribute("function", "process_batch")
+		ricci = doc.createElement('ricci')
+		ricci.setAttribute('version', '1.0')
+		ricci.setAttribute('function', 'process_batch')
 		async_str = None
 		if async:
 			async_str = 'true'
 		else:
 			async_str = 'false'
-		ricci.setAttribute("async", async_str)
+		ricci.setAttribute('async', async_str)
 		doc.appendChild(ricci)
 		ricci.appendChild(batch_xml)#.cloneNode(True))
 
@@ -209,25 +212,25 @@
 		try:
 			self.__send(doc, self.__timeout_short)
 		except Exception, e:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:PB1: Error sending XML \"%s\" to host %s' % (doc.toxml(), self.__hostname))
-			raise RicciError, 'Error sending XML to host %s: %s' \
-					% (self.__hostname, str(e))
-		except:
-			raise RicciError, 'Error sending XML to host %s' % self.__hostname
+			errstr = 'Error sending XML batch command to %s:%d: %s' \
+						% (self.__hostname, self.__port, str(e))
+			luci_log.info(errstr)
+			if LUCI_DEBUG_NET is True:
+				luci_log.debug_net_priv('RC:PB2: Error sending XML \"%s\" to host %s' % (doc.toxml(), self.__hostname))
+			raise RicciError, errstr
 
 		# receive response
 		doc = self.__receive(self.__timeout_long)
-		if LUCI_DEBUG_MODE is True:
+		if LUCI_DEBUG_NET is True:
 			try:
-				luci_log.debug_verbose('RC:PB2: received from %s XML \"%s\"' \
+				luci_log.debug_net_priv('RC:PB3: received from %s XML \"%s\"' \
 					% (self.__hostname, doc.toxml()))
 			except:
 				pass
 
 		if doc.firstChild.getAttribute('success') != '0':
 			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:PB3: batch command failed')
+				luci_log.debug_verbose('RC:PB4: batch command failed')
 			raise RicciError, 'The last ricci command to host %s failed' \
 					% self.__hostname
 
@@ -238,7 +241,8 @@
 					batch_node = node#.cloneNode(True)
 		if batch_node is None:
 			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:PB4: batch node missing <batch/>')
+				luci_log.debug_verbose('RC:PB5: no <batch/> from %s' \
+					% self.__hostname)
 			raise RicciError, 'missing <batch/> in ricci response from "%s"' \
 					% self.__hostname
 
@@ -248,24 +252,24 @@
 		try:
 			batch_xml_str = '<?xml version="1.0" ?><batch>%s</batch>' \
 				% batch_str
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:BRun0: attempting batch "%s" for host "%s"' % (batch_xml_str, self.__hostname))
+			if LUCI_DEBUG_NET is True:
+				luci_log.debug_net_priv('RC:BRun0: attempting batch "%s" for host "%s"' % (batch_xml_str, self.__hostname))
 			batch_xml = minidom.parseString(batch_xml_str).firstChild
 		except Exception, e:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:BRun1: received invalid batch XML for %s: "%s": "%s"' % (self.__hostname, batch_xml_str, str(e)))
+			if LUCI_DEBUG_NET is True:
+				luci_log.debug_net_priv('RC:BRun1: received invalid batch XML for %s: "%s": "%s"' % (self.__hostname, batch_xml_str, str(e)))
 			raise RicciError, 'batch XML is malformed'
 
 		try:
 			ricci_xml = self.process_batch(batch_xml, async)
-			if LUCI_DEBUG_MODE is True:
+			if LUCI_DEBUG_NET is True:
 				try:
-					luci_log.debug_verbose('RC:BRun2: received XML "%s" from host %s in response to batch command.' % (ricci_xml.toxml(), self.__hostname))
+					luci_log.debug_net_priv('RC:BRun2: received XML "%s" from host %s in response to batch command.' % (ricci_xml.toxml(), self.__hostname))
 				except:
 					pass
 		except:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:BRun3: An error occurred while trying to process the batch job: "%s"' % batch_xml_str)
+			if LUCI_DEBUG_NET is True:
+				luci_log.debug_net_priv('RC:BRun3: An error occurred while trying to process the batch job: "%s"' % batch_xml_str)
 			return None
 
 		doc = minidom.Document()
@@ -273,8 +277,8 @@
 		return doc
 
 	def batch_report(self, batch_id):
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:BRep0: [auth=%d] asking for batchid# %s for host %s' % (self.__authed, batch_id, self.__hostname))
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net('RC:BRep0: [auth=%d] asking for batchid# %s for host %s' % (self.__authed, batch_id, self.__hostname))
 
 		if not self.authed():
 			raise RicciError, 'Not authenticated to host %s' % self.__hostname
@@ -290,7 +294,6 @@
 		# send request
 		self.__send(doc, self.__timeout_short)
 
-
 		# receive response
 		doc = self.__receive(self.__timeout_short)
 		if doc.firstChild.getAttribute('success') == '12':
@@ -308,62 +311,63 @@
 
 
 	def __send(self, xml_doc, timeout):
-		buff = '%s\n' % xml_doc.toxml()
 		try:
-			self.ss.send(buff, timeout)
+			self.ss.send(xml_doc.toxml(), timeout)
+			self.ss.send('\n', timeout)
 		except Exception, e:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:send0: Error sending XML "%s" to %s: %s' % (buff, self.__hostname, str(e)))
-			raise RicciError, 'write error while sending XML to host %s' \
-					% self.__hostname
-		except:
-			raise RicciError, 'write error while sending XML to host %s' \
+			if LUCI_DEBUG_NET is True:
+				luci_log.debug_net_priv('RC:send0: sending XML "%s" to %s: %s' \
+					% (xml_doc.toxml(), self.__hostname, str(e)))
+			luci_log.info('Error sending batch command to %s:%d: %s' \
+				% (self.__hostname, self.__port, str(e)))
+			raise RicciError, 'Write error while sending XML to host %s' \
 					% self.__hostname
-		if LUCI_DEBUG_MODE is True:
+
+		if LUCI_DEBUG_NET is True:
 			try:
-				luci_log.debug_verbose('RC:send1: Sent XML "%s" to host %s' \
+				luci_log.debug_net_priv('RC:send1: Sent XML "%s" to host %s' \
 					% (xml_doc.toxml(), self.__hostname))
 			except:
 				pass
 		return
 
 	def __receive(self, timeout):
-		doc = None
 		xml_in = ''
 		try:
 			xml_in = self.ss.recv(timeout)
 		except Exception, e:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:recv0: Error reading from %s: %s' \
-					% (self.__hostname, str(e)))
-			raise RicciError, 'Error reading data from host %s' \
-				% self.__hostname
-		except:
-			raise RicciError, 'Error reading data from host %s' \
-				% self.__hostname
+			errstr = 'Error reading from %s:%d: %s' \
+						% (self.__hostname, self.__port, str(e))
+			luci_log.info(errstr)
+			raise RicciError, errstr
 
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:recv1: Received XML "%s" from host %s' \
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net_priv('RC:recv1: Received XML "%s" from host %s' \
 				% (xml_in, self.__hostname))
 
+		doc = None
 		try:
-			if doc is None:
-				doc = minidom.parseString(xml_in)
+			doc = minidom.parseString(xml_in)
 		except Exception, e:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('RC:recv2: parsing XML "%s" from %s' \
+			errstr = 'Error parsing XML from host %s:%d: %s' \
+						% (self.__hostname, self.__port, str(e))
+			luci_log.info(errstr)
+			if LUCI_DEBUG_NET is True:
+				luci_log.debug_net_priv('RC:recv2: parsing XML "%s" from %s' \
 					% (xml_in, str(e)))
-			raise RicciError, 'Error parsing XML from host %s: %s' \
-					% (self.__hostname, str(e))
+			raise RicciError, errstr
 
 		if not doc or not doc.firstChild:
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('RC:recv3: empty XML response from %s' \
+					% self.__hostname)
 			raise RicciError, 'Error an empty response was received from host %s' % self.__hostname
 
 		try:
 			if doc.firstChild.nodeName != 'ricci':
-				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('RC:recv3: Expecting "ricci" got XML "%s" from %s' % (xml_in, self.__hostname))
-				raise Exception, 'Expecting first XML child node to be "ricci"'
+				if LUCI_DEBUG_NET is True:
+					luci_log.debug_net_priv('RC:recv4: Expecting "<ricci>" tag, got XML "%s" from %s' % (xml_in, self.__hostname))
+				raise Exception, 'Expected first XML child node to be "<ricci>"'
 		except Exception, e:
 			raise RicciError, 'Invalid XML ricci response from host %s' \
 					% self.__hostname
@@ -374,10 +378,12 @@
 		return None
 
 	try:
-		return RicciCommunicator(hostname)
+		rc = RicciCommunicator(hostname)
+		if not rc:
+			raise Exception, 'initialization failed'
 	except Exception, e:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:GRC0: Error creating a ricci connection to %s: %s' % (hostname, str(e)))
+		luci_log.info('Error creating a ricci connection to %s: %r %s' \
+			% (hostname, e, str(e)))
 		return None
 
 def ricci_get_called_hostname(self, ricci):
@@ -413,9 +419,10 @@
 
 def batch_status(batch_xml):
 	if batch_xml.nodeName != 'batch':
-		if LUCI_DEBUG_MODE is True:
+		if LUCI_DEBUG_NET is True:
 			try:
-				luci_log.debug_verbose('RC:BS0: Expecting an XML batch node. Got \"%s\"' % batch_xml.toxml())
+				luci_log.debug_net_priv('RC:BS0: batch node. Got \"%s\"' \
+					% batch_xml.toxml())
 			except:
 				pass
 		raise RicciError, 'Not an XML batch node'
@@ -435,11 +442,12 @@
 					last = last + 1
 					last = last - 2 * last
 	try:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:BS1: Returning (%d, %d) for batch_status("%s")' % (last, total, batch_xml.toxml()))
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net_priv('RC:BS1: (%d, %d) for batch_status("%s")' \
+				% (last, total, batch_xml.toxml()))
 	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:BS2: error %r %s: (last, total)' \
+			luci_log.debug_verbose('RC:BS2: error %r %s: (%d, %d)' \
 				% (e, str(e), last, total))
 	return (last, total)
 
@@ -464,8 +472,8 @@
 
 def extract_module_status(batch_xml, module_num=1):
 	if batch_xml.nodeName != 'batch':
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('RC:EMS0: Expecting "batch" got "%s"' \
+		if LUCI_DEBUG_NET is True:
+			luci_log.debug_net_priv('RC:EMS0: Expecting "batch" got "%s"' \
 				% batch_xml.toxml())
 		raise RicciError, 'Invalid XML node; expecting a batch node'
 
--- conga/luci/site/luci/Extensions/LuciSyslog.py	2007/05/18 02:36:59	1.11.4.3
+++ conga/luci/site/luci/Extensions/LuciSyslog.py	2007/06/08 18:26:15	1.11.4.4
@@ -32,37 +32,9 @@
 	def initialized(self):
 		return self.__init > 0
 
-	def info(self, msg):
-		if not self.__init:
-			return
-		try:
-			syslog(LOG_INFO, msg)
-		except:
-			#raise LuciSyslogError, 'syslog info call failed'
-			pass
-
-	def warn(self, msg):
-		if not self.__init:
-			return
-		try:
-			syslog(LOG_WARNING, msg)
-		except:
-			#raise LuciSyslogError, 'syslog warn call failed'
-			pass
-
-	def private(self, msg):
+	def log_msg(self, pri, msg):
 		if not self.__init:
 			return
-		try:
-			syslog(LOG_AUTH, msg)
-		except:
-			#raise LuciSyslogError, 'syslog private call failed'
-			pass
-
-	def debug_verbose(self, msg):
-		if not LUCI_DEBUG_MODE or LUCI_DEBUG_VERBOSITY < 2 or not self.__init:
-			return
-
 		msg_len = len(msg)
 		if msg_len < 1:
 			return
@@ -70,8 +42,9 @@
 		while True:
 			cur_len = min(msg_len, 800)
 			cur_msg = msg[:cur_len]
+
 			try:
-				syslog(LOG_DEBUG, cur_msg)
+				syslog(pri, cur_msg)
 			except:
 				pass
 
@@ -81,14 +54,34 @@
 			else:
 				break
 
+	def info(self, msg):
+		self.log_msg(LOG_INFO, msg)
+
+	def warn(self, msg):
+		self.log_msg(LOG_WARNING, msg)
+
+	def private(self, msg):
+		self.log_msg(LOG_AUTH, msg)
+
+	def debug_verbose(self, msg):
+		if LUCI_DEBUG_MODE is not True or LUCI_DEBUG_VERBOSITY < 2:
+			return
+		self.log_msg(LOG_DEBUG, msg)
+
+	def debug_net(self, msg):
+		if LUCI_DEBUG_MODE is not True or LUCI_DEBUG_VERBOSITY < 3:
+			return
+		self.log_msg(LOG_DEBUG, msg)
+
+	def debug_net_priv(self, msg):
+		if LUCI_DEBUG_MODE is not True or LUCI_DEBUG_VERBOSITY < 3:
+			return
+		self.log_msg(LOG_AUTH, msg)
+
 	def debug(self, msg):
-		if not LUCI_DEBUG_MODE or not self.__init:
+		if LUCI_DEBUG_MODE is not True:
 			return
-		try:
-			syslog(LOG_DEBUG, msg)
-		except:
-			#raise LuciSyslogError, 'syslog debug call failed'
-			pass
+		self.log_msg(LOG_DEBUG, msg)
 
 	def close(self):
 		try:



^ permalink raw reply	[flat|nested] 3+ messages in thread
* [Cluster-devel] conga/luci/site/luci/Extensions conga_constant ...
@ 2007-05-14 16:02 rmccabe
  0 siblings, 0 replies; 3+ messages in thread
From: rmccabe @ 2007-05-14 16:02 UTC (permalink / raw)
  To: cluster-devel.redhat.com

CVSROOT:	/cvs/cluster
Module name:	conga
Branch: 	EXPERIMENTAL
Changes by:	rmccabe at sourceware.org	2007-05-14 16:02:16

Modified files:
	luci/site/luci/Extensions: conga_constants.py LuciDB.py 

Log message:
	More cleanup..

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/conga_constants.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.39.2.2&r2=1.39.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/LuciDB.py.diff?cvsroot=cluster&only_with_tag=EXPERIMENTAL&r1=1.1.2.3&r2=1.1.2.4

--- conga/luci/site/luci/Extensions/conga_constants.py	2007/05/04 19:10:24	1.39.2.2
+++ conga/luci/site/luci/Extensions/conga_constants.py	2007/05/14 16:02:11	1.39.2.3
@@ -140,7 +140,8 @@
 CLUSTER_NODE_NOT_MEMBER	= 0x02
 CLUSTER_NODE_ADDED		= 0x04
 
-# Debugging parameters. Set LUCI_DEBUG_MODE to 1 and LUCI_DEBUG_VERBOSITY
+# Debugging parameters. Set LUCI_DEBUG_MODE to True and LUCI_DEBUG_VERBOSITY
 # to >= 2 to get full debugging output in syslog (LOG_DAEMON/LOG_DEBUG).
-LUCI_DEBUG_MODE			= 1
+
+LUCI_DEBUG_MODE			= True
 LUCI_DEBUG_VERBOSITY	= 2
--- conga/luci/site/luci/Extensions/Attic/LuciDB.py	2007/05/08 22:19:35	1.1.2.3
+++ conga/luci/site/luci/Extensions/Attic/LuciDB.py	2007/05/14 16:02:11	1.1.2.4
@@ -1,43 +1,52 @@
 from AccessControl import getSecurityManager
-from conga_constants import CLUSTER_FOLDER_PATH, BATCH_ID, TASKTYPE, FLAG_DESC, CLUSTER_ADD, CLUSTER_NODE_ADDED, CLUSTER_NODE_NEED_AUTH, LAST_STATUS, PLONE_ROOT, STORAGE_FOLDER_PATH, CLUSTER_NODE_NOT_MEMBER
 import RicciQuery as rq
 from ricci_communicator import RicciCommunicator
 from LuciZope import isAdmin
 
+from conga_constants import CLUSTER_FOLDER_PATH, BATCH_ID, TASKTYPE, \
+	FLAG_DESC, CLUSTER_ADD, CLUSTER_NODE_ADDED, CLUSTER_NODE_NEED_AUTH, \
+	LAST_STATUS, PLONE_ROOT, STORAGE_FOLDER_PATH, CLUSTER_NODE_NOT_MEMBER, \
+	LUCI_DEBUG_MODE
+
 from homebase_adapters import luci_log
 
 def getClusterNode(self, nodename, clustername):
 	try:
-		cluster_node = self.restrictedTraverse('%s%s/%s' % (CLUSTER_FOLDER_PATH, clustername, nodename))
+		cluster_node = self.restrictedTraverse('%s%s/%s' \
+			% (CLUSTER_FOLDER_PATH, clustername, nodename))
 		if not cluster_node:
 			return None
 		return cluster_node
 	except Exception, e:
-		luci_log.debug_verbose('getClusterNode0: %s %s: %r' \
-			% (nodename, clustername, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('getClusterNode0: %s %s: %r' \
+				% (nodename, clustername, e))
 	return None
 
 def getStorageNode(self, nodename):
 	try:
-		storage_node = self.restrictedTraverse('%s%s' % (STORAGE_FOLDER_PATH, nodename))
+		storage_node = self.restrictedTraverse('%s%s' \
+			% (STORAGE_FOLDER_PATH, nodename))
 		if not storage_node:
 			return None
 		return storage_node
 	except Exception, e:
-		luci_log.debug_verbose('getStorageNode0: %s: %r' % (nodename, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('getStorageNode0: %s: %r' % (nodename, e))
 	return None
 
-def testNodeFlag(node, flag_mask):
+def testNodeStatus(node, flag_mask):
 	try:
 		flags = node.getProperty('flags')
 		if flags is None:
 			return False
 		return flags & flag_mask != 0
 	except Exception, e:
-		luci_log.debug_verbose('testNodeFlag0: %r' % e)
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('testNodeStatus0: %r' % e)
 	return False
 
-def setNodeFlag(node, flag_mask):
+def setNodeStatus(node, flag_mask):
 	try:
 		flags = node.getProperty('flags')
 		if flags is None:
@@ -47,9 +56,10 @@
 		try:
 			node.manage_addProperty('flags', flag_mask, 'int')
 		except Exception, e:
-			luci_log.debug_verbose('setNodeFlag0: %r' % e)
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('setNodeStatus0: %r' % e)
 
-def delNodeFlag(node, flag_mask):
+def clearNodeStatus(node, flag_mask):
 	try:
 		flags = node.getProperty('flags')
 		if flags is None:
@@ -57,7 +67,8 @@
 		if flags & flag_mask != 0:
 			node.manage_changeProperties({ 'flags': flags & ~flag_mask })
 	except Exception, e:
-		luci_log.debug_verbose('delNodeFlag0: %r' % e)
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('clearNodeStatus0: %r' % e)
 
 def set_node_flag(self, cluname, agent, batchid, task, desc):
 	path = '%s%s' % (CLUSTER_FOLDER_PATH, cluname)
@@ -76,14 +87,17 @@
 	except Exception, e:
 		errmsg = 'SNF0: error creating flag (%s,%s,%s) at %s: %r' \
 					% (batch_id, task, desc, objpath, e)
-		luci_log.debug_verbose(errmsg)
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose(errmsg)
 		raise Exception, errmsg
 
-def noNodeFlagsPresent(self, nodefolder, flagname, hostname):
+def noNodeStatussPresent(self, nodefolder, flagname, hostname):
 	try:
 		items = nodefolder.objectItems('ManagedSystem')
 	except Exception, e:
-		luci_log.debug('NNFP0: error getting flags for %s: %r' % (nodefolder[0], e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug('NNFP0: error getting flags for %s: %r' \
+				% (nodefolder[0], e))
 		return None
 
 	for item in items:
@@ -95,27 +109,32 @@
 			# hostname must be a FQDN
 			rc = RicciCommunicator(hostname)
 		except Exception, e:
-			luci_log.info('NNFP1: ricci error %s: %r' % (hostname, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.info('NNFP1: ricci error %s: %r' % (hostname, e))
 			return None
 
 		if not rc.authed():
 			try:
 				snode = getStorageNode(self, hostname)
-				setNodeFlag(snode, CLUSTER_NODE_NEED_AUTH)
+				setNodeStatus(snode, CLUSTER_NODE_NEED_AUTH)
 			except:
 				pass
-			luci_log.info('NNFP2: %s not authenticated' % item[0])
+			if LUCI_DEBUG_MODE is True:
+				luci_log.info('NNFP2: %s not authenticated' % item[0])
 
 		batch_ret = rq.checkBatch(rc, item[1].getProperty(BATCH_ID))
 		finished = batch_ret[0]
 		if finished == True or finished == -1:
 			if finished == -1:
-				luci_log.debug_verbose('NNFP2: batch error: %s' % batch_ret[1])
+				if LUCI_DEBUG_MODE is True:
+					luci_log.debug_verbose('NNFP2: batch error: %s' \
+						% batch_ret[1])
 			try:
 				nodefolder.manage_delObjects([item[0]])
 			except Exception, e:
-				luci_log.info('NNFP3: manage_delObjects for %s failed: %r' \
-					% (item[0], e))
+				if LUCI_DEBUG_MODE is True:
+					luci_log.info('NNFP3: manage_delObjects for %s failed: %r' \
+						% (item[0], e))
 				return None
 			return True
 		else:
@@ -130,8 +149,9 @@
 		clusterfolder = self.restrictedTraverse(path)
 		objs = clusterfolder.objectItems('Folder')
 	except Exception, e:
-		luci_log.debug_verbose('RNN0: error for %s/%s: %r' \
-			% (nodename, clustername, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('RNN0: error for %s/%s: %r' \
+				% (nodename, clustername, e))
 		return nodename
 
 	for obj in objs:
@@ -141,8 +161,9 @@
 		except:
 			continue
 
-	luci_log.debug_verbose('RNN1: failed for %s/%s: nothing found' \
-		% (nodename, clustername))
+	if LUCI_DEBUG_MODE is True:
+		luci_log.debug_verbose('RNN1: failed for %s/%s: nothing found' \
+			% (nodename, clustername))
 	return nodename
 
 def resolveClusterChanges(self, clusterName, model):
@@ -151,17 +172,19 @@
 		if not mb_nodes or not len(mb_nodes):
 			raise Exception, 'node list is empty'
 	except Exception, e:
-		luci_log.debug_verbose('RCC0: no model builder nodes found for %s: %r' \
-				% (clusterName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('RCC0: no model builder nodes found for %s: %r' % (clusterName, e))
 		return 'Unable to find cluster nodes for %s' % clusterName
 
 	try:
-		cluster_node = self.restrictedTraverse('%s/systems/cluster/%s' % (PLONE_ROOT, clusterName))
+		cluster_node = self.restrictedTraverse('%s/systems/cluster/%s' \
+			% (PLONE_ROOT, clusterName))
 		if not cluster_node:
 			raise Exception, 'cluster node is none'
 	except Exception, e:
-		luci_log.debug('RCC1: cant find cluster node for %s: %r'
-			% (clusterName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug('RCC1: cant find cluster node for %s: %r' \
+				% (clusterName, e))
 		return 'Unable to find an entry for %s in the Luci database.' % clusterName
 
 	try:
@@ -170,7 +193,8 @@
 			raise Exception, 'no database nodes'
 	except Exception, e:
 		# Should we just create them all? Can this even happen?
-		luci_log.debug('RCC2: error: %r' % e)
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug('RCC2: error: %r' % e)
 		return 'Unable to find database entries for any nodes in %s' % clusterName
 
 	same_host = lambda x, y: x == y or x[:len(y) + 1] == y + '.' or y[:len(x) + 1] == x + '.'
@@ -201,24 +225,27 @@
 		try:
 			# or alternately
 			# new_node = cluster_node.restrictedTraverse(i)
-			# #setNodeFlag(self, new_node, CLUSTER_NODE_NOT_MEMBER)
+			# #setNodeStatus(self, new_node, CLUSTER_NODE_NOT_MEMBER)
 			cluster_node.delObjects([i])
 			messages.append('Node "%s" is no longer in a member of cluster "%s." It has been deleted from the management interface for this cluster.' % (i, clusterName))
-			luci_log.debug_verbose('VCC3: deleted node %s' % i)
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('VCC3: deleted node %s' % i)
 		except Exception, e:
-			luci_log.debug_verbose('VCC4: delObjects: %s: %r' % (i, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('VCC4: delObjects: %s: %r' % (i, e))
 
 	new_flags = CLUSTER_NODE_NEED_AUTH | CLUSTER_NODE_ADDED
 	for i in new_list:
 		try:
-			cluster_node.manage_addFolder(i, '__luci__:csystem:%s' % clusterName)
+			cluster_node.manage_addFolder(i)
 			new_node = cluster_node.restrictedTraverse(i)
-			setNodeFlag(self, new_node, new_flags)
+			setNodeStatus(self, new_node, new_flags)
 			messages.append('A new cluster node, "%s," is now a member of cluster "%s." It has been added to the management interface for this cluster, but you must authenticate to it in order for it to be fully functional.' % (i, clusterName))
 		except Exception, e:
 			messages.append('A new cluster node, "%s," is now a member of cluster "%s,". but it has not been added to the management interface for this cluster as a result of an error creating a database entry for it.' % (i, clusterName))
-			luci_log.debug_verbose('VCC5: addFolder: %s/%s: %r' \
-				% (clusterName, i, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('VCC5: addFolder: %s/%s: %r' \
+					% (clusterName, i, e))
 
 	return messages
 
@@ -228,7 +255,9 @@
 	try:
 		clusterfolder = self.restrictedTraverse(path)
 	except Exception, e:
-		luci_log.debug_verbose('buildCCF0: no cluster folder at %s: %r' % (path, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('buildCCF0: no cluster folder at %s: %r' \
+				% (path, e))
 		return None
 
 	for key in batch_map.keys():
@@ -248,8 +277,8 @@
 			flag.manage_addProperty(FLAG_DESC, 'Creating node "%s" for cluster "%s"' % (key, clusterName), 'string')
 			flag.manage_addProperty(LAST_STATUS, 0, 'int')
 		except Exception, e:
-			luci_log.debug_verbose('buildCCF1: error creating flag for %s: %r' \
-				% (key, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('buildCCF1: error creating flag for %s: %r' % (key, e))
 
 def manageCluster(self, clusterName, node_list, cluster_os):
 	clusterName = str(clusterName)
@@ -259,48 +288,55 @@
 		if not clusters:
 			raise Exception, 'cannot find the cluster entry in the DB'
 	except Exception, e:
-		luci_log.debug_verbose('MC0: %s: %r' % (clusterName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('MC0: %s: %r' % (clusterName, e))
 		return 'Unable to create cluster %s: the cluster directory is missing.' % clusterName
 
 	try:
 		newCluster = self.restrictedTraverse('%s%s' % (CLUSTER_FOLDER_PATH, clusterName))
 		if newCluster:
-			luci_log.debug_verbose('MC1: cluster %s: already exists' % clusterName)
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('MC1: cluster %s: already exists' \
+					% clusterName)
 			return 'A cluster named %s is already managed by Luci' % clusterName
 	except:
 		pass
 
 	try:
-		clusters.manage_addFolder(clusterName, '__luci__:cluster')
+		clusters.manage_addFolder(clusterName)
 		newCluster = self.restrictedTraverse('%s%s' % (CLUSTER_FOLDER_PATH, clusterName))
 		if not newCluster:
 			raise Exception, 'unable to create the cluster DB entry for %s' % clusterName
 	except Exception, e:
-		luci_log.debug_verbose('MC2: %s: %r' % (clusterName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('MC2: %s: %r' % (clusterName, e))
 		return 'Unable to create cluster %s: %r' % (clusterName, e)
 
 	try:
 		newCluster.manage_acquiredPermissions([])
 		newCluster.manage_role('View', ['Access Contents Information', 'View'])
 	except Exception, e:
-		luci_log.debug_verbose('MC3: %s: %r' % (clusterName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('MC3: %s: %r' % (clusterName, e))
 		try:
 			clusters.manage_delObjects([clusterName])
 		except Exception, e:
-			luci_log.debug_verbose('MC4: %s: %r' % (clusterName, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('MC4: %s: %r' % (clusterName, e))
 		return 'Unable to set permissions on new cluster: %s: %r' % (clusterName, e)
 
 	try:
 		newCluster.manage_addProperty('cluster_os', cluster_os, 'string')
 	except Exception, e:
-		luci_log.debug_verbose('MC5: %s: %s: %r' \
-			% (clusterName, cluster_os, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('MC5: %s: %s: %r' \
+				% (clusterName, cluster_os, e))
 
 	for i in node_list:
 		host = node_list[i]['host']
 
 		try:
-			newCluster.manage_addFolder(host, '__luci__:csystem:%s' % clusterName)
+			newCluster.manage_addFolder(host)
 			newSystem = self.restrictedTraverse('%s%s/%s' % (CLUSTER_FOLDER_PATH, clusterName, host))
 			if not newSystem:
 				raise Exception, 'unable to create cluster system DB entry for node %s' % host
@@ -310,11 +346,13 @@
 			try:
 				clusters.manage_delObjects([clusterName])
 			except Exception, e:
-				luci_log.debug_verbose('MC6: %s: %s: %r' \
-					% (clusterName, host, e))
+				if LUCI_DEBUG_MODE is True:
+					luci_log.debug_verbose('MC6: %s: %s: %r' \
+						% (clusterName, host, e))
 
-			luci_log.debug_verbose('MC7: %s: %s: %r' \
-				% (clusterName, host, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('MC7: %s: %s: %r' \
+					% (clusterName, host, e))
 			return 'Unable to create cluster node %s for cluster %s: %r' \
 				% (host, clusterName, e)
 
@@ -323,7 +361,8 @@
 		if not ssystem:
 			raise Exception, 'The storage DB entry is missing'
 	except Exception, e:
-		luci_log.debug_verbose('MC8: %s: %s: %r' % (clusterName, host, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('MC8: %s: %s: %r' % (clusterName, host, e))
 		return 'Error adding storage node %s: %r' % (host, e)
 
 	# Only add storage systems if the cluster and cluster node DB
@@ -339,12 +378,14 @@
 			pass
 
 		try:
-			ssystem.manage_addFolder(host, '__luci__:system')
+			ssystem.manage_addFolder(host)
 			newSystem = self.restrictedTraverse('%s%s' % (STORAGE_FOLDER_PATH, host))
 			newSystem.manage_acquiredPermissions([])
 			newSystem.manage_role('View', [ 'Access contents information' , 'View' ])
 		except Exception, e:
-			luci_log.debug_verbose('MC9: %s: %s: %r' % (clusterName, host, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('MC9: %s: %s: %r' \
+					% (clusterName, host, e))
 
 def createClusterSystems(self, clusterName, node_list):
 	try:
@@ -352,7 +393,8 @@
 		if not clusterObj:
 			raise Exception, 'cluster %s DB entry is missing' % clusterName
 	except Exception, e:
-		luci_log.debug_verbose('CCS0: %s: %r' % (clusterName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('CCS0: %s: %r' % (clusterName, e))
 		return 'No cluster named "%s" is managed by Luci' % clusterName
 
 	for x in node_list:
@@ -360,9 +402,11 @@
 		host = str(i['host'])
 
 		try:
-			clusterObj.manage_addFolder(host, '__luci__:csystem:%s' % clusterName)
+			clusterObj.manage_addFolder(host)
 		except Exception, e:
-			luci_log.debug_verbose('CCS0a: %s: %s: %r' % (clusterName, host, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('CCS0a: %s: %s: %r' \
+					% (clusterName, host, e))
 
 		try:
 			newSystem = self.restrictedTraverse('%s%s/%s' % (CLUSTER_FOLDER_PATH, clusterName, host))
@@ -371,7 +415,9 @@
 			newSystem.manage_acquiredPermissions([])
 			newSystem.manage_role('View', [ 'Access contents information' , 'View' ])
 		except Exception, e:
-			luci_log.debug_verbose('CCS1: %s: %s: %r' % (clusterName, host, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('CCS1: %s: %s: %r' \
+					% (clusterName, host, e))
 			return 'Unable to create cluster node %s for cluster %s: %r' \
 				% (host, clusterName, e)
 
@@ -381,7 +427,8 @@
 			raise Exception, 'storage DB entry is missing'
 	except Exception, e:
 		# This shouldn't fail, but if it does, it's harmless right now
-		luci_log.debug_verbose('CCS2: %s: %r' % (clusterName, host, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('CCS2: %s: %r' % (clusterName, host, e))
 		return None
 
 	# Only add storage systems if the and cluster node DB
@@ -398,13 +445,13 @@
 			pass
 
 		try:
-			ssystem.manage_addFolder(host, '__luci__:system')
+			ssystem.manage_addFolder(host)
 			newSystem = self.restrictedTraverse('%s%s' % (STORAGE_FOLDER_PATH, host))
 			newSystem.manage_acquiredPermissions([])
 			newSystem.manage_role('View', [ 'Access contents information' , 'View' ])
 		except Exception, e:
-			luci_log.debug_verbose('CCS3: %s: %r' % (clusterName, host, e))
-
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('CCS3: %s: %r' % (clusterName, host, e))
 
 def delSystem(self, systemName):
 	try:
@@ -412,7 +459,8 @@
 		if not ssystem:
 			raise Exception, 'storage DB entry is missing'
 	except Exception, e:
-		luci_log.debug_verbose('delSystem0: %s: %r' % (systemName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('delSystem0: %s: %r' % (systemName, e))
 		return 'Unable to find storage system %s: %r' % (systemName, e)
 
 	try:
@@ -423,9 +471,11 @@
 		try:
 			ssystem.manage_delObjects([ systemName ])
 		except Exception, e1:
-			luci_log.debug_verbose('delSystem1: %s: %r' % (systemName, e1))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('delSystem1: %s: %r' % (systemName, e1))
 			return 'Unable to delete the storage system %s' % systemName
-		luci_log.debug_verbose('delSystem2: %s: %r' % (systemName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('delSystem2: %s: %r' % (systemName, e))
 		return
 
 	# Only unauthenticate if the system isn't a member of
@@ -458,18 +508,19 @@
 	try:
 		ssystem.manage_delObjects([ systemName ])
 	except Exception, e:
-		luci_log.debug_verbose('delSystem3: %s: %r' % (systemName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('delSystem3: %s: %r' % (systemName, e))
 		return 'Unable to delete storage system %s: %r' \
 			% (systemName, e)
 
-
 def delCluster(self, clusterName):
 	try:
 		clusters = self.restrictedTraverse(CLUSTER_FOLDER_PATH)
 		if not clusters:
 			raise Exception, 'clusters DB entry is missing'
 	except Exception, e:
-		luci_log.debug_verbose('delCluster0: %r' % e)
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('delCluster0: %r' % e)
 		return 'Unable to find cluster %s' % clusterName
 
 	err = delClusterSystems(self, clusterName)
@@ -479,7 +530,8 @@
 	try:
 		clusters.manage_delObjects([ clusterName ])
 	except Exception, e:
-		luci_log.debug_verbose('delCluster1: %s %r' % (clusterName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('delCluster1: %s %r' % (clusterName, e))
 		return 'Unable to delete cluster %s' % clusterName
 
 def delClusterSystem(self, cluster, systemName):
@@ -491,14 +543,15 @@
 			rc = RicciCommunicator(systemName, enforce_trust=False)
 			rc.unauth()
 		except Exception, e:
-			luci_log.debug_verbose('delClusterSystem0: ricci error for %s: %r' \
-				% (systemName, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('delClusterSystem0: ricci error for %s: %r' % (systemName, e))
 
 	try:
 		cluster.manage_delObjects([ systemName ])
 	except Exception, e:
 		err_str = 'Error deleting cluster object %s: %r' % (systemName, e)
-		luci_log.debug_verbose('delClusterSystem1: %s' % err_str)
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('delClusterSystem1: %s' % err_str)
 		return err_str
 
 def delClusterSystems(self, clusterName):
@@ -512,19 +565,23 @@
 			if not csystems or len(csystems) < 1:
 				return None
 		except Exception, e:
-			luci_log.debug_verbose('delCluSystems0: %r' % e)
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('delCluSystems0: %r' % e)
 			return None
 	except Exception, er:
-		luci_log.debug_verbose('delCluSystems1: error for %s: %r' \
-			% (clusterName, er))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('delCluSystems1: error for %s: %r' \
+				% (clusterName, er))
 		return str(er)
 
 	error_list = list()
 	for i in csystems:
 		err = delClusterSystem(self, cluster, i[0])
 		if err:
-			error_list.append('Unable to delete the cluster system %s: %s\n' % (i[0], err))
-			luci_log.debug_verbose('delCluSystems2: %s' % err)
+			error_list.append('Unable to delete the cluster system %s: %s\n' \
+				% (i[0], err))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('delCluSystems2: %s' % err)
 	return ''.join(error_list)
 
 # In case we want to give access to non-admin users in the future
@@ -562,7 +619,7 @@
 	need_auth_hash = {}
 	for i in storage:
 		storageList.append(i[0])
-		if testNodeFlag(i[1], CLUSTER_NODE_NEED_AUTH) != False:
+		if testNodeStatus(i[1], CLUSTER_NODE_NEED_AUTH) != False:
 			need_auth_hash[i[0]] = i[1]
 
 	chash = {}
@@ -570,7 +627,7 @@
 		csystems = getClusterSystems(self, i[0])
 		cslist = list()
 		for c in csystems:
-			if testNodeFlag(c[1], CLUSTER_NODE_NEED_AUTH) != False:
+			if testNodeStatus(c[1], CLUSTER_NODE_NEED_AUTH) != False:
 				need_auth_hash[c[0]] = c[1]
 			cslist.append(c[0])
 		chash[i[0]] = cslist
@@ -581,131 +638,67 @@
 	return ret
 
 def getClusterSystems(self, clusterName):
-	if isAdmin(self):
-		try:
-			return self.restrictedTraverse('%s%s/objectItems' % (CLUSTER_FOLDER_PATH, clusterName))('Folder')
-		except Exception, e:
-			luci_log.debug_verbose('GCSy0: %s: %r' % (clusterName, e))
-			return None
-
 	try:
-		i = getSecurityManager().getUser()
-		if not i:
-			raise Exception, 'security manager says no user'
+		cluster_nodes = self.restrictedTraverse('%s%s/objectItems' % (CLUSTER_FOLDER_PATH, clusterName))('Folder')
 	except Exception, e:
-		luci_log.debug_verbose('GCSy1: %s: %r' % (clusterName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('GCSy0: %s: %r' % (clusterName, e))
 		return None
 
+	if isAdmin(self):
+		return cluster_nodes
+
 	try:
-		csystems = self.restrictedTraverse('%s%s/objectItems' % (CLUSTER_FOLDER_PATH, clusterName))('Folder')
-		if not csystems or len(csystems) < 1:
-			return None
+		cluster =  self.restrictedTraverse('%s%s/objectItems' \
+			% (CLUSTER_FOLDER_PATH, clusterName))
 	except Exception, e:
-		luci_log.debug_verbose('GCSy2: %s: %r' % (clusterName, e))
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('GCSy1: %s: %r' % (clusterName, e))
 		return None
 
-	allowedCSystems = list()
-	for c in csystems:
-		try:
-			if i.has_role('View', c[1]):
-				allowedCSystems.append(c)
-		except Exception, e:
-			luci_log.debug_verbose('GCSy3: %s: %s: %r' \
-				% (clusterName, c[0], e))
-
-	return allowedCSystems
+	if cluster_permission_check(self, cluster):
+		return cluster_nodes 
+	return None
 
 def getClusters(self):
-	if isAdmin(self):
-		try:
-			return self.restrictedTraverse('%s/systems/cluster/objectItems' % PLONE_ROOT)('Folder')
-		except Exception, e:
-			luci_log.debug_verbose('GC0: %r' % e)
-			return None
-	try:
-		i = getSecurityManager().getUser()
-		if not i:
-			raise Exception, 'GSMGU failed'
-	except Exception, e:
-		luci_log.debug_verbose('GC1: %r' % e)
-		return None
-
 	try:
 		clusters = self.restrictedTraverse('%s/systems/cluster/objectItems' % PLONE_ROOT)('Folder')
-		if not clusters or len(clusters) < 1:
-			return None
 	except Exception, e:
-		luci_log.debug_verbose('GC2: %r' % e)
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('GC0: %r' % e)
 		return None
 
-	allowedClusters = list()
-	for c in clusters:
-		try:
-			if i.has_role('View', c[1]):
-				allowedClusters.append(c)
-		except Exception, e:
-			luci_log.debug_verbose('GC3: %s: %r' % (c[0], e))
-
-	return allowedClusters
-
-
-def getStorage(self):
 	if isAdmin(self):
-		try:
-			return self.restrictedTraverse('%s/systems/storage/objectItems' % PLONE_ROOT)('Folder')
-		except Exception, e:
-			luci_log.debug_verbose('GS0: %r' % e)
-			return None
-
-	try:
-		i = getSecurityManager().getUser()
-		if not i:
-			raise Exception, 'GSMGU failed'
-	except Exception, e:
-		luci_log.debug_verbose('GS1: %r' % e)
-		return None
+		return clusters
+	return check_clusters(self, clusters)
 
+def getStorage(self):
 	try:
 		storage = self.restrictedTraverse('%s/systems/storage/objectItems' % PLONE_ROOT)('Folder')
-		if not storage or len(storage) < 1:
-			return None
 	except Exception, e:
-		luci_log.debug_verbose('GS2: %r' % e)
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('GS0: %r' % e)
 		return None
-
-	allowedStorage = list()
-	for s in storage:
-		try:
-			if i.has_role('View', s[1]):
-				allowedStorage.append(s)
-		except Exception, e:
-			luci_log.debug_verbose('GS3: %r' % e)
-
-	return allowedStorage
+	if isAdmin(self):
+		return storage
+	return allowed_systems(storage)
 
 def check_clusters(self, clusters):
-	sm = getSecurityManager()
-	user = sm.getUser()
-
-	clist = list()
-	for cluster in clusters:
-		if user.has_permission('View', cluster):
-			clist.append(cluster)
-	return clist
+	user = getSecurityManager().getUser()
+	return filter(lambda x: user.has_role('View', x[1]), clusters)
 
 def cluster_permission_check(cluster):
 	try:
-		sm = getSecurityManager()
-		user = sm.getUser()
-		if user.has_permission('View', cluster):
+		user = getSecurityManager().getUser()
+		if user.has_role('View', cluster[1]):
 			return True
 	except:
 		pass
 	return False
 
-def allowed_systems(self, user, systems):
-	user = getSecurityManager().getUser().getUser()
-	return map(lambda x: user.has_permission('View', x[1]), systems)
+def allowed_systems(self, systems):
+	user = getSecurityManager().getUser()
+	return filter(lambda x: user.has_role('View', x[1]), systems)
 
 def access_to_host_allowed(self, hostname, allowed_systems_list):
 	allowed = dict(map(lambda x: [ x[0], None ], allowed_systems_list))
@@ -717,31 +710,37 @@
 		if not perm:
 			return None
 	except Exception, e:
-		luci_log.debug_verbose('GRA0: %r' % e)
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('GRA0: %r' % e)
 		return None
 
 	try:
 		path = '%s%s' % (CLUSTER_FOLDER_PATH, clustername)
 		clusterfolder = self.restrictedTraverse(path)
 		if not clusterfolder:
-			luci_log.debug('GRA1: cluster folder %s for %s is missing' \
-				% (path, clustername))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug('GRA1: cluster folder %s for %s is missing' \
+					% (path, clustername))
 			return None
 
 		nodes = clusterfolder.objectItems('Folder')
 		if len(nodes) < 1:
-			luci_log.debug('GRA2: no cluster nodes for %s found.' % clustername)
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug('GRA2: no cluster nodes for %s found' \
+					% clustername)
 			raise Exception, 'No cluster nodes were found@%s' % path
 	except Exception, e:
 		try:
-			luci_log.debug('GRA3: cluster folder %s for %s is missing: %r' \
-				% (path, clustername, e))
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug('GRA3: cluster folder %s for %s is missing: %r' \
+					% (path, clustername, e))
 
 			if len(clusterfolder.objectItems()) < 1:
 				clusters = self.restrictedTraverse(str(CLUSTER_FOLDER_PATH))
 				clusters.manage_delObjects([clustername])
 		except Exception, ein:
-			luci_log.debug_verbose('GRA4: %r' % ein)
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('GRA4: %r' % ein)
 		return None
 
 	cluname = clustername.lower()
@@ -757,12 +756,14 @@
 		try:
 			rc = RicciCommunicator(hostname)
 			if not rc:
-				luci_log.debug_verbose('GRA5: rc is None')
+				if LUCI_DEBUG_MODE is True:
+					luci_log.debug_verbose('GRA5: rc is None')
 				continue
 
 			ricci_hostname = rc.hostname()
 			if not ricci_hostname:
-				luci_log.debug_verbose('GRA6: ricci_hostname is blank')
+				if LUCI_DEBUG_MODE is True:
+					luci_log.debug_verbose('GRA6: ricci_hostname is blank')
 				continue
 
 			clu_info = rc.cluster_info()
@@ -770,25 +771,32 @@
 			cur_name = str(clu_info[0]).strip().lower()
 			if not cur_name:
 				cur_name = None
-				luci_log.debug_verbose('GRA7: cluster name is none for %s' % ricci_hostname)
+				if LUCI_DEBUG_MODE is True:
+					luci_log.debug_verbose('GRA7: cluster name is none for %s' \
+						% ricci_hostname)
 
 			cur_alias = str(clu_info[1]).strip().lower()
 			if not cur_alias:
 				cur_alias = None
-				luci_log.debug_verbose('GRA8: cluster alias is none for %s' % ricci_hostname)
+				if LUCI_DEBUG_MODE is True:
+					luci_log.debug_verbose('GRA8: no cluster alias for %s' \
+						% ricci_hostname)
 
 			if (cur_name is not None and cluname != cur_name) and (cur_alias is not None and cluname != cur_alias):
-				luci_log.debug('GRA9: node %s reports it\'s in cluster %s:%s; we expect %s' % (hostname, clu_info[0], clu_info[1], cluname))
-				setNodeFlag(self, node, CLUSTER_NODE_NOT_MEMBER)
+				if LUCI_DEBUG_MODE is True:
+					luci_log.debug('GRA9: node %s reports it\'s in cluster [%s:%s] we expect %s' % (hostname, clu_info[0], clu_info[1], cluname))
+				setNodeStatus(self, node, CLUSTER_NODE_NOT_MEMBER)
 				continue
 
 			if rc.authed():
 				return rc
 
-			setNodeFlag(node[1], CLUSTER_NODE_NEED_AUTH)
+			setNodeStatus(node[1], CLUSTER_NODE_NEED_AUTH)
 		except Exception, eout:
-			luci_log.debug_verbose('GRA10: %r' % eout)
+			if LUCI_DEBUG_MODE is True:
+				luci_log.debug_verbose('GRA10: %r' % eout)
 
-	luci_log.debug('GRA11: no ricci agent could be found for cluster %s' \
-		% cluname)
+	if LUCI_DEBUG_MODE is True:
+		luci_log.debug('GRA11: no ricci agent could be found for cluster %s' \
+			% cluname)
 	return None



^ permalink raw reply	[flat|nested] 3+ messages in thread
* [Cluster-devel] conga/luci/site/luci/Extensions conga_constant ...
@ 2006-07-24 19:39 jparsons
  0 siblings, 0 replies; 3+ messages in thread
From: jparsons @ 2006-07-24 19:39 UTC (permalink / raw)
  To: cluster-devel.redhat.com

CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	jparsons at sourceware.org	2006-07-24 19:39:06

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

Log message:
	Support for cluster config

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/conga_constants.py.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.8&r2=1.9
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ModelBuilder.py.diff?cvsroot=cluster&r1=1.3&r2=1.4

--- conga/luci/site/luci/Extensions/conga_constants.py	2006/07/14 16:48:23	1.3
+++ conga/luci/site/luci/Extensions/conga_constants.py	2006/07/24 19:39:06	1.4
@@ -3,6 +3,7 @@
 CLUSTER="5"
 CLUSTER_ADD="6"
 CLUSTER_CONFIG="7"
+CLUSTER_PROCESS="8"
 NODE="9"
 NODES="10"
 NODE_LIST="11"
@@ -43,7 +44,13 @@
 NODE_FENCE="103"
 NODE_DELETE="104"
 
+BASECLUSTER="201"
+FENCEDAEMON="202"
+MULTICAST="203"
+QUORUMD="204"
+
 PAGETYPE="pagetype"
+ACTIONTYPE="actiontype"
 CLUNAME="clustername"
 
 PATH_TO_PRIVKEY="/var/lib/luci/var/certs/privkey.pem"
--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/07/21 14:49:47	1.8
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/07/24 19:39:06	1.9
@@ -921,7 +921,84 @@
   response = req.RESPONSE
   response.redirect(req['HTTP_REFERER'] + "&busyfirst=true")
   
+def getClusterInfo(self, model, req):
+  baseurl = req['URL'] + "?" + PAGETYPE + "=" + CLUSTER_PROCESS + "&" + CLUNAME + "=" + cluname + "&"
+  cluname = req[CLUNAME]
+  map = {}
+  basecluster_url = baseurl + ACTIONTYPE + "=" + BASECLUSTER
+  #needed:
+  map['basecluster_url'] = basecluster_url
+  #name field
+  map['clustername'] = model.getClusterAlias()
+  #config version
+  cp = model.getClusterPtr()
+  map['config_version'] = cp.getConfigVersion()
+  #-------------
+  #new cluster params - if rhel5
+  #-------------
+  #Fence Daemon Props
+  fencedaemon_url = baseurl + ACTIONTYPE + "=" + FENCEDAEMON
+  map['fencedaemon_url'] = fencedaemon_url
+  fdp = model.getFenceDaemonPtr()
+  pjd = fdp.getAttribute('post_join_delay')
+  if pjd == None:
+    pjd = "6"
+  pfd = fdp.getAttribute('post_fail_delay')
+  if pfd == None:
+    pfd = "0"
+  #post join delay
+  map['pjd'] = pjd
+  #post fail delay
+  map['pfd'] = pfd
+  #-------------
+  #if multicast
+  multicast_url = baseurl + ACTIONTYPE + "=" + MULTICAST
+  map['multicast_url'] = multicast_url
+  #mcast addr
+  is_mcast = model.isMulticast()
+  map['is_mcast'] = is_mcast
+  if is_mcast:
+    map['mcast_addr'] = model.getMcastAddr()
+    
+  #-------------
+  #quorum disk params
+  quorumd_url = baseurl + ACTIONTYPE + "=" + QUORUMD
+  map['quorumd_url'] = quorumd_url
+  is_quorumd = model.isQuorumd()
+  map['is_quorumd'] = is_quorumd
+  if is_quorumd:
+    qdp = model.getQuorumdPtr()
+    interval = qdp.getAttribute('interval')
+    tko = qdp.getAttribute('tko')
+    votes = qdp.getAttribute('votes')
+    min_score = qdp.getAttribute('min_score')
+    device = qdp.getAttribute('device')
+    label = qdp.getAttribute('label')
+    heuristic_kids = qdp.getChildren()
+    h_ctr = 0
+    hlist = list()
+    for kid in heuristic_kids:
+      hmap = {}
+      hname = kid.getAttribute('name')
+      if hname == None:
+        hname = h_ctr
+        h_ctr++
+      hprog = kid.getAttribute('program')
+      hscore = kid.getAttribute('score')
+      hinterval = kid.getAttribute('interval')
+      if hprog == None:
+        continue
+      hmap['hname'] = hname
+      hmap['hprog'] = hprog
+      if hscore != None:
+        hmap['hscore'] = hscore
+      if hinterval != None:
+        hmap['hinterval'] = hinterval
+      hlist.append(hmap)
+    if len(hlist) > 0:
+      map['hlist'] = hlist
 
+  return map
 
 def getClustersInfo(self,status,req):
   map = {}
@@ -941,7 +1018,10 @@
 
   clu = clulist[0]
   clustername = clu['name']
-  map['clusteralias'] = clu['alias']
+  if clu['alias'] != "":
+    map['clusteralias'] = clu['alias']
+  else:
+    map['clusteralias'] = clustername
   map['clustername'] = clustername
   if clu['quorate'] == "true":
     map['status'] = "Quorate"
@@ -951,6 +1031,7 @@
     map['running'] = "false"
   map['votes'] = clu['votes']
   map['minquorum'] = clu['minQuorum']
+  map['clucfg'] = baseurl + "?" + PAGETYPE + "=" + CLUSTER_CONFIG + "&" + CLUNAME + "=" + clustername
   svc_dict_list = list()
   for svc in svclist:
       svc_dict = {}
--- conga/luci/site/luci/Extensions/ModelBuilder.py	2006/07/20 21:36:34	1.3
+++ conga/luci/site/luci/Extensions/ModelBuilder.py	2006/07/24 19:39:06	1.4
@@ -120,7 +120,7 @@
     self.command_handler = CommandHandler()
     self.isModified = False
     self.quorumd_ptr = None
-    self.isQuorumd = False
+    self.usesQuorumd = False
     if mcast_addr == None:
       self.usesMulticast = False
     else:
@@ -194,7 +194,7 @@
         self.fence_daemon_ptr = new_object
       elif parent_node.nodeName == QUORUMD_PTR_STR:
         self.quorumd_ptr = new_object
-        self.isQuorumd = True
+        self.usesQuorumd = True
       elif parent_node.nodeName == GULM_TAG_STR:
         self.GULM_ptr = new_object
         self.lock_type = GULM_TYPE
@@ -597,6 +597,12 @@
   def getMcastAddr(self):
     return self.mcast_address
 
+  def isQuorumd(self):
+    return self.usesQuorumd
+
+  def getQuorumdPtr(self):
+    return quorumd_ptr
+
   def check_empty_ptrs(self):
     if self.resourcemanager_ptr == None:
       rm = Rm()



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-06-08 18:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-08 18:26 [Cluster-devel] conga/luci/site/luci/Extensions conga_constant rmccabe
  -- strict thread matches above, loose matches on Subject: below --
2007-05-14 16:02 rmccabe
2006-07-24 19:39 jparsons

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.