Presentation is loading. Please wait.

Presentation is loading. Please wait.

Plugs: https://learninglabs.cisco.com Coding 101 Lab Coding 102 Lab

Similar presentations


Presentation on theme: "Plugs: https://learninglabs.cisco.com Coding 101 Lab Coding 102 Lab"— Presentation transcript:

1

2 Plugs: https://learninglabs.cisco.com Coding 101 Lab Coding 102 Lab
Use Coding 102 for system setup help: Chrome A text editor (text wrangler, notepad ++, sublime text etc.) Postman REST Client -- Python Go to command prompt and type python Install instructions -- Python Requests library --

3 More Plugs: learninglabs.cisco.com
Check these out

4 What We Know

5 Easier Network Element Management
REST / JSON is the answer of the day Customers Demand Easier Network Element Management

6 The Evolution of Device Interaction
Bootstrap Configure Extend Plug n Play PoAP Smart Install Auto Install CLI Controllers Openstack Puppet/Chef REST JSON RPC NETCONF CLI I2RS onePK OpenFlow Onbox Python EEM Evolving First – categorize the different APIs/protocols/frameworks into buckets. Some cross buckets, some enable technologies in other buckets, but in general, they are all optimized for particular kinds of tasks. Bootstrap – day one configuration Configure – into the capabilities of the network device Extending what you can do with the device. Dynamic programming, also sometimes used to do configuration Generally speaking optimized for extension Look from bottom up. CLI is tool of choice for bootstrap and configure. Middle bucket is where we want to concentrate on. By far the most things people want is a configurator, and to handle configuration tasks. Solve immediate pain points Traditional

7 REST Follows a Familiar Model
Web Browsing REST API Twitter: IDs of last five followers {"ids":[ , , , , , ], "next_cursor":0, "next_cursor_str":"0", "previous_cursor":0, "previous_cursor_str":"0"} HTTP GET HTTP GET HTML JSON/XML Here is an example of a rest call to twitter This is a real return value Describes how data should be displayed to please human viewer Describes data in a format applications can understand

8 REST is An Architectural Style (Not a protocol)
REST= REpresentational State Transfer Proposed by Roy Fielding in 2000 Developed by W3C in parallel with HTTP 1.1 Simple CRUD using HTTP Stateless client-server model Uses URIs to identify resources of interest Rest its an architectural style, it is not a protocol it is a suggestion on how to behave works over crud ( Create, Read, Update, Delete)

9 There Are LOTS of RESTful APIs
Thousands of programs use rest apis

10 Why Does This Matter for Networking?
Easy to use Why Does This Matter for Networking? Human Readable Software Friendly Large Developer Base Client Libraries in Many Languages Lot of people that can program rest Easy

11 REST: It’s Not Just for Web Services
Products and applications can consume restful apis Even at cisco Vmware ucs ucs-director, open daylight

12 REST: Coming Soon to a Device Near You
Supported on CSR1kV since XE 3.10 ASR1K in XE 3.14 Primarily for Config DNS, NTP, Interface, Routing, ACL, NAT Some Stats Interface, CPU, Memory Runs in a service container Uses onePK Python APIs under the hood Seeing experimentation on bringing rest apis to you Csr1kv Kind of limited now but being built out

13 Sample: Grab Hosts from APIC-EM
Application Policy Infrastructure Controller (APIC) Enterprise Module (EM) 3rd Party App Request Response 3rd Party App GET rec} List of Hosts returned in JSON Cisco APIC-EM Request Response

14 Anatomy of a REST Request
Method GET, POST, PUT, DELETE URL Example: Authentication Basic HTTP, OAuth, none Custom Headers HTTP Headers Example: Content-Type: application/json Request Body JSON or XML containing data needed to complete request JSON -- JavaScript Object Notation, is a lightweight text-based open standard designed for human-readable data interchange.

15 And what is in the Response?
HTTP Status Codes 200 OK 201 Created 500 Internal Error Headers Body JSON XML

