All of lore.kernel.org
 help / color / mirror / Atom feed
From: kupcevic@sourceware.org <kupcevic@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/luci/site/luci/Extensions ricci_communic ...
Date: 10 Oct 2006 21:07:19 -0000	[thread overview]
Message-ID: <20061010210719.29480.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	kupcevic at sourceware.org	2006-10-10 21:07:18

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

Log message:
	luci: helper functions to process ricci's response

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

--- conga/luci/site/luci/Extensions/ricci_communicator.py	2006/09/29 21:41:43	1.6
+++ conga/luci/site/luci/Extensions/ricci_communicator.py	2006/10/10 21:07:18	1.7
@@ -162,6 +162,9 @@
         return batch_node
     
     
+    
+    
+    
     def __send(self, xml_doc):
         buff = xml_doc.toxml() + '\n'
         #print buff
@@ -228,3 +231,113 @@
     return ricci.auth(password)
 def ricci_unauthenticate(self, ricci):
     return ricci.unauth()
+
+
+
+
+
+
+
+
+########## helpers to process batch as returned by ricci #############
+
+
+
+
+
+# check the status of batch
+# returns (int num, int total)
+# * total:
+#          total number of modules in batch
+# * num:
+#          if num == total: 
+#             all modules in the batch completed successfuly
+#          if num > 0: 
+#             last seq. number of module that successfuly finished
+#          if num < 0: 
+#             module (-num) failed (next module won't be processed)
+def batch_status(batch_xml):
+    if batch_xml.nodeName != 'batch':
+        raise 'not a batch'
+    total = 0
+    last  = 0
+    for node in batch_xml.childNodes:
+        if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+            if node.nodeName == 'module':
+                total = total + 1
+                status = node.getAttribute('status')
+                if status == '0':
+                    # success
+                    last = last + 1
+                elif status == '3' or status == '4':
+                    # failure
+                    last = last + 1
+                    last = last - 2 * last
+    return (last, total)
+
+
+
+# extract error_code from module's response
+# * module_num:
+#              1-based seq. number of module to process
+#
+# returns (int error_code, string error_msg)
+# * error_code: each module defines own error codes, which are >0
+#          -101 - in progress
+#          -102 - scheduled
+#          -103 - removed from schedule
+#          -104 - failed to execute module
+#
+#          >-3  - module executed. Following codes are defined:
+#             -2   - API error
+#             -1   - undefined error occured (msg not necesarily very informative)
+#             0    - no error (msg is empty string)
+#             >0   - predefined error has occured
+#                        (check respective API, msg will be fully descriptive)
+# * error_msg:  error message
+def extract_module_status(batch_xml, module_num=1):
+    if batch_xml.nodeName != 'batch':
+        raise 'not a batch'
+    c = 0
+    for node in batch_xml.childNodes:
+        if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+            if node.nodeName == 'module':
+                module_xml = node
+                c = c + 1
+                if c == module_num:
+                    status = module_xml.getAttribute('status')
+                    if status == '0' or status == '4':
+                        # module executed, dig deeper into request
+                        for node_i in module_xml.childNodes:
+                            if node_i.nodeType == xml.dom.Node.ELEMENT_NODE:
+                                if node_i.nodeName == 'API_error':
+                                    return -2, 'API error'
+                                elif node_i.nodeName == 'response':
+                                    for node_j in node_i.childNodes:
+                                        if node_j.nodeType == xml.dom.Node.ELEMENT_NODE:
+                                            if node_j.nodeName == 'function_response':
+                                                code = -11111111
+                                                msg  = 'BUG'
+                                                for var in node_j.childNodes:
+                                                    if var.nodeType == xml.dom.Node.ELEMENT_NODE:
+                                                        if var.nodeName == 'var':
+                                                            if var.getAttribute('name') == 'success' and var.getAttribute('value') == 'true':
+                                                                return 0, ''
+                                                            elif var.getAttribute('name') == 'error_code':
+                                                                code = int(var.getAttribute('value'))
+                                                            elif var.getAttribute('name') == 'error_description':
+                                                                msg = var.getAttribute('value')
+                                                return code, msg
+                                            
+                        pass
+                    elif status == '1':
+                        return -102, 'module scheduled for execution'
+                    elif status == '2':
+                        return -101, 'module is being executed'
+                    elif status == '3':
+                        return -104, 'failed to locate/execute module'
+                    elif status == '5':
+                        return -103, 'module removed from schedule'
+    
+    raise 'no ' + str(module_num) + 'th module in the batch, or malformed response'
+



             reply	other threads:[~2006-10-10 21:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-10 21:07 kupcevic [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-07-26  4:23 [Cluster-devel] conga/luci/site/luci/Extensions ricci_communic rmccabe
2007-07-03 16:56 rmccabe
2006-10-20 18:37 rmccabe
2006-09-26 21:04 kupcevic
2006-06-21 23:07 rmccabe
2006-06-19 17:10 rmccabe

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=20061010210719.29480.qmail@sourceware.org \
    --to=kupcevic@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.