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

[Cluster-devel] conga/luci cluster/form-macros site/luci/Exten ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2006-11-13 21:40:55

Modified files:
	luci/cluster   : form-macros 
	luci/site/luci/Extensions: cluster_adapters.py 
	                           conga_constants.py ricci_bridge.py 

Log message:
	fix for bz# 215034 (Cannot change daemon properties via luci web app)

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/form-macros.diff?cvsroot=cluster&r1=1.104&r2=1.105
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.162&r2=1.163
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/conga_constants.py.diff?cvsroot=cluster&r1=1.25&r2=1.26
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ricci_bridge.py.diff?cvsroot=cluster&r1=1.42&r2=1.43

--- conga/luci/cluster/form-macros	2006/11/12 02:10:52	1.104
+++ conga/luci/cluster/form-macros	2006/11/13 21:40:55	1.105
@@ -1791,7 +1791,7 @@
 		tal:condition="python: nodeinfo['nodestate'] == '0' or nodeinfo['nodestate'] == '1'">
 
 	<h3>Cluster daemons running on this node</h3>
-	<form name="daemon_form">
+	<form name="daemon_form" method="post">
 	<table class="systemsTable">
 		<thead>
 			<tr class="systemsTable">
@@ -1803,23 +1803,38 @@
 		<tfoot class="systemsTable">
 			<tr class="systemsTable"><td class="systemsTable" colspan="3">
 				<div class="systemsTableEnd">
-					<input type="button" value="Update node daemon properties" />
+					<input type="Submit" value="Update node daemon properties" />
 				</div>
 			</td></tr>
 		</tfoot>
 		<tbody class="systemsTable">
 			<tr class="systemsTable" tal:repeat="demon nodeinfo/d_states">
 				<td class="systemsTable"><span tal:replace="demon/name"/></td>
-				<td class="systemsTable"><span tal:replace="python: demon['running'] and 'yes' or 'no'" /></td>
+				<td class="systemsTable"><span tal:replace="python: demon['running'] == 'true' and 'yes' or 'no'" /></td>
 				<td class="systemsTable">
-					<input type="checkbox"
-						tal:attributes="
-							name python: nodeinfo['nodename'] + ':' + demon['name'];
-							checked python: demon['enabled'] and 'checked'" />
+					<input type="hidden" tal:attributes="
+						name python: '__daemon__:' + demon['name'] + ':';
+						value demon/name" />
+
+					<input type="hidden" tal:attributes="
+						name python: '__daemon__:' + demon['name'] + ':';
+						value python: demon['enabled'] == 'true' and '1' or '0'" />
+
+					<input type="checkbox" tal:attributes="
+						name python: '__daemon__:' + demon['name'] + ':';
+						checked python: demon['enabled'] == 'true' and 'checked'" />
 				</td>
 			</tr>
 		</tbody>
 	</table>
+
+	<input type="hidden" name="nodename"
+		tal:attributes="value nodeinfo/nodename | request/nodename | nothing" />
+
+	<input type="hidden" name="clustername"
+		tal:attributes="value request/clustername | nothing" />
+
+	<input type="hidden" name="pagetype" value="55" />
 	</form>
 	<hr/>
 	</tal:block>
--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/11/12 02:10:53	1.162
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/11/13 21:40:55	1.163
@@ -815,7 +815,7 @@
 		except Exception, e:
 			luci_log.debug_verbose('VCC4: export model as string failed: %s' \
 				% str(e))
-			errors.append('unable to store the new cluster configuration')
+			errors.append('Unable to store the new cluster configuration')
 
 	try:
 		clustername = model.getClusterName()
@@ -823,7 +823,7 @@
 			raise Exception, 'cluster name from modelb.getClusterName() is blank'
 	except Exception, e:
 		luci_log.debug_verbose('VCC5: error: getClusterName: %s' % str(e))
-		errors.append('unable to determine cluster name from model') 
+		errors.append('Unable to determine cluster name from model') 
 
 	if len(errors) > 0:
 		return (retcode, {'errors': errors, 'messages': messages})
@@ -832,14 +832,14 @@
 		rc = getRicciAgent(self, clustername)
 		if not rc:
 			luci_log.debug_verbose('VCC6: unable to find a ricci agent for the %s cluster' % clustername)
