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

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



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	jparsons sourceware org	2006-07-28 11:46:35

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

Log message:
	Big fixes for resource support

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/cluster_adapters.py.diff?cvsroot=cluster&r1=1.17&r2=1.18
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/ricci_bridge.py.diff?cvsroot=cluster&r1=1.9&r2=1.10

--- conga/luci/site/luci/Extensions/cluster_adapters.py	2006/07/27 16:34:11	1.17
+++ conga/luci/site/luci/Extensions/cluster_adapters.py	2006/07/28 11:46:35	1.18
@@ -5,6 +5,13 @@
 from ricci_bridge import *
 import time
 import Products.ManagedSystem
+from Ip import Ip
+from Clusterfs import Clusterfs
+from Fs import Fs
+from NFSClient import NFSClient
+from Netfs import Netfs
+from Script import Script
+from Samba import Samba
 
 #Policy for showing the cluster chooser menu:
 #1) If there are no clusters in the ManagedClusterSystems
@@ -1320,7 +1327,7 @@
                                                                                 
   return {}
                                                                                 
-def addResource(self, request):
+def addResource(self, request, ragent):
   if not request.form:
     return "Nothing submitted, no changes made."
                                                                                 
@@ -1336,20 +1343,32 @@
            'smb': addSmb}
                                                                                 
   type = request.form["type"]
-  return types[type](request)
+  res = types[type](request)
+  modelb = request.SESSION.get('model')
+  modelstr = ""
+  conf = modelb.exportModelAsString()
+  rb = ricci_bridge(ragent)
+  #try:
+  if True:
+    batch_id, result = rb.setClusterConf(str(conf))
+  #except:
+  else:
+    return "Some error occured in setClusterConf\n"
+
+  return "Resource Added"
 
 def getResourceForEdit(modelb, name):
-  resPtr = modelb.getResourcesPtr()
-  resources = resPrt.getChildren()
-                                                                                
+  resources = modelb.getResourcesPtr().getChildren()
+                                                                               
   for res in resources:
     if res.getName() == name:
       resources.removeChild(res)
       break
-                                                                                
+                                                                              
   return res
+
 def addIp(request):
-  modelb = request.SESSION["model"]
+  modelb = request.SESSION.get('model')
   if request.form.has_key('edit'):
     res = getResourceForEdit(modelb, request.form['oldname'])
   else:
@@ -1365,7 +1384,7 @@
   return res
 
 def addFs(request):
-  modelb = request.SESSION["model"]
+  modelb = request.SESSION.get('model')
   if request.form.has_key('edit'):
     res = getResourceForEdit(modelb, request.form['oldname'])
   else:
@@ -1396,7 +1415,7 @@
   return res
                                                                                 
 def addGfs(request):
-  modelb = request.SESSION["model"]
+  modelb = request.SESSION.get('model')
   if request.form.has_key('edit'):
     res = getResourceForEdit(modelb, request.form['oldname'])
   else:
@@ -1417,7 +1436,7 @@
   return res
 
 def addNfsm(request):
-  modelb = request.SESSION["model"]
+  modelb = request.SESSION.get('model')
   if request.form.has_key('edit'):
     res = getResourceForEdit(modelb, request.form['oldname'])
   else:
@@ -1439,7 +1458,7 @@
   return res
                                                                                 
 def addNfsc(request):
-  modelb = request.SESSION["model"]
+  modelb = request.SESSION.get('model')
   if request.form.has_key('edit'):
     res = getResourceForEdit(modelb, request.form['oldname'])
   else:
@@ -1453,7 +1472,7 @@
   return res
                                                                                 
 def addNfsx(request):
-  modelb = request.SESSION["model"]
+  modelb = request.SESSION.get('model')
   if request.form.has_key('edit'):
     res = getResourceForEdit(modelb, request.form['oldname'])
   else:
@@ -1465,7 +1484,7 @@
   return res
 
 def addScr(request):
-  modelb = request.SESSION["model"]
+  modelb = request.SESSION.get('model')
   if request.form.has_key('edit'):
     res = getResourceForEdit(modelb, request.form['oldname'])
   else:
@@ -1478,7 +1497,7 @@
   return res
                                                                                 
 def addSmb(request):
-  modelb = request.SESSION["model"]
+  modelb = request.SESSION.get('model')
   if request.form.has_key('edit'):
     res = getResourceForEdit(modelb, request.form['oldname'])
   else:
@@ -1493,5 +1512,8 @@
 def appendModel(request, model):
   try:
     request.SESSION.set('model', model)
