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

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



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2007-02-24 07:02:42

Modified files:
	luci/cluster   : form-macros validate_sys_svc.js 
	luci/site/luci/Extensions: ricci_bridge.py system_adapters.py 

Log message:
	Cleanups to the system services management interface

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/form-macros.diff?cvsroot=cluster&r1=1.193&r2=1.194
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/cluster/validate_sys_svc.js.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ricci_bridge.py.diff?cvsroot=cluster&r1=1.59&r2=1.60
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/system_adapters.py.diff?cvsroot=cluster&r1=1.1&r2=1.2

--- conga/luci/cluster/form-macros	2007/02/23 22:07:45	1.193
+++ conga/luci/cluster/form-macros	2007/02/24 07:02:42	1.194
@@ -5062,7 +5062,7 @@
 			<td class="systemsTable">
 				<span
 					tal:content="s/state |string:[unknown]"
-					tal:attributes="id python: '__STATUS__:' + s['name']" />
+					tal:attributes="id python: '__STATUS__' + s['name']" />
 			</td>
 
 			<td class="systemsTable">
--- conga/luci/cluster/validate_sys_svc.js	2007/02/23 22:07:45	1.1
+++ conga/luci/cluster/validate_sys_svc.js	2007/02/24 07:02:42	1.2
@@ -3,16 +3,45 @@
 		if (xmlHttp_object.status == 200) {
 			var response = xmlHttp_object.responseXML;
 			if (response) {
-				req_status = response.getAttribute('success');
-				req_op = response.getAttribute('operation');
-				req_svc = response.getAttribute('service');
-				req_msg = response.getAttribute('message');
-				//alert(req_msg + ' / ' + req_status + ' / ' + req_op + ' / ' + req_svc);
+				var result = response.getElementsByTagName('result')[0];
+				var req_status = result.getAttribute('success');
+				var req_op = result.getAttribute('operation');
+				var req_svc = result.getAttribute('service');
+				var req_msg = result.getAttribute('message');
+
+				if (req_status != '0') {
+					var op_str = null;
+					if (req_op == 'stop')
+						op_str = 'stopped';
+					else
+						op_str = req_op + 'ed';
+
+					alert('Service ' + req_svc + ' was successfully ' + op_str);
+
+					var status_elem = document.getElementById('__STATUS__' + req_svc);
+					var start_elem = document.getElementById('__START__' + req_svc);
+					var restart_elem = document.getElementById('__RESTART__' + req_svc);
+					var stop_elem = document.getElementById('__STOP__' + req_svc);
+
+					if (req_op == 'stop') {
+						stop_elem.disabled = 'disabled';
+						restart_elem.disabled = 'disabled';
+						start_elem.disabled = '';
+						status_elem.innerHTML = 'Stopped';
+					} else {
+						stop_elem.disabled = '';
+						restart_elem.disabled = '';
+						start_elem.disabled = 'disabled';
+						status_elem.innerHTML = 'Running';
+					}
+				} else {
+					alert('An error occurred while attempting to ' + req_op + ' service ' + req_svc + ': ' + req_msg);
+				}
 			} else {
-				alert(xmlHttp_object.responseText);
+				alert('Error retrieving data from server');
 			}
 		} else {
-			//alert('Error retrieving data from server: ' + xmlHttp_object.status);
+			alert('Error retrieving data from server: ' + xmlHttp_object.status);
 		}
 	}
 }
--- conga/luci/site/luci/Extensions/ricci_bridge.py	2007/02/23 22:07:45	1.59
+++ conga/luci/site/luci/Extensions/ricci_bridge.py	2007/02/24 07:02:42	1.60
@@ -491,16 +491,15 @@
 
 	doc = minidom.Document()
 	elem = doc.createElement('result')
+	elem.setAttribute('success', '0')
 
 	if not servicename:
 		elem.setAttribute('service', 'No service name was specified.')
 		elem.setAttribute('message', 'No service name was specified.')
-		elem.setAttribute('success', '0')
 
 	if not op:
 		elem.setAttribute('operation', 'No operation was specified.')
 		elem.setAttribute('message', 'No operation was specified.')
-		elem.setAttribute('success', '0')
 
 	if not servicename or not op:
 		doc.appendChild(elem)
