Giter Club home page Giter Club logo

devnet-1229's Introduction

Exploring Network Programmability with Python and YANG

Intro

Welcome to the lab, this guide will help you get started programming network devices using YANG and Python over gRPC. Using YANG and Python, the network is easier to program and configuration is more predictable.

Get the environment set up.

  1. Download the Github

    git clone http://www.github.com/skkumaravel/devnet-1229

  2. cd into directory and start the vagrant box.

    cd devnet-1229 && vagrant up

  3. Install python gRPC library

    pip install iosxr_grpc

Create your first gRPC call.

  1. Open up a new file called example.py in your favorite editor and add the following code.
from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient
from grpc.framework.interfaces.face.face import AbortionError


def main():
    client = CiscoGRPCClient('127.0.0.1', 57777, 10, 'vagrant', 'vagrant')
    path = ''
    try:
        err, result = client.getconfig(path)
        if err:
            print(err)
        print(result)
    except AbortionError:
        print('Unable to connect to local box, check your gRPC destination.')


if __name__ == '__main__':
    main()
  1. Run it.

    python example.py

You should get the config of the entire box in yang format.

Changing an interface

  1. Test basic connectivity

    1. vagrant ssh devbox
    2. ping 11.1.1.10
    3. exit
  2. Change the path to the interface YANG path in example.py.

    path = '{"openconfig-interfaces:interfaces": {}}'

  3. Lets run the output to a file and look at it.

    python example.py > interface.json

  4. Lets turn off a interface. Edit interface.json and change gig 0/0/0/0 enabled to false.

        "name": "GigabitEthernet0/0/0/0",
        "config": {
         "name": "GigabitEthernet0/0/0/0",
         "type": "iana-if-type:ethernetCsmacd",
         "enabled": false
        },
  5. Create merge.py and add the following code. This will allow you to open a file and merge the config in.

    from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient
    from grpc.framework.interfaces.face.face import AbortionError
    
    
    def main2():
        client = CiscoGRPCClient('127.0.0.1', 57777, 10, 'vagrant', 'vagrant')
        path = open('interface.json').read()
        try:
            err = client.mergeconfig(path)
            if err:
                print(err)
        except AbortionError:
            print('Unable to connect to local box, check your gRPC destination.')
    
    if __name__ == '__main__':
        main2()
  6. Run the program to merge the config.

    python merge.py

  7. Test connectivity again.

    1. vagrant ssh devbox
    2. ping 11.1.1.10
    3. exit

Conclusion

There are a lot more configuration options available in the library that can be used with automation.

Check out:

devnet-1229's People

Contributors

brmcdoug avatar dcarrier avatar remingtonc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.