-  except: pass
+  except:
+    pass
+  return
+
 
--- conga/luci/site/luci/Extensions/ricci_bridge.py	2006/07/27 14:23:59	1.9
+++ conga/luci/site/luci/Extensions/ricci_bridge.py	2006/07/28 11:46:35	1.10
@@ -1,4 +1,3 @@
-
 from time import *
 import os
 from socket import *
@@ -10,526 +9,516 @@
 
 
 class ricci_bridge:
-    def __init__(self, hostname, port=11111):
-        self.__hostname = hostname
-        self.__port = port
-        return
+  def __init__(self, hostname, port=11111):
+    self.__hostname = hostname
+    self.__port = port
+    return
     
     
-    def process(self, xml_out):
-        #if os.path.exists("/opt/zopetooey/Extensions/certs/privkey.pem"):
-        #  return "<h1>Path Exists</h1>"
-        #else:
-        #  return "<h1>Path Does Not Exist</h1>"
-        CLUSTER_STR='<?xml version="1.0" ?><ricci async="false" function="process_batch" version="1.0"><batch><module name="cluster"><request API_version="1.0"><function_call name="get_cluster.conf"/></request></module></batch></ricci>'
+  def process(self, xml_out):
+    CLUSTER_STR='<?xml version="1.0" ?><ricci async="false" function="process_batch" version="1.0"><batch><module name="cluster"><request API_version="1.0"><function_call name="get_cluster.conf"/></request></module></batch></ricci>'
         
-        doc = self.makeConnection(CLUSTER_STR)
+    doc = self.makeConnection(CLUSTER_STR)
         
-        if doc == None:
-          print "Sorry, doc is None"
-        if doc != None:
-          bt_node = None
-          for node in doc.firstChild.childNodes:
+    if doc == None:
+      print "Sorry, doc is None"
+    if doc != None:
+      bt_node = None
+      for node in doc.firstChild.childNodes:
+        if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+          if node.nodeName == 'batch':
+            bt_node = node
+      if bt_node == None:
+        print "bt_node == None"
+        doc = None
+      else:
+        #print doc.toxml()
+        mod_node = None
+        for node in bt_node.childNodes:
             if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-              if node.nodeName == 'batch':
-                bt_node = node
-          if bt_node == None:
-            print "bt_node == None"
+                if node.nodeName == 'module':
+                    mod_node = node
+        if mod_node == None:
+            print "mod_node == None"
             doc = None
-          else:
-            #print doc.toxml()
-            mod_node = None
-            for node in bt_node.childNodes:
+        else:
+            resp_node = None
+            for node in mod_node.childNodes:
                 if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                    if node.nodeName == 'module':
-                        mod_node = node
-            if mod_node == None:
-                print "mod_node == None"
+                    resp_node = node
+            if resp_node == None:
+                print "resp_node == None"
                 doc = None
             else:
-                resp_node = None
-                for node in mod_node.childNodes:
+                fr_node = None
+                for node in resp_node.childNodes:
                     if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                        resp_node = node
-                if resp_node == None:
-                    print "resp_node == None"
+                      fr_node = node
+                if fr_node == None:
+                    print "fr_node == None"
                     doc = None
                 else:
-                    fr_node = None
-                    for node in resp_node.childNodes:
-                        if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                          fr_node = node
-                    if fr_node == None:
-                        print "fr_node == None"
-                        doc = None
+                    varnode = None
+                    for node in fr_node.childNodes:
+                      if node.nodeName == 'var':
+                          varnode = node
+                          break
+                    if varnode == None:
+                       print "varnode == None"
+                       doc = None
                     else:
-                        varnode = None
-                        for node in fr_node.childNodes:
-                          if node.nodeName == 'var':
-                              varnode = node
+                      cl_node = None
+                      for node in varnode.childNodes:
+                          if node.nodeName == 'cluster':
+                              cl_node = node
                               break
-                        if varnode == None:
-                           print "varnode == None"
-                           doc = None
-                        else:
-                          cl_node = None
-                          for node in varnode.childNodes:
-                              if node.nodeName == 'cluster':
-                                  cl_node = node
-                                  break
-                          if cl_node == None:
-                            print "cl_node == None"
-                            doc = None
-                          else:
-                              docc = minidom.Document()
-                              docc.appendChild(cl_node)
-
-        return docc
-    
-    def __sendall(self, str, ssl_sock):
-        print str
-        s = str
-        while len(s) != 0:
-            pos = ssl_sock.write(s)
-            s = s[pos:]
-        return
-    
+                      if cl_node == None:
+                        print "cl_node == None"
+                        doc = None
+                      else:
+                          docc = minidom.Document()
+                          docc.appendChild(cl_node)
+
+    return docc
     
-    def __receive(self, ssl_sock):
-        doc = None
-        xml_in = ''
-        try:
-            while True:
-                buff = ssl_sock.read(1024)
-                if buff == '':
-                    break
-                xml_in += buff
-                try:
-                    doc = minidom.parseString(xml_in)
-                    break
-                except:
-                    pass
-        except:
-            pass
-        try:
-            #print 'try parse xml'
-            doc = minidom.parseString(xml_in)
-            #print 'xml is good'
-        except:
-            pass
-        #print "response--------------------------------"
-        #print doc.toxml()
-        #print "response--------------------------------"
-        return doc
+  def __sendall(self, str, ssl_sock):
+    print str
+    s = str
+    while len(s) != 0:
+        pos = ssl_sock.write(s)
+        s = s[pos:]
+    return
 
-    def getClusterStatus(self):
-        CLUSTER_STR='<?xml version="1.0" ?><ricci async="false" function="process_batch" version="1.0"><batch><module name="cluster"><request API_version="1.0"><function_call name="status"/></request></module></batch></ricci>'
-        # socket
-        sock = socket(AF_INET, SOCK_STREAM)
-        sock.connect((self.__hostname, self.__port))
-        ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
-
-        # receive ricci header
-        hello = self.__receive(ss)
-        if hello != None:
-            pass
-            #print hello.toxml()
-        self.__sendall(CLUSTER_STR, ss)
-        
-        
-        # receive response
-        doc = self.__receive(ss)
-        if doc == None:
-          print "Sorry, doc is None"
-        else:
-          payload = self.extractPayload(doc)
-        sock.shutdown(2)
-        sock.close()
-
-        return payload
-
-    def startService(self,servicename, preferrednode = None):
-        if preferrednode != None:
-          QUERY_STR='<?xml version="1.0" ?><ricci async="true" function="process_batch" version="1.0"><batch><module name="cluster"><request sequence="1254" API_version="1.0"><function_call name="start_service"><var mutable="false" name="servicename" type="string" value=\"' + servicename + '\"/><var mutable="false" name="nodename" type="string" value=\"' + preferrednode + '\" /></function_call></request></module></batch></ricci>'
-        else:
-          QUERY_STR='<?xml version="1.0" ?><ricci async="true" function="process_batch" version="1.0"><batch><module name="cluster"><request sequence="1254" API_version="1.0"><function_call name="start_service"><var mutable="false" name="servicename" type="string" value=\"' + servicename + '\"/></function_call></request></module></batch></ricci>'
+    
+  def __receive(self, ssl_sock):
+    doc = None
+    xml_in = ''
+    try:
+        while True:
+            buff = ssl_sock.read(1024)
+            if buff == '':
+                break
+            xml_in += buff
+            try:
+                doc = minidom.parseString(xml_in)
+                break
+            except:
+                pass
+    except:
+        pass
+    try:
+        #print 'try parse xml'
+        doc = minidom.parseString(xml_in)
+        #print 'xml is good'
+    except:
+        pass
+    return doc
+
+  def getClusterStatus(self):
+    CLUSTER_STR='<?xml version="1.0" ?><ricci async="false" function="process_batch" version="1.0"><batch><module name="cluster"><request API_version="1.0"><function_call name="status"/></request></module></batch></ricci>'
+    # socket
+    sock = socket(AF_INET, SOCK_STREAM)
+    sock.connect((self.__hostname, self.__port))
+    ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
+
+    # receive ricci header
+    hello = self.__receive(ss)
+    if hello != None:
+        pass
+        #print hello.toxml()
+    self.__sendall(CLUSTER_STR, ss)
+    
+    
+    # receive response
+    doc = self.__receive(ss)
+    if doc == None:
+      print "Sorry, doc is None"
+    else:
+      payload = self.extractPayload(doc)
+    sock.shutdown(2)
+    sock.close()
+
+    return payload
+
+  def startService(self,servicename, preferrednode = None):
+    if preferrednode != None:
+      QUERY_STR='<?xml version="1.0" ?><ricci async="true" function="process_batch" version="1.0"><batch><module name="cluster"><request sequence="1254" API_version="1.0"><function_call name="start_service"><var mutable="false" name="servicename" type="string" value=\"' + servicename + '\"/><var mutable="false" name="nodename" type="string" value=\"' + preferrednode + '\" /></function_call></request></module></batch></ricci>'
+    else:
+      QUERY_STR='<?xml version="1.0" ?><ricci async="true" function="process_batch" version="1.0"><batch><module name="cluster"><request sequence="1254" API_version="1.0"><function_call name="start_service"><var mutable="false" name="servicename" type="string" value=\"' + servicename + '\"/></function_call></request></module></batch></ricci>'
 
-        try:
-          payload = self.makeConnection(QUERY_STR)
-        except RicciReceiveError, r:
-          return None
-          
+    try:
+      payload = self.makeConnection(QUERY_STR)
+    except RicciReceiveError, r:
+      return None
+      
 
-        batch_number, result = self.batchAttemptResult(payload)
-        return (batch_number, result)
+    batch_number, result = self.batchAttemptResult(payload)
+    return (batch_number, result)
 
-    def restartService(self,servicename):
-        QUERY_STR='<?xml version="1.0" ?><ricci async="true" function="process_batch" version="1.0"><batch><module name="cluster"><request sequence="1254" API_version="1.0"><function_call name="restart_service"><var mutable="false" name="servicename" type="string" value=\"' + servicename + '\"/></function_call></request></module></batch></ricci>'
+  def restartService(self,servicename):
+    QUERY_STR='<?xml version="1.0" ?><ricci async="true" function="process_batch" version="1.0"><batch><module name="cluster"><request sequence="1254" API_version="1.0"><function_call name="restart_service"><var mutable="false" name="servicename" type="string" value=\"' + servicename + '\"/></function_call></request></module></batch></ricci>'
 
-        try:
-          payload = self.makeConnection(QUERY_STR)
-        except RicciReceiveError, r:
-          return None
-          
+    try:
+      payload = self.makeConnection(QUERY_STR)
+    except RicciReceiveError, r:
+      return None
+      
 
-        batch_number, result = self.batchAttemptResult(payload)
-        return (batch_number, result)
+    batch_number, result = self.batchAttemptResult(payload)
+    return (batch_number, result)
 
 
-    def stopService(self,servicename):
-        QUERY_STR='<?xml version="1.0" ?><ricci async="true" function="process_batch" version="1.0"><batch><module name="cluster"><request sequence="1254" API_version="1.0"><function_call name="stop_service"><var mutable="false" name="servicename" type="string" value=\"' + servicename + '\"/></function_call></request></module></batch></ricci>'
+  def stopService(self,servicename):
+    QUERY_STR='<?xml version="1.0" ?><ricci async="true" function="process_batch" version="1.0"><batch><module name="cluster"><request sequence="1254" API_version="1.0"><function_call name="stop_service"><var mutable="false" name="servicename" type="string" value=\"' + servicename + '\"/></function_call></request></module></batch></ricci>'
 
-        try:
-          payload = self.makeConnection(QUERY_STR)
-        except RicciReceiveError, r:
-          return None
-          
+    try:
+      payload = self.makeConnection(QUERY_STR)
+    except RicciReceiveError, r:
+      return None
+      
 
-        batch_number, result = self.batchAttemptResult(payload)
-        return (batch_number, result)
+    batch_number, result = self.batchAttemptResult(payload)
+    return (batch_number, result)
 
-    def getDaemonStates(self, dlist):
-      CLUSTER_STR='<?xml version="1.0" ?><ricci async="false" function="process_batch" version="1.0"><batch><module name="service"><request API_version="1.0"><function_call name="query"><var mutable="false" name="search" type="list_xml">'
-                                                                                
-      for item in dlist:
-        CLUSTER_STR = CLUSTER_STR + '<service name=\"' + item + '\"/>'
+  def getDaemonStates(self, dlist):
+    CLUSTER_STR='<?xml version="1.0" ?><ricci async="false" function="process_batch" version="1.0"><batch><module name="service"><request API_version="1.0"><function_call name="query"><var mutable="false" name="search" type="list_xml">'
                                                                                 
-      CLUSTER_STR = CLUSTER_STR + '</var></function_call></request></module></batch></ricci>'
+    for item in dlist:
+      CLUSTER_STR = CLUSTER_STR + '<service name=\"' + item + '\"/>'
                                                                                 
-      try:
-        payload = self.makeConnection(CLUSTER_STR)
-      except RicciReceiveError, r:
-        return None
+    CLUSTER_STR = CLUSTER_STR + '</var></function_call></request></module></batch></ricci>'
                                                                                 
