Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Created March 17, 2017 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffbrl/ee324dc9d7d2523f5c45bfafd14ee4e8 to your computer and use it in GitHub Desktop.
Save jeffbrl/ee324dc9d7d2523f5c45bfafd14ee4e8 to your computer and use it in GitHub Desktop.
Using PyEZ's get_config RPC
# This gist demonstrates how to use PyEZ's get_config RPC
from jnpr.junos import Device
from lxml import etree
def example_one(dev):
# This uses default options
cnf = dev.rpc.get_config()
print etree.tostring(cnf)
def example_two(dev):
# You can use a dict to specify parameters from
# https://www.juniper.net/documentation/en_US/junos/topics/reference/tag-summary/junos-xml-protocol-get-configuration.html
options = {'database':'candidate', 'format': 'text'}
cnf = dev.rpc.get_config(options=options)
print cnf.xpath('//configuration-text')[0].text
def example_three(dev):
# Using filters
cnf = dev.rpc.get_config(filter_xml=etree.XML('<configuration><interfaces/></configuration>'))
print etree.tostring(cnf)
if __name__ == '__main__':
dev = Device(host='router', port=22, gather_facts=False)
dev.open()
example_one(dev)
example_two(dev)
example_three(dev)
dev.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment