Exemplo n.º 1
0
	def getXMLNodeReply(self):
		"""
			Generate the XML node with the contents of the instance.
			@rtype: cDomlette
			@return: It is an XML node.
		"""
		if (self.isError()):
			doc = implementation.createDocument(C.NETCONF_XMLNS, None, None)
			
			rpcerrornode = self.createNode(doc=doc, parent=doc,tag="rpc-error",value=None)
			self.createNode(doc=doc,parent=rpcerrornode,tag="error-type",value=self.error_type)
			self.createNode(doc=doc,parent=rpcerrornode,tag="error-tag",value=self.error_tag)
			self.createNode(doc=doc,parent=rpcerrornode,tag="error-severity",value=self.error_severity)
			if ( self.error_tag_app != None):
				self.createNode(doc=doc,parent=rpcerrornode,tag="error-app-tag",value=self.error_tag_app)
			if ( self.error_path != None):
				self.createNode(doc=doc,parent=rpcerrornode,tag="error-path",value=self.error_path)
			if ( self.error_message != None):
				self.createNode(doc=doc,parent=rpcerrornode,tag="error-message",value=self.error_message)
			if ( self.error_info != {}):
				infonode = self.createNode(doc=doc,parent=rpcerrornode,tag="error-info",value=None)
				for key,item in self.error_info:
					self.createNode(doc=doc,parent=infonode,tag=key,value=item)
			self.replynode = doc.documentElement
		elif (self.replynode == None):
			doc = implementation.createDocument(C.NETCONF_XMLNS, None, None)
			self.createNode(doc=doc,parent=doc,tag=C.OK,value=None)
			self.replynode = doc.documentElement
			
		return self.replynode
Exemplo n.º 2
0
    def getXMLNodeReply(self):
        """
			Generate the XML node with the contents of the instance.
			@rtype: cDomlette
			@return: It is an XML node.
		"""
        if (self.isError()):
            doc = implementation.createDocument(C.NETCONF_XMLNS, None, None)

            rpcerrornode = self.createNode(doc=doc,
                                           parent=doc,
                                           tag="rpc-error",
                                           value=None)
            self.createNode(doc=doc,
                            parent=rpcerrornode,
                            tag="error-type",
                            value=self.error_type)
            self.createNode(doc=doc,
                            parent=rpcerrornode,
                            tag="error-tag",
                            value=self.error_tag)
            self.createNode(doc=doc,
                            parent=rpcerrornode,
                            tag="error-severity",
                            value=self.error_severity)
            if (self.error_tag_app != None):
                self.createNode(doc=doc,
                                parent=rpcerrornode,
                                tag="error-app-tag",
                                value=self.error_tag_app)
            if (self.error_path != None):
                self.createNode(doc=doc,
                                parent=rpcerrornode,
                                tag="error-path",
                                value=self.error_path)
            if (self.error_message != None):
                self.createNode(doc=doc,
                                parent=rpcerrornode,
                                tag="error-message",
                                value=self.error_message)
            if (self.error_info != {}):
                infonode = self.createNode(doc=doc,
                                           parent=rpcerrornode,
                                           tag="error-info",
                                           value=None)
                for key, item in self.error_info:
                    self.createNode(doc=doc,
                                    parent=infonode,
                                    tag=key,
                                    value=item)
            self.replynode = doc.documentElement
        elif (self.replynode == None):
            doc = implementation.createDocument(C.NETCONF_XMLNS, None, None)
            self.createNode(doc=doc, parent=doc, tag=C.OK, value=None)
            self.replynode = doc.documentElement

        return self.replynode
Exemplo n.º 3
0
    def serialize(self):
        doc = implementation.createDocument(self.namespace, None, None)
        #doc=Document()
        ipsec_element = doc.createElementNS(self.namespace, "ipsec")
        sad_element = doc.createElementNS(self.namespace, "sad")
        spd_element = doc.createElementNS(self.namespace, "spd")
        ipsec_element.appendChild(sad_element)
        ipsec_element.appendChild(spd_element)
        doc.appendChild(ipsec_element)
        if self.SAs:
            for sa in self.SAs:
                saNode = sa.serialize(doc, self.namespace)
                sad_element.appendChild(saNode)
        else:
            print 'No SAD entries.'

        if self.SPs:
            for sp in self.SPs:
                spNode = sp.serialize(doc, self.namespace)
                spd_element.appendChild(spNode)
        else:
            print 'No SPD entries.'

        #print doc.toprettyxml()
        return doc.documentElement
Exemplo n.º 4
0
    def test_transform(self):
        SIZE=10
        
        import sys
        from amara.xslt import transform

        #Create the matrix to be transposed
        from Ft.Xml.Domlette import implementation
        doc = implementation.createDocument(None, 'table', None)
        counter = 1
        for row in range(SIZE):
            row_elem = doc.createElementNS(None, 'row')
            doc.documentElement.appendChild(row_elem)
            for col in range(SIZE):
                col_elem = doc.createElementNS(None, 'column')
                row_elem.appendChild(col_elem)
                content = doc.createTextNode(str(counter))
                col_elem.appendChild(content)
                counter = counter + 1

        stream = cStringIO.StringIO()
        from Ft.Xml.Domlette import Print
        Print(doc,stream)

        self.source = stringsource(stream.getvalue())
        result = transform(self.source, self.transform, output=io)
        self.assert_(treecompare.html_compare(self.expected, io.getvalue()))
        return
