All of lore.kernel.org
 help / color / mirror / Atom feed
From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/luci/site/luci/Extensions LuciClusterInf ...
Date: 28 Jun 2007 19:31:46 -0000	[thread overview]
Message-ID: <20070628193146.6274.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2007-06-28 19:31:46

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

Log message:
	cleanup

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/LuciClusterInfo.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.258&r2=1.259

--- conga/luci/site/luci/Extensions/LuciClusterInfo.py	2007/06/25 16:11:30	1.3
+++ conga/luci/site/luci/Extensions/LuciClusterInfo.py	2007/06/28 19:31:45	1.4
@@ -1544,7 +1544,7 @@
 	rc = getRicciAgent(self, clustername)
 	if not rc:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('GMFC0: unable to find a ricci agent for %s' % clustername)
+			luci_log.debug_verbose('GMFC0: no ricci agent for %s' % clustername)
 		return None
 
 	try:
--- conga/luci/site/luci/Extensions/cluster_adapters.py	2007/06/27 08:14:13	1.258
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2007/06/28 19:31:45	1.259
@@ -25,7 +25,6 @@
 from HelperFunctions import resolveOSType
 from LuciSyslog import get_logger
 from ResourceHandler import create_resource
-from system_adapters import validate_svc_update
 from homebase_adapters import parseHostForm
 from LuciClusterInfo import getClusterInfo, getModelBuilder, getModelForCluster
 from LuciClusterActions import propagateClusterConfAsync
@@ -44,8 +43,7 @@
 	REDIRECT_SEC, LUCI_CLUSTER_BASE_URL
 
 from FenceHandler import validateNewFenceDevice, \
-	validateFenceDevice, validate_fenceinstance, \
-	FD_VAL_FAIL, FD_VAL_SUCCESS
+	validateFenceDevice, validate_fenceinstance, FD_VAL_SUCCESS
 
 from ricci_communicator import RicciCommunicator, RicciError, \
 	batch_status, extract_module_status
@@ -932,7 +930,7 @@
 
 	ret = propagateClusterConfAsync(self, model, rc=None,
 			action=action_type, pmsg=action_msg % service_name)
-	if ret[0] is False:
+	if ret[0] is not True:
 		return ret
 
 	response = request.RESPONSE
@@ -1221,9 +1219,6 @@
 		version_num = int(form['cfgver'])
 		if version_num < old_ver:
 			raise ValueError, 'configuration version number must be %d or greater' % old_ver
-		if version_num != old_ver:
-			# we'll increment the cluster version before propagating it.
-			version_num -= 1
 	except KeyError, e:
 		errors.append('No cluster configuration version was given')
 	except ValueError, e:
@@ -1422,131 +1417,84 @@
 def validateConfigCluster(self, request):
 	errors = list()
 	messages = list()
-	rc = None
+	fvar = GetReqVars(request, [ 'configtype', 'clustername', 'URL' ])
 
-	try:
-		model = LuciExtractCluModel(self, request)
-	except Exception, e:
+	baseurl = fvar['URL'] or LUCI_CLUSTER_BASE_URL
+	clustername = fvar['clustername']
+
+	model = LuciExtractCluModel(self, request, clustername)
+	if model is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VCC0a: no model, no cluster name')
+			luci_log.debug_verbose('VCC0: no model, no cluster name')
 		return (False, {'errors': ['No cluster model was found']})
 
-	try:
-		if not request.form.has_key('configtype'):
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('VCC2: no configtype')
-			raise Exception, 'no config type'
-	except Exception, e:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VCC2a: %r %s' % (e, str(e)))
-		return (False, {'errors': [ 'No configuration type was submitted' ]})
+	if clustername is None:
+		clustername = model.getClusterName()
 
-	if not configFormValidators.has_key(request.form['configtype']):
+	config_type = fvar['configtype']
+	if config_type is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VCC3: invalid config type: %s' \
-				% request.form['configtype'])
-		return (False, { 'errors': [ 'An invalid configuration type was submitted' ]})
+			luci_log.debug_verbose('VCC1: no config type')
+		return (False, {'errors': [ 'No configuration type was given' ]})
 
-	try:
-		cp = model.getClusterPtr()
-	except:
+	if not configFormValidators.has_key(config_type):
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VCC3a: getClusterPtr failed')
-		return (False, {'errors': ['No cluster model was found']})
+			luci_log.debug_verbose('VCC2: invalid config type: %s' \
+				% config_type)
+		return (False, { 'errors': [ 'An invalid configuration type "%s" was submitted' % config_type ]})
 
-	config_validator = configFormValidators[request.form['configtype']]
+	config_validator = configFormValidators[config_type]
 	ret = config_validator(model, request.form)
 
 	retcode = ret[0]
-	if 'errors' in ret[1]:
+	if ret[1].has_key('errors'):
 		errors.extend(ret[1]['errors'])
-
-	if 'messages' in ret[1]:
+	if ret[1].has_key('messages'):
 		messages.extend(ret[1]['messages'])
 
-	if retcode is True:
-		try:
-			config_ver = int(cp.getConfigVersion()) + 1
-			# always increment the configuration version
-			cp.setConfigVersion(str(config_ver))
-			model.setModified(True)
-			conf_str = model.exportModelAsString()
-			if not conf_str:
-				raise Exception, 'conf_str is none'
-		except Exception, e:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('VCC4: export model as string failed: %r %s' % (e, str(e)))
-			errors.append('Unable to store the new cluster configuration')
-
-	try:
-		clustername = model.getClusterName()
-		if not clustername:
-			raise Exception, 'cluster name from model.getClusterName() is blank'
-	except Exception, e:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VCC5: error: getClusterName: %r %s' \
-				% (e, str(e)))
-		errors.append('Unable to determine cluster name from model')
-
-	if len(errors) > 0:
-		return (retcode, {'errors': errors, 'messages': messages})
-
-	if not rc:
-		rc = getRicciAgent(self, clustername)
-	if not rc:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VCC6: unable to find a ricci agent for the %s cluster' % clustername)
-		errors.append('Unable to contact a ricci agent for cluster %s' \
-			% clustername)
-
-	if rc:
-		batch_id, result = rq.setClusterConf(rc, str(conf_str))
-		if batch_id is None or result is None:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('VCC7: setCluserConf: batchid or result is None')
-			errors.append('Unable to propagate the new cluster configuration for %s' % clustername)
-		else:
-			try:
-				set_node_flag(self, clustername, rc.hostname(), batch_id, CLUSTER_CONFIG, 'Updating cluster configuration')
-			except:
-				pass
+	if retcode is not True or len(errors) > 0:
+		return (False, {'errors': errors, 'messages': messages})
 
-	if len(errors) < 1:
-		messages.append('The cluster properties have been updated')
-	else:
+	ret = propagateClusterConfAsync(self, model, None,
+			CLUSTER_CONFIG, 'Updating cluster configuration')
+	if ret[0] is not True:
+		if ret[1].has_key('errors'):
+			errors.extend(ret[1]['errors'])
 		return (retcode, {'errors': errors, 'messages': messages})
 
-	response = request.RESPONSE
-	response.redirect('%s?pagetype=%s&clustername=%s&busyfirst=true' \
-		% (request['URL'], CLUSTER_CONFIG, clustername))
+	request.RESPONSE.redirect('%s?pagetype=%s&clustername=%s&busyfirst=true' \
+		% (baseurl, CLUSTER_CONFIG, clustername))
 
 def LuciExtractCluModel(self, request, cluster_name=None):
+	model = None
+	try:
+		model = request.SESSION.get('model')
+		model.getClusterName()
+		return model
+	except Exception, e:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('LECM0: %s: %r %s' \
+				% (cluster_name, e, str(e)))
+		model = None
+
 	if not cluster_name:
 		fvar = GetReqVars(request, [ 'clustername' ])
 		cluster_name = fvar['clustername']
 		if cluster_name is None:
 			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('LECM0: no cluster name')
+				luci_log.debug_verbose('LECM1: no cluster name')
 
-	model = None
-	try:
-		model = request.SESSION.get('model')
-		if not model:
-			model = None
-	except Exception, e:
-		model = None
+	if cluster_name is None:
+		return None
 
 	try:
 		model = getModelForCluster(self, cluster_name)
-		if not model:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('LECM1: empty model')
-			model = None
+		model.getClusterName()
+		return model
 	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
 			luci_log.debug_verbose('LECM2: no model: %r %s' % (e, str(e)))
-		model = None
-	return model
+	return None
 
 def validateFenceAdd(self, request):
 	errors = list()
@@ -1582,178 +1530,106 @@
 
 def validateFenceEdit(self, request):
 	errors = list()
-	messages = list()
-	rc = None
 
-	try:
-		model = request.SESSION.get('model')
-		if not model:
-			raise Exception, 'model is none'
-	except Exception, e:
-		model = None
-		try:
-			cluname = request.form['clustername']
-		except:
-			try:
-				cluname = request['clustername']
-			except:
-				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('VFE: no model, no cluster name')
-				return (False, {'errors': ['No cluster model was found']})
-
-		try:
-			model = getModelForCluster(self, cluname)
-		except:
-			model = None
-
-		if model is None:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('VFE: unable to get model from session')
-			return (False, {'errors': ['No cluster model was found']})
+	fvar = GetReqVars(request, [ 'clustername', 'URL' ])
+	baseurl = fvar['URL'] or LUCI_CLUSTER_BASE_URL
 
-	form = None
-	try:
-		response = request.response
-		form = request.form
-		if not form:
-			form = None
-			raise Exception, 'no form was submitted'
-	except:
-		pass
+	clustername = fvar['clustername']
+	if clustername is None:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('VFE: No cluster name')
+		return (False, {'errors': ['No cluster name was given']})
 
-	if form is None:
+	model = LuciExtractCluModel(self, request, clustername)
+	if model is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VFE: no form was submitted')
-		return (False, {'errors': ['No form was submitted']})
+			luci_log.debug_verbose('VFE: unable to get model from session')
+		return (False, {'errors': ['No cluster model was found']})
 
 	# This is a fence edit situation, so the model should already have an
 	# entry for this fence device.
 	#
 	# pass form and model to validation method, then save changes if it passes.
