cisco devnet series · hostess: kara sullivan | cisco networking academy 14 september 2017 session...

38
Speaker: Matt Denapoli Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series

Upload: others

Post on 26-Mar-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Speaker: Matt Denapoli

Hostess: Kara Sullivan | Cisco Networking Academy

14 September 2017

Session 2: Introduction to Coding

Cisco DevNet Series

Page 2: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

2© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Welcome to the 2nd session of the

Cisco DevNetwebinar series

• Use the Q and A panel to ask questions.

• Use the Chat panel to communicate with attendees and panelists.

• A link to a recording of the session will be sent to all registered attendees.

• Please take the feedback survey at the end of the webinar.

Page 3: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

3© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Matt DenapoliDeveloper EvangelistDevNet, Cisco

Giuseppe CinqueManager for the Emerging TechnologiesNetAcad, Cisco

Joining You Today:

Page 4: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

THIRD SESSION:

Intent Networks

25 October – 9:00 A.M. PT

Register at: http://bit.ly/DevNetSession3

Next DevNet Session

Page 5: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Intro to Coding

September 2017

Solutions & Marketing

Giuseppe Cinque & Wadih Zaatar

Page 6: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

CarTelephone Router

The world is becoming connected and programmable

Page 7: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

This is the Digital Transformation

You can ernoll today to learn more http://bit.ly/IntroIoT

Page 8: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

WHERE THE NETWORK

IS PROGRAMMABLE

Page 9: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

DevNet Developer Evangelist

Matthew DeNapoli

Intro to CodingModule 01

Page 10: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

10© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Agenda

Getting Started

Learning APIC-EM

APIC-EM with Postman – HTTP Calls & Generate Code

Calling APIC-EM REST APIs with Python

Q&A

Page 11: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

11© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Learning APIC-EM

Page 12: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

• Easy QoS

• Application Priority

• Plug-n-Play

• Agent based control

• IWAN

• Policy based automated deployment

• Path Trace

• Path troubleshooting

APIC-EM Applications and Use Cases

Page 13: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

APIC-EM Uses REST

13

• Hosts

• Devices

• Users

• + more

Easy to use:

• In mobile apps

• In console apps

• In web apps

How does this work?

Cisco APIC-EM REST APIs

Page 14: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Anatomy of a REST Request

14

Method

– POST, GET, PUT, DELETE (CRUD)

URL

– Example: http://{APIC-EMController}/api/v1/host

Authentication

– Basic HTTP, OAuth, none, Custom

Custom Headers

– HTTP Headers

– Example: Content-Type: application/json

Request Body

– JSON or XML containing data needed to complete request

Page 15: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

APIC-EM Example: Post Ticket

15

3rd Party

App

POST http://{APIC-EMController}/api/v1/ticket

Authorization Code returned in JSON

Application Policy Infrastructure Controller (APIC) Enterprise Module (EM)

Request

Response

Page 16: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

APIC-EM Example: Get Host

16

3rd Party

App

GET http://{APIC-EMController}/api/v1/host

List of Hosts returned in JSON

Application Policy Infrastructure Controller (APIC) Enterprise Module (EM)

Request

Response

Page 17: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Using the API Reference Documentation

Page 18: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

API Reference Guide Details

Page 19: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

19© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

APIC-EM with Postman

Page 20: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

https://www.getpostman.com

Page 21: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Postman

Page 22: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Create a ticket

22

Request body

method url

Page 23: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Header Specification

23

Header Key Header Value

Page 24: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Ticket Returned in Response Body

24

Response Ticket

(save this)

Page 25: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Use ticket in Header in all API Calls

25

Header Ticket

Page 26: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

APIC-EM – List of Hosts

26

Header

URL

Method

Response

Body

Return Code

Page 27: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Using Postman to Generate Code

Page 28: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Selecting the Code to Generate

Page 29: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Generated Python Requests Code

Page 30: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

REST Demo – Using Postman

30

Get Hosts– Method: GET– Headers: ‘X-Auth-Token’ (insert your ticket value)– URL: http://<APIC-EMController>/api/v1/host

Get Devices– Method: GET– Headers: ‘X-Auth-Token’ (insert your ticket value)– URL: http://<APIC-EMController>/api/v1/network-device

Get Users– Method: GET– Headers: ‘X-Auth-Token’ (insert your ticket value)– URL: http://<APIC-EMController>/api/v1/user

Page 31: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

31© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

APIC-EM with Python

Page 32: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

First APIC-EM REST call from Python

32

import requests

import json

url = 'https://198.18.129.100/api/v1/ticket’

payload = {"username":“admin","password":"C1sco12345"}

header = {"content-type": "application/json”}

response= requests.post(url,data=json.dumps(payload), headers=header, verify=False)

print(response.text)

Page 33: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Getting Ticket Function

apic_em_ip = "https://198.18.129.100/api/v1"

def get_token(url):

api_call = "/ticket"

payload = {"username": "admin", "password": "C1sco12345"}

headers = {"content-type": "application/json"}

url += api_call

response = requests.post(url, data=json.dumps(payload),

headers=headers, verify=False).json()

return response["response"]["serviceTicket"]

Page 34: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

Getting Network Device ID/Config Functions

def get_device_id(token, url):

api_call = "/network-device"

headers = {"X-AUTH-TOKEN": token}

url += api_call

response = requests.get(url, headers=headers, verify=False).json()

for item in response['response']:

if item['role'] == 'ACCESS':

return item['id']

Page 35: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

35© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Q&A

Page 36: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

36© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

This is the Digital Transformation

You can ernoll today to learn more http://bit.ly/IntroIoT

Page 37: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header

THIRD SESSION:

Intent Networks

25 October – 9:00 A.M. PT

Register at: http://bit.ly/DevNetSession3

Next DevNet Session

Page 38: Cisco DevNet Series · Hostess: Kara Sullivan | Cisco Networking Academy 14 September 2017 Session 2: Introduction to Coding Cisco DevNet Series ... Header Specification 23 Header