Exemplo n.º 5
0
def node_to_xml(node):
	"Takes an XML node and returns an XML documentElement suitable for saving."
	root = implementation.createDocument(None, 'root', None)
	new = node.cloneNode(1)
	new = root.importNode(new, 1)
	root.replaceChild(new, root.documentElement)
	return root
Exemplo n.º 6
0
    def test_transform(self):
        SIZE = 10

        import sys
        from amara.xslt import transform

        #Create the matrix to be transposed
        from Ft.Xml.Domlette import implementation
        doc = implementation.createDocument(None, 'table', None)
        counter = 1
        for row in range(SIZE):
            row_elem = doc.createElementNS(None, 'row')
            doc.documentElement.appendChild(row_elem)
            for col in range(SIZE):
                col_elem = doc.createElementNS(None, 'column')
                row_elem.appendChild(col_elem)
                content = doc.createTextNode(str(counter))
                col_elem.appendChild(content)
                counter = counter + 1

        stream = cStringIO.StringIO()
        from Ft.Xml.Domlette import Print
        Print(doc, stream)

        self.source = stringsource(stream.getvalue())
        result = transform(self.source, self.transform, output=io)
        self.assert_(treecompare.html_compare(self.expected, io.getvalue()))
        return
Exemplo n.º 7
0
    def execute(self):
        """
			Execute the get-config operation.
		"""

        if self.operationReply.isError():
            return self.operationReply

        if self.source in [C.RUNNING, C.CANDIDATE, C.STARTUP]:
            self.getConfig(self.source)

        if self.operationReply.isError():
            return self.operationReply

        self.filterResponse()

        if self.operationReply.isError():
            return self.operationReply

        doc = implementation.createDocument(C.NETCONF_XMLNS, 'data', None)
        dataNode = doc.documentElement
        nn = self.operationReply.getNode()
        dataNode.appendChild(nn)
        self.operationReply.setNode(dataNode)
        return self.operationReply
Exemplo n.º 8
0
    def serialize(self):
        doc = implementation.createDocument(self.namespace, None, None)
        # doc=Document()
        ipsec_element = doc.createElementNS(self.namespace, "ipsec")
        sad_element = doc.createElementNS(self.namespace, "sad")
        spd_element = doc.createElementNS(self.namespace, "spd")
        ipsec_element.appendChild(sad_element)
        ipsec_element.appendChild(spd_element)
        doc.appendChild(ipsec_element)
        if self.SAs:
            for sa in self.SAs:
                saNode = sa.serialize(doc, self.namespace)
                sad_element.appendChild(saNode)
        else:
            print "No SAD entries."

        if self.SPs:
            for sp in self.SPs:
                spNode = sp.serialize(doc, self.namespace)
                spd_element.appendChild(spNode)
        else:
            print "No SPD entries."

        # print doc.toprettyxml()
        return doc.documentElement
Exemplo n.º 9
0
    def generate_edit_config(self,
                             msgID,
                             targetName,
                             inlineconfig,
                             error_option=None,
                             default_operation=None,
                             test_option=None):
        doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
        operationNode = self.setOperationNode(doc, msgID, C.EDIT_CONFIG)
        if error_option != None:
            self.setOption(doc, operationNode, error_option, C.ERROR_OPTION)
        if default_operation != None:
            self.setOption(doc, operationNode, default_operation,
                           C.DEFAULT_OPERATION)
        if test_option != None:
            self.setOption(doc, operationNode, test_option, C.TEST_OPTION)

        self.setTarget(doc, operationNode, targetName)

        configNode = doc.createElementNS(C.NETCONF_NS, C.CONFIG)
        operationNode.appendChild(configNode)
        #cNode = NonvalidatingReader.parseString(inlineconfig).documentElement
        cNode = doc.importNode(inlineconfig, True)
        configNode.appendChild(cNode)
        return doc
Exemplo n.º 10
0
 def generate_get_config(self, msgID, sourceName, filtertype, filterdata):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, C.GET_CONFIG)
     self.setSource(doc, operationNode, sourceName)
     if filterdata != '':
         self.setFilter(doc, operationNode, filtertype, filterdata)
     return doc
Exemplo n.º 11
0
 def generate_kill_session(self, msgID, session_id):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, C.KILL_SESSION)
     sessionIdNode = doc.createElementNS(C.NETCONF_NS, C.SESSION_ID)
     operationNode.appendChild(sessionIdNode)
     sNode = doc.createTextNode(session_id)
     sessionIdNode.appendChild(sNode)
     return doc
Exemplo n.º 12
0
 def generate_copy_config(self,
                          msgID,
                          targetName,
                          sourceName,
                          inlineconfig=None):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, C.COPY_CONFIG)
     self.setSource(doc, operationNode, sourceName, inlineconfig)
     self.setTarget(doc, operationNode, targetName)
     return doc
Exemplo n.º 13
0
	def serialize(self):
		doc = implementation.createDocument(self.namespace, None, None)
		element = doc.createElementNS(self.namespace,"routes")
		element.setAttributeNS(self.namespace, "ip-version", "IPv4")
		doc.appendChild(element)
		
		for route in self.routes:
			routeEntryNode = route.serialize(doc, self.namespace)
			element.appendChild(routeEntryNode)
		
		return doc.documentElement
Exemplo n.º 14
0
	def __init__(self, initialNode, xpathRequestList, NSS = {}):
		"""
			initialNode is the node that will be filtered.
			initialNode will not be modified.
			Only the matching nodes are cloned from initialNode and rearranged to make a new document.
		"""

		self.initialNode = initialNode
		self.xpathRequestList = xpathRequestList
		self.NSS = NSS
		self.resultDocument = implementation.createDocument(C.YENCAP_XMLNS, "netconf", None)
