def getDOMElement(self, name): '''returns a DOM Element from the given member name''' from comoonics import XmlTools file=self.ahandler.getFileObj(name) doc=XmlTools.parseXMLFP(file) self.ahandler.closeAll() return doc.documentElement
def getEnterprisecopy(self): from comoonics import XmlTools import xml.dom import odict import os.path ret_doc=None ret_element=None _sets=odict.Odict() for _templatefile in self.templatefiles: _file=open(os.path.join(self.sysreport_templatesbase, _templatefile),"r") doc=XmlTools.parseXMLFP(_file) # Initially create ret_doc. Cannot do it before cause we need the doc if not ret_doc: ret_doc=XmlTools.getDOMImplementation().createDocument(None, doc.documentElement.tagName, None) ret_element=ret_doc.documentElement for _child in doc.documentElement.childNodes: if _child.nodeType==xml.dom.Node.ELEMENT_NODE: if _child.hasAttribute("name"): _sets[_child.getAttribute("name")]=XmlTools.clone_node(_child, ret_doc) elif _child.nodeType == xml.dom.Node.ATTRIBUTE_NODE: ret_element.appendChild(XmlTools.clone_node(_child, ret_doc)) # remove the save-sysreport and add it to the end _save_set= _sets[self.save_set] del _sets[self.save_set] _sets[self.save_set]=_save_set for _set in _sets.values(): Sysreport.logger.debug("getEnterprisecopy() adding child: %s" %_set.getAttribute("name")) ret_element.appendChild(_set) del _sets[self.save_set] del _sets[self.head_set] self.sets=_sets return EnterpriseCopy(ret_element, ret_doc)
def parseClusterConfFP(_clusterconffp, _clusterconf, _validate=False): from comoonics import ComLog from comoonics import XmlTools try: doc = XmlTools.parseXMLFP(_clusterconffp) except Exception, arg: ComLog.getLogger().critical("Problem while reading clusterconfiguration (%s): %s" %(_clusterconf, str(arg))) raise
def getNextDOMElement(self): ''' returns a DOM representation of the next defined file <file name="filename.xml"/> ''' from comoonics import XmlTools file=self.getNextFileObj() # there is no nextElement if file == None: return None doc=XmlTools.parseXMLFP(file) self.ahandler.closeAll() return doc.documentElement
def setUp(self): from comoonics import XmlTools import StringIO from comoonics.storage.ComDevice import Device from comoonics.storage.ComMountpoint import MountPoint from comoonics.storage.ComFileSystem import getFileSystem xmlfp=StringIO.StringIO(self.xml) doc=XmlTools.parseXMLFP(xmlfp) __device=doc.documentElement self.device=Device(__device, doc) __fs=__device.getElementsByTagName("filesystem")[0] self.filesystem=getFileSystem(__fs, doc) __mp=__device.getElementsByTagName("mountpoint")[0] self.mountpoint=MountPoint(__mp, doc)
def fromXML(options, xmlfile): from comoonics import XmlTools import xml.dom if options.xml=="-": logger.debug("Parsing document from stdin") doc = XmlTools.parseXMLFP(sys.stdin, options.xmlvalidate) elif os.path.isfile(options.xml): logger.debug("Parsing document %s " % options.xml) doc = XmlTools.parseXMLFile(options.xml, options.xmlvalidate) if options.clusterconf: from xml import xpath if options.nodename != None or options.nodename != "": (rc, options.nodename)=ComSystem.execLocalStatusOutput("cman_tool status | grep 'Node name:'") logger.debug("options.nodename: %s" %options.nodename) options.nodename=options.nodename.split(" ")[2] _xmlnodepath='/cluster/clusternodes/clusternode[@name="%s"]/com_info/fenceackserver' %(options.nodename) logger.debug("Nodename: %s, path: %s" %(options.nodename, _xmlnodepath)) node=xpath.Evaluate(_xmlnodepath, doc)[0] elif options.xmlnodepath and options.xmlnodepath != "": from xml import xpath logger.debug("Path2Config: %s" %options.xmlnodepath) node=xpath.Evaluate(options.xmlnodepath, doc)[0] else: node=doc.documentElement if node.hasAttribute("port"): options.port=node.getAttribute("port") if node.hasAttribute("user"): options.user=node.getAttribute("user") if node.hasAttribute("passwd"): options.password=node.getAttribute("passwd") if node.hasAttribute("bind"): options.bind=node.getAttribute("bind") sslnodes=node.getElementsByTagName("ssl") if sslnodes: options.ssl=True if node.hasAttribute("keyfile"): options.ssl_keyfile=node.getAttribute("keyfile") if node.hasAttribute("certfile"): options.ssl_certfile=node.getAttribute("certfile") if node.hasAttribute("verifyfile"): options.ssl_verifyfile=node.getAttribute("verifyfile") return