Skip to content

Latest commit

 

History

History
 
 

restconf_update_ipaddress

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Calling RESTCONF with Python

This example script uses the requests Python library to interact with a RESTCONF Agent.

This Python script leverages RESTCONF to:

  • retrieve a list of interfaces on a device
  • ask the user for the interface to configure
  • displays the interface IP information
  • asks user for new IP information
  • updates the IP address on the interface
  • displays the final IP information on the interface

This script has been tested with Python 3.5, however may work with other versions.

DevNet Sandbox

This script targets the RESTCONF DevNet Sandbox that leverages a CSR1000v as a target.

Find details on the Sandbox here.

To execute this script against a different device, update the variables that list the connectivity, management interface, and url_base for RESTCONF.

Requirements

Python

  • requests

Getting Started

  • Clone the Python Examples and change into the directory.

    git clone //github.com/CiscoDevNet/python_code_samples_network
    cd restconf_update_ipaddress
  • Create and activate a virtualenv

    virtualenv venv --python=python3.5
    source venv/bin/activate 
  • Install the requirements

    pip install -r requirements.text
  • Run the script

    $ python updateip.py
    
    # Output
    The router has the following interfaces:
    
      * GigabitEthernet1
      * GigabitEthernet2
      * GigabitEthernet3
    
    Which Interface do you want to configure? GigabitEthernet2
    GigabitEthernet2
    Starting Interface Configuration
    Name:  GigabitEthernet2
    IP Address:  101.101.10.10 / 255.255.255.0
    
    What IP address do you want to set? 9.9.9.9
    What Subnet Mask do you want to set? 255.255.255.0
    
    Ending Interface Configuration
    Name:  GigabitEthernet2
    IP Address:  9.9.9.9 / 255.255.255.0