Exemplo n.º 15
0
	def serialize(self):
		
		doc = implementation.createDocument(self.namespace, None, None)
		element = doc.createElementNS(self.namespace,"routes")
		element.setAttributeNS(self.namespace, "ip-version", "IPv4")
		doc.appendChild(element)
		
		for route in self.routes:
			routeEntryNode = route.serialize(doc, self.namespace)
			element.appendChild(routeEntryNode)
		
		return doc.documentElement
Exemplo n.º 16
0
    def __init__(self, initialNode, xpathRequestList, NSS={}):
        """
			initialNode is the node that will be filtered.
			initialNode will not be modified.
			Only the matching nodes are cloned from initialNode and rearranged to make a new document.
		"""

        self.initialNode = initialNode
        self.xpathRequestList = xpathRequestList
        self.NSS = NSS
        self.resultDocument = implementation.createDocument(
            C.YENCAP_XMLNS, "netconf", None)
Exemplo n.º 17
0
 def generate_rbac(self, msgID, rbac_op, rbac_rolename):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, "rbac")
     rbacopNode = doc.createElementNS(EMPTY_NAMESPACE, rbac_op)
     operationNode.appendChild(rbacopNode)
     rolesNode = doc.createElementNS(EMPTY_NAMESPACE, "roles")
     rbacopNode.appendChild(rolesNode)
     roleNode = doc.createElementNS(EMPTY_NAMESPACE, "role")
     rolesNode.appendChild(roleNode)
     rNode = doc.createTextNode(rbac_rolename)
     roleNode.appendChild(rNode)
     return doc
Exemplo n.º 18
0
 def __init__(self, ownerDoc=None, implementation=implementation, outputParams=None):
     """
     Note: if no ownerDoc, there is no way to set the document's base URI.
     """
     NullWriter.NullWriter.__init__(self)
     if not ownerDoc:
         ownerDoc = implementation.createDocument(None, None, None)
         self._root = ownerDoc
     else:
         self._root = ownerDoc.createDocumentFragment()
     self._ownerDoc = ownerDoc
     self._nodeStack = [self._root]
     self._currElement = None
     self._currText = ''
     return
Exemplo n.º 19
0
	def construct_XML(self,data):
		"""
			It Creates the XML configuration document according to the data argument.
			@type data: primities types
			@param data: It is the typeData
			@rtype : cDocument
			@return : The actual created document.
		"""
		self.doc = implementation.createDocument(self.namespaceURI, None, None)
		structnode = self.structXML.rootNode.xpath("/documentlink")[0]
		createnode = self.makeNodeFromData(self.doc,structnode, ParseStruct(data),{})
		
		if (self.instance != None):
			self.doc.documentElement.setAttributeNS(self.namespaceURI, "instance", self.instance)
		
		return self.doc
	def initConfig(self, configName, configType):
		"""
			Build the XML datastore template.
			@type configName : string
			@param configName : the name of the configuration datastore ('running', 'candidate' or 'startup') 
			@type configType : string
			@param configType : the type of the configuration datastore ('state' or 'config') 
		"""

		doc = implementation.createDocument(C.YENCAP_XMLNS, "netconf", None)

		self.configurations[configName][configType] = doc
		
		for module in self.moduleManager.getModules():

			self.initConfigModule(module, configName, configType)
Exemplo n.º 21
0
	def serialize(self, commands):
		doc = implementation.createDocument(self.namespace, None, None)
		element = doc.createElementNS(self.namespace,"rip")
		element.setAttributeNS(self.namespace, "version", "2")
		doc.appendChild(element)

		redistributeNode = None
		networkNode = None
		neighborNode = None
		passive_interfaceNode = None
		routeNode = None
		distribute_listNode = None

		for command in commands:
			node = command.toXML(doc, self.namespace)
			if command.name == "redistribute":
				if redistributeNode == None:
					redistributeNode = doc.createElementNS(self.namespace,"redistribute")
					element.appendChild(redistributeNode)
				redistributeNode.appendChild(node)
			elif command.name == "network":
				if networkNode == None:
					networkNode = doc.createElementNS(self.namespace,"networks")
					element.appendChild(networkNode)
				networkNode.appendChild(node)
			elif command.name == "neighbor":
				if neighborNode == None:
					neighborNode = doc.createElementNS(self.namespace,"neighbors")
					element.appendChild(neighborNode)
				neighborNode.appendChild(node)
			elif command.name == "passive-interface":
				if passive_interfaceNode == None:
					passive_interfaceNode = doc.createElementNS(self.namespace,"passive-interfaces")
					element.appendChild(passive_interfaceNode)
				passive_interfaceNode.appendChild(node)
			elif command.name == "route":
				if routeNode == None:
					routeNode = doc.createElementNS(self.namespace,"routes")
					element.appendChild(routeNode)
				routeNode.appendChild(node)
			elif command.name == "distribute-list":
				if distribute_listNode == None:
					distribute_listNode = doc.createElementNS(self.namespace,"distribute-lists")
					element.appendChild(distribute_listNode)
				distribute_listNode.appendChild(node)
		
		return doc.documentElement
Exemplo n.º 22
0
    def generate_manage_mib_modules(self,
                                    msgID,
                                    m_op,
                                    m_name,
                                    m_xpath=None,
                                    m_namespace=None,
                                    m_cachelifetime=None,
                                    m_file=None,
                                    m_pref=None):
        doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
        operationNode = self.setOperationNode(doc, msgID, "manage-mib-modules")
        mmopNode = doc.createElementNS(EMPTY_NAMESPACE, m_op)
        operationNode.appendChild(mmopNode)
        nameNode = doc.createElementNS(EMPTY_NAMESPACE, "name")
        mmopNode.appendChild(nameNode)
        nNode = doc.createTextNode(m_name)
        nameNode.appendChild(nNode)

        if m_op == 'deploy':

            tmpNode = doc.createElementNS(EMPTY_NAMESPACE, "xpath")
            mmopNode.appendChild(tmpNode)
            nNode = doc.createTextNode(m_xpath)
            tmpNode.appendChild(nNode)

            tmpNode = doc.createElementNS(EMPTY_NAMESPACE, "namespace")
            mmopNode.appendChild(tmpNode)
            nNode = doc.createTextNode(m_namespace)
            tmpNode.appendChild(nNode)
            tmpNode.setAttributeNS(EMPTY_NAMESPACE, "pref", m_pref)

            tmpNode = doc.createElementNS(EMPTY_NAMESPACE, "cachelifetime")
            mmopNode.appendChild(tmpNode)
            nNode = doc.createTextNode(m_cachelifetime)
            tmpNode.appendChild(nNode)

            tmpNode = doc.createElementNS(EMPTY_NAMESPACE, "file")
            mmopNode.appendChild(tmpNode)
            nNode = doc.createTextNode(m_file)
            tmpNode.appendChild(nNode)

            tmpNode = doc.createElementNS(EMPTY_NAMESPACE, "parameters")
            mmopNode.appendChild(tmpNode)

        return doc
Exemplo n.º 23
0
 def __init__(self,
              ownerDoc=None,
              implementation=implementation,
              outputParams=None):
     """
     Note: if no ownerDoc, there is no way to set the document's base URI.
     """
     NullWriter.NullWriter.__init__(self)
     if not ownerDoc:
         ownerDoc = implementation.createDocument(None, None, None)
         self._root = ownerDoc
     else:
         self._root = ownerDoc.createDocumentFragment()
     self._ownerDoc = ownerDoc
     self._nodeStack = [self._root]
     self._currElement = None
     self._currText = ''
     return
Exemplo n.º 24
0
    def parse(self):
        """
			Parse all Asterisk configuration files
		"""
        doc = implementation.createDocument(self.namespace, 'asterisk', None)

        root = doc.documentElement

        files = os.listdir(ASTERISK_HOME)

        for f in files:

            if f.endswith('.conf'):

                node = self.parseFile(f, doc)

                root.appendChild(node)

        return doc
Exemplo n.º 25
0
	def parse(self):
		"""
			Parse all Asterisk configuration files
		"""
		doc = implementation.createDocument(self.namespace, 'asterisk', None)

		root = doc.documentElement
		
		files = os.listdir(ASTERISK_HOME)
		
		for f in files:
			
			if f.endswith('.conf'):
				
				node = self.parseFile(f,doc)
				
				root.appendChild(node)
		
		
		return doc
Exemplo n.º 26
0
def Test(tester):
    #Create the matrix to be transposed
    doc = implementation.createDocument(None, 'table', None)
    counter = 1
    for row in range(SIZE):
        row_elem = doc.createElementNS(None, 'row')
        doc.documentElement.appendChild(row_elem)
        for col in range(SIZE):
            col_elem = doc.createElementNS(None, 'column')
            row_elem.appendChild(col_elem)
            content = doc.createTextNode(str(counter))
            col_elem.appendChild(content)
            counter = counter + 1

    stream = cStringIO.StringIO()
    Print(doc, stream)

    source = test_harness.FileInfo(string=stream.getvalue())
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester, source, [sheet], expected_1)
    return
Exemplo n.º 27
0
def Test(tester):
    #Create the matrix to be transposed
    doc = implementation.createDocument(None, 'table', None)
    counter = 1
    for row in range(SIZE):
        row_elem = doc.createElementNS(None, 'row')
        doc.documentElement.appendChild(row_elem)
        for col in range(SIZE):
            col_elem = doc.createElementNS(None, 'column')
            row_elem.appendChild(col_elem)
            content = doc.createTextNode(str(counter))
            col_elem.appendChild(content)
            counter = counter + 1


    stream = cStringIO.StringIO()
    Print(doc,stream)

    source = test_harness.FileInfo(string=stream.getvalue())
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester, source, [sheet], expected_1)
    return
Exemplo n.º 28
0
    def getConfig(self, configName):
        """
            Generate the interfaces XML configuration.
            @rtype: ModuleReply
            @return: the main node of the network interfaces.
            ** Relates to the netconf get-config operation
        """

        self.doc = implementation.createDocument(self.namespace, None, None)
        dnsnode = self.doc.createElementNS(self.namespace, "dns")
        self.doc.appendChild(dnsnode)

        listNs = self.getNameServers()
        if listNs != []:
            for dns in listNs:
                node = self.doc.createElementNS(self.namespace, "server")
                self.doc.documentElement.appendChild(node)
                server = self.doc.createTextNode(dns)
                node.appendChild(server)

        modulereply = ModuleReply(replynode=self.doc.documentElement)
        return modulereply
Exemplo n.º 29
0
    def getConfig(self, configName):

        dict = ["sysname", "nodename", "release", "version", "machine"]
        tuple = os.uname()

        doc = implementation.createDocument(self.namespace, None, None)
        element = doc.createElementNS(self.namespace, "system")
        doc.appendChild(element)
        i = 0
        for t in tuple:
            node = doc.createElementNS(self.namespace, dict[i])
            element.appendChild(node)
            textNode = doc.createTextNode(t)
            node.appendChild(textNode)
            i = i + 1

        # Execute shell command
        #res = os.popen3("rpmquery -a | grep xorg")
        res = os.popen3("rpmquery -a")
        # Read stdout output
        resultat = res[1].read()
        # Split the result to get rpm names in an array
        rpmlist = resultat.split("\n")

        rpmsElement = doc.createElementNS(self.namespace, "rpm-list")
        element.appendChild(rpmsElement)
        i = 0
        for rpm in rpmlist:
            if rpm != "":
                node = doc.createElementNS(slf.namespace, "rpm")
                rpmsElement.appendChild(node)
                textNode = doc.createTextNode(rpm)
                node.appendChild(textNode)
            i = i + 1

        modulereply = ModuleReply(replynode=doc.documentElement)
        return modulereply
    def setParameters(self, operation, NSS=None):
        """
		Set the source parameter and the config parameter, config then contains the configuration to validate.

		@type  operation: Node
		@param operation: The operation node of the current Netconf request.
		"""
        for child in operation.childNodes:
            if child.nodeType == Node.ELEMENT_NODE:
                if child.tagName == C.SOURCE:
                    for node in child.childNodes:
                        if node.nodeType == Node.ELEMENT_NODE:
                            if node.tagName in [C.CANDIDATE, C.STARTUP, C.RUNNING]:
                                self.target = node.tagName
                            elif node.tagName == C.CONFIG:
                                self.target = node.tagName
                                for blub in node.childNodes:
                                    if blub.nodeType == Node.ELEMENT_NODE:
                                        if blub.localName == "netconf" and blub.namespaceURI == C.YENCAP_XMLNS:
                                            # We build a new document containing the "filter" to compare more easily
                                            self.config = implementation.createDocument(C.YENCAP_XMLNS, "netconf", None)
                                            clone = self.config.importNode(blub, True)
                                            # self.config is a document which documentElement is "netconf"
                                            self.config.replaceChild(clone, self.config.documentElement)
                                            return

                else:
                    moduleReply = ModuleReply(
                        error_type=ModuleReply.PROTOCOL,
                        error_tag=ModuleReply.UNKNOWN_ELEMENT,
                        error_severity=ModuleReply.ERROR,
                        error_message="An element is not known.",
                    )
                    moduleReply.addErrorInfo("bad-element", child.tagName)
                    self.operationReply.setError()
                    self.operationReply.setNode(moduleReply.getXMLNodeReply())
                    return
	def execute(self):
		"""
			Execute the get-config operation.
		"""

		if self.operationReply.isError():
			return self.operationReply

		if self.source in [C.RUNNING, C.CANDIDATE, C.STARTUP]:
			self.getConfig(self.source)
			
		if self.operationReply.isError():
			return self.operationReply
		
		self.filterResponse()

		if self.operationReply.isError():
			return self.operationReply

		doc = implementation.createDocument(C.NETCONF_XMLNS, 'data', None)
		dataNode = doc.documentElement
		dataNode.appendChild(self.operationReply.getNode())
		self.operationReply.setNode(dataNode)
		return self.operationReply
Exemplo n.º 32
0
	def getConfig(self):
		dict = ["sysname", "nodename", "release", "version", "machine"]
		tuple = os.uname()

		doc = implementation.createDocument(EMPTY_NAMESPACE, None, None)
		element = doc.createElementNS(EMPTY_NAMESPACE,"system")
		doc.appendChild(element)
		i=0
		for t in tuple:
			node = doc.createElementNS(EMPTY_NAMESPACE,dict[i])
			element.appendChild(node)
			textNode = doc.createTextNode(t)
			node.appendChild(textNode)
			i=i+1

		# Execute shell command
		#res = os.popen3("rpmquery -a | grep xorg")
		res = os.popen3("rpmquery -a")
		# Read stdout output
		resultat = res[1].read()
		# Split the result to get rpm names in an array
		rpmlist = resultat.split("\n")

		rpmsElement = doc.createElementNS(EMPTY_NAMESPACE,"rpm-list")
		element.appendChild(rpmsElement)
		i=0
		for rpm in rpmlist:
			if rpm!="":
				node = doc.createElementNS(EMPTY_NAMESPACE,"rpm")
				rpmsElement.appendChild(node)
				textNode = doc.createTextNode(rpm)
				node.appendChild(textNode)
			i=i+1

		modulereply = ModuleReply(replynode=doc.documentElement)
		return modulereply
	def setParameters(self, operation, NSS = None):
		"""
		Set the source parameter and the config parameter, config then contains the configuration to validate.

		@type  operation: Node
		@param operation: The operation node of the current Netconf request.
		"""
		for child in operation.childNodes:
			if child.nodeType==Node.ELEMENT_NODE:
				if child.tagName == C.SOURCE:
					for node in child.childNodes:
						if node.nodeType==Node.ELEMENT_NODE:
							if node.tagName in [C.CANDIDATE, C.STARTUP, C.RUNNING]:
								self.target = node.tagName			
							elif node.tagName == C.CONFIG:
								self.target = node.tagName
								for blub in node.childNodes:
									if blub.nodeType==Node.ELEMENT_NODE:
										if blub.localName == "netconf" and blub.namespaceURI == C.YENCAP_XMLNS:
											# We build a new document containing the "filter" to compare more easily
											self.config =  implementation.createDocument(C.YENCAP_XMLNS, "netconf", None)
											clone = self.config.importNode(blub, True)
											# self.config is a document which documentElement is "netconf"
											self.config.replaceChild(clone, self.config.documentElement)
											return
				
				else:
					moduleReply = ModuleReply(
					error_type = ModuleReply.PROTOCOL,
					error_tag = ModuleReply.UNKNOWN_ELEMENT,
					error_severity = ModuleReply.ERROR,
					error_message = "An element is not known.")
					moduleReply.addErrorInfo("bad-element",child.tagName)
					self.operationReply.setError()
					self.operationReply.setNode(moduleReply.getXMLNodeReply())
					return