-	error_code, retobj = validateFenceDevice(form, model)
-	if error_code == FD_VAL_SUCCESS:
-		try:
-			conf_str = model.exportModelAsString()
-			if not conf_str:
-				raise Exception, 'conf_str is none'
-		except Exception, e:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('VFE: export model as string failed: %r %s' % (e, str(e)))
-			errors.append('Unable to store the new cluster configuration')
-
-		try:
-			clustername = model.getClusterName()
-			if not clustername:
-				raise Exception, 'cluster name from model.getClusterName() is blank'
-		except Exception, e:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('VFA: error: getClusterName: %r %s' \
-					% (e, str(e)))
-			errors.append('Unable to determine cluster name from model')
+	error_code, retobj = validateFenceDevice(request.form, model)
+	if error_code != FD_VAL_SUCCESS:
+		errors.extend(retobj)
+		return (False, { 'errors': errors })
 
-		if not rc:
-			rc = getRicciAgent(self, clustername)
-			if not rc:
-				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('VFA: unable to find a ricci agent for the %s cluster' % clustername)
-				errors.append('Unable to contact a ricci agent for cluster %s' \
-					% clustername)
-
-		if rc:
-			batch_id, result = rq.setClusterConf(rc, str(conf_str))
-			if batch_id is None or result is None:
-				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('VFA: setClusterConf: batchid or result is None')
-				errors.append('Unable to propagate the new cluster configuration for %s' \
-					% clustername)
-			else:
-				try:
-					set_node_flag(self, clustername, rc.hostname(), batch_id,
-						CLUSTER_CONFIG, 'Updating fence device "%s"' % retobj)
-				except:
-					pass
+	ret = propagateClusterConfAsync(self, model, None,
+			CLUSTER_CONFIG, 'Updating fence device "%s"' % retobj)
+	if ret[0] is not True:
+		return ret
 
-		response.redirect('%s?pagetype=%s&clustername=%s&fencename=%s&busyfirst=true' % (request['URL'], FENCEDEV, clustername, retobj))
-	else:
-		errors.extend(retobj)
-		return (False, {'errors': errors, 'messages': messages})
+	request.RESPONSE.redirect('%s?pagetype=%s&clustername=%s&fencename=%s&busyfirst=true' % (baseurl, FENCEDEV, clustername, retobj))
 
 def validateNodeFenceConfig(self, request):
 	errors = list()
+	fvar = GetReqVars(request,
+			[ 'fence_xml', 'fence_level', 'nodename', 'clustername', 'URL' ])
 
-	try:
-		form_xml = request['fence_xml'].strip()
-		if not form_xml:
-			raise KeyError, 'form_xml must not be blank'
-	except Exception, e:
+	baseurl = fvar['URL'] or LUCI_CLUSTER_BASE_URL
+
+	if fvar['fence_xml'] is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC0: no form_xml: %r %s' % (e, str(e)))
+			luci_log.debug_verbose('vNFC0: no fence_xml for node %s' \
+				% fvar['nodename'])
 		return (False, {'errors': ['No fence data was supplied']})
 
-	try:
-		fence_level = int(request.form['fence_level'].strip())
-	except Exception, e:
+	if fvar['fence_level'] is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC1: no fence level: %r %s' % (e, str(e)))
+			luci_log.debug_verbose('vNFC1: no fence level for %s' \
+				% fvar['nodename'])
 		return (False, {'errors': ['No fence level was supplied']})
 
 	try:
-		nodename = request['nodename']
-		if not nodename:
-			raise Exception, 'nodename is blank'
+		fence_level = int(fvar['fence_level'])
 	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC2: no nodename: %r %s' % (e, str(e)))
+			luci_log.debug_verbose('vNFC2: invalid fence level: %s: %r %s' \
+				% (fvar['fence_level'], e, str(e)))
+		return (False, {'errors': ['"%s" is an invalid fence level' % fvar['fence_level'] ]})
+
+	nodename = fvar['nodename']
+	if nodename is None:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('vNFC3: no nodename: %r %s' % (e, str(e)))
 		return (False, {'errors': ['No node name was given']})
 
-	try:
-		clustername = request['clustername']
-		if not clustername:
-			raise Exception, 'clustername is blank'
-	except Exception, e:
+	clustername = fvar['clustername']
+	if clustername is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC3: no clustername: %r %s' % (e, str(e)))
+			luci_log.debug_verbose('vNFC4: no clustername: %r %s' % (e, str(e)))
 		return (False, {'errors': ['No cluster name was given']})
 
-	try:
-		model = request.SESSION.get('model')
-		if not model:
-			raise Exception, 'model is none'
-	except Exception, e:
-		model = None
-		try:
-			model = getModelForCluster(self, clustername)
-		except:
-			model = None
-
+	model = LuciExtractCluModel(self, request, clustername)
 	if model is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC4: unable to get model for cluster %s' % clustername)
+			luci_log.debug_verbose('vNFC6: unable to get model for cluster %s' \
+				% clustername)
 		return (False, {'errors': ['No cluster model was found']})
 
 	try:
-		doc = minidom.parseString(form_xml)
+		doc = minidom.parseString(fvar['fence_xml'])
 	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC5: error: %r %s' % (e, str(e)))
+			luci_log.debug_verbose('vNFC7: error: %r %s' % (e, str(e)))
 		return (False, {'errors': ['The fence data submitted is not properly formed']})
 
 	try:
 		node = model.retrieveNodeByName(nodename)
-	except GeneralError, e:
+	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC6: unable to find node name %s in current node list: %r %s' % (str(nodename), e, str(e)))
-		return (False, {'errors': ['Unable to find the cluster node %s in the node list' % str(nodename) ]})
+			luci_log.debug_verbose('vNFC8: unable to find node name %s in current node list: %r %s' % (nodename, e, str(e)))
+		return (False, {'errors': ['Unable to find the cluster node %s in the node list' % nodename ]})
 
