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

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



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2006-10-02 22:30:09

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

Log message:
	more validation and improved fault tolerance code

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

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/10/02 21:42:49	1.79
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/10/02 22:30:09	1.80
@@ -2185,7 +2185,10 @@
 	modelb = request.SESSION.get('model')
 	form = request.form
 
-	if 'edit' in form and form['edit'] == 'True':
+	if not modelb or not form:
+		return None
+
+	if form.has_key('edit'):
 		try:
 			oldname = form['oldname'].strip()
 			if not oldname:
@@ -2196,153 +2199,387 @@
 	else:
 		res = apply(Ip)
 
+	if not res:
+		return None
+
 	try:
 		addr = form['ip_address'].strip()
 		if not addr:
 			raise KeyError('ip_address is blank')
+		# XXX: validate IP addr
 		res.attr_hash['address'] = addr
 	except KeyError, e:
 		return None
 
-	try:
-		monitor = form['monitorLink'].strip()
-		if monitor == '':
-			raise KeyError('monitorLink is blank.')
-	except KeyError, e:
-		return None
-
-	if monitor == '1' or monitor == 'True':
+	if 'monitorLink' in form:
 		res.attr_hash['monitor_link'] = '1'
 	else:
 		res.attr_hash['monitor_link'] = '0'
+
 	modelb.getResourcesPtr().addChild(res)
 	return res
 
 def addFs(request):
-  modelb = request.SESSION.get('model')
-  if request.form.has_key('edit'):
-    res = getResourceForEdit(modelb, request.form['oldname'])
-  else:
-    res = apply(Fs)
-  form = request.form
-  res.attr_hash["name"] = form["resourceName"]
-  res.attr_hash["mountpoint"] = form["mountpoint"]
-  res.attr_hash["device"] = form["device"]
-  res.attr_hash["options"] = form["options"]
-  res.attr_hash["fstype"] = form["fstype"]
-  res.attr_hash["fsid"] = form["fsid"]
-  if form.has_key('forceunmount'):
-    res.attr_hash["force_unmount"] = '1'
-  else:
-    res.attr_hash["force_unmount"] = '0'
-
-  if form.has_key('selffence'):
-    res.attr_hash["self_fence"] = '1'
-  else:
-    res.attr_hash["self_fence"] = '0'
-
-  if form.has_key('checkfs'):
-    res.attr_hash["force_fsck"] = '1'
-  else:
-    res.attr_hash["force_fsck"] = '0'
+	modelb = request.SESSION.get('model')
+	form = request.form
 
-  modelb.getResourcesPtr().addChild(res)
-  return res
+	if not modelb or not form:
+		return None
+
+	if form.has_key('edit'):
+		try:
+			oldname = form['oldname'].strip()
+			if not oldname:
+				raise KeyError('oldname is blank.')
+			res = getResourceForEdit(modelb, oldname)
+		except KeyError, e:
+			return None
+	else:
+		res = apply(Fs)
+
+	if not res:
+		return None
+
+	# XXX: sanity check these fields
+	try:
+		name = form['resourceName'].strip()
+		res.attr_hash['name'] = name
+	except:
+		return None
+
+	try:
+		mountpoint = form['mountpoint'].strip()
+		res.attr_hash['mountpoint'] = mountpoint
+	except:
+		return None
+
+	try:
+		device = form['device'].strip()
+		res.attr_hash['device'] = device
+	except:
+		return None
+
+	try:
+		options = form['options'].strip()
+		res.attr_hash['options'] = options
+	except:
+		return None
+
+	try:
+		fstype = form['fstype'].strip()
+		res.attr_hash['fstype'] = fstype
+	except:
+		return None
+
+	try:
+		fsid = form['fsid'].strip()
+		res.attr_hash['fsid'] = fsid
+	except:
+		return None
+
+	if form.has_key('forceunmount'):
+		res.attr_hash['force_unmount'] = '1'
+	else:
+		res.attr_hash['force_unmount'] = '0'
+
+	if form.has_key('selffence'):
+		res.attr_hash['self_fence'] = '1'
+	else:
+		res.attr_hash['self_fence'] = '0'
+
+	if form.has_key('checkfs'):
+		res.attr_hash['force_fsck'] = '1'
+	else:
+		res.attr_hash['force_fsck'] = '0'
+
+	modelb.getResourcesPtr().addChild(res)
+	return res
 
 def addGfs(request):
