Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »


https://www.juniper.net/documentation/en_US/junos-pyez/topics/reference/general/junos-pyez-configuration-process-and-data-formats.html



4 steps
  1. Lock the configuration using lock()

  2. Modify the configuration by performing one of the following actions:

  3. Commit the configuration using commit(), as described in Committing the Configuration and Using Junos PyEZ to Commit the Configuration

  4. Unlock the configuration using unlock()


set interface xxx disable
from jnpr.junos import Device
from jnpr.junos.utils.config import Config

dev = Device(host='dc1a1.example.com').open()
with Config(dev, mode='private') as cu:  
    cu.load('set interface ge-0/0/7 disable', format='set')
    cu.pdiff()
    cu.commit()

dev.close()

rpc command
labuser@saltsackmaster:~/project/python_script$ more disable_int.py
from jnpr.junos import Device
from jnpr.junos.utils.config import Config
from pprint import pprint
 
junos_hosts = [ '172.30.95.177' ]
 
for ip in junos_hosts:
 
    ## open session with juniper device
    dev = Device(host=ip, user='Netbox', password='Netbox')
    dev.open()
 
    ## Add or bound the configuration instance variable to the dev instance
    dev.bind(cu=Config)
 
    ## change config
    cmd_chg_hostname='set interfaces xe-0/0/10 disable'
    #cmd_chg_hostname='delete interfaces xe-0/0/10 disable'
    result = dev.cu.load(cmd_chg_hostname,format='set')
    pprint (result)
    dev.cu.pdiff()
 
    ## commit changes
    dev.cu.commit()
    ## close the session
    dev.close()


rpc command
jcluser@ubuntu:/var/local/healthbot/input$ more generic_functions.py

import sys
import requests
from jnpr.junos.device import Device
from pprint import pprint

prev_value = {}
prev_time = {}
previous_time = {}

# for value function
prev_bps = {}
previous_value = {}


#UDF

#Restart both the RE's
def reboot_both_routing_engines(**kwargs):
        device_details = get_device_info(**kwargs)
        dev = connect_to_device(**device_details)
        response = dev.rpc.request_reboot(both_routing_engines = True)
        dev.close()
        return response
#Restart the other RE's
def reboot_other_routing_engine(**kwargs):
        device_details = get_device_info(**kwargs)
        dev = connect_to_device(**device_details)
        response = dev.rpc.request_reboot(other_routing_engine = True)
        dev.close()
        return response

#Restart the other RE's
def disable_interface(**kwargs):
        device_details = get_device_info(**kwargs)
        dev = connect_to_device(**device_details)
        cmd_chg_hostname='set interfaces ge-0/0/7 disable'
        #cmd_chg_hostname='delete interfaces xe-0/0/7 disable'
        response = dev.rpc.load(cmd_chg_hostname,format='set')
		dev.rpc.commit()
        dev.close()
        return response








  • No labels