-      result = self.extractDaemonInfo(payload)
+    try:
+      payload = self.makeConnection(CLUSTER_STR)
+    except RicciReceiveError, r:
+      return None
                                                                                 
-      return result
-                                                                                
-    def makeConnection(self,query_str):
-        # socket
-        sock = socket(AF_INET, SOCK_STREAM)
-        sock.connect((self.__hostname, self.__port))
-        ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
-
-        # receive ricci header
-        hello = self.__receive(ss)
-        if hello != None:
-            pass
-            #print hello.toxml()
-        self.__sendall(query_str, ss)
-        
-        
-        # receive response
-        payload = self.__receive(ss)
-        if payload == None:
-          raise RicciReceiveError('FATAL',"Unable to receive ricci data for %s" % self.__hostname)
-        sock.shutdown(2)
-        sock.close()
-
-        return payload
-
-
-    def extractPayload(self, doc):
-          docc = None
-          bt_node = None
-          for node in doc.firstChild.childNodes:
-            if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-              if node.nodeName == 'batch':
-                bt_node = node
-          if bt_node == None:
-            doc = None
-          else:
-            #print doc.toxml()
-            mod_node = None
-            for node in bt_node.childNodes:
-                if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                    if node.nodeName == 'module':
-                        mod_node = node
-            if mod_node == None:
-                doc = None
-            else:
-                resp_node = None
-                for node in mod_node.childNodes:
-                    if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                        resp_node = node
-                if resp_node == None:
-                    doc = None
-                else:
-                    fr_node = None
-                    for node in resp_node.childNodes:
-                        if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                          fr_node = node
-                    if fr_node == None:
-                        doc = None
-                    else:
-                        varnode = None
-                        for node in fr_node.childNodes:
-                          if node.nodeName == 'var':
-                              varnode = node
-                              break
-                        if varnode == None:
-                           doc = None
-                        else:
-                          cl_node = None
-                          for node in varnode.childNodes:
-                              if node.nodeName == 'cluster':
-                                  cl_node = node
-                                  break
-                          if cl_node == None:
-                            doc = None
-                          else:
-                              docc = minidom.Document()
-                              docc.appendChild(cl_node)
-          return docc
-
-
-    def getBatchResult(self, doc):
-          docc = None
-          bt_node = None
-          for node in doc.firstChild.childNodes:
-            if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-              if node.nodeName == 'batch':
-                bt_node = node
-          if bt_node == None:
-            doc = None
+    result = self.extractDaemonInfo(payload)
+                                                                              
+    return result
+                                                                              
+  def makeConnection(self,query_str):
+    # socket
+    sock = socket(AF_INET, SOCK_STREAM)
+    sock.connect((self.__hostname, self.__port))
+    ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
+
+    # receive ricci header
+    hello = self.__receive(ss)
+    if hello != None:
+        pass
+        #print hello.toxml()
+    self.__sendall(query_str, ss)
+    
+    
+    # receive response
+    payload = self.__receive(ss)
+    if payload == None:
+      raise RicciReceiveError('FATAL',"Unable to receive ricci data for %s" % self.__hostname)
+    sock.shutdown(2)
+    sock.close()
+
+    return payload
+
+
+  def extractPayload(self, doc):
+    docc = None
+    bt_node = None
+    for node in doc.firstChild.childNodes:
+      if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+        if node.nodeName == 'batch':
+          bt_node = node
+    if bt_node == None:
+      doc = None
+    else:
+      #print doc.toxml()
+      mod_node = None
+      for node in bt_node.childNodes:
+          if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+              if node.nodeName == 'module':
+                  mod_node = node
+      if mod_node == None:
+          doc = None
+      else:
+          resp_node = None
+          for node in mod_node.childNodes:
+              if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                  resp_node = node
+          if resp_node == None:
+              doc = None
           else:
-            #print doc.toxml()
-            mod_node = None
-            for node in bt_node.childNodes:
-                if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                    if node.nodeName == 'module':
-                        mod_node = node
-            if mod_node == None:
-                doc = None
-            else:
-                resp_node = None
-                for node in mod_node.childNodes:
-                    if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                        resp_node = node
-                if resp_node == None:
-                    doc = None
-                else:
-                    fr_node = None
-                    for node in resp_node.childNodes:
-                        if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                          fr_node = node
-                    if fr_node == None:
-                        doc = None
+              fr_node = None
+              for node in resp_node.childNodes:
+                  if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                    fr_node = node
+              if fr_node == None:
+                  doc = None
+              else:
+                  varnode = None
+                  for node in fr_node.childNodes:
+                    if node.nodeName == 'var':
+                        varnode = node
+                        break
+                  if varnode == None:
+                     doc = None
+                  else:
+                    cl_node = None
+                    for node in varnode.childNodes:
+                        if node.nodeName == 'cluster':
+                            cl_node = node
+                            break
+                    if cl_node == None:
+                      doc = None
                     else:
-                        varnode = None
-                        for node in fr_node.childNodes:
-                          if node.nodeName == 'var':
-                              varnode = node
-                              break
-                        if varnode == None:
-                           doc = None
-                        else:
-                          cl_node = None
-                          for node in varnode.childNodes:
-                              if node.nodeName == 'cluster':
-                                  cl_node = node
-                                  break
-                          if cl_node == None:
-                            doc = None
-                          else:
-                              docc = minidom.Document()
-                              docc.appendChild(cl_node)
-          return docc
-
-    def extractClusterConf(self, doc):
-          docc = None
-          bt_node = None
-          for node in doc.firstChild.childNodes:
-            if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-              if node.nodeName == 'batch':
-                bt_node = node
-          if bt_node == None:
-            print "bt_node == None"
-            doc = None
+                        docc = minidom.Document()
+                        docc.appendChild(cl_node)
+    return docc
+
+
+  def getBatchResult(self, doc):
+    docc = None
+    bt_node = None
+    for node in doc.firstChild.childNodes:
+      if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+        if node.nodeName == 'batch':
+          bt_node = node
+    if bt_node == None:
+      doc = None
+    else:
+      #print doc.toxml()
+      mod_node = None
+      for node in bt_node.childNodes:
+          if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+              if node.nodeName == 'module':
+                  mod_node = node
+      if mod_node == None:
+          doc = None
+      else:
+          resp_node = None
+          for node in mod_node.childNodes:
+              if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                  resp_node = node
+          if resp_node == None:
+              doc = None
           else:
-            #print doc.toxml()
-            mod_node = None
-            for node in bt_node.childNodes:
-                if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                    if node.nodeName == 'module':
-                        mod_node = node
-            if mod_node == None:
-                print "mod_node == None"
-                doc = None
-            else:
-                resp_node = None
-                for node in mod_node.childNodes:
-                    if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                        resp_node = node
-                if resp_node == None:
-                    print "resp_node == None"
-                    doc = None
-                else:
-                    fr_node = None
-                    for node in resp_node.childNodes:
-                        if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                          fr_node = node
-                    if fr_node == None:
-                        print "fr_node == None"
-                        doc = None
+              fr_node = None
+              for node in resp_node.childNodes:
+                  if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                    fr_node = node
+              if fr_node == None:
+                  doc = None
+              else:
+                  varnode = None
+                  for node in fr_node.childNodes:
+                    if node.nodeName == 'var':
+                        varnode = node
+                        break
+                  if varnode == None:
+                     doc = None
+                  else:
+                    cl_node = None
+                    for node in varnode.childNodes:
+                        if node.nodeName == 'cluster':
+                            cl_node = node
+                            break
+                    if cl_node == None:
+                      doc = None
                     else:
-                        varnode = None
-                        for node in fr_node.childNodes:
-                          if node.nodeName == 'var':
-                              varnode = node
-                              break
-                        if varnode == None:
-                           print "varnode == None"
-                           doc = None
-                        else:
-                          cl_node = None
-                          for node in varnode.childNodes:
-                              if node.nodeName == 'cluster':
-                                  cl_node = node
-                                  break
-                          if cl_node == None:
-                            print "cl_node == None"
-                            doc = None
-                          else:
-                              docc = minidom.Document()
-                              docc.appendChild(cl_node)
-
-          return docc
-
-    def extractDaemonInfo(self, doc):
-          print "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV"
-          print doc.toxml()
-          print "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
-          resultlist = list()
-          docc = None
-          bt_node = None
-          for node in doc.firstChild.childNodes:
-            if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-              if node.nodeName == 'batch':
-                bt_node = node
-          if bt_node == None:
-            print "bt_node == None"
-            doc = None
+                      docc = minidom.Document()
+                      docc.appendChild(cl_node)
+    return docc
+
+  def extractClusterConf(self, doc):
+    docc = None
+    bt_node = None
+    for node in doc.firstChild.childNodes:
+      if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+        if node.nodeName == 'batch':
+          bt_node = node
+    if bt_node == None:
+      print "bt_node == None"
+      doc = None
+    else:
+      #print doc.toxml()
+      mod_node = None
+      for node in bt_node.childNodes:
+          if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+              if node.nodeName == 'module':
+                  mod_node = node
+      if mod_node == None:
+          print "mod_node == None"
+          doc = None
+      else:
+          resp_node = None
+          for node in mod_node.childNodes:
+              if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                  resp_node = node
+          if resp_node == None:
+              print "resp_node == None"
+              doc = None
           else:
-            #print doc.toxml()
-            mod_node = None
-            for node in bt_node.childNodes:
-                if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                    if node.nodeName == 'module':
-                        mod_node = node
-            if mod_node == None:
-                print "mod_node == None"
-                doc = None
-            else:
-                resp_node = None
-                for node in mod_node.childNodes:
-                    if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                        resp_node = node
-                if resp_node == None:
-                    print "resp_node == None"
-                    doc = None
-                else:
-                    fr_node = None
-                    for node in resp_node.childNodes:
-                        if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                          fr_node = node
-                    if fr_node == None:
-                        print "fr_node == None"
-                        doc = None
+              fr_node = None
+              for node in resp_node.childNodes:
+                  if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                    fr_node = node
+              if fr_node == None:
+                  print "fr_node == None"
+                  doc = None
+              else:
+                  varnode = None
+                  for node in fr_node.childNodes:
+                    if node.nodeName == 'var':
+                        varnode = node
+                        break
+                  if varnode == None:
+                     print "varnode == None"
+                     doc = None
+                  else:
+                    cl_node = None
+                    for node in varnode.childNodes:
+                        if node.nodeName == 'cluster':
+                            cl_node = node
+                            break
+                    if cl_node == None:
+                      print "cl_node == None"
+                      doc = None
                     else:
-                        varnode = None
-                        for node in fr_node.childNodes:
-                          if node.nodeName == 'var':
-                              varnode = node
-                              break
-                        if varnode == None:
-                           print "varnode == None"
-                           doc = None
-                        else:
-                          svc_node = None
-                          for node in varnode.childNodes:
-                              if node.nodeName == 'service':
-                                  svchash = {}
-                                  svchash['name'] = node.getAttribute('name')
-                                  svchash['enabled'] = node.getAttribute('enabled')
-                                  svchash['running'] = node.getAttribute('running')
-                                  resultlist.append(svchash)
-                                                                                
-          return resultlist
+                        docc = minidom.Document()
+                        docc.appendChild(cl_node)
+
+    return docc
 
-    def batchAttemptResult(self, doc):
-          docc = None
-          rc_node = None
-          for node in doc.firstChild.childNodes:
+  def extractDaemonInfo(self, doc):
+    resultlist = list()
+    docc = None
+    bt_node = None
+    for node in doc.firstChild.childNodes:
+      if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+        if node.nodeName == 'batch':
+          bt_node = node
+    if bt_node == None:
+      print "bt_node == None"
+      doc = None
+    else:
+      #print doc.toxml()
+      mod_node = None
+      for node in bt_node.childNodes:
+          if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+              if node.nodeName == 'module':
+                  mod_node = node
+      if mod_node == None:
+          print "mod_node == None"
+          doc = None
+      else:
+          resp_node = None
+          for node in mod_node.childNodes:
               if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-                  if node.nodeName == 'batch':
-                      #get batch number and status code
-                      batch_number = node.getAttribute('batch_id')
-                      result = node.getAttribute('status')
-                      return (batch_number, result)
+                  resp_node = node
+          if resp_node == None:
+              print "resp_node == None"
+              doc = None
+          else:
+              fr_node = None
+              for node in resp_node.childNodes:
+                  if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+                    fr_node = node
+              if fr_node == None:
+                  print "fr_node == None"
+                  doc = None
+              else:
+                  varnode = None
+                  for node in fr_node.childNodes:
+                    if node.nodeName == 'var':
+                        varnode = node
+                        break
+                  if varnode == None:
+                     print "varnode == None"
+                     doc = None
                   else:
-                      print "RETURNING NONE!!!"
-                      return (None, None )
-      
+                    svc_node = None
+                    for node in varnode.childNodes:
+                        if node.nodeName == 'service':
+                            svchash = {}
+                            svchash['name'] = node.getAttribute('name')
+                            svchash['enabled'] = node.getAttribute('enabled')
+                            svchash['running'] = node.getAttribute('running')
+                            resultlist.append(svchash)
+                                                                          
+    return resultlist
+
+  def batchAttemptResult(self, doc):
+    docc = None
+    rc_node = None
+    for node in doc.firstChild.childNodes:
+        if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+            if node.nodeName == 'batch':
+                #get batch number and status code
+                batch_number = node.getAttribute('batch_id')
+                result = node.getAttribute('status')
+                return (batch_number, result)
+            else:
+                print "RETURNING NONE!!!"
+                return (None, None )
+
 
         
-    def getRicciResponse(self):
-      sock = socket(AF_INET, SOCK_STREAM)
-      try:
-        sock.connect((self.__hostname, self.__port))
-      except:
-        return False
-      ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
-      # receive ricci header
-      hello = self.__receive(ss)
-      if hello != None:
-        return True
-      else:
-        return False
+  def getRicciResponse(self):
+    sock = socket(AF_INET, SOCK_STREAM)
+    try:
+      sock.connect((self.__hostname, self.__port))
+    except:
+      return False
+    ss = ssl(sock, PATH_TO_PRIVKEY, PATH_TO_CACERT)
+    # receive ricci header
+    hello = self.__receive(ss)
+    if hello != None:
+      return True
+    else:
+      return False
 
-    def checkBatch(self, batch_id):
-      QUERY_STR = '<?xml version="1.0" ?><ricci version="1.0" function="batch_report" batch_id="' + batch_id + '"/>'
+  def checkBatch(self, batch_id):
+    QUERY_STR = '<?xml version="1.0" ?><ricci version="1.0" function="batch_report" batch_id="' + batch_id + '"/>'
 
-      try:
-        payload = self.makeConnection(QUERY_STR)
-      except RicciReceiveError, r:
-        return None
-          
-      #return true if finished or not present
-      success = payload.firstChild.getAttribute('success')
-      if success != "0":
-          return True  #I think this is ok...if id cannot be found
-      for node in payload.firstChild.childNodes:
-          if node.nodeType == xml.dom.Node.ELEMENT_NODE:
-              if node.nodeName == 'batch':
-                  #get batch number and status code
-                  batch_number = node.getAttribute('batch_id')
-                  result = node.getAttribute('status')
-                  if result == "0":
-                      return True
-                  else:
-                      return False
-              else:
-                  return False
+    try:
+      payload = self.makeConnection(QUERY_STR)
+    except RicciReceiveError, r:
+      return None
+        
+    #return true if finished or not present
+    success = payload.firstChild.getAttribute('success')
+    if success != "0":
+        return True  #I think this is ok...if id cannot be found
+    for node in payload.firstChild.childNodes:
+        if node.nodeType == xml.dom.Node.ELEMENT_NODE:
+            if node.nodeName == 'batch':
+                #get batch number and status code
+                batch_number = node.getAttribute('batch_id')
+                result = node.getAttribute('status')
+                if result == "0":
+                    return True
+                else:
+                    return False
+            else:
+                return False
 
-      return False
+    return False
 
-def setClusterConf(clusterconf, propagate=True):
-  if propagate == True:
-    propg = "True"
-  else:
-    propg = "False"
-
-  QUERY_STR='<?xml version="1.0" ?><ricci async="true" function="process_batch" version="1.0"><batch><module name="cluster"><request API_version="1.0"><function_call name="set_cluster.conf"/><var propagate="' + propg + '" cluster.conf="' + clusterconf + '"/></request></module></batch></ricci>'
-
-  try:
-    payload = self.makeConnection(QUERY_STR)
-  except RicciReceiveError, r:
-    return None
-                                                                                
-                                                                                
-  batch_number, result = self.batchAttemptResult(payload)
-  return (batch_number, result)
+  def setClusterConf(self, clusterconf, propagate=True):
+    if propagate == True:
+      propg = "True"
+    else:
+      propg = "False"
+
+    QUERY_STR='<?xml version="1.0" ?><ricci async="true" function="process_batch" version="1.0"><batch><module name="cluster"><request API_version="1.0"><function_call name="set_cluster.conf"/><var propagate="' + propg + '" cluster.conf="' + str(clusterconf) + '"/></request></module></batch></ricci>'
+
+    try:
+      payload = self.makeConnection(QUERY_STR)
+    except RicciReceiveError, r:
+      return None
+                                                                            
+                                                                            
+    batch_number, result = self.batchAttemptResult(payload)
+    return (batch_number, result)
 
 
 def createClusterBatch(cluster_name, cluster_alias, nodeList, services, shared_storage, LVS):


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