From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/luci/site/luci/Extensions LuciZopeAsync.py
Date: 8 Aug 2007 21:16:36 -0000 [thread overview]
Message-ID: <20070808211636.32681.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: conga
Branch: RHEL5
Changes by: rmccabe at sourceware.org 2007-08-08 21:16:36
Modified files:
luci/site/luci/Extensions: LuciZopeAsync.py
Log message:
Fix 230451, pass 3
- luci backend support for managing fence_xvm keys, pass 2
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/LuciZopeAsync.py.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.1&r2=1.1.2.2
--- conga/luci/site/luci/Extensions/LuciZopeAsync.py 2007/08/08 21:14:38 1.1.2.1
+++ conga/luci/site/luci/Extensions/LuciZopeAsync.py 2007/08/08 21:16:35 1.1.2.2
@@ -0,0 +1,182 @@
+# Copyright (C) 2007 Red Hat, Inc.
+#
+# This program is free software; you can redistribute
+# it and/or modify it under the terms of version 2 of the
+# GNU General Public License as published by the
+# Free Software Foundation.
+
+from xml.dom import minidom
+
+from LuciSyslog import get_logger
+from LuciZope import GetReqVars
+from ricci_communicator import RicciCommunicator
+from conga_constants import LUCI_DEBUG_MODE
+
+luci_log = get_logger()
+
+def write_xml_resp(request, xml_obj):
+ request.RESPONSE.setHeader('Content-Type', 'text/xml; charset=UTF-8')
+ request.RESPONSE.setHeader('Cache-Control', 'no-cache, no-store, private')
+ request.RESPONSE.write(str(xml_obj.toprettyxml()))
+
+def result_to_xml(result):
+ import types
+
+ numeric_types = [
+ types.IntType, types.BooleanType, types.LongType, types.FloatType
+ ]
+
+ root = minidom.Document()
+
+ def pyobj_to_xml(element_name, element, parent_node):
+ if type(element) is types.DictType:
+ if len(element) > 0:
+ xml_elem = root.createElement('dict')
+ xml_elem.setAttribute('name', str(element_name))
+
+ for i in element.iterkeys():
+ pyobj_to_xml(i, element[i], xml_elem)
+ else:
+ xml_elem = None
+ elif type(element) in [ types.ListType, types.TupleType ]:
+ if len(element) > 0:
+ xml_elem = root.createElement('list')
+ xml_elem.setAttribute('name', str(element_name))
+ for i in element:
+ pyobj_to_xml(element_name, i, xml_elem)
+ else:
+ xml_elem = None
+ else:
+ cur_tagname = None
+ try:
+ if parent_node.tagName == 'list':
+ cur_tagname = parent_node.getAttribute('name')
+ except:
+ cur_tagname = None
+
+ if not cur_tagname:
+ xml_elem = root.createElement('var')
+ else:
+ xml_elem = root.createElement(cur_tagname)
+
+ if type(element) in types.StringTypes:
+ cur_type = 'str'
+ elif type(element) in numeric_types:
+ cur_type = 'num'
+ else:
+ cur_type = None
+
+ if cur_type:
+ try:
+ if parent_node.tagName == 'dict':
+ xml_elem.setAttribute('name', str(element_name))
+ except:
+ pass
+
+ xml_elem.setAttribute('type', cur_type)
+ xml_elem.setAttribute('value', str(element))
+ else:
+ xml_elem = None
+
+ if xml_elem is not None:
+ parent_node.appendChild(xml_elem)
+
+ pyobj_to_xml('result', result[1], root)
+ res_elem = root.createElement('result')
+ res_elem.setAttribute('name', 'success')
+ res_elem.setAttribute('value', str(result[0]).lower())
+ root.firstChild.appendChild(res_elem)
+ return root
+
+def write_err_async(request, err_msg):
+ xml_obj = result_to_xml((False, { 'errors': err_msg }))
+ write_xml_resp(request, xml_obj)
+
+def get_cluster_nodes_async(self, request):
+ from LuciClusterInfo import getClusterConfNodes
+ from RicciQueries import getClusterConf
+
+ fvars = GetReqVars(request, [ 'QUERY_STRING' ])
+ if fvars['QUERY_STRING'] is None:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCNA: No query string was given')
+ write_err_async(request, 'No node names were given')
+ return None
+
+ try:
+ nodes = fvars['QUERY_STRING'].split('&')
+ node_list = map(lambda x: x[1], filter(lambda x: x[0][:4] == 'node', map(lambda x: x.split('='), nodes)))
+ if not node_list or len(node_list) < 1:
+ raise Exception, 'No node list'
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCNA: %r %s' % (e, str(e)))
+ write_err_async(request, 'No node names were given')
+ return None
+
+ errors = list()
+ ret = {}
+ for node_host in node_list:
+ try:
+ rc = RicciCommunicator(node_host)
+ cluster_name = rc.cluster_info()[0]
+ if not cluster_name:
+ errors.append('%s is not a member of a cluster' \
+ % cluster_name)
+ continue
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCNA0: ricci: %s: %r %s' \
+ % (node_host, e, str(e)))
+ errors.append('Unable to communicate with the ricci agent on %s' \
+ % node_host)
+ continue
+
+ try:
+ conf = getClusterConf(rc)
+ node_names = getClusterConfNodes(conf)
+ if not node_names or len(node_names) < 1:
+ raise Exception, 'no nodes'
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GCNA1: ricci: %s: %r %s' \
+ % (node_host, e, str(e)))
+ errors.append('Unable to retrieve a list of cluster nodes from %s' \
+ % node_host)
+ continue
+ ret[cluster_name] = {
+ 'cluster': cluster_name,
+ 'num_nodes': len(node_names),
+ 'clusternode': node_names
+ }
+
+ ret['errors'] = errors
+ xml_obj = result_to_xml((len(errors) < len(node_list), ret))
+ write_xml_resp(request, xml_obj)
+
+def get_sysinfo_async(self, request):
+ from HelperFunctions import get_system_info
+
+ fvars = GetReqVars(request, [ 'QUERY_STRING' ])
+ try:
+ nodes = fvars['QUERY_STRING'].split('&')
+ node_list = map(lambda x: x[1], filter(lambda x: x[0][:4] == 'node', map(lambda x: x.split('='), nodes)))
+ if not node_list or len(node_list) < 1:
+ raise Exception, 'No node list'
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GSIA: %r %s' % (e, str(e)))
+ write_err_async(request, 'No node names were given')
+ return None
+
+ ret = {}
+ try:
+ ret = get_system_info(self, node_list)
+ except Exception, e:
+ if LUCI_DEBUG_MODE is True:
+ luci_log.debug_verbose('GNFPA %r: %r %s' \
+ % (request['nodenames'], e, str(e)))
+ write_err_async(request, 'Error retrieving information')
+ return None
+ xml_obj = result_to_xml(True, { 'result': ret })
+ write_xml_resp(request, xml_obj)
reply other threads:[~2007-08-08 21:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070808211636.32681.qmail@sourceware.org \
--to=rmccabe@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).