-	fence_level_num = int(fence_level)
 	levels = node.getFenceLevels()
 	try:
-		method_id = levels[fence_level_num - 1].getAttribute('name')
+		method_id = levels[fence_level - 1].getAttribute('name')
 		if not method_id:
 			raise Exception, 'No method ID'
 		fence_method = Method()
 		fence_method.addAttribute('name', str(method_id))
-		levels[fence_level_num - 1] = fence_method
+		levels[fence_level - 1] = fence_method
 	except Exception, e:
 		method_id = fence_level
 		fence_method = Method()
@@ -1772,7 +1648,7 @@
 				node.getChildren()[0].removeChild(delete_target)
 			except Exception, e:
 				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('vNFC6a: %s: %r %s' \
+					luci_log.debug_verbose('vNFC9: %s: %r %s' \
 						% (method_id, e, str(e)))
 				return (False, {'errors': ['An error occurred while deleting fence method %s' % method_id ]})
 		else:
@@ -1794,7 +1670,7 @@
 				input_type = str(i.getAttribute('type'))
 			except Exception, e:
 				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('vNFC7: input type: %r %s' \
+					luci_log.debug_verbose('vNFC10: input type: %r %s' \
 						% (e, str(e)))
 				continue
 
@@ -1805,7 +1681,7 @@
 				dummy_form[str(i.getAttribute('name'))] = str(i.getAttribute('value'))
 			except Exception, e:
 				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('vNFC8: parsing XML: %r %s' \
+					luci_log.debug_verbose('vNFC11: parsing XML: %r %s' \
 						% (e, str(e)))
 
 		if len(dummy_form) < 1:
@@ -1816,7 +1692,7 @@
 				parent = dummy_form['parent_fencedev']
 			except:
 				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('vNFC9: no parent for instance')
+					luci_log.debug_verbose('vNFC12: no parent for instance')
 				return (False, {'errors': [ 'Unable to determine what device the current instance uses' ]})
 
 			try:
@@ -1824,7 +1700,7 @@
 				del dummy_form['fence_instance']
 			except Exception, e:
 				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('vNFC10: no parent for instance')
+					luci_log.debug_verbose('vNFC13: no parent for instance')
 				return (False, {'errors': [ 'Unable to determine what device the current instance uses' ]})
 		else:
 			form_hash[form_id] = (dummy_form, list())
@@ -1839,7 +1715,7 @@
 			fence_form, instance_list = form_hash[i]
 		except Exception, e:
 			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('vNFC11: %r %s' % (e, str(e)))
+				luci_log.debug_verbose('vNFC14: %r %s' % (e, str(e)))
 			continue
 
 		try:
@@ -1848,10 +1724,10 @@
 				raise Exception, 'fence type is blank'
 		except Exception, e:
 			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('vNFC12: %s: %r %s' % (i, e, str(e)))
+				luci_log.debug_verbose('vNFC15: %s: %r %s' % (i, e, str(e)))
 			fence_type = None
 
-		if 'existing_device' in fence_form:
+		if fence_form.has_key('existing_device'):
 			try:
 				fencedev_name = fence_form['name']
 				if not fencedev_name.strip():
@@ -1866,7 +1742,7 @@
 				# All we care about is its name.
 				fencedev_unknown = True
 			else:
-				if not 'sharable' in fence_form:
+				if not fence_form.has_key('sharable'):
 					# If it's a shared fence device that already exists, the
 					# user could not have edited it (without playing dirty
 					# games), so it's safe to pull the existing entry from
@@ -1900,7 +1776,7 @@
 			# If it's not shared, we need to create an instance form
 			# so the appropriate XML goes into the <method> block inside
 			# <node><fence>. All we need for that is the device name.
-			if not 'sharable' in fence_form:
+			if not fence_form.has_key('sharable'):
 				if type == 'fence_manual':
 					instance_list.append({'name': fencedev_name, 'nodename': nodename })
 				else:
@@ -1939,215 +1815,100 @@
 	if len(errors) > 0:
 		return (False, {'errors': errors })
 
-	try:
-		model.setModified(True)
-		conf = str(model.exportModelAsString())
-		if not conf:
-			raise Exception, 'model string is blank'
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC16: exported "%s"' % conf)
-	except Exception, e:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC17: exportModelAsString failed: %r %s' \
-				% (e, str(e)))
-		return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration' ]})
-
-	rc = getRicciAgent(self, clustername)
-	if not rc:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC18: unable to find a ricci agent for cluster %s' % clustername)
-		return (False, {'errors': ['Unable to find a ricci agent for the %s cluster' % clustername ]})
-	ragent = rc.hostname()
-
-	batch_number, result = rq.setClusterConf(rc, conf)
-	if batch_number is None or result is None:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC19: missing batch and/or result')
-		return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration' ]})
+	ret = propagateClusterConfAsync(self, model, None, FENCEDEV_NODE_CONFIG,
+			'Updating fence configuration for node "%s"' % fvar['nodename'])
+	if ret[1] is not True:
+		return ret
 
-	try:
-		set_node_flag(self, clustername, ragent, str(batch_number), FENCEDEV_NODE_CONFIG, "Updating fence configuration for node \'%s\'" % nodename)
-	except Exception, e:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('vNFC20: failed to set flags: %r %s' \
-				% (e, str(e)))
-
-	response = request.RESPONSE
-	response.redirect('%s?pagetype=%s&clustername=%s&nodename=%s&busyfirst=true' % (request['URL'], NODE, clustername, nodename))
+	request.RESPONSE.redirect('%s?pagetype=%s&clustername=%s&nodename=%s&busyfirst=true' % (baseurl, NODE, clustername, nodename))
 
 def deleteFenceDevice(self, request):
 	errors = list()
-	messages = list()
-	rc = None
 
-	try:
-		model = request.SESSION.get('model')
-		if not model:
-			raise Exception, 'model is none'
-	except Exception, e:
-		model = None
-		try:
-			cluname = request.form['clustername']
-		except:
-			try:
-				cluname = request['clustername']
-			except:
-				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('VFE: no model, no cluster name')
-				return (False, {'errors': ['No cluster model was found']})
+	fvar = GetReqVars(request,
+			[ 'orig_name', 'nodename', 'clustername', 'URL' ])
 
-		try:
-			model = getModelForCluster(self, cluname)
-		except:
-			model = None
+	baseurl = fvar['URL'] or LUCI_CLUSTER_BASE_URL
 
-		if model is None:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('VFE: unable to get model from session')
-			return (False, {'errors': ['No cluster model was found']})
+	nodename = fvar['nodename']
+	if nodename is None:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('VFE: no node name')
+		return (False, {'errors': ['No node name was given']})
 
-	form = None
-	try:
-		response = request.RESPONSE
-		form = request.form
-		if not form:
-			form = None
-			raise Exception, 'no form was submitted'
-	except:
-		pass
+	clustername = fvar['clustername']
+	if clustername is None:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('VFE: no cluster name')
+		return (False, {'errors': ['No cluster name was given']})
 
-	if form is None:
+	model = LuciExtractCluModel(self, request, clustername)
+	if model is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VFE: no form was submitted')
-		return (False, {'errors': ['No form was submitted']})
+			luci_log.debug_verbose('VFE: model, no cluster name')
+		return (False, {'errors': ['No cluster model was found']})
 
-	#get name of fencedev
-	try:
-		fencedev_name = form['orig_name']
-		fencedev_name = fencedev_name.strip()
-	except KeyError, e:
-		return (False, {'errors':['No device name in form submission']})
+	fencedev_name = fvar['orig_name']
+	if fencedev_name is None:
+		return (False, {'errors': ['No device name in form submission']})
 
 	fdev_to_delete = None
-	#iterate thru list of current fencedevs and find one to be deleted
 	fdevs = model.getFenceDevices()
 	for fdev in fdevs:
 		if fdev.getName().strip() == fencedev_name:
 			fdev_to_delete = fdev
 			break
+
 	if fdev_to_delete is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VFD: Could not find fence device name in model')
-		return (False, {'errors':['Could not find fence device name in model']})
+			luci_log.debug_verbose('VFD: Could not find fence device "%s" in model' % fencedev_name)
+		return (False, {'errors': ['Could not find fence device "%s" in model' % fencedev_name ]})
 
-	#get fencedev ptr
 	fdev_ptr = model.getFenceDevicePtr()
-	#remove child
 	try:
 		fdev_ptr.removeChild(fdev_to_delete)
-		error_code = FD_VAL_SUCCESS
-		error_string = "Fence device %s successfully removed from configuration" % fencedev_name
 	except:
-		error_code = FD_VAL_FAIL
-		error_string = "Fence device %s could not be removed from configuration" % fencedev_name
+		errors.append('Fence device "%s" could not be removed from configuration' % fencedev_name)
+		return (False, { 'errors': errors })
 
 	try:
 		model.removeFenceInstancesForFenceDevice(fencedev_name)
-	except:
+	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VFD: Could not remove fence instances for')
-
-
-	if error_code == FD_VAL_SUCCESS:
-		messages.append(error_string)
-		try:
-			model.setModified(True)
-			conf_str = model.exportModelAsString()
-			if not conf_str:
-				raise Exception, 'conf_str is none'
-		except Exception, e:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('VFE: export model as string failed: %r %s' % (e, str(e)))
-			errors.append('Unable to store the new cluster configuration')
-
-		try:
-			clustername = model.getClusterName()
-			if not clustername:
-				raise Exception, 'cluster name from model.getClusterName() is blank'
-		except Exception, e:
-			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('VFA: error: getClusterName: %r %s' \
-					% (e, str(e)))
-			errors.append('Unable to determine cluster name from model')
-
-		if not rc:
-			rc = getRicciAgent(self, clustername)
-			if not rc:
-				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('VFA: unable to find a ricci agent for the %s cluster' % clustername)
-				errors.append('Unable to contact a ricci agent for cluster %s' \
-				% clustername)
+			luci_log.debug_verbose('VFD: error removing %s: %r %s' \
+				% (fencedev_name, e, str(e)))
 
-		if rc:
-			batch_id, result = rq.setClusterConf(rc, str(conf_str))
-			if batch_id is None or result is None:
-				if LUCI_DEBUG_MODE is True:
-					luci_log.debug_verbose('VFA: setCluserConf: batchid or result is None')
-				errors.append('Unable to propagate the new cluster configuration for %s' \
-				% clustername)
-			else:
-				try:
-					set_node_flag(self, clustername, rc.hostname(), batch_id,
-						CLUSTER_CONFIG, 'Removing fence device "%s"' % fencedev_name)
-				except:
-					pass
+	ret = propagateClusterConfAsync(self, model, None, CLUSTER_CONFIG,
+			'Removing fence device "%s"' % fencedev_name)
+	if ret[0] is not True:
+		return ret
 
-		response.redirect('%s?pagetype=%s&clustername=%s&busyfirst=true' \
-		% (request['URL'], FENCEDEVS, clustername))
-		return (True, {'errors': errors, 'messages': messages})
-	else:
-		errors.append(error_string)
-		return (False, {'errors': errors, 'messages': messages})
+	request.RESPONSE.redirect('%s?pagetype=%s&clustername=%s&busyfirst=true' \
+		% (baseurl, FENCEDEVS, clustername))
 
 def validateDaemonProperties(self, request):
 	errors = list()
 
-	form = None
-	try:
-		response = request.response
-		form = request.form
-		if not form:
-			form = None
-			raise Exception, 'no form was submitted'
-	except:
-		pass
+	fvar = GetReqVars(request,
+			[ 'orig_name', 'nodename', 'clustername', 'URL' ])
 
-	if form is None:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VDP0: no form was submitted')
-		return (False, {'errors': ['No form was submitted']})
+	baseurl = fvar['URL'] or LUCI_CLUSTER_BASE_URL
 
-	try:
-		nodename = form['nodename'].strip()
-		if not nodename:
-			raise Exception, 'nodename is blank'
-	except Exception, e:
-		errors.append('Unable to determine the current node name')
+	clustername = fvar['clustername']
+	if clustername is None:
+		errors.append('Unable to determine the current cluster name')
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VDP1: no nodename: %r %s' % (e, str(e)))
+			luci_log.debug_verbose('VDP2: no clustername')
 
-	try:
-		clustername = form['clustername'].strip()
-		if not clustername:
-			raise Exception, 'clustername is blank'
-	except Exception, e:
-		errors.append('Unable to determine the current cluster name')
+	nodename = fvar['nodename']
+	if nodename is None:
+		errors.append('Unable to determine the current node name')
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('VDP2: no clustername: %r %s' % (e, str(e)))
+			luci_log.debug_verbose('VDP1: no nodename for %s' % clustername)
 
 	disable_list = list()
 	enable_list = list()
-	for i in form.items():
+	for i in request.form.items():
 		try:
 			if i[0][:11] == '__daemon__:':
 				daemon_prop = i[1]
@@ -2159,13 +1920,14 @@
 						enable_list.append(daemon_prop[0])
 		except Exception, e:
 			if LUCI_DEBUG_MODE is True:
-				luci_log.debug_verbose('VDP3: error: %s' % str(i))
+				luci_log.debug_verbose('VDP3: error: %s: %r %s' \
+					% (str(i), e, str(e)))
 
 	if len(enable_list) < 1 and len(disable_list) < 1:
 		if LUCI_DEBUG_MODE is True:
 			luci_log.debug_verbose('VDP4: no changes made')
-		response.redirect('%s?pagetype=%s&clustername=%s&nodename=%s' \
-			% (request['URL'], NODE, clustername, nodename))
+		request.RESPONSE.redirect('%s?pagetype=%s&clustername=%s&nodename=%s' \
+			% (baseurl, NODE, clustername, nodename))
 
 	nodename_resolved = resolve_nodename(self, clustername, nodename)
 	try:
@@ -2193,26 +1955,34 @@
 		if len(disable_list) > 0:
 			status_msg = 'Updating node "%s" daemon properties: disabling "%s"' \
 				% (nodename_resolved, str(disable_list)[1:-1])
-		set_node_flag(self, clustername, rc.hostname(), batch_id, CLUSTER_DAEMON, status_msg)
-	except:
-		pass
+		set_node_flag(self, clustername, rc.hostname(), batch_id,
+			CLUSTER_DAEMON, status_msg)
+	except Exception, e:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('VDP: %r %s' % (e, str(e)))
 
 	if len(errors) > 0:
 		return (False, {'errors': errors})
 
-	response.redirect('%s?pagetype=%s&clustername=%s&nodename=%s&busyfirst=true' % (request['URL'], NODE, clustername, nodename))
+	request.RESPONSE.redirect('%s?pagetype=%s&clustername=%s&nodename=%s&busyfirst=true' % (baseurl, NODE, clustername, nodename))
 
 def validateFdom(self, request):
 	errors = list()
+	fvar = GetReqVars(request, [ 'clustername', 'name', 'oldname', 'URL' ])
+	baseurl = fvar['URL'] or LUCI_CLUSTER_BASE_URL
 
-	try:
-		model = request.SESSION.get('model')
-		if not model:
-			raise Exception, 'no model'
-	except Exception, e:
+	clustername = fvar['clustername']
+	if clustername is None:
+		errors.append('Unable to determine this cluster\'s name')
+
+	name = fvar['name']
+	if name is None:
+		errors.append('No name was given for this failover domain')
+
+	model = LuciExtractCluModel(self, request, clustername)
+	if model is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateFdom0: no model: %r %s' \
-				% (e, str(e)))
+			luci_log.debug_verbose('validateFdom0: no model: %r %s')
 		return (False, {'errors': [ 'Unable to retrieve cluster information' ]})
 
 	prioritized = False
@@ -2227,39 +1997,7 @@
 	except:
 		restricted = False
 
-	clustername = None
-	try:
-		clustername = request.form['clustername'].strip()
-		if not clustername:
-			raise Exception, 'blank'
-	except:
-		try:
-			clustername = model.getClusterName()
-			if not clustername:
-				raise Exception, 'blank'
-		except:
-			clustername = None
-
-	if not clustername:
-		errors.append('Unable to determine this cluster\'s name')
-
-	try:
-		name = request.form['name'].strip()
-		if not name:
-			raise Exception, 'blank'
-	except Exception, e:
-		errors.append('No name was given for this failover domain')
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateFdom0: %r %s' \
-				% (e, str(e)))
-
-	oldname = None
-	try:
-		oldname = request.form['oldname'].strip()
-		if not oldname:
-			raise Exception, 'blank'
-	except:
-		pass
+	oldname = fvar['oldname']
 
 	if oldname is None or oldname != name:
 		if model.getFailoverDomainByName(name) is not None:
@@ -2292,9 +2030,7 @@
 	else:
 		fdom.addAttribute('restricted', '0')
 
-	cluster_nodes = map(lambda x: str(x.getName()), model.getNodes())
-
-	for i in cluster_nodes:
+	for i in model.getNodeNames():
 		if request.form.has_key(i):
 			fdn = FailoverDomainNode()
 			fdn.addAttribute('name', i)
@@ -2313,8 +2049,6 @@
 		fdom_ptr = model.getFailoverDomainPtr()
 		if not oldname:
 			fdom_ptr.addChild(fdom)
-		model.setModified(True)
-		conf = str(model.exportModelAsString())
 	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
 			luci_log.debug_verbose('validateFdom2: %r %s' % (e, str(e)))
@@ -2323,104 +2057,74 @@
 	if len(errors) > 0:
 		return (False, {'errors': errors })
 
-	rc = getRicciAgent(self, clustername)
-	if not rc:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateFdom3: unable to find a ricci agent for cluster %s' % clustername)
-		return (False, {'errors': ['Unable to find a ricci agent for the %s cluster' % clustername ]})
-	ragent = rc.hostname()
-
-	batch_number, result = rq.setClusterConf(rc, conf)
-	if batch_number is None or result is None:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateFdom4: missing batch and/or result')
-		return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration' ]})
+	if oldname:
+		action = FDOM
+		status_msg = 'Updating failover domain "%s"' % oldname
+	else:
+		action = FDOM_ADD
+		status_msg = 'Creating failover domain "%s"' % name
 
-	try:
-		if oldname:
-			set_node_flag(self, clustername, ragent, str(batch_number), FDOM, 'Updating failover domain "%s"' % oldname)
-		else:
-			set_node_flag(self, clustername, ragent, str(batch_number), FDOM_ADD, 'Creating failover domain "%s"' % name)
-	except Exception, e:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateFdom5: failed to set flags: %r %s' \
-				% (e, str(e)))
+	ret = propagateClusterConfAsync(self, model, None, action, status_msg)
+	if ret[0] is not True:
+		return ret
 
-	response = request.RESPONSE
-	response.redirect('%s?pagetype=%s&clustername=%s&fdomname=%s&busyfirst=true' \
-		% (request['URL'], FDOM, clustername, name))
+	request.RESPONSE.redirect('%s?pagetype=%s&clustername=%s&fdomname=%s&busyfirst=true' % (baseurl, FDOM, clustername, name))
 
 def validateVM(self, request):
 	errors = list()
 
-	model = request.SESSION.get('model')
+	fvar = GetReqVars(request, [ 'clustername', 'vmname', 'oldname', 'vmpath', 'recovery', 'domain', 'URL' ])
 
-	try:
-		vm_name = request.form['vmname'].strip()
-		if not vm_name:
-			raise Exception, 'blank'
-	except Exception, e:
+	baseurl = fvar['URL'] or LUCI_CLUSTER_BASE_URL
+
+	clustername = fvar['clustername']
+	if clustername is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateVM0: no vm name: %r %s' \
-				% (e, str(e)))
+			luci_log.debug_verbose('validateVM0: no cluster name was given')
+		return (False, {'errors': [ 'No cluster name was given' ]})
+
+	model = LuciExtractCluModel(self, request, clustername)
+	if model is None:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('validateVM0: no model')
+		return (False, {'errors': [ 'Unable to retrieve cluster information' ]})
+
+	vm_name = fvar['vmname']
+	if vm_name is None:
+		if LUCI_DEBUG_MODE is True:
+			luci_log.debug_verbose('validateVM0: no vm name')
 		errors.append('No virtual machine name was given')
 
-	try:
-		vm_path = request.form['vmpath'].strip()
-		if not vm_path:
-			raise Exception, 'blank'
-	except Exception, e:
+	vm_path = fvar['vmpath']
+	if vm_path is None:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateVM1: no vm path: %r %s' \
-				% (e, str(e)))
-		errors.append('No path to the virtual machine configuration file was given')
+			luci_log.debug_verbose('validateVM1: no vm path')
+		errors.append('No path to the virtual machine configuration directory was given')
 
 	autostart = 1
-	try:
-		if request.form.has_key('autostart'):
-			autostart = 1
-		else:
-			autostart = 0
-	except:
+	if request.form.has_key('autostart'):
 		autostart = 1
+	else:
+		autostart = 0
 
 	exclusive = 0
-	try:
-		if request.form.has_key('exclusive'):
-			exclusive = 1
-		else:
-			exclusive = 0
-	except:
+	if request.form.has_key('exclusive'):
+		exclusive = 1
+	else:
 		exclusive = 0
 
-	recovery = None
-	try:
-		recovery = request.form['recovery'].strip()
-		if not recovery:
-			recovery = None
-		else:
-			if recovery != 'restart' and recovery != 'relocate' and recovery != 'disable':
-				errors.append('You entered an invalid recovery option: "%s" Valid options are "restart" "relocate" and "disable"')
-	except:
-		recovery = None
+	recovery = fvar['recovery']
+	if recovery is not None and recovery != 'restart' and recovery != 'relocate' and recovery != 'disable':
+		errors.append('You entered an invalid recovery option: "%s" Valid options are "restart" "relocate" and "disable"')
 
-	fdom = None
-	try:
-		fdom = request.form['domain'].strip()
-		if not fdom:
-			raise Exception, 'blank'
-	except:
-		fdom = None
+	fdom = fvar['domain']
 
 	if len(errors) > 0:
 		return (False, {'errors': errors })
 
 	isNew = False
-	try:
-		old_name = request.form['oldname'].strip()
-		if not old_name:
-			raise KeyError, 'oldname'
-	except KeyError, e:
+	old_name = fvar['oldname']
+	if old_name is None:
 		isNew = True
 
 	delete_vm = False
@@ -2469,55 +2173,22 @@
 		except:
 			pass
 
-	try:
-		model.setModified(True)
-		stringbuf = str(model.exportModelAsString())
-		if not stringbuf:
-			raise Exception, 'model is blank'
-	except Exception, e:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateVM2: %r %s' % (e, str(e)))
-		errors.append('Unable to update the cluster model')
-
-	try:
-		clustername = model.getClusterName()
-		if not clustername:
-			raise Exception, 'cluster name from model.getClusterName() is blank'
-	except Exception, e:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateVM3: %r %s' % (e, str(e)))
-		errors.append('Unable to determine the cluster name')
-
-	if len(errors) > 0:
-		return (False, {'errors': errors })
-
-	rc = getRicciAgent(self, clustername)
-	if not rc:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateVM4: no ricci for %s' % clustername)
-		return (False, {'errors': ['Unable to contact a ricci agent for this cluster']})
-
-	batch_number, result = rq.setClusterConf(rc, stringbuf)
-	if batch_number is None or result is None:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateVM5: missing batch and/or result')
-		return (False, {'errors': [ 'Error creating virtual machine %s' % vm_name ]})
+	if delete_vm is True:
+		action = VM_CONFIG
+		status_msg = 'Deleting virtual machine service "%s"' % vm_name
+	elif isNew is True:
+		action = VM_ADD
+		status_msg = 'Creating virtual machine service "%s"' % vm_name
+	else:
+		action = VM_CONFIG
+		status_msg = 'Configuring virtual machine service "%s"' % vm_name
 
-	try:
-		if delete_vm is True:
-			set_node_flag(self, clustername, rc.hostname(), str(batch_number), VM_CONFIG, "Deleting virtual machine service \'%s\'" % vm_name)
-		elif isNew is True:
-			set_node_flag(self, clustername, rc.hostname(), str(batch_number), VM_ADD, "Creating virtual machine service \'%s\'" % vm_name)
-		else:
-			set_node_flag(self, clustername, rc.hostname(), str(batch_number), VM_CONFIG, "Configuring virtual machine service \'%s\'" % vm_name)
-	except Exception, e:
-		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('validateVM6: failed to set flags: %r %s' \
-				% (e, str(e)))
+	ret = propagateClusterConfAsync(self, model, None, action, status_msg)
+	if ret[0] is not True:
+		return ret
 
-	response = request.RESPONSE
-	response.redirect('%s?pagetype=%s&clustername=%s&busyfirst=true' \
-		% (request['URL'], SERVICES, clustername))
+	request.RESPONSE.redirect('%s?pagetype=%s&clustername=%s&busyfirst=true' \
+		% (baseurl, SERVICES, clustername))
 
 def process_cluster_conf_editor(self, req):
 	clustername = req['clustername']
@@ -3276,8 +2947,7 @@
 	baseurl = fvars['URL'] or LUCI_CLUSTER_BASE_URL
 
 	try:
-		model = LuciExtractCluModel(self, req,
-					cluster_name=fvars['clustername'])
+		model = LuciExtractCluModel(self, req, fvars['clustername'])
 		if not model:
 			raise Exception, 'no model'
 	except Exception, e:



             reply	other threads:[~2007-06-28 19:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-28 19:31 rmccabe [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-09-21 16:06 [Cluster-devel] conga/luci/site/luci/Extensions LuciClusterInf rmccabe
2007-07-26  5:52 rmccabe
2007-07-16 21:35 rmccabe
2007-07-03 17:06 rmccabe
2007-06-08 18:27 rmccabe
2007-05-30 22:06 rmccabe
2007-05-16 21:27 rmccabe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070628193146.6274.qmail@sourceware.org \
    --to=rmccabe@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.