Ejemplo n.º 1
0
def main():
    """Basic use example"""
    # create scrapli_netconf connection just like with scrapli, open the connection
    conn = NetconfScrape(**JUNOS_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) in the case of junos since its
    # just a config, not a model and we are filtering for things under `configuration` this has to
    # live in a single filter unlike iosxr
    result = conn.get_config(filters=CONFIG_FILTER)
    print(result.result)

    # get some operational data via "rpc" for juniper style rpc calls; note the `filter_` to
    # not reuse builtins
    result = conn.rpc(filter_=COMMIT_FILTER)
    print(result.result)

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

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

    # edit multiple config elements
    result = conn.edit_config(config=EDIT_MULTIPLE, 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()
Ejemplo n.º 2
0
from scrapli_netconf.driver import NetconfScrape
from mydevice import *

import logging
logging.basicConfig(level=logging.DEBUG)

xpath_filter = '''
<get>
<filter xmlns:t="http://cisco.com/ns/yang/Cisco-IOS-XE-ospf-oper" type="xpath" select="/ospf-oper-data/ospf-state/ospf-instance[af='address-family-ipv4' and router-id='168432911']" />
</get>
'''

conn = NetconfScrape(**router)
conn.open()
response = conn.rpc(filter_=xpath_filter)
print(response.result)
Ejemplo n.º 3
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()

rpc_filter = '''
<get>
  <filter xmlns:t="urn:ietf:params:xml:ns:yang:ietf-interfaces" type="xpath" select="/interfaces/interface[name='Vlan500']/description"/>
</get>
'''

response = conn.rpc(rpc_filter)
print(response.result)