[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-09-21 03:02:47

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

Log message:
	Factor fence addition and deletion out of the luci code and stuff it into the cluster model code.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/FenceHandler.py.diff?cvsroot=cluster&r1=1.23&r2=1.24
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.271&r2=1.272
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ClusterModel/ModelBuilder.py.diff?cvsroot=cluster&r1=1.10&r2=1.11

--- conga/luci/site/luci/Extensions/FenceHandler.py	2007/09/20 22:37:32	1.23
+++ conga/luci/site/luci/Extensions/FenceHandler.py	2007/09/21 03:02:46	1.24
@@ -51,13 +51,6 @@
 	ILLEGAL_CHARS = re.compile(':| ')
 	return ILLEGAL_CHARS.sub('_', name)
 
-def check_unique_fd_name(model, name):
-	fds = model.getFenceDevices()
-	for fd in fds:
-		if fd.getName() == name:
-			return False
-	return True
-
 def validateNewFenceDevice(form, model):
 	from ClusterModel.FenceDevice import FenceDevice
 	fencedev = FenceDevice()
@@ -65,8 +58,7 @@
 	try:
 		ret = validate_fencedevice(form, model, fencedev)
 		if len(ret) < 1:
-			fencedevptr = model.getFenceDevicePtr()
-			fencedevptr.addChild(fencedev)
+			model.addFenceDevice(fencedev)
 			model.setModified(True)
 			return (FD_VAL_SUCCESS, fencedev.getAttribute('name'))
 	except Exception, e:
@@ -88,11 +80,7 @@
 
 	fencedev = None
 	try:
-		fencedevs = model.getFenceDevices()
-		for fd in fencedevs:
-			if fd.getName().strip() == old_fence_name:
-				fencedev = fd
-				break
+		fencedev = model.getFenceDeviceByName(old_fence_name)
 		if fencedev is None:
 			raise Exception, 'fencedev is None'
 	except Exception, e:
@@ -805,12 +793,13 @@
 				raise Exception, 'blank'
 		except Exception, e:
 			return [ FD_PROVIDE_NAME ]
+
 		if old_fence_name != fence_name:
-			if check_unique_fd_name(model, fence_name) is False:
+			if model.getFenceDeviceByName(fence_name) is not None:
 				return [ FD_PROVIDE_NAME ]
 			name_change = True
 	else:
-		if check_unique_fd_name(model, fence_name) is False:
+		if model.getFenceDeviceByName(fence_name) is not None:
 			return [ FD_PROVIDE_NAME ]
 
 	try:
--- conga/luci/site/luci/Extensions/cluster_adapters.py	2007/09/20 22:37:32	1.271
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2007/09/21 03:02:47	1.272
@@ -1794,34 +1794,23 @@
 
 	fencedev_name = fvar['orig_name']
 	if fencedev_name is None:
-		return (False, {'errors': ['No device name in form submission']})
+		return (False, {'errors': ['No fence device name in form submission']})
 
-	# XXX - FIXME: use new model calls to do this.
-	fdev_to_delete = None
-	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('DFD3: Could not find fence device "%s" in model' % fencedev_name)
-		return (False, {'errors': ['Could not find fence device "%s" in model' % fencedev_name ]})
-
-	fdev_ptr = model.getFenceDevicePtr()
 	try:
-		fdev_ptr.removeChild(fdev_to_delete)
-	except:
-		errors.append('Fence device "%s" could not be removed from configuration' % fencedev_name)
-		return (False, { 'errors': errors })
-
-	try:
-		model.removeFenceInstancesForFenceDevice(fencedev_name)
+		fdev = model.getFenceDeviceByName(fencedev_name)
+		if fdev:
+			if model.deleteFenceDevice(fdev) is not True:
+				raise Exception, 'failed to remove %s' % fdev.getName()
+			model.removeFenceInstancesForFenceDevice(fencedev_name)
+		else:
+			raise Exception, 'no fence device named "%s" was found' \
+					% fencedev_name
 	except Exception, e:
 		if LUCI_DEBUG_MODE is True:
-			luci_log.debug_verbose('DFD4: error removing %s: %r %s' \
+			luci_log.debug_verbose('DFD3: %s: %r %s' \
 				% (fencedev_name, e, str(e)))
+		return (False, { 'errors': [ 'Error removing fence device %s: %s' \
+										% (fencedev_name, str(e)) ]})
 
 	ret = propagateClusterConfAsync(self, model, None, CLUSTER_CONFIG,
 			'Removing fence device "%s"' % fencedev_name)
--- conga/luci/site/luci/Extensions/ClusterModel/ModelBuilder.py	2007/09/20 22:37:32	1.10
+++ conga/luci/site/luci/Extensions/ClusterModel/ModelBuilder.py	2007/09/21 03:02:47	1.11
@@ -335,9 +335,10 @@
 
   def getFenceDeviceByName(self, name):
     device = filter(lambda x: x.getName() == name, self.getFenceDevices())
-    if len(device) > 1:
-      raise Exception, '%d fence devices named %s exist' % (len(device), name)
-    if len(device) < 1:
+    num_fdevs = len(device)
+    if num_fdevs > 1:
+      raise Exception, '%d fence devices named %s exist' % (num_fdevs, name)
+    if num_fdevs < 1:
       return None
     return device[0]
       
@@ -621,6 +622,9 @@
       self.cluster_ptr.removeChild(self.fence_xvmd_ptr)
       self.fence_xvmd_ptr = None
 
+  def addFenceDevice(self, device):
+    self.fencedevices_ptr.addChild(device)
+
   def deleteFenceDevice(self, device):
     if self.fencedevices_ptr is None or device is None:
       return False


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