当前位置: 首页>>代码示例>>Python>>正文


Python xml_.to_ele函数代码示例

本文整理汇总了Python中ncclient.xml_.to_ele函数的典型用法代码示例。如果您正苦于以下问题:Python to_ele函数的具体用法?Python to_ele怎么用?Python to_ele使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了to_ele函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_access_vlan

    def set_access_vlan(self, interface_id, vlan):
        update_attributes = []
        update_vlan_members = []

        config = self.query(all_interfaces, all_vlans)

        self.get_vlan_config(vlan, config)

        interface_node = self.get_interface_config(interface_id, config)
        interface = self.node_to_interface(interface_node, config)

        if interface.port_mode == TRUNK:
            raise InterfaceInWrongPortMode("trunk")
        elif self.get_port_mode(interface_node) is None:
            update_attributes.append(self.custom_strategies.set_interface_port_mode_update_element("access"))

        if interface.access_vlan != vlan:
            for members in interface_node.xpath("unit/family/ethernet-switching/vlan/members"):
                update_vlan_members.append(to_ele('<members operation="delete">{}</members>'.format(members.text)))
            update_vlan_members.append(to_ele("<members>{}</members>".format(vlan)))

        if update_attributes or update_vlan_members:
            update = Update()
            update.add_interface(interface_update(interface_id, "0", update_attributes, update_vlan_members))

            try:
                self._push(update)
            except RPCError as e:
                if "No vlan matches vlan tag" in e.message:
                    raise UnknownVlan(vlan)
                raise
开发者ID:mat128,项目名称:netman,代码行数:31,代码来源:base.py

示例2: unset_interface_auto_negotiation_state

    def unset_interface_auto_negotiation_state(self, interface_id):
        config = self.query(one_interface(interface_id))
        interface_node = self.get_interface_config(interface_id, config)

        if interface_node is None:
            self._get_physical_interface(interface_id)
            return

        auto_negotiation_present = first(interface_node.xpath('ether-options/auto-negotiation')) is not None
        no_auto_negotiation_present = first(interface_node.xpath('ether-options/no-auto-negotiation')) is not None

        if auto_negotiation_present or no_auto_negotiation_present:
            content = to_ele("""
                <interface>
                    <name>{0}</name>
                </interface>
            """.format(interface_id))
            ether_options = to_ele("<ether-options/>")
            if auto_negotiation_present:
                ether_options.append(to_ele("<auto-negotiation operation=\"delete\"/>"))
            elif no_auto_negotiation_present:
                ether_options.append(to_ele("<no-auto-negotiation operation=\"delete\"/>"))
            update = Update()

            content.append(ether_options)
            update.add_interface(content)

            self._push_interface_update(interface_id, update)
开发者ID:stephanerobert,项目名称:netman,代码行数:28,代码来源:base.py

示例3: add_enslave_to_bond_operations

    def add_enslave_to_bond_operations(self, update, interface, bond):
        ether_options = [
            to_ele("<auto-negotiation/>"),
            to_ele("""
                <ieee-802.3ad>
                    <bundle>{0}</bundle>
                </ieee-802.3ad>
            """.format(bond.interface.name))]

        update.add_interface(interface_replace(interface, *ether_options))
开发者ID:mlecours,项目名称:netman,代码行数:10,代码来源:qfx_copper.py

示例4: vlan_update

def vlan_update(number, description):
    content = to_ele("""
        <vlan>
            <name>VLAN{0}</name>
            <vlan-id>{0}</vlan-id>
        </vlan>
    """.format(number))

    if description is not None:
        content.append(to_ele("<description>{}</description>".format(description)))
    return content
开发者ID:mat128,项目名称:netman,代码行数:11,代码来源:base.py

示例5: set_interface_auto_negotiation_state

    def set_interface_auto_negotiation_state(self, interface_id, negotiation_state):
        content = to_ele("""
            <interface>
                <name>{0}</name>
            </interface>
            """.format(interface_id))
        if negotiation_state == ON:
            content.append(to_ele("<ether-options><auto-negotiation></ether-options>"))
        else:
            content.append(to_ele("<ether-options><no-auto-negotiation></ether-options>"))
        update = Update()
        update.add_interface(content)

        self._push_interface_update(interface_id, update)
开发者ID:stephanerobert,项目名称:netman,代码行数:14,代码来源:base.py

示例6: interface_update

def interface_update(name, unit, attributes=None, vlan_members=None):
    content = to_ele("""
        <interface>
            <name>{}</name>
            <unit>
                <name>{}</name>
                <family>
                    <ethernet-switching>
                    </ethernet-switching>
                </family>
            </unit>
        </interface>
        """.format(name, unit))
    ethernet_switching_node = first(content.xpath("//ethernet-switching"))

    for attribute in (attributes if attributes is not None else []):
        ethernet_switching_node.append(attribute)

    if vlan_members:
        vlan = new_ele("vlan")
        for attribute in vlan_members:
            vlan.append(attribute)
        ethernet_switching_node.append(vlan)

    return content
开发者ID:mat128,项目名称:netman,代码行数:25,代码来源:base.py

示例7: configure_native_vlan

    def configure_native_vlan(self, interface_id, vlan):
        update_attributes = []

        config = self.query(all_interfaces, all_vlans)

        self.get_vlan_config(vlan, config)

        interface_node = self.get_interface_config(interface_id, config)

        interface = self.node_to_interface(interface_node, config)

        actual_port_mode = self.get_port_mode(interface_node)
        if actual_port_mode is ACCESS:
            raise InterfaceInWrongPortMode("access")
        elif actual_port_mode is None:
            update_attributes.append(self.custom_strategies.set_interface_port_mode_update_element("trunk"))

        if vlan in interface.trunk_vlans:
            raise VlanAlreadyInTrunk(vlan)
        elif interface.trunk_native_vlan != vlan:
            update_attributes.append(to_ele("<native-vlan-id>{}</native-vlan-id>".format(vlan)))

        if update_attributes:

            update = Update()
            update.add_interface(interface_update(interface_id, "0", update_attributes))

            try:
                self._push(update)
            except RPCError as e:
                if "No vlan matches vlan tag" in e.message:
                    raise UnknownVlan(vlan)
                raise
开发者ID:mat128,项目名称:netman,代码行数:33,代码来源:base.py

示例8: bond_lacp_options

def bond_lacp_options():
    return to_ele("""
        <lacp>
            <active/>
            <periodic>slow</periodic>
        </lacp>
    """)
开发者ID:mat128,项目名称:netman,代码行数:7,代码来源:base.py

示例9: handle_raw_dispatch

 def handle_raw_dispatch(self, raw):
     if 'routing-engine' in raw:
         raw = re.sub(r'<ok/>', '</routing-engine>\n<ok/>', raw)
         return raw
     # check if error is during capabilites exchange itself
     elif re.search('\<rpc-reply\>.*?\</rpc-reply\>.*\</hello\>?', raw, re.M | re.S):
         errs = re.findall(
             '\<rpc-error\>.*?\</rpc-error\>', raw, re.M | re.S)
         err_list = []
         if errs:
             add_ns = """
                     <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                       <xsl:output indent="yes"/>
                         <xsl:template match="*">
                         <xsl:element name="{local-name()}" namespace="urn:ietf:params:xml:ns:netconf:base:1.0">
                         <xsl:apply-templates select="@*|node()"/>
                         </xsl:element>
                       </xsl:template>
                     </xsl:stylesheet>"""
             for err in errs:
                 doc = etree.ElementTree(etree.XML(err))
                 # Adding namespace using xslt
                 xslt = etree.XSLT(etree.XML(add_ns))
                 transformed_xml = etree.XML(etree.tostring(xslt(doc)))
                 err_list.append(RPCError(transformed_xml))
             return RPCError(to_ele("<rpc-reply>"+''.join(errs)+"</rpc-reply>"), err_list)
     else:
         return False
开发者ID:davidhankins,项目名称:ncclient,代码行数:28,代码来源:junos.py

示例10: rpc

    def rpc(self, cmd):
        """
        Write the XML cmd and return the response as XML object.

        :cmd:
          <str> of the XML command.  if the :cmd: is not XML, then
          this routine will perform the brackets; i.e. if given
          'get-software-information', this routine will turn
          it into '<get-software-information/>'

        NOTES:
          The return XML object is the first child element after
          the <rpc-reply>.  There is also no error-checking
          performing by this routine.
        """
        if not cmd.startswith('<'):
            cmd = '<{0}/>'.format(cmd)
        rpc = six.b('<rpc>{0}</rpc>'.format(cmd))
        logger.info('Calling rpc: %s' % rpc)
        self._tty.rawwrite(rpc)

        rsp = self._receive()
        rsp = rsp.decode('utf-8') if isinstance(rsp, bytes) else rsp
        reply = RPCReply(rsp)
        errors = reply.errors
        if len(errors) > 1:
            raise RPCError(to_ele(reply._raw), errs=errors)
        elif len(errors) == 1:
            raise reply.error
        return rsp
开发者ID:GIC-de,项目名称:py-junos-eznc,代码行数:30,代码来源:tty_netconf.py

示例11: exec_command

    def exec_command(self, request):
        """Sends the request to the node and returns the reply
        The method accepts two forms of request.  The first form is as a byte
        string that represents xml string be send over netconf session.
        The second form is a json-rpc (2.0) byte string.
        """
        try:
            obj = json.loads(to_text(request, errors='surrogate_or_strict'))

            if 'jsonrpc' in obj:
                if self._netconf:
                    out = self._exec_rpc(obj)
                else:
                    out = self.internal_error("netconf plugin is not supported for network_os %s" % self._play_context.network_os)
                return 0, to_bytes(out, errors='surrogate_or_strict'), b''
            else:
                err = self.invalid_request(obj)
                return 1, b'', to_bytes(err, errors='surrogate_or_strict')

        except (ValueError, TypeError):
            # to_ele operates on native strings
            request = to_native(request, errors='surrogate_or_strict')

        req = to_ele(request)
        if req is None:
            return 1, b'', b'unable to parse request'

        try:
            reply = self._manager.rpc(req)
        except RPCError as exc:
            return 1, b'', to_bytes(to_xml(exc.xml), errors='surrogate_or_strict')

        return 0, to_bytes(reply.data_xml, errors='surrogate_or_strict'), b''
开发者ID:ernstp,项目名称:ansible,代码行数:33,代码来源:netconf.py

示例12: interface_state_update

def interface_state_update(name, state):
    interface_state = """<disable />""" if state is OFF else """<disable operation="delete" />"""
    return to_ele("""
        <interface>
            <name>{}</name>
            {}
        </interface>""".format(name, interface_state))
开发者ID:stephanerobert,项目名称:netman,代码行数:7,代码来源:base.py

示例13: m

 def m():
     return to_ele("""
         <vlans>
             <vlan>
                 <name>%s</name>
             </vlan>
         </vlans>
     """ % vlan_name)
开发者ID:mlecours,项目名称:netman,代码行数:8,代码来源:base.py

示例14: _matches

 def _matches(self, other):
     otherxml = other if not isinstance(other, basestring) else to_ele(other)
     try:
         self.compare_nodes(self.expected, otherxml)
         return True
     except AssertionError as e:
         self.last_error = e
         return False
开发者ID:emmurd,项目名称:fake-switches,代码行数:8,代码来源:netconf_protocol_test.py

示例15: m

 def m():
     return to_ele("""
         <vlans>
             <vlan>
                 <vlan-id>{}</vlan-id>
             </vlan>
         </vlans>
     """.format(vlan_id))
开发者ID:stephanerobert,项目名称:netman,代码行数:8,代码来源:base.py


注:本文中的ncclient.xml_.to_ele函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。