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

rmccabe at sourceware.org rmccabe at sourceware.org
Wed Jan 10 20:06:27 UTC 2007


CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2007-01-10 20:06:26

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

Log message:
	code to propagate node fence config changes

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

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2007/01/10 16:00:42	1.196
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2007/01/10 20:06:26	1.197
@@ -23,6 +23,7 @@
 from QuorumD import QuorumD
 from Heuristic import Heuristic
 from clusterOS import resolveOSType
+from Fence import Fence
 from Method import Method
 from FenceDevice import FenceDevice
 from Device import Device
@@ -1448,7 +1449,7 @@
 	try:
 		fence_level = int(request.form['fence_level'].strip())
 	except Exception, e:
-		luci_log.debug_verbose('vNFC0a: no fence level: %s' % str(e))
+		luci_log.debug_verbose('vNFC1: no fence level: %s' % str(e))
 		return (False, {'errors': ['No fence level was supplied.']})
 
 	try:
@@ -1456,7 +1457,7 @@
 		if not nodename:
 			raise Exception, 'nodename is blank'
 	except Exception, e:
-		luci_log.debug_verbose('vNFC1: no nodename: %s' % str(e))
+		luci_log.debug_verbose('vNFC2: no nodename: %s' % str(e))
 		return (False, {'errors': ['No node name was given.']})
 
 	try:
@@ -1464,7 +1465,7 @@
 		if not clustername:
 			raise Exception, 'clustername is blank'
 	except Exception, e:
-		luci_log.debug_verbose('vNFC2: no clustername: %s' % str(e))
+		luci_log.debug_verbose('vNFC3: no clustername: %s' % str(e))
 		return (False, {'errors': ['No cluster name was given.']})
 
 	try:
@@ -1479,7 +1480,7 @@
 			model = None
 
 	if model is None:
-		luci_log.debug_verbose('vNFC2a: unable to get model for cluster %s' % clustername)
+		luci_log.debug_verbose('vNFC4: unable to get model for cluster %s' % clustername)
 		return (False, {'errors': ['No cluster model was found.']})
 
 	try:
@@ -1488,15 +1489,30 @@
 		if len(forms) < 1:
 			raise
 	except Exception, e:
-		luci_log.debug_verbose('vNFC2b: error: %s' % str(e))
+		luci_log.debug_verbose('vNFC5: error: %s' % str(e))
 		return (False, {'errors': ['The fence data submitted is not properly formed.']})
 
+	try:
+		node = model.retrieveNodeByName(nodename)
+	except GeneralError, e:
+		luci_log.debug_verbose('vNFC6: unable to find node name %s in current node list' % (str(nodename), str(e)))
+		return (False, {'errors': ['Unable to find the cluster node %s in the node list.' % str(nodename) ]})
+
+	fence_level_num = int(fence_level)
+	levels = node.getFenceLevels()
+	try:
+		method_id = levels[fence_level_num - 1].getAttribute('name')
+		if not method_id:
+			raise Exception, 'No method ID'
+	except Exception, e:
+		method_id = fence_level
+	
 	fence_method = Method()
-	fence_method.addAttribute('name', str(fence_level))
+	fence_method.addAttribute('name', str(method_id))
 
 	form_hash = {}
 	for i in forms:
-		form_id = i.getAttribute('name')
+		form_id = i.getAttribute('id')
 		if not form_id:
 			continue
 		ielems = i.getElementsByTagName('input')
@@ -1509,7 +1525,7 @@
 			try:
 				input_type = str(i.getAttribute('type'))
 			except Exception, e:
-				luci_log.debug_verbose('vNFC4: input type: %s' % str(e))
+				luci_log.debug_verbose('vNFC7: input type: %s' % str(e))
 				continue
 
 			if not input_type or input_type == 'button':
@@ -1518,19 +1534,24 @@
 			try:
 				dummy_form[str(i.getAttribute('name'))] = str(i.getAttribute('value'))
 			except Exception, e:
-				luci_log.debug_verbose('vNFC5: parsing XML: %s' % str(e))
+				luci_log.debug_verbose('vNFC8: parsing XML: %s' % str(e))
 
 		if len(dummy_form) < 1:
 			continue
 
-		if 'instance' in dummy_form:
+		if 'fence_instance' in dummy_form:
 			try:
 				parent = dummy_form['parent_fencedev']
-				parent_form = form_hash[parent][1].append(dummy_form)
 			except:
-				luci_log.debug_verbose('vNFC6: no parent for instance: %s' \
-					% dummy_form['name'])
-				raise Exception, 'instance has no owner'
+				luci_log.debug_verbose('vNFC9: no parent for instance')
+				return (False, {'errors': [ 'Unable to determine what device the current instance uses.' ]})
+
+			try:
+				parent_form = form_hash[parent][1].append(dummy_form)
+				del dummy_form['fence_instance']
+			except Exception, e:
+				luci_log.debug_verbose('vNFC10: no parent for instance')
+				return (False, {'errors': [ 'Unable to determine what device the current instance uses.' ]})
 		else:
 			form_hash[form_id] = (dummy_form, list())
 
