def main():
    # create scrapli_netconf connection just like with scrapli, open the connection
    conn = NetconfScrape(**IOSXR_DEVICE)
    conn.open()

    # lock the candidate config before starting because why not
    result = conn.lock(target="candidate")
    print(result.result)

    # get the whole config; just like scrapli the result is a `Response` object, in this case a
    # `NetconfResponse` object with some additional methods
    result = conn.get_config()
    # print xml text result
    print(result.result)
    # print xml element result
    print(result.xml_result)

    # get the whole config, but apply some filters (subtree filters)
    filters = [INTERFACE_ACTIVE_FILTER, NETCONF_YANG_FILTER]
    result = conn.get_config(filters=filters)
    print(result.result)

    # get something other than the config; note the `filter_` to not reuse builtins
    result = conn.get(filter_=PLATFORM_FILTER)
    print(result.result)

    # edit the candidate configuration
    result = conn.edit_config(config=EDIT_CDP, target="candidate")
    print(result.result)

    # commit config changes
    conn.commit()
    print(result.result)

    # stage a config we'll discard
    config = EDIT_BANNER
    result = conn.edit_config(config=config, target="candidate")
    print(result.result)

    # discard this config change
    result = conn.discard()
    print(result.result)

    # unlock the candidate now that we're done
    result = conn.unlock(target="candidate")
    print(result.result)

    # close the session
    conn.close()
Пример #2
0
from scrapli_netconf.driver import NetconfScrape

my_device = {
    "host": "sandbox-iosxe-latest-1.cisco.com",
    "auth_username": "******",
    "auth_password": "******",
    "auth_strict_key": False,
    "port": 830
}

conn = NetconfScrape(**my_device)
conn.open()

ospf_xpath = '/ospf-oper-data/ospf-state/ospf-instance[af="address-family-ipv4" and router-id="235802126"]/ospf-area[area-id=599]/ospf-interface[name="Loopback14"]'
response = conn.get(filter_=ospf_xpath, filter_type='xpath')
print(response.result)
Пример #3
0
# conn = NetconfScrape(**my_device)
# conn.open()
# result = conn.edit_config(config=template, target="running")
# print(result.result)

filter_ = """
  <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
    <interface>
        <name>GigabitEthernet3</name>
    </interface>
  </interfaces>
"""

conn = NetconfScrape(**my_device)
conn.open()
response = conn.get(filter_=filter_, filter_type="subtree")
print(response.result)

# template = f"""
#   <config>
#     <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
#       <interface>
#         <name>{name}</name>
#         <description>{descr}</description>
#         <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:ethernetCsmacd</type>
#         <enabled>true</enabled>
#         <ipv4 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
#           <address operation="delete">
#             <ip>{ip_addr}</ip>
#             <netmask>{netmask_addr}</netmask>
#           </address>
Пример #4
0
    "host": "sandbox-iosxe-latest-1.cisco.com",
    "auth_username": "******",
    "auth_password": "******",
    "auth_strict_key": False,
    "port": 830
}

conn = NetconfScrape(**my_device)
conn.open()

ospf_filter = """
<ospf-oper-data xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf-oper">
  <ospf-state>
    <ospf-instance>
        <af>address-family-ipv4</af>
        <router-id>235802126</router-id>
          <ospf-area>
            <area-id>599</area-id>
            <ospf-interface>
               <name>Loopback14</name>
            </ospf-interface>
          </ospf-area>
    </ospf-instance>
  </ospf-state>
</ospf-oper-data>
"""

response = conn.get(
    filter_=ospf_filter, filter_type='subtree')
print(response.result)
Пример #5
0
from scrapli_netconf.driver import NetconfScrape

my_device = {
    "host": "10.10.20.100",
    "auth_username": "******",
    "auth_password": "******",
    "auth_strict_key": False,
    "port": 830
}

conn = NetconfScrape(**my_device)
conn.open()

interface_filter_xpath = '/interfaces/interface[name="Vlan500"]/description'

response = conn.get(filter_=interface_filter_xpath, filter_type='xpath')
print(response.result)
Пример #6
0
from scrapli_netconf.driver import NetconfScrape
from mydevice import *

import logging

logging.basicConfig(level=logging.DEBUG)

eigrp_filter = '/eigrp-oper-data/eigrp-instance/eigrp-topo/eigrp-network[afi="eigrp-af-ipv4" and ip-prefix="192.168.10.0/24"]/rd-vecmetric'
ospf_filter = '/ospf-oper-data'

conn = NetconfScrape(**router)
conn.open()
response = conn.get(
    filter_=ospf_filter,
    filter_type='xpath',
)
print(response.result)
Пример #7
0
from scrapli_netconf.driver import NetconfScrape

my_device = {
    "host": "10.10.20.100",
    "auth_username": "******",
    "auth_password": "******",
    "auth_strict_key": False,
    "port": 830
}

conn = NetconfScrape(**my_device)
conn.open()

interface_filter = """
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"  xmlns:if="urn:ietf:params:xml:ns:yang:ietf-interfaces">
  <interface>
    <name>Vlan500</name>
    <description></description>
  </interface>
</interfaces>
"""

response = conn.get(filter_=interface_filter, filter_type='subtree')
print(response.result)
Пример #8
0
from scrapli_netconf.driver import NetconfScrape
my_device = {
    "host": "10.10.10.2",
    "auth_username": "******",
    "auth_password": "******",
    "auth_strict_key": False,
    "port": 830
}
conn = NetconfScrape(**my_device)
conn.open()
response = conn.get(
    filter_='//eigrp-network[ip-prefix="192.168.10.0/24"]/rd-vecmetric',
    filter_type="xpath")
print(response.result)