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

[Cluster-devel] conga/luci/site/luci/Extensions FenceHandler.p ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2007-01-19 21:48:23

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

Log message:
	use the new fence validation code to validate fence add/edit and node fence operations

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/FenceHandler.py.diff?cvsroot=cluster&r1=1.14&r2=1.15
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.206&r2=1.207

--- conga/luci/site/luci/Extensions/FenceHandler.py	2007/01/19 20:57:38	1.14
+++ conga/luci/site/luci/Extensions/FenceHandler.py	2007/01/19 21:48:23	1.15
@@ -37,7 +37,7 @@
 # For every new fence added, there will be a fence instance and fence device
 # form needed. There will also be a populate and a validate method for each
 # form. The methods will need to be added to this file, and the four hash
-# tables (self.fi_populate, self.fi_validate, self.fd_populate, 
+# tables (self.fi_populate, self.fi_validate, self.fd_populate,
 # self.fd_validate) must be updated. The methods will use fields in the
 # forms to set_text and to check.
 
@@ -183,7 +183,7 @@
 	'fence_ipmilan': ['name', 'ipaddr', 'login', 'passwd', 'lanplus', 'auth'],
 	'fence_drac': ['name', 'ipaddr', 'login', 'passwd'],
 	'fence_rsa': ['name', 'hostname', 'login', 'passwd'],
-	'fence_rps10':  ['name', 'device', 'port'],
+	'fence_rps10': ['name', 'device', 'port'],
 	'fence_manual': ['name']
 }
 
@@ -205,23 +205,23 @@
 
 	try:
 		ret = validate_fencedevice(form, model, fencedev)
-		if ret is None:
+		if len(ret) < 1:
 			fencedevptr = model.getFenceDevicePtr()
 			fencedevptr.addChild(fencedev)
 			model.setModified(True)
 			return (FD_VAL_SUCCESS, fencedev.getAttribute('name'))
 	except Exception, e:
-		ret = FD_PROVIDE_AGENT
+		ret = [ FD_PROVIDE_AGENT ]
 
 	return (FD_VAL_FAIL, ret)
 
-def validateFenceDevice(form, model): 
+def validateFenceDevice(form, model):
 	try:
 		old_fence_name = form['orig_name'].strip()
 		if not old_fence_name:
 			raise Exception, 'blank'
 	except Exception, e:
-		return (FD_VAL_FAIL, FD_PROVIDE_NAME)
+		return (FD_VAL_FAIL, [ FD_PROVIDE_NAME ])
 
 	fencedev = None
 	try:
@@ -233,15 +233,15 @@
 		if fencedev is None:
 			raise Exception, 'fencedev is None'
 	except Exception, e:
-		return (FD_VAL_FAIL, FD_PROVIDE_NAME)
+		return (FD_VAL_FAIL, [ FD_PROVIDE_NAME ])
 
 	try:
 		ret = validate_fencedevice(form, model, fencedev, fence_edit=True)
-		if ret is None:
+		if len(ret) < 1:
 			model.setModified(True)
 			return (FD_VAL_SUCCESS, fencedev.getAttribute('name'))
 	except Exception, e:
-		ret = FD_PROVIDE_NAME
+		ret = [ FD_PROVIDE_NAME ]
 
 	return (FD_VAL_FAIL, ret)
 
@@ -252,7 +252,7 @@
 			raise Exception, 'blank'
 		fence_name = makeNCName(fence_name)
 	except Exception, e:
-		return FD_PROVIDE_NAME
+		return [ FD_PROVIDE_NAME ]
 
 	name_change = False
 	if fence_edit is True:
@@ -261,357 +261,385 @@
 			if not old_fence_name:
 				raise Exception, 'blank'
 		except Exception, e:
-			return FD_PROVIDE_NAME
+			return [ FD_PROVIDE_NAME ]
 		if old_fence_name != fence_name:
 			if check_unique_fd_name(model, fence_name) is False:
-				return FD_PROVIDE_NAME
+				return [ FD_PROVIDE_NAME ]
 			name_change = True
 	else:
 		if check_unique_fd_name(model, fence_name) is False:
-			return FD_PROVIDE_NAME
+			return [ FD_PROVIDE_NAME ]
 
 	try:
 		fence_agent = form['agent'].strip()
 		if not fence_agent:
 			raise Exception, 'blank agent'
 	except Exception, e:
-		return FD_PROVIDE_AGENT
+		return [ FD_PROVIDE_AGENT ]
 
 	fencedev.addAttribute('name', fence_name)
 	fencedev.addAttribute('agent', fence_agent)
 
 	try:
 		ret = FD_VALIDATE[fence_agent](form, fencedev)
-		if ret is None and name_change is True:
+		if len(ret) < 1 and name_change is True:
 			try:
 				model.rectifyNewFencedevicenameWithFences(old_fence_name, fence_name)
 			except:
-				return FD_NEW_FAIL % fence_agent
+				return [ FD_NEW_FAIL % fence_agent ]
 		return ret
 	except:
-		return FD_NEW_FAIL % fence_agent
+		return [ FD_NEW_FAIL % fence_agent ]
 
 def val_apc_fd(form, fencedev):
+	errors = list()
+
 	try:
 		ip = form['ipaddr'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_IP
+		errors.append(FD_PROVIDE_IP)
 
 	try:
 		log = form['login'].strip()
 		if not log:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_LOGIN
+		errors.append(FD_PROVIDE_LOGIN)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('ipaddr', ip)
 	fencedev.addAttribute('login', log)
 	fencedev.addAttribute('passwd', pwd)
-	return None
+	return errors
 
 def val_wti_fd(form, fencedev):
+	errors = list()
+
 	try:
 		ip = form['ipaddr'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_IP
+		errors.append(FD_PROVIDE_IP)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('ipaddr', ip)
 	fencedev.addAttribute('passwd', pwd)
-	return None
- 
+	return errors
+
 def val_brocade_fd(form, fencedev):
+	errors = list()
+
 	try:
 		ip = form['ipaddr'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_IP
+		errors.append(FD_PROVIDE_IP)
 
 	try:
 		log = form['login'].strip()
 		if not log:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_LOGIN
+		errors.append(FD_PROVIDE_LOGIN)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('ipaddr', ip)
 	fencedev.addAttribute('login', log)
 	fencedev.addAttribute('passwd', pwd)
-	return None
- 
+	return errors
+
 def val_vixel_fd(form, fencedev):
+	errors = list()
+
 	try:
 		ip = form['ipaddr'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_IP
+		errors.append(FD_PROVIDE_IP)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('ipaddr', ip)
 	fencedev.addAttribute('passwd', pwd)
-	return None
- 
+	return errors
+
 def val_mcdata_fd(form, fencedev):
+	errors = list()
+
 	try:
 		ip = form['ipaddr'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_IP
+		errors.append(FD_PROVIDE_IP)
 
 	try:
 		log = form['login'].strip()
 		if not log:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_LOGIN
+		errors.append(FD_PROVIDE_LOGIN)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('ipaddr', ip)
 	fencedev.addAttribute('login', log)
 	fencedev.addAttribute('passwd', pwd)
-	return None
- 
+	return errors
+
 def val_gnbd_fd(form, fencedev):
+	errors = list()
+
 	try:
 		server = form['server'].strip()
 		if not server:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_SERVER
+		errors.append(FD_PROVIDE_SERVER)
 
 	fencedev.addAttribute('server', server)
-	return None
- 
+	return errors
+
 def val_egenera_fd(form, fencedev):
+	errors = list()
+
 	try:
 		cserver = form['cserver'].strip()
 		if not cserver:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_CSERVER
+		errors.append(FD_PROVIDE_CSERVER)
 
 	fencedev.addAttribute('cserver', cserver)
-	return None
- 
+	return errors
+
 def val_sanbox2_fd(form, fencedev):
+	errors = list()
+
 	try:
 		ip = form['ipaddr'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_IP
+		errors.append(FD_PROVIDE_IP)
 
 	try:
 		log = form['login'].strip()
 		if not log:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_LOGIN
+		errors.append(FD_PROVIDE_LOGIN)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('ipaddr', ip)
 	fencedev.addAttribute('login', log)
 	fencedev.addAttribute('passwd', pwd)
-	return None
+	return errors
 
 def val_bladecenter_fd(form, fencedev):
+	errors = list()
+
 	try:
 		ip = form['ipaddr'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_IP
+		errors.append(FD_PROVIDE_IP)
 
 	try:
 		log = form['login'].strip()
 		if not log:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_LOGIN
+		errors.append(FD_PROVIDE_LOGIN)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('ipaddr', ip)
 	fencedev.addAttribute('login', log)
 	fencedev.addAttribute('passwd', pwd)
-	return None
+	return errors
 
 def val_bullpap_fd(form, fencedev):
+	errors = list()
+
 	try:
 		ip = form['ipaddr'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_IP
+		errors.append(FD_PROVIDE_IP)
 
 	try:
 		log = form['login'].strip()
 		if not log:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_LOGIN
+		errors.append(FD_PROVIDE_LOGIN)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('ipaddr', ip)
 	fencedev.addAttribute('login', log)
 	fencedev.addAttribute('passwd', pwd)
-	return None
+	return errors
 
 def val_noop_fd(dummy, dummy):
-	return None
+	return []
 
 # non-shared devices
 
 def val_rsa_fd(form, fencedev):
+	errors = list()
+
 	try:
 		hostname = form['hostname'].strip()
 		if not hostname:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_HOSTNAME
+		errors.append(FD_PROVIDE_HOSTNAME)
 
 	try:
 		log = form['login'].strip()
 		if not log:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_LOGIN
+		errors.append(FD_PROVIDE_LOGIN)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('hostname', hostname)
 	fencedev.addAttribute('login', log)
 	fencedev.addAttribute('passwd', pwd)
-	return None
+	return errors
 
 def val_drac_fd(form, fencedev):
+	errors = list()
+
 	try:
 		ip = form['ipaddr'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_IP
+		errors.append(FD_PROVIDE_IP)
 
 	try:
 		log = form['login'].strip()
 		if not log:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_LOGIN
+		errors.append(FD_PROVIDE_LOGIN)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('ipaddr', ip)
 	fencedev.addAttribute('login', log)
 	fencedev.addAttribute('passwd', pwd)
-	return None
+	return errors
 
 def val_rps10_fd(form, fencedev):
+	errors = list()
+
 	try:
 		device = form['device'].strip()
 		if not device:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_DEVICE
+		errors.append(FD_PROVIDE_DEVICE)
 
 	try:
 		port = form['port'].strip()
 		if not port:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PORT
+		errors.append(FD_PROVIDE_PORT)
 
 	fencedev.addAttribute('device', device)
 	fencedev.addAttribute('port', port)
-	return None
+	return errors
 
 def val_ipmilan_fd(form, fencedev):
+	errors = list()
+
 	try:
 		ip = form['ipaddr'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_IP
+		errors.append(FD_PROVIDE_IP)
 
 	try:
 		log = form['login'].strip()
 		if not log:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_LOGIN
+		errors.append(FD_PROVIDE_LOGIN)
 
 	try:
 		pwd = form['passwd'].strip()
 		if not pwd:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	try:
 		auth_type = form['auth_type'].strip().lower()
@@ -620,11 +648,11 @@
 		elif auth_type == 'password' or auth_type == 'md5':
 			fencedev.setAttribute('auth_type', auth_type)
 		else:
-			return FD_PROVIDE_IPMILAN_AUTH
+			errors.append(FD_PROVIDE_IPMILAN_AUTH)
 	except KeyError, e:
 		fencedev.removeAttribute('auth_type')
 	except Exception, e:
-		return FD_PROVIDE_IPMILAN_AUTH
+		errors.append(FD_PROVIDE_IPMILAN_AUTH)
 
 	try:
 		lanplus = form['lanplus'].strip().lower()
@@ -638,34 +666,36 @@
 	fencedev.addAttribute('ipaddr', ip)
 	fencedev.addAttribute('login', log)
 	fencedev.addAttribute('passwd', pwd)
-	return None
+	return errors
 
 def val_ilo_fd(form, fencedev):
+	errors = list()
+
 	try:
 		hostname = form['hostname'].strip()
 		if not hostname:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_HOSTNAME
+		errors.append(FD_PROVIDE_HOSTNAME)
 
 	try:
 		log = form['login'].strip()
 		if not log:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FD_PROVIDE_LOGIN
+		errors.append(FD_PROVIDE_LOGIN)
 
 	try:
 		pwd = form['passwd'].strip()
 	except Exception, e:
-		return FD_PROVIDE_PASSWD
+		errors.append(FD_PROVIDE_PASSWD)
 
 	fencedev.addAttribute('hostname', hostname)
 	fencedev.addAttribute('login', log)
 	fencedev.addAttribute('passwd', pwd)
-	return None
+	return errors
 
-# Validation Methods for Fence Instances 
+# Validation Methods for Fence Instances
 
 def validate_fenceinstance(form, parent_name):
 	try:
@@ -673,33 +703,35 @@
 		if not fence_agent:
 			raise Exception, 'blank'
 	except:
-		return FD_PROVIDE_AGENT
+		return [ FD_PROVIDE_AGENT ]
 
 	try:
 		if not parent_name.strip():
-			return FI_PROVIDE_PARENT
+			return [ FI_PROVIDE_PARENT ]
 	except:
-		return FI_PROVIDE_PARENT
+		return [ FI_PROVIDE_PARENT ]
 
 	fenceinst = Device()
 	fenceinst.addAttribute('name', parent_name)
 
 	try:
 		ret = FI_VALIDATE[fence_agent](form, fenceinst)
-		if ret is not None:
+		if len(ret) > 0:
 			return (FD_VAL_FAIL, ret)
 	except Exception, e:
-		return (FD_VAL_FAIL, FI_NEW_FAIL % fence_agent)
+		return (FD_VAL_FAIL, [ FI_NEW_FAIL % fence_agent ])
 
 	return (FD_VAL_SUCCESS, fenceinst)
 
 def val_apc_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		port = form['port'].strip()
 		if not port:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_PORT
+		errors.append(FI_PROVIDE_PORT)
 
 	try:
 		switch = form['switch'].strip()
@@ -709,138 +741,162 @@
 	except KeyError, e:
 		# switch is optional
 		fenceinst.removeAttribute('switch')
+	except Exception, e:
+		errors.append(FI_PROVIDE_SWITCH)
 
 	fenceinst.addAttribute('port', port)
-	return None
+	return errors
 
 def val_wti_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		port = form['port'].strip()
 		if not port:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_PORT
+		errors.append(FI_PROVIDE_PORT)
 
 	fenceinst.addAttribute('port', port)
-	return None
+	return errors
 
 def val_brocade_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		port = form['port'].strip()
 		if not port:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_PORT
+		errors.append(FI_PROVIDE_PORT)
 
 	fenceinst.addAttribute('port', port)
-	return None
+	return errors
 
 def val_vixel_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		port = form['port'].strip()
 		if not port:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_PORT
+		errors.append(FI_PROVIDE_PORT)
 
 	fenceinst.addAttribute('port', port)
-	return None
+	return errors
 
 def val_gnbd_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		ip = form['ipaddress'].strip()
 		if not ip:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_IPADDRESS
+		errors.append(FI_PROVIDE_IPADDRESS)
 
 	fenceinst.addAttribute('ipaddress', ip)
-	return None
+	return errors
 
 def val_sanbox2_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		port = form['port'].strip()
 		if not port:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_PORT
+		errors.append(FI_PROVIDE_PORT)
 
 	fenceinst.addAttribute('port', port)
-	return None
+	return errors
 
 def val_bladecenter_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		blade = form['blade'].strip()
 		if not blade:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_BLADE
+		errors.append(FI_PROVIDE_BLADE)
 
 	fenceinst.addAttribute('blade', blade)
-	return None
+	return errors
 
 def val_mcdata_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		port = form['port'].strip()
 		if not port:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_PORT
+		errors.append(FI_PROVIDE_PORT)
 
 	fenceinst.addAttribute('port', port)
-	return None
+	return errors
 
 def val_egenera_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		lpan = form['lpan'].strip()
 		if not lpan:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_ELPAN
+		errors.append(FI_PROVIDE_ELPAN)
 
 	try:
 		pserver = form['pserver'].strip()
 		if not pserver:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_ELPAN
+		errors.append(FI_PROVIDE_ELPAN)
 
 	fenceinst.addAttribute('lpan', lpan)
 	fenceinst.addAttribute('pserver', pserver)
-	return None
+	return errors
 
 def val_bullpap_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		domain = form['domain'].strip()
 		if not domain:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_DOMAIN
+		errors.append(FI_PROVIDE_DOMAIN)
 
 	fenceinst.addAttribute('domain', domain)
-	return None
+	return errors
 
 def val_xvm_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		domain = form['domain'].strip()
 		if not domain:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_DOMAIN
+		errors.append(FI_PROVIDE_DOMAIN)
 
 	fenceinst.addAttribute('domain', domain)
-	return None
+	return errors
 
 def val_scsi_fi(form, fenceinst):
+	errors = list()
+
 	try:
 		nodename = form['nodename'].strip()
 		if not nodename:
 			raise Exception, 'blank'
 	except Exception, e:
-		return FI_PROVIDE_NODENAME
+		errors.append(FI_PROVIDE_NODENAME)
 
 	fenceinst.addAttribute('nodename', nodename)
-	return None
+	return errors
 
 def val_noop_fi(dummy, dummy):
-	return None
+	return []
--- conga/luci/site/luci/Extensions/cluster_adapters.py	2007/01/19 19:41:26	1.206
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2007/01/19 21:48:23	1.207
@@ -32,7 +32,7 @@
 from Method import Method
 from FenceDevice import FenceDevice
 from Device import Device
-from FenceHandler import validateNewFenceDevice, FENCE_OPTS, validateFenceDevice
+from FenceHandler import validateNewFenceDevice, FENCE_OPTS, validateFenceDevice, validate_fenceinstance
 from GeneralError import GeneralError
 from homebase_adapters import manageCluster, createClusterSystems, havePermCreateCluster, setNodeFlag, delNodeFlag, userAuthenticated, getStorageNode, getClusterNode, delCluster, parseHostForm
 from LuciSyslog import LuciSyslog
@@ -1296,13 +1296,9 @@
     return (False, {'errors': ['No form was submitted']})
 
   #fencehandler = FenceHandler()
-  error_code, error_string = validateNewFenceDevice(form, model)
+  error_code, retobj = validateNewFenceDevice(form, model)
   if error_code == FD_VAL_SUCCESS:
-    messages.append(error_string)
     try:
-      cp = model.getClusterPtr()
-      cp.incrementConfigVersion()
-      model.setModified(True)
       conf_str = model.exportModelAsString()
       if not conf_str:
         raise Exception, 'conf_str is none'
@@ -1335,14 +1331,13 @@
       else:
         try:
           set_node_flag(self, clustername, rc.hostname(), batch_id,
-          CLUSTER_CONFIG, 'Updating cluster configuration')
+          CLUSTER_CONFIG, 'Adding new fence device \"%s\"' % retobj)
         except:
           pass
 
-    response.redirect(request['URL'] + "?pagetype=" + FENCEDEV + "&clustername=" + clustername + "&fencename=" + form['name'] + '&busyfirst=true')
-    return (True, {'errors': errors, 'messages': messages})
+    response.redirect(request['URL'] + "?pagetype=" + FENCEDEV + "&clustername=" + clustername + "&fencename=" + retobj + '&busyfirst=true')
   else:
-    errors.append(error_string)
+    errors.extend(retobj)
     return (False, {'errors': errors, 'messages': messages})
 
 
@@ -1393,19 +1388,15 @@
   #entry for this fence device.
   #
   #pass form and model to validation method, then save changes if it passes.
-  error_code, error_string = validateFenceDevice(form, model)
+  error_code, retobj = validateFenceDevice(form, model)
   if error_code == FD_VAL_SUCCESS:
-    messages.append(error_string)
     try:
-      cp = model.getClusterPtr()
-      cp.incrementConfigVersion()
-      model.setModified(True)
       conf_str = model.exportModelAsString()
       if not conf_str:
         raise Exception, 'conf_str is none'
     except Exception, e:
       luci_log.debug_verbose('VFE: export model as string failed: %s' \
-      % str(e))
+        % str(e))
       errors.append('Unable to store the new cluster configuration')
 
     try:
@@ -1421,28 +1412,29 @@
       if not rc:
         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)
+          % clustername)
 
     if rc:
       batch_id, result = setClusterConf(rc, str(conf_str))
       if batch_id is None or result is None:
         luci_log.debug_verbose('VFA: setClusterConf: batchid or result is None')
         errors.append('Unable to propagate the new cluster configuration for %s' \
-        % clustername)
+          % clustername)
       else:
         try:
           set_node_flag(self, clustername, rc.hostname(), batch_id,
-          CLUSTER_CONFIG, 'Updating cluster configuration')
+          CLUSTER_CONFIG, 'Updating fence device \"%s\"' % retobj)
         except:
           pass
 
-    response.redirect(request['URL'] + "?pagetype=" + FENCEDEV + "&clustername=" + clustername + "&fencename=" + request['fencename'] + '&busyfirst=true')
-    return (True, {'errors': errors, 'messages': messages})
+    response.redirect(request['URL'] + "?pagetype=" + FENCEDEV + "&clustername=" + clustername + "&fencename=" + retobj + '&busyfirst=true')
   else:
-    errors.append(error_string)
+    errors.extend(retobj)
     return (False, {'errors': errors, 'messages': messages})
 
 def validateNodeFenceConfig(self, request):
+	errors = list()
+
 	try:
 		form_xml = request['fence_xml']
 		if not form_xml:
@@ -1581,7 +1573,6 @@
 	for i in fh_keys:
 		fencedev_name = None
 		fencedev_unknown = False
-		fencedev_obj = None
 
 		try:
 			fence_form, instance_list = form_hash[i]
@@ -1593,140 +1584,70 @@
 			fence_type = fence_form['fence_type']
 			if not fence_type:
 				raise Exception, 'fence type is blank'
-			fence_form['agent'] = fence_type
 		except Exception, e:
 			luci_log.debug_verbose('vNFC12: %s %s' % (i, str(e)))
 			fence_type = None
 
-		try:
-			del fence_form['fence_type']
-		except:
-			pass
-
 		if 'existing_device' in fence_form:
-			del fence_form['existing_device']
-
 			try:
 				fencedev_name = fence_form['name']
 				if not fencedev_name.strip():
 					raise Exception, 'no fence name'
 			except Exception, e:
-				return (False, {'errors': [ 'You must provide a unique name for all fence devices.' ]})
+				errors.append('You must provide a unique name for all fence devices.')
+				continue
 
 			if fence_type is None:
-				# An unknown device. Pull the data out of
+				# An unknown fence device agent. Pull the data out of
 				# the model and persist it and all instances.
 				# All we care about is its name.
 				fencedev_unknown = True
 			else:
-				if 'sharable' in fence_form:
+				if not 'sharable' in fence_form:
 					# 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
-					# the model. All we need is the device name.
-					del fence_form['sharable']
-				else:
-					# An existing non-shared device; build up the device
-					# from scratch since the user could have edited it.
-					try:
-						old_name = fence_form['old_name']
-						if not old_name:
-							raise Exception, 'old name is blank'
-						del fence_form['old_name']
-					except Exception, e:
-						luci_log.debug_verbose('vNFC12: no old name for %s %s' \
-							% (fence_form['name'], str(e)))
-						return (False, {'errors': [ 'Unable to determine the original name for the device now named %s' % fencedev_name ]})
-
-					fencedev_obj = None
-					fence_dev_list = model.getFenceDevices()
-					for fd in fence_dev_list:
-						if fd.getAttribute('name') == old_name:
-							fencedev_obj = fd
-							break
-
-					if fencedev_obj is None:
-						luci_log.debug_verbose('vNFC14: no fence device named %s was found' % old_name)
-						return (False, {'errors': ['No fence device named %s was found' % old_name ] })
+					# the model. All we need is the device name, and nothing
+					# else needs to be done here.
+					# 
+					# For an existing non-shared device update the device
+					# in the model, since the user could have edited it.
+					retcode, retmsg = validateFenceDevice(fence_form, model)
+					if retcode != FD_VAL_SUCCESS:
+						errors.extend(retmsg)
+						continue
 					else:
-						try:
-							model.fencedevices_ptr.removeChild(fd)
-						except Exception, e:
-							luci_log.debug_verbose('VNFC8a: %s: %s' \
-								% (old_name, str(e)))
-							return (False, {'errors': [ 'Unable to remove old fence device %s' % old_name ]})
-
-					for k in fence_form.keys():
-						if fence_form[k]:
-							fencedev_obj.addAttribute(k, str(fence_form[k]))
+						fencedev_name = retmsg
 
 					# Add back the tags under the method block
 					# for the fence instance
 					instance_list.append({'name': fencedev_name })
 		else:
 			# The user created a new fence device.
-			try:
-				fencedev_name = fence_form['name']
-				if not fencedev_name.strip():
-					raise Exception, 'no fence name'
-			except Exception, e:
-				return (False, {'errors': [ 'You must provide a unique name for all fence devices.' ]})
-
-			fencedev_obj = FenceDevice()
-			for k in fence_form.keys():
-				if fence_form[k]:
-					fencedev_obj.addAttribute(k, str(fence_form[k]))
+			retcode, retmsg = validateNewFenceDevice(fence_form, model)
+			if retcode != FD_VAL_SUCCESS:
+				errors.extend(retmsg)
+				continue
+			else:
+				fencedev_name = retmsg
 
 			# 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:
 				instance_list.append({'name': fencedev_name })
-			else:
-				del fence_form['sharable']
-
-		if fencedev_obj is not None:
-			# If a device with this name exists in the model
-			# already, replace it with the current object. If
-			# this block is not executed, we don't need to make
-			# any changes to the fencedevices block for this
-			# device
-			fence_dev_list = model.getFenceDevices()
-			for fd in fence_dev_list:
-				if fencedev_name == fd.getAttribute('name'):
-					luci_log.debug_verbose('vNFC15: fence ident %s already in use' % fencedev_name)
-					return (False, {'errors': ['There is already a fence device named %s' % fencedev_name ] })
-			model.fencedevices_ptr.addChild(fencedev_obj)
 
 		if fencedev_unknown is True:
 			# Save any instances for this fence device.
+			# XXX FIX ME - instances must be saved.
 			pass
 
 		for inst in instance_list:
-			try:
-				del inst['parent_fencedev']
-			except:
-				pass
-			try:
-				del inst['new_instance']
-			except:
-				pass
-			try:
-				del inst['name']
-			except:
-				pass
-			try:
-				del inst['existing_instance']
-			except:
-				pass
-
-			device_obj = Device()
-			device_obj.setAgentType(fence_type)
-			device_obj.addAttribute('name', fencedev_name)
-			for k in inst.keys():
-				if inst[k]:
-					device_obj.addAttribute(k, str(inst[k]))
-			fence_method.addChild(device_obj)
+			retcode, retobj = validate_fenceinstance(inst, fencedev_name)
+			if retcode != FD_VAL_SUCCESS:
+				errors.extend(retobj)
+				continue
+			fence_method.addChild(retobj)
 
 		if len(node.getChildren()) > 0:
 			# There's already a <fence> block
@@ -1746,9 +1667,10 @@
 			fence_node.addChild(fence_method)
 			node.addChild(fence_node)
 
+	if len(errors) > 0:
+		return (False, {'errors': errors })
+
 	try:
-		cp = model.getClusterPtr()
-		cp.incrementConfigVersion()
 		model.setModified(True)
 		conf = str(model.exportModelAsString())
 		if not conf:


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