28
Santiago Álvarez March 2017 YANG Development Kit (YDK) Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

Embed Size (px)

Citation preview

Page 1: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

Santiago Álvarez

March 2017

YANG Development Kit (YDK)

Simplifying Network Automation Using Python Model-Driven APIs

@111pontes

@111pontes

Page 2: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

• Speed and scale demand software automation and data analytics

• Rapid innovation as competitive advantage

• One network operator per 1000s / 10000s of complex network devices

Motivations for Network Programmability

Page 3: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

Encoding XML JSON GPB

Protocol NETCONF gRPCRESTCONF

Model-Driven Programmability Stack

Models

APIs

Apps

Model-Driven APIs

YANG Development Kit (YDK)

YANG Models

(native, open)

App1 App2 App3

SSH HTTPTransport

Model-Driven

Configuration

Model-Driven

Telemetry

Page 4: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

• Model based, structured, computer friendly

• Multiple model types (native, common, OpenConfig, IETF, etc.)

• Models decoupled from transport, protocol and encoding

• Choice of transport, protocol and encoding

• Model-driven APIs for abstraction and simplification

• Wide standard support while leveraging open source

Benefits of Model-Driven Programmability

Page 5: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

• Model structures data (config, operational and RPC/actions) as a tree

• Models files are self-documented and ship with devices

• Cisco IOS XR supports ~250 YANG models (native and OpenConfig) in release 6.1.2

• OpenConfig support includes BGP, routing policy, interfaces, MPLS, telemetry and VLAN

• Native models provide most coverage

• OpenConfig models are mapped to native models

XR Data Models

Native / Common OpenConfig / IETF

Page 6: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

• Modeling language for network devices

• Main node types

• Leaf – node with name and value of certain type (no children)

• Leaf list – sequence of leafs

• Container – groups nodes and has no value

• List – Sequence of records with key leafs

• Augmentations extend a model

• Deviations specify divergence from model

YANG

Leaf

Node without a value

Node with a value

Leaf list

Container List

key

Page 7: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

YANG Model Example

container community-sets {description “Container for community sets";list community-set {

key community-set-name;description "Definitions for community sets";leaf community-set-name {

type string;description "name of the community set";

}leaf-list community-member {

type string {pattern '([0-9]+:[0-9]+)';

}description "members of the community set";

}}

}

community-setscommunity-set C-SET165172:1,65172:2,65172:3

!community-set C-SET1065172:10,65172:20,65172:30

!!

YANG CLI

Page 8: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

Model Data Example

<community-sets><community-set>

<community-set-name>C-SET1</community-set-name><community-member>65172:1</community-member><community-member>65172:2</community-member><community-member>65172:3</community-member>

</community-set><community-set>

<community-set-name>C-SET10</community-set-name><community-member>65172:10</community-member><community-member>65172:20</community-member><community-member>65172:30</community-member>

</community-set></community-sets>

community-setscommunity-set C-SET165172:1,65172:2,65172:3

!community-set C-SET1065172:10,65172:20,65172:30

!!

XML CLI

Page 9: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

• Simplify app development

• Abstract protocol, transport, encoding, modeling language

• API generated from YANG model

• One-to-one correspondence between model and class hierarchy

• Rich data validation

• Multi-language (Python, C++, Ruby, Go, etc.)

Model-Driven APIs

9

YANG ModelClass Hierarchy

(Python, C++, Ruby, Go)

Page 10: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

Generation of Model-Driven APIs Using YANG Development Kit (YDK)

YAN

G

YANG

YANG

Data

Models

(YANG)

API

Generator

DocsPython

C++

: :

Ruby

go

Docs

Docs

Docs

C♯ Docs

YDK-gen

YDK-Py

YDK

YDK-Cpp

Page 11: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

• Client will automatically perform local validation based on model constraints

• Check between config (read-write) and state (read-only)

• Type check (enum, string, etc.)

• Value check (range, pattern, etc.)

• Semantic check (key uniqueness/presence, mandatory leafs, etc.)

• Model deviation check (unsupported leafs, etc.)

YDK Client-Side Validation

Application

(client)

Device

(server)

Page 12: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

YDK API Structure

Models(BGP, IS-IS, etc)

Services(CRUD, NETCONF, Codec, Executor, etc.)

Providers(NETCONF, Codec, etc.)

• Models group Python APIs created for each YANG model

• Services perform operations on model objects (interface)

• Providers implement services (implementation)

Page 13: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

ydk.services

YDK-Py 0.5.0 Package Structure (Bundles)

ydk.models.cisco_ios_xr

ydk.providers

ydk.types

ydk.errors

ydk.models.openconfig

ydk.models.ietf

Cisco IOS XR

Core

OpenConfig

IETF

Page 14: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

# Cisco YDK-Py OC-BGP “Hello world”from ydk.services import CRUDServicefrom ydk.providers import NetconfServiceProviderfrom ydk.models.openconfig import openconfig_bgp as oc-bgp

if __name__ == "__main__":provider = NetconfServiceProvider(address=10.0.0.1,

port=830,username=“admin”,password=“admin”,protocol=“ssh”)

crud = CRUDService() # create CRUD servicebgp = oc_bgp.Bgp() # create oc-bgp objectbgp.global_.config.as_ = 65000 # set local AS numbercrud.create(provider, bgp) # create on NETCONF deviceprovider.close()exit()

# End of script

A YDK-Py “Hello World” Using OC-BGP

module: openconfig-bgp+--rw bgp!

