[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-09-28 20:10:29

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

Log message:
	flesh out more of the backend form handlers

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

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/09/27 18:46:08	1.74
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/09/28 20:10:29	1.75
@@ -1,3 +1,4 @@
+import socket
 from ModelBuilder import ModelBuilder
 from ZPublisher import HTTPRequest
 import AccessControl
@@ -278,8 +279,185 @@
 def validateResourceEdit(self, request):
 	return (True, {})
 
+
+## Cluster properties form validation routines
+
+def validateMCastConfig(self, form):
+	try:
+		mcast_val = form['mcast'].strip().lower()
+		if mcast_val != 'true' and mcast_val != 'false':
+			raise KeyError(mcast_val)
+		if mcast_val == 'true':
+			mcast_val = 1
+		else:
+			mcast_val = 0
+	except KeyError, e:
+		return (False, {'errors': 'An invalid multicast selection was made.'})
+
+	if not mcast_val:
+		return (True, {'messages': 'Changes accepted. - FILL ME IN'})
+
+	try:
+		addr_str = form['mcast_addr'].strip()
+		socket.inet_pton(socket.AF_INET, addr_str)
+	except KeyError, e:
+		return (False, {'errors': 'No multicast address was given'})
+	except socket.error, e:
+		try:
+			socket.inet_pton(socket.AF_INET6, addr_str)
+		except socket.error, e6:
+			return (False, {'errors': 'An invalid multicast address was given: ' + e})
+
+	return (True, {'messages': 'Changes accepted. - FILL ME IN'})
+
+def validateQDiskConfig(self, form):
+	errors = list()
+
+	try:
+		qdisk_val = form['quorumd'].strip().lower()
+		if qdisk_val != 'true' and qdisk_val != 'false':
+			raise KeyError(qdisk_val)
+		if qdisk_val == 'true':
+			qdisk_val = 1
+		else:
+			qdisk_val = 0
+	except KeyError, e:
+		return (False, {'errors': 'An invalid quorum partition selection was made.'})
+
+	if not qdisk_val:
+		return (True, {'messages': 'Changes accepted. - FILL ME IN'})
+
+	try:
+		interval = int(form['interval'])
+		if interval < 0:
+			raise ValueError('Interval must be 0 or greater')
+	except KeyError, e:
+		errors.append('No Interval value was given.')
+	except ValueError, e:
+		errros.append('An invalid Interval value was given: ' + e)
+
+	try:
+		votes = int(form['votes'])
+		if votes < 1:
+			raise ValueError('Votes must be greater than 0')
+	except KeyError, e:
+		errors.append('No Votes value was given.')
+	except ValueError, e:
+		errors.append('An invalid Votes value was given: ' + e)
+
+	try:
+		tko = int(form['tko'])
+		if tko < 0:
+			raise ValueError('TKO must be 0 or greater')
+	except KeyError, e:
+		errors.append('No TKO value was given.')
+	except ValueError, e:
+		errors.append('An invalid TKO value was given: ' + e)
+
+	try:
+		min_score = int(form['min_score'])
+		if min_score < 1:
+			raise ValueError('Minimum Score must be greater than 0')
+	except KeyError, e:
+		errors.append('No Minimum Score value was given.')
+	except ValueError, e:
+		errors.append('An invalid Minimum Score value was given: ' + e)
+
+	try:
+		device = form['device'].strip()
+	except KeyError, e:
+		errors.append('No Device value was given.')
+
+	try:
+		label = form['label'].strip()
+	except KeyError, e:
+		errors.append('No Label value was given.')
+
+	if len(errors) > 0:
+		return (False, {'errors': errors })
+
+	# heur: heuristicN:hname heuristicN:hprog heuristicN:hint heuristicN:score
+	return (True, {'messages': 'Changes accepted. - FILL ME IN'})
+
+def validateGeneralConfig(self, form):
+	errors = list()
+
+	try:
+		cluster_name = form['cluname'].strip()
+	except KeyError, e:
+		errors.append('No cluster name was given.')
+
+	try:
+		version_num = int(form['cfgver'])
+		if version_num < 0:
+			raise ValueError('configuration version numbers must be 0 or greater.')
+	except KeyError, e:
+		errors.append('No cluster configuration version was given.')
+	except ValueError, e:
+		errors.append('An invalid configuration version was given: ' + e)
+
+	if len(errors) > 0:
+		return (False, {'errors': errors})
+
+	return (True, {'messages': 'Changes accepted. - FILL ME IN'})
+
+def validateFenceConfig(self, form):
+	errors = list()
+
+	try:
+		post_fail_delay = int(form['post_fail_delay'])
+		if post_fail_delay < 0:
+			raise ValueError('post fail delay values must be 0 or greater.')
+	except KeyError, e:
+		errors.append('No post fail delay was given.')
+	except ValueError, e:
+		errors.append('Invalid post fail delay: ' + e)
+
+	try:
+		post_join_delay = int(form['post_join_delay'])
+		if post_join_delay < 0:
+			raise ValueError('post join delay values must be 0 or greater.')
+	except KeyError, e:
+		errors.append('No post join delay was given.')
+	except ValueError, e:
+		errors.append('Invalid post join delay: ' + e)
+
+	if len(errors) > 0:
+		return (False, {'errors': errors })
+
+	return (True, {'messages': 'Changes accepted. - FILL ME IN'})
+
+configFormValidators = {
+	'general': validateGeneralConfig,
+	'mcast': validateMCastConfig,
+	'fence': validateFenceConfig,
+	'qdisk': validateQDiskConfig
+}
+
 def validateConfigCluster(self, request):
-	return (True, {})
+	errors = list()
+	messages = list()
+
+	if not 'form' in request:
+		return (False, {'errors': 'No form was submitted.' })
+	if not 'configtype' in request.form:
+		return (False, {'errors': 'No configuration type was submitted.' })
+	if not request.form['configtype'] in configFormValidators:
+		return (False, {'errors': 'An invalid configuration type was submitted.' })
+
+	val = configFormValidators[request.form['configtype']]
+	ret = val(self, request.form)
+
+	retcode = ret[0]
+	if 'errors' in ret[1]:
+		errors.extend(ret[1]['errors'])
+	if 'messages' in ret[1]:
+		messages.extend(ret[1]['messages'])
+
+	if len(errors) < 1:
+		messages.append('The cluster properties have been updated.')
+
+	return (retcode, {'errors': errors, 'messages': messages})
 
 def validateFenceAdd(self, request):
 	return (True, {})
@@ -296,7 +474,7 @@
 	31: validateResourceAdd,
 	33: validateResourceEdit,
 	51: validateFenceAdd,
-	50: validateFenceEdit
+	50: validateFenceEdit,
 }
 
 def validatePost(self, request):


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