Exemplo n.º 34
0
	def __init__(self, configDocument, filterDocument):
		self.configDocument = configDocument
		self.filterDocument = filterDocument
		self.resultDocument = implementation.createDocument(EMPTY_NAMESPACE, None, None)
Exemplo n.º 35
0
 def generate_discard_changes(self, msgID):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, C.DISCARD_CHANGES)
     return doc
	def setParameters(self, operation, NSS = None):
		"""
		Set the source and target parameters

		@type  operation: Node
		@param operation: The operation node of the current Netconf request.
		"""
		
		self.prefixes = NSS

		for child in operation.childNodes:
			if child.nodeType==Node.ELEMENT_NODE:

				if child.tagName == C.SOURCE:
					for node in child.childNodes:
						if node.nodeType==Node.ELEMENT_NODE:
							if node.tagName in [C.CANDIDATE, C.STARTUP, C.RUNNING, C.URL]:
								self.source = node.tagName
								if node.tagName == C.URL:
									self.sourceTarget = string.strip(str(node.childNodes[0].nodeValue))
							elif node.tagName == "config":
								self.source = node.tagName
								for cn in node.childNodes:
									if cn.nodeType==Node.ELEMENT_NODE:
										if cn.localName == "netconf" and cn.namespaceURI == C.YENCAP_XMLNS:
											# We build a new document containing the "filter" to compare more easily
											self.sourceInbound = implementation.createDocument(C.YENCAP_XMLNS, "netconf", None)
											clone = self.sourceInbound.importNode(cn, True)
											# self.config is a document which documentElement is "netconf"
											self.sourceInbound.replaceChild(clone, self.sourceInbound.documentElement)
							else:
								moduleReply = ModuleReply(
								error_type = ModuleReply.PROTOCOL,
								error_tag = ModuleReply.UNKNOWN_ELEMENT,
								error_severity = ModuleReply.ERROR,
								error_message = "An element is not known.")
								moduleReply.addErrorInfo("bad-element",node.tagName)
								self.operationReply.setError()
								self.operationReply.setNode(moduleReply.getXMLNodeReply())
								return

				elif child.tagName == C.TARGET:
					for node in child.childNodes:
						if node.nodeType==Node.ELEMENT_NODE:
							if node.tagName in [C.CANDIDATE, C.STARTUP, C.RUNNING, C.URL]:
								self.target = node.tagName
								if node.tagName == C.URL:
									self.urlTarget = string.strip(str(node.childNodes[0].nodeValue))
							else:
								moduleReply = ModuleReply(
								error_type = ModuleReply.PROTOCOL,
								error_tag = ModuleReply.UNKNOWN_ELEMENT,
								error_severity = ModuleReply.ERROR,
								error_message = "An element is not known.")
								moduleReply.addErrorInfo("bad-element",node.tagName)
								self.operationReply.setError()
								self.operationReply.setNode(moduleReply.getXMLNodeReply())
								return
				else:
					moduleReply = ModuleReply(
					error_type = ModuleReply.PROTOCOL,
					error_tag = ModuleReply.UNKNOWN_ELEMENT,
					error_severity = ModuleReply.ERROR,
					error_message = "An element is not known.")
					moduleReply.addErrorInfo("bad-element",child.tagName)
					self.operationReply.setError()
					self.operationReply.setNode(moduleReply.getXMLNodeReply())
					return
Exemplo n.º 37
0
 def generate_close_session(self, msgID):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, C.CLOSE_SESSION)
     return doc
Exemplo n.º 38
0
 def generate_commit(self, msgID):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, C.COMMIT)
     return doc
Exemplo n.º 39
0
 def parse(self):
     doc = implementation.createDocument(self.namespace, None, None)
     olsr = doc.createElementNS(self.namespace, "olsr")
     doc.appendChild(olsr)
     self.parseConfigFile(doc, olsr, self.namespace)
     return doc