@@ -517,8 +516,7 @@
 		else:
 			raise Exception, op
 	except Exception, e:
-		elem.setAttribute('success', '0');
-		elem.setAttribute('message', 'Unknown operation')
+		elem.setAttribute('message', 'Unknown operation: %s' % str(e))
 		doc.appendChild(elem)
 		return doc
 
@@ -526,14 +524,31 @@
 		
 	ricci_xml = rc.batch_run(batch_str, async=False)
 	if not ricci_xml or not ricci_xml.firstChild:
-		luci_log.debug_verbose('SVCM0: None returned')
-		elem.setAttribute('success', '0')
 		elem.setAttribute('message', 'operation failed')
 		doc.appendChild(elem)
 		return doc
 
-	elem.setAttribute('success', '0')
-	elem.setAttribute('message', str(ricci_xml.toxml()))
+	try:
+		mod_elem = ricci_xml.getElementsByTagName('module')
+		status_code = int(mod_elem[0].getAttribute('status'))
+		if status_code == 0:
+			var_elem = mod_elem[0].getElementsByTagName('var')
+			for i in var_elem:
+				name = i.getAttribute('name').lower()
+				if name == 'success':
+					success = i.getAttribute('value').lower()
+					if success == 'true':
+						elem.setAttribute('success', '1')
+						elem.setAttribute('message', 'success')
+					else:
+						elem.setAttribute('message', 'operation failed')
+					break
+		else:
+			err_msg = mod_elem[0].childNodes[1].getAttribute('description')
+			elem.setAttribute('message', err_msg)
+	except Exception, e:
+		elem.setAttribute('message', 'operation failed')
+
 	doc.appendChild(elem)
 	return doc
 
--- conga/luci/site/luci/Extensions/system_adapters.py	2007/02/23 22:07:45	1.1
+++ conga/luci/site/luci/Extensions/system_adapters.py	2007/02/24 07:02:42	1.2
@@ -1,6 +1,7 @@
 from ricci_communicator import RicciCommunicator
 from ricci_bridge import list_services, updateServices, svc_manage
 from LuciSyslog import LuciSyslog
+from xml.dom import minidom
 
 try: 
 	luci_log = LuciSyslog()
@@ -104,31 +105,45 @@
 	request.RESPONSE.redirect(request['URL'] + '?pagetype=90&systemname=' + hostname)
 
 def validate_manage_svc(self, request):
+	ret = minidom.Document()
+
+	result = ret.createElement('result')
+	result.setAttribute('success', '0')
+
+	servicename = None
 	try:
-		hostname = request['systemname'].strip()
+		servicename = request['svcname'].strip()
+		result.setAttribute('service', servicename)
 	except:
-		return None
+		result.setAttribute('service', 'this service')
 
-	servicename = None
 	op = None
 	try:
-		servicename = request['svcname'].strip()
 		op = request['operation'].strip()
 	except:
-		pass
+		result.setAttribute('operation', 'manage')
 
 	try:
-		rc = RicciCommunicator(hostname)
-		if not rc:
-			raise Exception, 'none'
+		hostname = request['systemname'].strip()
+		if not hostname:
+			raise Exception, 'blank'
 	except Exception, e:
-		return None
+		hostname = None
+		result.setAttribute('message', 'No system was specified')
+		ret.appendChild(result)
 
-	ret = None
-	try:
-		ret = svc_manage(rc, hostname, servicename, op)
-		luci_log.debug_verbose('VMC0: returning %s' % str(ret.toxml()))
-	except:
-		pass
-
-	return ret
+	if hostname and op and servicename:
+		try:
+			rc = RicciCommunicator(hostname)
+			if not rc:
+				raise Exception, 'none'
+			ret = svc_manage(rc, hostname, servicename, op)
+		except Exception, e:
+			result.setAttribute('message', str(e))
+			ret.appendChild(result)
+	else:
+		ret.appendChild(result)
+
+	request.RESPONSE.setHeader('Content-Type', 'text/xml; charset=UTF-8')
+	request.RESPONSE.setHeader('Cache-Control', 'no-cache, no-store, private')
+	request.RESPONSE.write(str(ret.toxml()))


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