@@ -1542,7 +1563,7 @@
 		try:
 			fence_form, instance_list = form_hash[i]
 		except Exception, e:
-			luci_log.debug_verbose('vNFC7: %s' % str(e))
+			luci_log.debug_verbose('vNFC11: %s' % str(e))
 			continue
 
 		try:
@@ -1551,7 +1572,7 @@
 				raise Exception, 'fence type is blank'
 			fence_form['agent'] = fence_type
 		except Exception, e:
-			luci_log.debug_verbose('vNFC8: %s' % str(e))
+			luci_log.debug_verbose('vNFC12: %s %s' % (i, str(e)))
 			fence_type = None
 
 		try:
@@ -1559,9 +1580,9 @@
 		except:
 			pass
 
-		fencedev_name = fence_form['name']
 		if 'existing_device' in fence_form:
 			del fence_form['existing_device']
+			fencedev_name = fence_form['name']
 
 			if fence_type is None:
 				# An unknown device. Pull the data out of
@@ -1584,18 +1605,36 @@
 							raise Exception, 'old name is blank'
 						del fence_form['old_name']
 					except Exception, e:
-						luci_log.debug_verbose('vNFC8: no old name for %s %s' \
+						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 ]})
+
+					fence_dev_list = model.getFenceDevices()
+					fencedev_obj = None
+					for fd in fence_dev_list:
+						if fd.getAttribute('name') == 'old_name':
+							fencedev_obj = fd
+							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 ]})
+							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 ] })
 
-					fencedev_obj = FenceDevice()
 					for k in fence_form.keys():
-						fencedev_obj.addAttribute(k, fence_form[k])
+						if fence_form[k]:
+							fencedev_obj.addAttribute(k, str(fence_form[k]))
 		else:
 			# The user created a new fence device.
 			fencedev_name = fence_form['name']
 			fencedev_obj = FenceDevice()
 			for k in fence_form.keys():
-				fencedev_obj.addAttribute(k, fence_form[k])
+				if fence_form[k]:
+					fencedev_obj.addAttribute(k, str(fence_form[k]))
 
 		if fencedev_obj is not None:
 			# If a device with this name exists in the model
@@ -1603,31 +1642,81 @@
 			# this block is not executed, we don't need to make
 			# any changes to the fencedevices block for this
 			# device
-			pass
+			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.
 			pass
 
 		for inst in instance_list:
-			new_instance = not 'existing_instance' in inst
 			try:
-				del inst['new_instance']
 				del inst['parent_fencedev']
-				del inst['existing_instance']
+			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 new_instance.keys():
-				device_obj.addAttribute(k, inst[k])
+			for k in inst.keys():
+				if inst[k]:
+					device_obj.addAttribute(k, str(inst[k]))
 			fence_method.addChild(device_obj)
 
-	luci_log.debug_verbose('vNFC7: got xml: %s' % doc.toprettyxml())
-	return (False, { 'errors': [ doc.toprettyxml() ]})
+		try:
+			levels[fence_level_num - 1] = fence_method
+		except:
+			fence_node = Fence()
+			fence_node.addChild(fence_method)
+			node.addChild(fence_node)
+
+	try:
+		cp = model.getClusterPtr()
+		cp.incrementConfigVersion()
+		model.setModified(True)
+		conf = str(model.exportModelAsString())
+		if not conf:
+			raise Exception, 'model string is blank'
+		luci_log.debug_verbose('vNFC16: exported \"%s\"' % conf)
+	except Exception, e:
+		luci_log.debug_verbose('vNFC17: exportModelAsString failed: %s' \
+			% str(e))
+		return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration.' ]})
+
+	rc = getRicciAgent(self, clustername)
+	if not rc:
+		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 = setClusterConf(rc, conf)
+	if batch_number is None or result is None:
+		luci_log.debug_verbose('vNFC19: missing batch and/or result')
+		return (False, {'errors': [ 'An error occurred while constructing the new cluster configuration.' ]})
+
+	try:
+		set_node_flag(self, clustername, ragent, str(batch_number), FENCEDEV_NODE_CONFIG, "Updating fence configuration for node \'%s\'" % nodename)
+	except Exception, e:
+		luci_log.debug_verbose('vNFC20: failed to set flags: %s' % str(e))
+
+	response = request.RESPONSE
+	response.redirect(request['URL'] + "?pagetype=" + NODE + "&clustername=" + clustername + '&nodename=' + nodename + '&busyfirst=true')
 
 def deleteFenceDevice(self, request):
   errors = list()




More information about the Cluster-devel mailing list