16 REST in Action: How can I try it?
HTTP clients can help you quickly test web services Postman - Firefox RestClient - https://addons.mozilla.org/en-US/firefox/addon/restclient/ Command Line using curl - SOAPUI Many IDEs have consoles for testing REST Services built in

17

18 Cost

19 REST Demo – Using Postman

20 REST Demo – Using Postman

21 REST Demo – Using Postman
Get Hosts Method: GET URL: Get Devices URL: Get Policies URL: Get Applications URL:

22 REST DEMO – Using the POST or PUT Method
To send data to a REST service and either create or update data, you will need to use POST or PUT. Create Policy Example Method: POST URL: Custom Headers: Content-Type: application/json Request Body: JSON that specifies details of new policy What if the Content-Type header is missing? What if there is a mistake in the JSON Request Body? Handy tool for validating JSON --

23 REST Demo – Using POST or PUT Method
Show what happens if you forget the Content-Type Header

24 First REST call from Python
Source code file: apic-em1.py #import requests library import requests #specify URL url = 'http://Your-API-EM-Controller/api/v0/host’ #Call REST API response = requests.get(url) #Print Response print response.text More info on requests library -

25 Python Examples Download Sample Code https://github.com/CiscoDevNet/coding-skills-sample-code Coding 102 apic-em1.py – simple example to get list of hosts apic-em-helloworld.py – “hello world” type example to show list of devices learning-lab-basics.py – Retrieves device list and pretty prints JSON learning-lab-basics-step2.py – Retrieves network device list and parses JSON to display networkDeviceId values learning-lab-basics-step3.py – Retrieves and lists all devices, hosts, policies and configured applications learning-lab-create-policy.py – Shows how to create a new policy using the POST Method

26 AD-HOC REST (REST like) Interface
Leverage existing automation technology Brownfield

27 Bonus JSON-RPC

28 Comparison: REST/JSON-RPC Similar: Both Send/Receive JSON over HTTP
JSON-RPC (N9K NX-API) REST (CSR 1000v) Both send and receive json over http Sometimes they seem the same Differences are not that important

29 Comparison: REST/JSON-RPC Different: Resources (URIs)
REST: Many Resources https:// /api/v1… …/global/banner …/global/hostname …/global/reload …/interfaces/… …/routing-svc/… …/nat-svc/… …/acl/… JSON-RPC: Few Resources https:// /ins Differences between them Rest operates on the idea of these different resources acls/interfaces… Resources for each thing you want to do Json has much fewer resources CSR1kV N9K

30 Different: Methods GET: Retrieve/List PUT: Replace
REST: Standard HTTP Methods GET: Retrieve/List PUT: Replace POST: Create New Entry DELETE: Delete JSON-RPC: POST + body method Rest only uses standard http methods Json rpc uses post. And puts information in the body of what you should do

31 JSON-RPC Details A very simple remote procedure call protocol encoded in JSON, sent over HTTP JSON RPC Request Properties method – (string) name of the method to be invoked. params – (array) objects to be passed as parameters to the defined method. Id – (any type) used to match the response with request JSON RPC Response Properties result - data returned by the invoked method. error - specified Error code if there was an error invoking the method, otherwise null. id - id of the corresponding request.

32 NXAPI Switch# conf t Switch(config)# feature nxapi
CLI Interaction with device over HTTP / HTTPS Input/Output encoded in JSON or XML (key for programmability) [ { "jsonrpc": "2.0", "method": "cli", "params": { "cmd": "show clock", "version": 1 }, "id": 1 } ] Show clock NXAPI Web Server (NGINX) Switch# conf t Switch(config)# feature nxapi Switch(config)# exit HTTP / HTTPS { "jsonrpc": "2.0", "result": { "body": { "simple_time": "15:00: PST Mon Aug \n" } }, "id": 1

33 NXAPI – Web Sandbox Point browser to IP Address of Network Element
Enter CLI Commands See formatted input and output

34 NXAPI – Python Generation
Click on the Python button, and the tool will generate python Interaction code for you.


Download ppt "Plugs: https://learninglabs.cisco.com Coding 101 Lab Coding 102 Lab"

Similar presentations


Ads by Google