Você está na página 1de 19

Introduction to Python Network Programming

for Network Architects and Engineers

Vince Kelly TSA


Session ID: DEVNET-1042
Agenda

Examples that use upper layer services


Creating spreadsheets with openpyxl
The Higher Layer Protocols & APIs: First, XMLRPC

ACI APIC Firefox XMLRPC


Browser

Requests
module
Python Higher Layer Libraries
HTTP, etc.
TCP/IP PROTOCOL STACK

Web FTP Telnet SMTP SNMP DNS


80 20,21 23 25 161 53
Socket Library
Python

TCP UDP

IP

Device Drivers
Framer/
Protocol
B decode
Tx U Rx
Buffers S Buffers

LAYER 1 NIC
DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 5
Building A Spreadsheet Primer

http://openpyxl.readthedocs.io/en/default/changes.html

Spreadsheet Follow Along:


followCreateSpreadsheet.py Creates an openpyxl spreadsheet, sets col width, adds values
followExistingSpreadsheet.py Opens an existing spreadsheet and adds values to it at the highest row
followRetrieveSpreadsheet.py Retrieves information from a spreadsheet

DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 6
XMLRPC

XMLRPC

Higher Layer Libraries


Socket Library
HTTP, etc.
Python
TCP/IP PROTOCOL STACK

TCP UDP

IP

Device Drivers
Framer/
Protocol
B decode
Tx U Rx
Buffers S Buffers

LAYER 1 NIC
DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 7
http://openpyxl.readthedocs.io/en/default/changes.html

Spreadsheet Follow Along:


followXMLRPC_Client.py Requests the current working directory from a remote machine
followXMLRPC_Server.py Executes an os.dirlist()
followXMLRPC_Client.py Creates and retrieves spreadsheet info on a remote machine
followXMLRPC_Server2.py Opens an existing spreadsheet and adds values to it at the highest row
How do we tell if someone messed with our file?

DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 8
The Higher Layer Protocols: Next, REST & HTTP

ACI APIC Firefox XMLRPC


Browser

Requests
module
Python Higher Layer Libraries
HTTP, etc.
TCP/IP PROTOCOL STACK

Web FTP Telnet SMTP SNMP DNS


80 20,21 23 25 161 53
Socket Library
Python

TCP UDP

IP

Device Drivers
Framer/
Protocol
B decode
Tx U Rx
Buffers S Buffers

LAYER 1 NIC
DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 9
REST and HTTP

HTTP Follow Along:


followHTTP_Google.py Send a REST Request to Google using sockets
followScreenScrape.py Screen Scrape ww.cisco.com using Python urllib
followHTTP_WebServer.py Pretend we are an Apache Web Server using sockets

DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 10
TCP Send a REST Request to Google
followHTTP_Google.py

import socket

# sends and receives an HTTP GET header to google

c=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

c.connect(('www.google.com',80))

c.sendall('GET / HTTP/1.0\r\n\r\n')

result = c.recv(65535)

c.close()

for line in result.split('\n'):


print line

DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 11
The Higher Layer Protocols: Next, REST & HTTP

ACI APIC Firefox XMLRPC


Browser

Requests
module
Python Higher Layer Libraries
HTTP, etc.
TCP/IP PROTOCOL STACK

Web FTP Telnet SMTP SNMP DNS


80 20,21 23 25 161 53
Socket Library
Python

TCP UDP

IP

Device Drivers
Framer/
Protocol
B decode
Tx U Rx
Buffers S Buffers

LAYER 1 NIC
DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 12
APIC REST Interface

HTTP Follow Along:


Requests.py Reads in XML file uses REST to send to APIC

DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 13
Infrastructure Configuration Using REST API Only

Policy
Management

APIC Cluster

XML

Configuration Library
- XML requests.py
- YAML Log into UCS, ACI or NX-OS

DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 14
Thank You
Q&A
Complete Your Online Session Evaluation
Please complete your Online
Session Evaluations after each
session
Complete 4 Session Evaluations &
the Overall Conference Evaluation
(available from Thursday) to receive
your Cisco Live T-shirt
All surveys can be completed via
the Cisco Live Mobile App or the
Dont forget: Cisco Live sessions will be available
Communication Stations for viewing on-demand after the event at
CiscoLive.com/Online

DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 17
Continue Your Education
Demos in the Cisco campus
Walk-in Self-Paced Labs
Lunch & Learn
Meet the Engineer 1:1 meetings
Related sessions

DEVNET-1042 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 18
Thank You