-  modelb = request.SESSION.get('model')
-  if request.form.has_key('edit'):
-    res = getResourceForEdit(modelb, request.form['oldname'])
-  else:
-    res = apply(Clusterfs)
-  form = request.form
-  res.attr_hash["name"] = form["resourceName"]
-  res.attr_hash["mountpoint"] = form["mountpoint"]
-  res.attr_hash["device"] = form["device"]
-  res.attr_hash["options"] = form["options"]
-  res.attr_hash["fsid"] = form["fsid"]
-
-  if form.has_key('forceunmount'):
-    res.attr_hash["force_unmount"] = '1'
-  else:
-    res.attr_hash["force_unmount"] = '0'
+	form = request.form
 
-  modelb.getResourcesPtr().addChild(res)
-  return res
+	modelb = request.SESSION.get('model')
+	if not modelb:
+		return None
+
+	if form.has_key('edit'):
+		try:
+			oldname = form['oldname'].strip()
+			if not oldname:
+				raise KeyError('oldname is blank.')
+			res = getResourceForEdit(modelb, oldname)
+		except KeyError, e:
+			return None
+	else:
+		res = apply(Clusterfs)
+
+	if not res:
+		return None
+
+	# XXX: sanity check these fields
+	try:
+		name = form['resourceName'].strip()
+		if not name:
+			raise
+		res.attr_hash['name'] = name
+	except:
+		return None
+
+	try:
+		mountpoint = form['mountpoint'].strip()
+		res.attr_hash['mountpoint'] = mountpoint
+	except:
+		return None
+
+	try:
+		device = form['device'].strip()
+		res.attr_hash['device'] = device
+	except:
+		return None
+
+	try:
+		options = form['options'].strip()
+		res.attr_hash['options'] = options
+	except:
+		return None
+
+	try:
+		fsid = form['fsid'].strip()
+		res.attr_hash['fsid'] = fsid
+	except:
+		return None
+
+	if form.has_key('forceunmount'):
+		res.attr_hash['force_unmount'] = '1'
+	else:
+		res.attr_hash['force_unmount'] = '0'
+
+	modelb.getResourcesPtr().addChild(res)
+	return res
 
 def addNfsm(request):
-  modelb = request.SESSION.get('model')
-  if request.form.has_key('edit'):
-    res = getResourceForEdit(modelb, request.form['oldname'])
-  else:
-    res = apply(Netfs)
-  form = request.form
-  res.attr_hash["name"] = form["resourceName"]
-  res.attr_hash["mountpoint"] = form["mountpoint"]
-  res.attr_hash["host"] = form["host"]
-  res.attr_hash["options"] = form["options"]
-  res.attr_hash["exportpath"] = form["export"]
-  res.attr_hash["nfstype"] = form["fstype"]
-
-  if form.has_key('forceunmount'):
-    res.attr_hash["force_unmount"] = '1'
-  else:
-    res.attr_hash["force_unmount"] = '0'
+	form = request.form
+	modelb = request.SESSION.get('model')
 
-  modelb.getResourcesPtr().addChild(res)
-  return res
+	if not form or not modelb:
+		return None
+
+	if form.has_key('edit'):
+		try:
+			oldname = form['oldname'].strip()
+			if not oldname:
+				raise KeyError('oldname is blank.')
+			res = getResourceForEdit(modelb, oldname)
+		except KeyError, e:
+			return None
+	else:
+		res = apply(Netfs)
+
+	if not res:
+		return None
+
+	# XXX: sanity check these fields
+	try:
+		name = form['resourceName'].strip()
+		if not name:
+			raise
+		res.attr_hash['name'] = name
+	except:
+		return None
+
+	try:
+		mountpoint = form['mountpoint'].strip()
+		res.attr_hash['mountpoint'] = mountpoint
+	except:
+		return None
+
+	try:
+		host = form['host'].strip()
+		res.attr_hash['host'] = host
+	except:
+		return None
+
+	try:
+		options = form['options'].strip()
+		res.attr_hash['options'] = options
+	except:
+		return None
+
+	try:
+		exportpath = form['exportpath'].strip()
+		res.attr_hash['exportpath'] = exportpath 
+	except:
+		return None
+
+	try:
+		nfstype = form['nfstype'].strip().lower()
+		if nfstype != 'nfs' and nfstype != 'nfs4':
+			raise
+		res.attr_hash['nfstype'] = nfstype
+	except:
+		return None
+
+	if form.has_key('forceunmount'):
+		res.attr_hash['force_unmount'] = '1'
+	else:
+		res.attr_hash['force_unmount'] = '0'
+
+	modelb.getResourcesPtr().addChild(res)
+	return res
 
 def addNfsc(request):
-  modelb = request.SESSION.get('model')
-  if request.form.has_key('edit'):
-    res = getResourceForEdit(modelb, request.form['oldname'])
-  else:
-    res = apply(NFSClient)
-  form = request.form
-  res.attr_hash["name"] = form["resourceName"]
-  res.attr_hash["target"] = form["target"]
-  res.attr_hash["options"] = form["options"]
+	form = request.form
+	modelb = request.SESSION.get('model')
 