+--rw global| +--rw config| | +--rw as| | +--rw router-id? | +--ro state| | +--ro as| | +--ro router-id? | | +--ro total-paths? | | +--ro total-prefixes?

...

Page 15: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

CRUD service

NETCONF provider

NETCONF service

Codec service

deviations

Service improvements

Better error handling

Bundles

(core, XR, OC, IETF)

Releases

C++ support

Bundle updates

0.3.0

Mar 2016

0.4.0

Apr 2016

0.4.1

May 2016

0.4.2

Jun 2016

0.5.0

Aug 2016

https://github.com/CiscoDevNet/ydk-gen/releases

Python 3

Bundle

updates

0.5.1

Oct 2016

0.5.2

Dec 2016

0.5.3

Jan 2017

RESTCONF

OpenDaylight

Page 16: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

• Additional providers (e.g. Google RPC, Cisco NSO)

• Additional services (e.g. GNMI)

• Additional languages (e.g. Go, Ruby, Java)

• Additional encodings (e.g. GPB)

• Telemetry support

• Model-mapping support

Future Work Items

Page 17: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

Accessing YDK-Py

Native Virtual Cloud

Install Python

Install YDK

Install Vagrant

Install Virtualbox

Download ydk-py-samplesYANG Development Kit Sandbox

Page 18: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

GitHub

• YDK Python API – YDK-Py (https://git.io/vaWsg)

• YDK-Py sample apps (https://git.io/vaw1U)

• YDK C++ API – YDK-Cpp (https://git.io/v1Cst) - alpha

• YDK-Cpp sample apps (https://git.io/v14Qh)

• YDK Generator – YDK-gen (https://git.io/vaw1M)

YDK Documentation

• YDK-Py docs (http://ydk.cisco.com/py/docs)

• YDK-Cpp docs (http://ydk.cisco.com/cpp/docs)

Resources (cont.)

18

Page 19: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

YDK Portal

• YDK at DevNet (https://goo.gl/Wqwp3C)

YDK Sandboxes

• Ubuntu YDK-Py Vagrant box (https://git.io/vaw1U)

• Ubuntu YDK-Cpp Vagrant box (https://git.io/v14Qh) – coming soon

YDK Support

• Cisco support community (https://communities.cisco.com/community/developer/ydk)

Resources (cont.)

19

Page 20: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

Conferences

• NANOG 68: Ok, We Got YANG Data Models. Now What? (http://youtu.be/2oqkiZ83vAA )

• LinuxCon NA 2016: Simplifying Network Programmability Using Model-Driven APIs (https://goo.gl/W6tH2X)

Resources (cont.)

20

Page 21: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

Demo

Page 22: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

dCLoud Sandbox

R2R1

Out-of-band

network

lo0

172.16.255.1/32

g0/0/0/0

172.16.1.0/31

lo0

172.16.255.2/32

IS-IS L2 (Area 49.0001)

198.18.1.254/24

198.18.1.12/24

g0/0/0/0

172.16.1.1/31

198.18.1.11/24

NETCONF NETCONF

Controller

YDK

Page 23: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

Backup

Page 24: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

• Install command line tools – xcode-select --install

• Install homebrew – http://brew.sh

• Install Python/PIP – brew install python

• Install YDK dependencies – brew install pkg-config libssh xml2 curl pcre

• Clone YDK-Py – git clone https://github.com/CiscoDevNet/ydk-py.git

Preparing for Manual Installation of YDK-Py(MacOS)

Page 25: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

Ubuntu (debian-based)

• Install Python/PIP extensions – sudo apt-get install python-pip python-lxmlpython-dev

• Install YDK dependencies – sudo apt-get install zlib1g-dev libxml2-dev libxslt1-dev

• Clone YDK-Py – git clone https://github.com/CiscoDevNet/ydk-py.git

Centos (Fedora-based)

• Install Python/PIP extensions – sudo yum install python-pip python-devel

• Install YDK dependencies – sudo yum install epel-release libxml2-devel libxslt-devel libcurl-devel libtool

• Clone YDK-Py – git clone https://github.com/CiscoDevNet/ydk-py.git

Preparing for Manual Installation of YDK-Py(Linux)

Page 26: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

• Install Git – https://git-scm.com/download/win

• Install Python :https://www.python.org/downloads/windows/

• Add Python to PATH – C:\Python27\;C:\Python27\Scripts\

• Download PIP install script – https://bootstrap.pypa.io/get-pip.py

• Install PIP – python get-pip.py

• Install Microsoft Visual C++ Compiler for Python - https://goo.gl/ujGcY0

• Clone YDK-Py – git clone https://github.com/CiscoDevNet/ydk-py.git

Preparing for Manual Installation of YDK-Py(Windows)

Page 27: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes

[email protected]

• Clone YDK-Py –

git clone https://github.com/CiscoDevNet/ydk-py.git

• Install YDK core package

cd core

python setup.py sdist

pip install dist/ydk*.gz

• Install IETF bundle

cd ../ietf

python setup.py sdist

pip install dist/ydk*.gz

• Install OpenConfig bundle

cd ../openconfig

python setup.py sdist

pip install dist/ydk*.gz

• Install Cisco-IOS-XR bundle

cd ../cisco-ios-xr

python setup.py sdist

pip install dist/ydk*.gz

Installing YDK

Page 28: Simplifying Network Automation Using Python …dfw.cisco-users.org/zips/20170301_DFWCUG_YDK... · Simplifying Network Automation Using Python Model-Driven APIs @111pontes @111pontes