-			errors.append('unable to contact a ricci agent for cluster %s' \
+			errors.append('Unable to contact a ricci agent for cluster %s' \
 				% clustername)
 
 	if rc:
 		batch_id, result = setClusterConf(rc, str(conf_str))
 		if batch_id is None or result is None:
 			luci_log.debug_verbose('VCC7: setCluserConf: batchid or result is None')
-			errors.append('unable to propagate the new cluster configuration for %s' \
+			errors.append('Unable to propagate the new cluster configuration for %s' \
 				% clustername)
 		else:
 			try:
@@ -862,6 +862,89 @@
 def validateFenceEdit(self, request):
 	return (True, {})
 
+def validateDaemonProperties(self, request):
+	errors = list()
+
+	form = None
+	try:
+		response = request.response
+		form = request.form
+		if not form:
+			form = None
+			raise Exception, 'no form was submitted'
+	except:
+		pass
+
+	if form is None:
+		luci_log.debug_verbose('VDP0: no form was submitted')
+		return (False, {'errors': ['No form was submitted']})
+
+	try:
+		nodename = form['nodename'].strip()
+		if not nodename:
+			raise Exception, 'nodename is blank'
+	except Exception, e:
+		errors.append('Unable to determine the current node name')
+		luci_log.debug_verbose('VDP1: no nodename: %s' % str(e))
+
+	try:
+		clustername = form['clustername'].strip()
+		if not clustername:
+			raise Exception, 'clustername is blank'
+	except Exception, e:
+		errors.append('Unable to determine the current cluster name')
+		luci_log.debug_verbose('VDP2: no clustername: %s' % str(e))
+
+	disable_list = list()
+	enable_list = list()
+	for i in form.items():
+		try:
+			if i[0][:11] == '__daemon__:':
+				daemon_prop = i[1]
+				if len(daemon_prop) == 2:
+					if daemon_prop[1] == '1':
+						disable_list.append(daemon_prop[0])
+				else:
+					if daemon_prop[1] == '0' and daemon_prop[2] == 'on':
+						enable_list.append(daemon_prop[0])
+		except Exception, e:
+			luci_log.debug_verbose('VDP3: error: %s' % str(i))
+
+	if len(enable_list) < 1 and len(disable_list) < 1:
+		luci_log.debug_verbose('VDP4: no changes made')
+		response.redirect(request['URL'] + "?pagetype=" + NODE + "&clustername=" + clustername + '&nodename=' + nodename)
+
+	nodename_resolved = resolve_nodename(self, clustername, nodename)
+	try:
+		rc = RicciCommunicator(nodename_resolved)
+		if not rc:
+			raise Exception, 'rc is None'
+	except Exception, e:
+		luci_log.debug_verbose('VDP5: RC %s: %s' % (nodename_resolved, str(e)))
+		errors.append('Unable to connect to the ricci agent on %s to update cluster daemon properties' % nodename_resolved)
+		return (False, {'errors': errors})
+		
+	batch_id, result = updateServices(rc, enable_list, disable_list)
+	if batch_id is None or result is None:
+		luci_log.debug_verbose('VDP6: setCluserConf: batchid or result is None')
+		errors.append('Unable to update the cluster daemon properties on node %s' % nodename_resolved)
+		return (False, {'errors': errors})
+
+	try:
+		status_msg = 'Updating %s daemon properties:' % nodename_resolved
+		if len(enable_list) > 0:
+			status_msg += ' enabling %s' % str(enable_list)[1:-1]
+		if len(disable_list) > 0:
+			status_msg += ' disabling %s' % str(disable_list)[1:-1]
+		set_node_flag(self, clustername, rc.hostname(), batch_id, CLUSTER_DAEMON, status_msg)
+	except:
+		pass
+
+	if len(errors) > 0:
+		return (False, {'errors': errors})
+
+	response.redirect(request['URL'] + "?pagetype=" + NODE + "&clustername=" + clustername + '&nodename=' + nodename + '&busyfirst=true')
+
 formValidators = {
 	6: validateCreateCluster,
 	7: validateConfigCluster,
@@ -872,11 +955,18 @@
 	33: validateResourceAdd,
 	51: validateFenceAdd,
 	50: validateFenceEdit,
+	55: validateDaemonProperties
 }
 
 def validatePost(self, request):
-	pagetype = int(request.form['pagetype'])
+	try:
+		pagetype = int(request.form['pagetype'])
+	except Exception, e:
+		luci_log.debug_verbose('VP0: error: %s' % str(e))
+		return None
+
 	if not pagetype in formValidators:
+		luci_log.debug_verbose('VP1: no handler for page type %d' % pagetype)
 		return None
 	else:
 		return formValidators[pagetype](self, request)
--- conga/luci/site/luci/Extensions/conga_constants.py	2006/11/12 02:10:53	1.25
+++ conga/luci/site/luci/Extensions/conga_constants.py	2006/11/13 21:40:55	1.26
@@ -42,6 +42,7 @@
 FENCEDEV_LIST="52"
 FENCEDEV_CONFIG="53"
 FENCEDEV="54"
+CLUSTER_DAEMON="55"
 
 #Cluster tasks
 CLUSTER_STOP = '1000'
--- conga/luci/site/luci/Extensions/ricci_bridge.py	2006/11/12 02:10:53	1.42
+++ conga/luci/site/luci/Extensions/ricci_bridge.py	2006/11/13 21:40:55	1.43
@@ -18,7 +18,7 @@
 		return False
 
 	try:
-		batchid = batch.getAttribute('batch_id')
+		dummy = batch.getAttribute('batch_id')
 		result = batch.getAttribute('status')
 	except:
 		return False
@@ -471,6 +471,26 @@
 	ricci_xml = rc.batch_run(batch_str)
 	return batchAttemptResult(ricci_xml)
 
+def updateServices(rc, enable_list, disable_list):
+	batch = ''
+
+	if enable_list and len(enable_list) > 0:
+		batch += '<module name="service"><request API_version="1.0"><function_call name="enable"><var mutable="false" name="services" type="list_xml">'
+		for i in enable_list:
+			batch += '<service name="%s"/>' % str(i)
+		batch += '</var></function_call></request></module>'
+
+	if disable_list and len(disable_list) > 0:
+		batch += '<module name="service"><request API_version="1.0"><function_call name="disable"><var mutable="false" name="services" type="list_xml">'
+		for i in disable_list:
+			batch += '<service name="%s"/>' % str(i)
+		batch += '</var></function_call></request></module>'
+
+	if batch == '':
+		return None
+	ricci_xml = rc.batch_run(batch)
+	return batchAttemptResult(ricci_xml)
+	
 def restartService(rc, servicename):
 	batch_str = '<module name="cluster"><request API_version="1.0"><function_call name="restart_service"><var mutable="false" name="servicename" type="string" value=\"' + servicename + '\"/></function_call></request></module>'
 


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