-  modelb.getResourcesPtr().addChild(res)
-  return res
+	if not form or not modelb:
+		return None
+
+	if form.has_key('edit'):
+		try:
+			oldname = form['oldname'].strip()
+			if not oldname:
+				raise KeyError('oldname is blank.')
+			res = getResourceForEdit(modelb, oldname)
+		except KeyError, e:
+			return None
+	else:
+		res = apply(NFSClient)
+
+	if not res:
+		return None
+
+	try:
+		name = form['resourceName'].strip()
+		if not name:
+			raise
+		res.attr_hash['name'] = name
+	except:
+		return None
+
+	try:
+		target = form['target'].strip()
+		res.attr_hash['target'] = target 
+	except:
+		return None
+
+	try:
+		options = form['options'].strip()
+		res.attr_hash['options'] = options
+	except:
+		return None
+
+	modelb.getResourcesPtr().addChild(res)
+	return res
 
 def addNfsx(request):
-  modelb = request.SESSION.get('model')
-  if request.form.has_key('edit'):
-    res = getResourceForEdit(modelb, request.form['oldname'])
-  else:
-    res = apply(NFSExport)
-  form = request.form
-  res.attr_hash["name"] = form["resourceName"]
+	modelb = request.SESSION.get('model')
+	form = request.form
 
-  modelb.getResourcesPtr().addChild(res)
-  return res
+	if not modelb or not form:
+		return None
+
+	if form.has_key('edit'):
+		try:
+			oldname = form['oldname'].strip()
+			if not oldname:
+				raise KeyError('oldname is blank.')
+			res = getResourceForEdit(modelb, oldname)
+		except KeyError, e:
+			return None
+	else:
+		res = apply(NFSExport)
+
+	if not res:
+		return None
+
+	try:
+		name = form['resourceName'].strip()
+		if not name:
+			raise
+		res.attr_hash['name'] = name
+	except:
+		return None
+
+	modelb.getResourcesPtr().addChild(res)
+	return res
 
 def addScr(request):
-  modelb = request.SESSION.get('model')
-  if request.form.has_key('edit'):
-    res = getResourceForEdit(modelb, request.form['oldname'])
-  else:
-    res = apply(Script)
-  form = request.form
-  res.attr_hash["name"] = form["resourceName"]
-  res.attr_hash["file"] = form["file"]
+	modelb = request.SESSION.get('model')
+	form = request.form
 
-  modelb.getResourcesPtr().addChild(res)
-  return res
+	if not modelb or not form:
+		return None
+
+	if form.has_key('edit'):
+		try:
+			oldname = form['oldname'].strip()
+			if not oldname:
+				raise KeyError('oldname is blank.')
+			res = getResourceForEdit(modelb, oldname)
+		except KeyError, e:
+			return None
+	else:
+		res = apply(Script)
+
+	if not res:
+		return None
+
+	try:
+		name = form['resourceName'].strip()
+		if not name:
+			raise
+		res.attr_hash['name'] = name
+	except:
+		return None
+
+	try:
+		file = form['file'].strip()
+		if not file:
+			raise
+		res.attr_hash['file'] = file
+	except:
+		return None
+
+	modelb.getResourcesPtr().addChild(res)
+	return res
 
 def addSmb(request):
-  modelb = request.SESSION.get('model')
-  if request.form.has_key('edit'):
-    res = getResourceForEdit(modelb, request.form['oldname'])
-  else:
-    res = apply(Samba)
-  form = request.form
-  res.attr_hash["name"] = form["resourceName"]
-  res.attr_hash["workgroup"] = form["workgroup"]
+	modelb = request.SESSION.get('model')
+	form = request.form
 
-  modelb.getResourcesPtr().addChild(res)
-  return res
+	if not modelb or not form:
+		return None
+
+	if form.has_key('edit'):
+		try:
+			oldname = form['oldname'].strip()
+			if not oldname:
+				raise KeyError('oldname is blank.')
+			res = getResourceForEdit(modelb, oldname)
+		except KeyError, e:
+			return None
+	else:
+		res = apply(Samba)
+
+	if not res:
+		return None
+
+	try:
+		name = form['resourceName'].strip()
+		if not name:
+			raise
+		res.attr_hash['name'] = name
+	except:
+		return None
+
+	try:
+		workgroup = form['workgroup'].strip()
+		res.attr_hash['workgroup'] = workgroup
+	except:
+		return None
+
+	modelb.getResourcesPtr().addChild(res)
+	return res
 
 resourceAddHandler = {
 	'ip': addIp,


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