Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Created June 26, 2015 15:48
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/9a69287996b28cc08117 to your computer and use it in GitHub Desktop.
Save jeffbrl/9a69287996b28cc08117 to your computer and use it in GitHub Desktop.
PyEZ Configuration actions
#!/usr/bin/env python
import sys
from jnpr.junos.utils.config import Config
from jnpr.junos import Device
from jnpr.junos.exception import *
jdev = Device(user='jeffl', host='10.10.10.1', password='pass123')
jdev.open(gather_facts=False)
if(not jdev):
print "connectivity or credentials error"
sys.exit(1)
# Associate Config with Device
cu = Config(jdev)
# Lock the configuration, load configuration changes, and commit
print "Locking the configuration"
try:
cu.lock()
except LockError:
print "Error: Unable to lock configuration"
sys.exit(1)
print "Loading the config"
try:
cu.load( path="config-example.conf", format='set' )
except ConfigLoadError, e:
print e
sys.exit(1)
print "Checking the config"
try:
cu.commit_check()
except CommitError, e:
print e
sys.exit(1)
print "Committing the config"
try:
cu.commit()
except Exception, e: # RpcError or CommitError
print e
sys.exit(1)
print "Successfully committed config"
print "Here is the delta- "
response = cu.diff(rb_id=1)
if response is not None:
print response
else:
print "No change"
jdev.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment