[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 21:42:49

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

Log message:
	more cleanup and robustness improvements

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

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/10/02 21:09:27	1.78
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/10/02 21:42:49	1.79
@@ -2065,27 +2065,46 @@
   return map
 
 def getClusterOS(self, ragent, request):
-  clustername = request['clustername']
-  ricci_agent = resolve_nodename(self, clustername, ragent)
-  rc = RicciCommunicator(ricci_agent)
-  map = {}
-  map['os'] = rc.os()
-  map['isVirtualized'] = rc.dom0()
-  return map
+	try:
+		clustername = request['clustername']
+	except KeyError, e:
+		try:
+			clustername = request.form['clustername']
+		except:
+			return {}
+	except:
+		return {}
+
+	ricci_agent = resolve_nodename(self, clustername, ragent)
+	rc = RicciCommunicator(ricci_agent)
+	map = {}
+	map['os'] = rc.os()
+	map['isVirtualized'] = rc.dom0()
+	return map
 
 def getResourcesInfo(modelb, request):
-  resList = list()
-  baseurl = request['URL']
-  cluname = request['clustername']
-  for item in modelb.getResources():
-    itemmap = {}
-    itemmap['name'] = item.getName()
-    itemmap['type'] = item.resource_type
-    itemmap['cfgurl'] = baseurl + "?" + "clustername=" + cluname + "&resourcename=" + item.getName() + "&pagetype=" + RESOURCE_CONFIG
-    itemmap['url'] = baseurl + "?" + "clustername=" + cluname + "&resourcename=" + item.getName() + "&pagetype=" + RESOURCE
-    itemmap['delurl'] = baseurl + "?" + "clustername=" + cluname + "&resourcename=" + item.getName() + "&pagetype=" + RESOURCE_REMOVE
-    resList.append(itemmap)
-  return resList
+	resList = list()
+	baseurl = request['URL']
+
+	try:
+		cluname = request['clustername']
+	except KeyError, e:
+		try:
+			cluname = request.form['clustername']
+		except:
+			return resList
+	except:
+		return resList
+
+	for item in modelb.getResources():
+		itemmap = {}
+		itemmap['name'] = item.getName()
+		itemmap['type'] = item.resource_type
+		itemmap['cfgurl'] = baseurl + "?" + "clustername=" + cluname + "&resourcename=" + item.getName() + "&pagetype=" + RESOURCE_CONFIG
+		itemmap['url'] = baseurl + "?" + "clustername=" + cluname + "&resourcename=" + item.getName() + "&pagetype=" + RESOURCE
+		itemmap['delurl'] = baseurl + "?" + "clustername=" + cluname + "&resourcename=" + item.getName() + "&pagetype=" + RESOURCE_REMOVE
+		resList.append(itemmap)
+	return resList
 
 def getResourceInfo(modelb, request):
 	try:
@@ -2095,6 +2114,8 @@
 			name = request.form['resourcename']
 		except:
 			return {}
+	except:
+		return {}
 
 	try:
 		cluname = request['clustername']
@@ -2103,10 +2124,12 @@
 			cluname = request.form['clustername']
 		except:
 			return {}
+	except:
+		return {}
 
 	try:
 		baseurl = request['URL']
-	except KeyError, e:
+	except:
 		return {}
 
 	for res in modelb.getResources():
@@ -2158,82 +2181,42 @@
   response = request.RESPONSE
   response.redirect(request['HTTP_REFERER'] + "&busyfirst=true")
 
+def addIp(request):
+	modelb = request.SESSION.get('model')
+	form = request.form
 
+	if 'edit' in form and form['edit'] == 'True':
+		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(Ip)
 
-def addResource(self, request, ragent):
-  if not request.form:
-    return "Nothing submitted, no changes made."
-
-  if request.form['type'] != 'ip' and  not request.form['resourceName']:
-    return "Please enter a name for the resource."
-  types = {'ip': addIp,
-           'fs': addFs,
-           'gfs': addGfs,
-           'nfsm': addNfsm,
-           'nfsx': addNfsx,
-           'nfsc': addNfsx,
-           'scr': addScr,
-           'smb': addSmb}
-
-
-  type = request.form["type"]
-  res = types[type](request)
-  modelb = request.SESSION.get('model')
-  modelstr = ""
-  conf = modelb.exportModelAsString()
-  rb = ricci_bridge(ragent)
-  #try:
-  if True:
-    batch_number, result = rb.setClusterConf(str(conf))
-  #except:
-  else:
-    return "Some error occured in setClusterConf\n"
-
-  clustername = request['clustername']
-  path = CLUSTER_FOLDER_PATH + clustername
-  clusterfolder = self.restrictedTraverse(path)
-  batch_id = str(batch_number)
-  objname = ragent + "____flag"
-  clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
-   #Now we need to annotate the new DB object
-  objpath = path + "/" + objname
-  flag = self.restrictedTraverse(objpath)
-  flag.manage_addProperty(BATCH_ID,batch_id, "string")
-  flag.manage_addProperty(TASKTYPE,RESOURCE_ADD, "string")
-  if type != 'ip':
-	  flag.manage_addProperty(FLAG_DESC,"Creating New Resource \'" + request.form['resourceName'] + "\'", "string")
-  else:
-	  flag.manage_addProperty(FLAG_DESC,"Creating New Resource \'" + res.attr_hash['address'] + "\'", "string")
-  response = request.RESPONSE
-  response.redirect(request['HTTP_REFERER'] + "&busyfirst=true")
-
-
-def getResourceForEdit(modelb, name):
-  resPtr = modelb.getResourcesPtr()
-  resources = resPtr.getChildren()
-
-  for res in resources:
-    if res.getName() == name:
-      resPtr.removeChild(res)
-      break
+	try:
+		addr = form['ip_address'].strip()
+		if not addr:
+			raise KeyError('ip_address is blank')
+		res.attr_hash['address'] = addr
+	except KeyError, e:
+		return None
 
-  return res
+	try:
+		monitor = form['monitorLink'].strip()
+		if monitor == '':
+			raise KeyError('monitorLink is blank.')
+	except KeyError, e:
+		return None
 
-def addIp(request):
-  modelb = request.SESSION.get('model')
-  if request.form.has_key('edit'):
-    res = getResourceForEdit(modelb, request.form['oldname'])
-  else:
-    res = apply(Ip)
-  form = request.form
-  addr = form['ip_address']
-  res.attr_hash["address"] = addr
-  if form.has_key('monitorLink'):
-    res.attr_hash["monitor_link"] = '1'
-  else:
-    res.attr_hash["monitor_link"] = '0'
-  modelb.getResourcesPtr().addChild(res)
-  return res
+	if monitor == '1' or monitor == 'True':
+		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')
@@ -2361,6 +2344,77 @@
   modelb.getResourcesPtr().addChild(res)
   return res
 
+resourceAddHandler = {
+	'ip': addIp,
+	'fs': addFs,
+	'gfs': addGfs,
+	'nfsm': addNfsm,
+	'nfsx': addNfsx,
+	'nfsc': addNfsx,
+	'scr': addScr,
+	'smb': addSmb
+}
+
+def addResource(self, request, ragent):
+	if not request.form:
+		return (False, {'errors': 'No form was submitted.'})
+
+	try:
+		type = request.form['type'].strip()
+		if not type or not type in resourceAddHandler:
+			raise
+	except:
+		return (False, {'errors': 'Form type is missing.'})
+
+	try:
+		resname = request.form['resourceName']
+	except KeyError, e:
+		# For IP, the IP address itself is the name.
+		if request.form['type'] != 'ip':
+			return (False, {'errors': 'No resource name was given.'})
+
+	res = resourceAddHandler[type](request)
+	modelb = request.SESSION.get('model')
+	modelstr = ""
+	conf = modelb.exportModelAsString()
+	rb = ricci_bridge(ragent)
+	#try:
+	if True:
+		batch_number, result = rb.setClusterConf(str(conf))
+	#except:
+	else:
+		return "Some error occured in setClusterConf\n"
+
+	clustername = request['clustername']
+	path = CLUSTER_FOLDER_PATH + clustername
+	clusterfolder = self.restrictedTraverse(path)
+	batch_id = str(batch_number)
+	objname = ragent + "____flag"
+	clusterfolder.manage_addProduct['ManagedSystem'].addManagedSystem(objname)
+	#Now we need to annotate the new DB object
+	objpath = path + "/" + objname
+	flag = self.restrictedTraverse(objpath)
+	flag.manage_addProperty(BATCH_ID,batch_id, "string")
+	flag.manage_addProperty(TASKTYPE,RESOURCE_ADD, "string")
+	if type != 'ip':
+		flag.manage_addProperty(FLAG_DESC,"Creating New Resource \'" + request.form['resourceName'] + "\'", "string")
+	else:
+		flag.manage_addProperty(FLAG_DESC,"Creating New Resource \'" + res.attr_hash['address'] + "\'", "string")
+	response = request.RESPONSE
+	response.redirect(request['HTTP_REFERER'] + "&busyfirst=true")
+
+def getResourceForEdit(modelb, name):
+  resPtr = modelb.getResourcesPtr()
+  resources = resPtr.getChildren()
+
+  for res in resources:
+    if res.getName() == name:
+      resPtr.removeChild(res)
+      break
+
+  return res
+
+
 def appendModel(request, model):
 	try:
 		request.SESSION.set('model', model)


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