Exemplo n.º 40
0
def Test(tester):
    tester.startGroup('Uche finds nested default namespace munging')
    doc = implementation.createDocument(None, None, None)
    elem1 = doc.createElementNS("http://example.com/1", "x:foo")
    doc.appendChild(elem1)
    elem2 = doc.createElementNS(None, "bar")
    elem1.appendChild(elem2)
    tester.startTest('Outer with prefix.  Print')
    stream = cStringIO.StringIO()
    Print(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED1_PRINTED, result)
    tester.testDone()
    tester.startTest('Outer with prefix.  PrettyPrint')
    stream = cStringIO.StringIO()
    PrettyPrint(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED1_PRETTY, result)
    tester.testDone()

    doc = implementation.createDocument(None, None, None)
    elem1 = doc.createElementNS("http://example.com/1", "foo")
    doc.appendChild(elem1)
    elem2 = doc.createElementNS(None, "bar")
    elem1.appendChild(elem2)
    tester.startTest('Outer without prefix.  Print')
    stream = cStringIO.StringIO()
    Print(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED2_PRINTED, result)
    tester.testDone()
    tester.startTest('Outer without prefix.  PrettyPrint')
    stream = cStringIO.StringIO()
    PrettyPrint(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED2_PRETTY, result)
    tester.testDone()

    doc = implementation.createDocument(None, None, None)
    elem1 = doc.createElementNS(None, "foo")
    doc.appendChild(elem1)
    elem2 = doc.createElementNS("http://example.com/1", "bar")
    elem1.appendChild(elem2)
    tester.startTest('outer no prefix or ns, inner ns no prefix.  Print')
    stream = cStringIO.StringIO()
    Print(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED3_PRINTED, result)
    tester.testDone()
    tester.startTest('outer no prefix or ns, inner ns no prefix.  PrettyPrint')
    stream = cStringIO.StringIO()
    PrettyPrint(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED3_PRETTY, result)
    tester.testDone()

    doc = implementation.createDocument(None, None, None)
    elem1 = doc.createElementNS(None, "foo")
    doc.appendChild(elem1)
    elem2 = doc.createElementNS("http://example.com/1", "bar")
    elem1.appendChild(elem2)
    elem3 = doc.createElementNS(None, "baz")
    elem2.appendChild(elem3)
    tester.startTest('outer no prefix or ns, then ns no prefix then no prefix no ns.  Print')
    stream = cStringIO.StringIO()
    Print(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED4_PRINTED, result)
    tester.testDone()
    tester.startTest('outer no prefix or ns, then ns no prefix then no prefix no ns.  PrettyPrint')
    stream = cStringIO.StringIO()
    PrettyPrint(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED4_PRETTY, result)
    tester.testDone()
    tester.groupDone()
    return
Exemplo n.º 41
0
 def generate_unlock(self, msgID, targetName):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, C.UNLOCK)
     self.setTarget(doc, operationNode, targetName)
     return doc
Exemplo n.º 42
0
 def generate_delete(self, msgID, targetName):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, C.DELETE_CONFIG)
     self.setTarget(doc, operationNode, targetName)
     return doc
Exemplo n.º 43
0
 def generate_validate(self, msgID, sourceName, inlineconfig=None):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, C.VALIDATE)
     self.setSource(doc, operationNode, sourceName, inlineconfig)
     return doc
	def setParameters(self, operation, NSS = None):
		"""
		Set the source and filter parameters

		@type  operation: Node
		@param operation: The operation node of the current Netconf request.
		"""
		self.prefixes = NSS
		
		for child in operation.childNodes:
			if child.nodeType==Node.ELEMENT_NODE:

				if child.tagName == C.SOURCE:
					for node in child.childNodes:
						if node.nodeType==Node.ELEMENT_NODE:
							if node.tagName in [C.RUNNING, C.CANDIDATE, C.STARTUP]:
								self.source = node.tagName
							else:
								moduleReply = ModuleReply(
								error_type = ModuleReply.PROTOCOL,
								error_tag = ModuleReply.BAD_ELEMENT,
								error_severity = ModuleReply.ERROR,
								error_message = "An element value is not correct.")
								moduleReply.addErrorInfo("bad-element",node.tagName)
								self.operationReply.setError()
								self.operationReply.setNode(moduleReply.getXMLNodeReply())
								return

				elif child.tagName == C.FILTER:
					self.filter = child
					for att in self.filter.attributes.values():
						if att.name == "type":
							if att.value == C.SUBTREE:
								self.filterType = C.SUBTREE
							elif att.value == C.XPATH:
								self.filterType = C.XPATH
							else:
								moduleReply = ModuleReply(
								error_type = ModuleReply.PROTOCOL,
								error_tag = ModuleReply.BAD_ATTRIBUTE,
								error_severity = ModuleReply.ERROR,
								error_message = "An attribute value is not correct")
								moduleReply.addErrorInfo("bad-attribute",att.name)
								moduleReply.addErrorInfo("bad-element",child.tagName)
								self.operationReply.setError()
								self.operationReply.setNode(moduleReply.getXMLNodeReply())
								return
						else:
							moduleReply = ModuleReply(
							error_type = ModuleReply.PROTOCOL,
							error_tag = ModuleReply.UNKNOWN_ATTRIBUTE,
							error_severity = ModuleReply.ERROR,
							error_message = "An unexpected attribute is present")
							moduleReply.addErrorInfo("bad-attribute",att.name)
							moduleReply.addErrorInfo("bad-element",child.tagName)
							self.operationReply.setError()
							self.operationReply.setNode(moduleReply.getXMLNodeReply())
							return

					if self.filterType == C.XPATH:
						tmpval = self.filter.childNodes[0].nodeValue
						self.xpathrequest = string.strip(str(tmpval))
						if self.xpathrequest == "":
							moduleReply = ModuleReply(
							error_type = ModuleReply.PROTOCOL,
							error_tag = ModuleReply.INVALID_VALUE,
							error_severity = ModuleReply.ERROR,
							error_message = "The request specifies an unacceptable value for one or more parameters.")
							self.operationReply.setError()
							self.operationReply.setNode(moduleReply.getXMLNodeReply())
							return

					elif self.filterType == C.SUBTREE:
						for node in self.filter.childNodes:
							if (node.nodeType==Node.ELEMENT_NODE):
								self.subtree = node
				else:
					moduleReply = ModuleReply(
					error_type = ModuleReply.PROTOCOL,
					error_tag = ModuleReply.UNKNOWN_ELEMENT,
					error_severity = ModuleReply.ERROR,
					error_message = "An element is not known.")
					moduleReply.addErrorInfo("bad-element",child.tagName)
					self.operationReply.setError()
					self.operationReply.setNode(moduleReply.getXMLNodeReply())
					return

		if self.filter == None:
			self.subtree = implementation.createDocument(C.YENCAP_XMLNS, 'netconf', None).documentElement
