Example #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()
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()