0% found this document useful (0 votes)
112 views

Devnet Session 2 Intro To Coding

dfgzdfgdgdgdf

Uploaded by

Igo Fernandes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

Devnet Session 2 Intro To Coding

dfgzdfgdgdgdf

Uploaded by

Igo Fernandes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Cisco DevNet Series

Session 2: Introduction to Coding

Speaker: Matt Denapoli


Hostess: Kara Sullivan | Cisco Networking Academy
14 September 2017
• Use the Q and A panel to ask
questions.
• Use the Chat panel to
communicate with attendees
Welcome to the and panelists.
2nd session of the • A link to a recording of the
Cisco DevNet session will be sent to all
webinar series registered attendees.
• Please take the feedback
survey at the end of the
webinar.

© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2
Matt Denapoli
Joining Developer Evangelist
DevNet, Cisco

You
Giuseppe Cinque
Today: Manager for the Emerging
Technologies
NetAcad, Cisco

© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 3
Next DevNet Session
THIRD SESSION:

Intent Networks
25 October – 9:00 A.M. PT
Register at: http://bit.ly/DevNetSession3
Intro to Coding
Giuseppe Cinque & Wadih Zaatar

Solutions & Marketing


September 2017
Telephone Car Rou
ter

The world is becoming connected and programmable


This is the Digital Transformation

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


WHERE THE NETWORK
IS PROGRAMMABLE
Module 01

Intro to Coding

Matthew DeNapoli
DevNet Developer Evangelist
Agenda

Getting Started

Learning APIC-EM
APIC-EM with Postman – HTTP Calls &
Generate Code
Calling APIC-EM REST APIs with Python

Q&A

© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 10
Learning APIC-EM

© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 11
APIC-EM Applications and Use Cases
• Easy QoS
• Application Priority
• Plug-n-Play
• Agent based control
• IWAN
• Policy based automated deployment
• Path Trace
• Path troubleshooting
APIC-EM Uses REST
Easy to use:

• In mobile apps
• In console apps
• In web apps
Cisco APIC-EM REST APIs
• Hosts
• Devices
• Users
• + more
How does this work?

13
Anatomy of a REST Request
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

14
APIC-EM Example: Post Ticket
Application Policy Infrastructure Controller (APIC) Enterprise Module (EM)

POST http://{APIC-EMController}/api/v1/ticket
3rd Party
Request
App
Authorization Code returned in JSON

Response

15
APIC-EM Example: Get Host
Application Policy Infrastructure Controller (APIC) Enterprise Module (EM)

GET http://{APIC-EMController}/api/v1/host
3rd Party
Request
App
List of Hosts returned in JSON

Response

16
Using the API Reference Documentation
API Reference Guide Details
APIC-EM with Postman

© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 19
https://www.getpostman.com
Postman
Create a ticket

method url

Request body

22
Header Specification

Header Key Header Value

23
Ticket Returned in Response Body

Response Ticket
(save this)

24
Use ticket in Header in all API Calls

Header Ticket

25
APIC-EM – List of Hosts
URL

Method Header

Return Code

Response
Body

26
Using Postman to Generate Code
Selecting the Code to Generate
Generated Python Requests Code
REST Demo – Using Postman
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

30
APIC-EM with Python

© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 31
First APIC-EM REST call from Python
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)

32
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"]
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']
Q&A

© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 35
This is the Digital Transformation

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


© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 36
Next DevNet Session
THIRD SESSION:

Intent Networks
25 October – 9:00 A.M. PT
Register at: http://bit.ly/DevNetSession3

You might also like