Exemplo n.º 45
0
 def generate_get(self, msgID, filtertype, filterdata):
     doc = implementation.createDocument(C.NETCONF_NS, C.RPC, None)
     operationNode = self.setOperationNode(doc, msgID, C.GET)
     if filterdata != '':
         self.setFilter(doc, operationNode, filtertype, filterdata)
     return doc
	def buildRootNode(self):
		self.doc = implementation.createDocument(self.namespace, None, None)
		interfacesNode = self.doc.createElementNS(self.namespace,"interfaces")
		self.doc.appendChild(interfacesNode)
	def setParameters(self, operation, NSS = None):
		"""
		Set the source and filter parameters

		@type  operation: Node
		@param operation: The operation node of the current Netconf request.
		"""
		
		for child in operation.childNodes:
			if child.nodeType==Node.ELEMENT_NODE:
				if child.tagName == C.TARGET:
					for node in child.childNodes:
						if node.nodeType==Node.ELEMENT_NODE:
							if node.tagName in [C.CANDIDATE, C.STARTUP, C.RUNNING]:
								self.target = node.tagName
								if node.tagName == C.URL:
									self.urlTarget = string.strip(str(node.childNodes[0].nodeValue))
							else:
								moduleReply = ModuleReply(
								error_type = ModuleReply.PROTOCOL,
								error_tag = ModuleReply.UNKNOWN_ELEMENT,
								error_severity = ModuleReply.ERROR,
								error_message = "An element is not known.")
								moduleReply.addErrorInfo("bad-element",node.tagName)
								self.operationReply.setError()
								self.operationReply.setNode(moduleReply.getXMLNodeReply())
								return
				
				elif child.tagName == C.CONFIG:
					for node in child.childNodes:
						if node.nodeType==Node.ELEMENT_NODE:
							if node.localName == "netconf" and node.namespaceURI == C.YENCAP_XMLNS:
								# We build a new document containing the "filter" to compare more easily
								self.config =  implementation.createDocument(C.YENCAP_XMLNS, "netconf", None)
								clone = self.config.importNode(node, True)
								# self.config is a document which documentElement is "netconf"
								self.config.replaceChild(clone, self.config.documentElement)
							else:
								moduleReply = ModuleReply(
								error_type = ModuleReply.PROTOCOL,
								error_tag = ModuleReply.UNKNOWN_ELEMENT,
								error_severity = ModuleReply.ERROR,
								error_message = "The root node of the configuration must be netconf.")
								moduleReply.addErrorInfo("bad-element",node.localName)
								self.operationReply.setError()
								self.operationReply.setNode(moduleReply.getXMLNodeReply())
								return

				elif child.tagName == C.DEFAULT_OPERATION:
					for node in child.childNodes:
						if node.nodeType==Node.TEXT_NODE:
							if node.nodeValue in [C.MERGE,C.REPLACE,C.NONE]:
								self.defaultOperation = node.nodeValue
							else:
								moduleReply = ModuleReply(
								error_type = ModuleReply.PROTOCOL,
								error_tag = ModuleReply.BAD_ELEMENT,
								error_severity = ModuleReply.ERROR,
								error_message = "An element value is not correct.")
								moduleReply.addErrorInfo("bad-element",node.nodeValue)
								self.operationReply.setError()
								self.operationReply.setNode(moduleReply.getXMLNodeReply())
								return

				elif child.tagName == C.TEST_OPTION:
					for node in child.childNodes:
						if node.nodeType==Node.TEXT_NODE:
							if node.nodeValue in [C.TEST_THEN_SET,C.SET]:
								self.testOption = node.nodeValue
							else:
								moduleReply = ModuleReply(
								error_type = ModuleReply.PROTOCOL,
								error_tag = ModuleReply.INVALID_VALUE,
								error_severity = ModuleReply.ERROR,
								error_message = "An element value is not correct.")
								moduleReply.addErrorInfo("bad-element",node.nodeValue)
								self.operationReply.setError()
								self.operationReply.setNode(moduleReply.getXMLNodeReply())
								return

				elif child.tagName == C.ERROR_OPTION:
					for node in child.childNodes:
						if node.nodeType==Node.TEXT_NODE:
							if node.nodeValue in [C.STOP_ON_ERROR, C.CONTINUE_ON_ERROR, C.ROLLBACK_ON_ERROR]:
								self.errorOption = node.nodeValue
							else:
								moduleReply = ModuleReply(
								error_type = ModuleReply.PROTOCOL,
								error_tag = ModuleReply.INVALID_VALUE,
								error_severity = ModuleReply.ERROR,
								error_message = "An element value is not correct.")
								moduleReply.addErrorInfo("bad-element",node.nodeValue)
								self.operationReply.setError()
								self.operationReply.setNode(moduleReply.getXMLNodeReply())
								return

				else:
					moduleReply = ModuleReply(
					error_type = ModuleReply.PROTOCOL,
					error_tag = ModuleReply.UNKNOWN_ELEMENT,
					error_severity = ModuleReply.ERROR,
					error_message = "An element is not known.")
					moduleReply.addErrorInfo("bad-element",child.tagName)
					self.operationReply.setError()
					self.operationReply.setNode(moduleReply.getXMLNodeReply())
					return
		
		self.checkNestingValidity(NSS)
Exemplo n.º 48
0
def newDocument(tag):
    # create a document and return document root
    doc = implementation.createDocument(None, tag, None)
    return doc.documentElement
Exemplo n.º 49
0
 def newDocument(self):
     """clear DOM"""
     self.doc = implementation.createDocument(None, self.rootTag, None)