Network Change Automation
Do More of...
PYTHON:
Notepad ++
notepad-plus-plus.org/download
Python
www.python.org/downloads
GNS3
www.gns3.com
Virtual Box
www.virtualbox.org/wiki/Downloads
C:\Python27>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> "hello world"
'hello world'
>>> exit()
1. intro.py
C:\Python27>python intro.py
hello world 2
Integer & Float:
Assigning Values to Variables:
Single value to several variables:
Multiple objects to multiple variables:
Delete reference to a number object:
C:\Python27>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> counter = 100
>>> counter
100
>>> anything=100
>>> anything
100
>>> miles = 1000.5
>>> miles
1000.5
>>> name = "John"
>>> name
'John'
>>> name = 'John155'
>>> name
'John155'
>>> a=b=c =1
>>> a
1
>>> b
1
>>> c
1
>>> del a
>>> a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> del b
>>> b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>> del c
>>> c
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'c' is not defined
>>> a,b,c = 1,2.8,'Jhon'
>>> a
1
>>> b
2.8
>>> c
'Jhon'
>>> exit()
2. Ex.py
C:\Python27>python Ex.py
500
2000.15
Andrew
500 2000.15 Andrew
The counter value is: 500
String:
C:\Python27>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> a = 'Some text'
>>> a = 'Chevy 427'
>>> a
'Chevy 427'
>>> a = 'Hello'
>>> b = 'World'
>>> a
'Hello'
>>> b
'World'
>>> c = a + b
>>> c
'HelloWorld'
>>> d = b + a
>>> d
'WorldHello'
>>> 50 + 30
80
>>> '50'+'30'
'5030'
>>> str = "Hello World"
>>> str
'Hello World'
>>> str[0]
'H'
>>> str[10]
'd'
>>> str[2:5]
'llo'
>>> str[2:8]
'llo Wo'
>>> str[:8]
'Hello Wo'
>>> str[2:]
'llo World'
>>> str[:]
'Hello World'
>>> str
'Hello World'
>>> new_string = "test "
>>> new_string
'test '
>>> new_string * 4
'test test test test '
>>> new_string + new_string
'test test '
>>> str= new_string * 4
>>> str
'test test test test '
>>> str= str + str
>>> str
'test test test test test test test test '
3. Ex2.py
C:\Python27>python Ex2.py
Hello World
The first word is: HelloHelloHelloHello
The next word is: WorldWorldWorld
Lists:
len([1, 2, 3]) = 3 < Length
[1, 2, 3] + [4, 5, 6] = [1, 2, 3, 4, 5, 6] < Concatenation
['Hi!'] * 4 = ['Hi!', 'Hi!', 'Hi!', 'Hi!'] < Repetition
B-)
Updating Dictionary
>>> dict = {'Name' : 'Zara','Age' : 7, 'Class' : 'first'}
>>> type(dict)
<type 'dict'>
>>> list1 = {'Name' : 'Zara','Age' : 7, 'Class' : 'first'}
>>> type(list1)
<type 'dict'>
>>> dict
{'Age': 7, 'Name': 'Zara', 'Class': 'first'}
>>> dict['Age']
7
>>> dict['age']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'age'
>>> dict['Age']=10
>>> dict
{'Age': 10, 'Name': 'Zara', 'Class': 'first'}
>>> dict['Class'] = 'Fifth'
>>> dict
{'Age': 10, 'Name': 'Zara', 'Class': 'Fifth'}
>>> del dict['Class']
>>> dict
{'Age': 10, 'Name': 'Zara'}
5. forloops.py
C:\Python27>python forloops.py
Current the fruit is banana
Goodbye
Current the fruit is apple
Goodbye
Current the fruit is mango
Goodbye
Current the fruit is orange
Goodbye
Current the fruit is berry
Goodbye
type = <type 'str'>
Current Letter = P
Current Letter = y
Current Letter = t
Current Letter = h
Current Letter = o
Current Letter = n
Goodbye
6. Whileloops.py
C:\Python27>python Whileloops.py
The count is: 0
The count is: 1
The count is: 2
The count is: 3
The count is: 4
The count is: 5
The count is: 6
The count is: 7
The count is: 8
Loop has done!
7. nest.py
C:\Python27>python nest.py
j= 1
j= 2
*i= 1
j= 1
j= 2
*i= 2
j= 1
j= 2
*i= 3
j= 1
j= 2
*i= 4
loops done
Control:
C:\Python27>python if.py
Area = length * width
Volume = length & width * height
1 - true
100
3 - true
a
9. ifelse.py
C:\Python27>python ifelse.py
1 - true
100
2 - got false
0
goodbye
10. ifelif.py
C:\Python27>python ifelif.py
1 got true
100
goodbye
Operators:
>>> a=10
>>> b=20
>>> a+b
30
>>> a-b
-10
>>> a*b
200
>>> b/a
2
>>> b%a => Modulus: / but returns remainder
0
>>> b=23
>>> b%a
3
>>> a=4
>>> b=3
>>> a**b => a^b
64
>>> 9//2 => / but the digits after the decimal point are removed
4
>>> 8//2
4
>>> 8.5//2
4.0
>>> 8.5/2
4.25
11. operators.py
C:\Python27>python operators.py
True
a = 100 == b = 100
True
a = 10 != b = 100
False - <>
a = 100 b = 100
True
a = 100 > b = 10
False - <
a = 100 b = 10
False - <=
a = 100 b = 10
True
a = 100 >= b = 10
True
a = 100 <= b = 100
end
12. andor.py
C:\Python27>python andor.py
True
a = 1 and b = 1000
True
a = 0 or b = 1000
True
not(a = 0 and b = 1000 )
end
Function:
13. funexamp.py
C:\Python27>python funexamp.py
I'm the first call to user defined function!
Again second call to the same function
stop
14. funexamp2.py
C:\Python27>python funexamp2.py
Values the function: [10, 20, 30, [1, 2, 3, 4]]
Project 1: Change Program
You are creating software to be sold by your company to vending machine manufacturers to count and return change. You are part of a Team, more code may be required to complete the obligations to the customer but you have been given the following assignment
C:\Python27>python proj1.py
This item costs 54
**Enter coins in form 1,5,10,25,..
enter coin values 1,5,10,25,1,1,10
(1, 5, 10, 25, 1, 1, 10)
C:\Python27>python proj1.py
This item costs 54
**Enter coins in form 1,5,10,25,..
enter coin values 1,5,10,25,1,1,10,12,17
(1, 5, 10, 25, 1, 1, 10, 12, 17)
Invalid Coins:
C:\Python27>python proj1.py
This item costs 54
**Enter coins in form 1,5,10,25,..
enter coin values 5,5,1,1,12,10
(5, 5, 1, 1, 12, 10) 6
count = 0 Coin Amount = 5
count = 1 Coin Amount = 5
count = 2 Coin Amount = 1
count = 3 Coin Amount = 1
count = 4 Coin Amount = 12
An Invalid coin was detected
enter coin values 5,5,1,1,10
count = 0 Coin Amount = 5
count = 1 Coin Amount = 5
count = 2 Coin Amount = 1
count = 3 Coin Amount = 1
count = 4 Coin Amount = 10
Coin Count:
C:\Python27>python proj1.py
This item costs 54
**Enter coins in form 1,5,10,25,..
enter coin values 5,10,5,10
(5, 10, 5, 10) 4
count = 0 Coin Amount = 5
count = 1 Coin Amount = 10
count = 2 Coin Amount = 5
count = 3 Coin Amount = 10
Coin count = q,d,n,p (0, 2, 2, 0)
Total value = 30
Make a decision:
C:\Python27>python proj1.py
This item costs 54
**Enter coins in form 1,5,10,25,..
enter coin values 25,25,1,1,1,1
(25, 25, 1, 1, 1, 1) 6
count = 0 Coin Amount = 25
count = 1 Coin Amount = 25
count = 2 Coin Amount = 1
count = 3 Coin Amount = 1
count = 4 Coin Amount = 1
count = 5 Coin Amount = 1
Coin count = q,d,n,p (2, 0, 0, 4)
Total value = 54
Thank you please take your item
C:\Python27>python proj1.py
This item costs 54
**Enter coins in form 1,5,10,25,..
enter coin values 25,25,10
(25, 25, 10) 3
count = 0 Coin Amount = 25
count = 1 Coin Amount = 25
count = 2 Coin Amount = 10
Coin count = q,d,n,p (2, 1, 0, 0)
Total value = 60
Please take your change of 6
Still need to update coin count
C:\Python27>python proj1.py
This item costs 54
**Enter coins in form 1,5,10,25,..
enter coin values 25,25
(25, 25) 2
count = 0 Coin Amount = 25
count = 1 Coin Amount = 25
Coin count = q,d,n,p (2, 0, 0, 0)
Total value = 50
Not enough money please enter 4
enter coin values 1,1,1,1
count = 0 Coin Amount = 1
count = 1 Coin Amount = 1
count = 2 Coin Amount = 1
count = 3 Coin Amount = 1
Coin count = q,d,n,p (0, 0, 0, 4)
Total value = 4
Thank you please take your item
16. proj1_g2.py
Case: 1st, Condition: Exact Change, Change in: 2 quarters, Total coins: (2,0,0,0), Total Value: 50, Action: Take Item
C:\Python27>python proj1_g2.py
*************New Purchase****************
This item costs 50
**Enter coins in form 1,5,10,25,..
25,25
(25, 25) 2
Is machine Being Serviced?
0 for no or 1 for yes
0
Checking for invalid coins
Checking for invalid coins
Thank you please take your item
Coin count= q,d,n,p (2, 0, 0, 0)
Total value= 50
***********End of Purchase****************
Case: 2nd, Condition: Exact Change, Change in: 5 dimes, Total coins: (2,5,0,0), Total Value: 100, Action: Take Item
C:\Python27>python func.py
Please enter a number to manipulate.
'k'
You must enter a valid number.
Please enter a number to manipulate.
2
('The final value is ', 14.0)
18. class1.py
19. op1.py
C:\Python27>python op1.py
Please enter a number.
2
('The manipulated value is ', 14.0)
upload.i4th.in.th/th/download.php?id=59493B941
22. TN7.py
testcmds.txt
C:\Python27>python TN7.py
Enter command file name and extension: testcmds.txt
ESW1#conf term
Enter configuration commands, one per line. End with CNTL/Z.
ESW1(config)#
ESW1(config)#int f0/0
ESW1(config-if)#
ESW1(config-if)#ip add 5.5.5.5 255.0.0.0
ESW1(config-if)#
ESW1(config-if)#end
ESW1#
ESW1#sho ip int brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 5.5.5.5 YES manual administratively down down
FastEthernet0/1 192.168.56.101 YES manual up up
...
upload.i4th.in.th/th/download.php?id=594E30291
What about networking skills?
23. TN20.py
C:\Python27>python TN20.py
Enter command file name and extension: ESW1cmds.txt
Enter command file name and extension: ESW2cmds.txt
Enter command file name and extension: ESW3cmds.txt
Enter command file name and extension: ESW4cmds.txt
IOS Telnet Configuration:
Telnet to n Number of Routers:
24. TN24.py
C:\Python27>python TN24.py
(1, '192.168.1.101')
(2, '192.168.1.102')
...
(26, '192.168.1.126')
25. TN25.py
C:\Python27>python TN25.py
Enter command file name and extension: ESW1cmds.txt
(1, '192.168.56.101')
Enter command file name and extension: ESW2cmds.txt
(2, '192.168.56.102')
26. TN1000.py
27. TN1001.py
>>> ip = '192.168.1.101'
>>> ip
'192.168.1.101'
>>> p3 = ip.rfind('.')
>>> p3
9
>>> temp_s = ip[:p3+1]
>>> temp_s
'192.168.1.'
>>> quad = ip[p3+1:]
>>> quad
'101'
>>> quad_int = int(quad)
>>> quad_int
101
>>> type(quad_int)
<type 'int'>
28. TN1003.py
C:\Python27>python TN1003.py
(1, '1.1.12.5')
(2, '1.1.12.6')
(3, '1.1.12.7')
(4, '1.1.12.8')
(5, '1.1.12.9')
(6, '1.1.12.10')
(7, '1.1.12.11')
(8, '1.1.12.12')
(9, '1.1.12.13')
Change ESW1 & ESW2 Management IP to 192.168.x.99 - 100 respectively
29. TN2000.py
C:\Python27>python TN2000.py
Enter command file name and extension: ESW1cmds.txt
(1, '192.168.56.99')
Enter command file name and extension: ESW2cmds.txt
(2, '192.168.56.100')
Program Your Career. Learn Network Programmability:
Network Engineer Job Role Evolution:
Digitization Is Changing The World:
CEO Technology Investment Priorities: 2014/15: Most Important Technology-Enabled Capability Investments Over the Next Five Years
www.gartner.com/doc/2704918/gartner-ceo-senior-executive-survey
www.gartner.com/smarterwithgartner/2017-ceo-survey-infographic
Emerging Jobs of the Future: College students are studying to prepare for jobs that do not exist... yet
www.itcareerfinder.com/brain-food/blog/entry/best-computer-jobs-for-the-future.html
www.infoworld.com/article/3160526/application-development/infoworlds-2017-technology-of-the-year-award-winners.html
www.networkworld.com/article/3158845/lan-wan/software-may-be-eating-the-world-but-cumulus-networks-is-still-keen-on-hardware.html
The Network at the Center of Every Evolution Step: Managing Your Career Through Key Market Transitions
Industry Relevant Bridge the Knowledge Gaps
Centralized > Silo'd > Unconnected > Network as Platform > Internet of Everything
Networker Responsibilities are Growing and Shifting:
Responsibility Focus:
<- Speeds - Users - Data Center - Mobile - Cloud - Threats - Big Data - Internet Of Things - SDN ->
Network Programmability in a Programmable Networking Environment:
Abstracting Conventional Policy Complexity:
ACI Abstracts System Management and Enables Programmable Driven Policies
Move from micro-managing "boxes" to a policy-driven, holistic view of the network
Proactive Network Applications: Automate Network Provisioning
Key Use Cases:
Key Skills:
Key Skills:
Development Economics - Deploying a physical network test-bed requires:
Time and money you probably don't have
VIRL can help simplify and streamline development processes and environments
What is VIRL? - A network orchestration and virtualization platform that enables:
Virtualized Network Operating Systems:
The Wall of Confusion: Or, why can't we all just get on together?
DevOps Virtuous Cycle:
Aspects of DevOps - Agile Development and CI/CD:
Continuous Integration and Deployment in the Development Cycle:
Introducing DevNet: Creating a Community of Software Developers who Leverage Cisco Technology in Their Work
Enabling a Robust Developer Ecosystem:
To Build Compelling and Innovative Apps
Network Programmability Certifications:
Evolution of Major IT Roles in the IT DevOps World: Orchestrating for Outcomes
Before > After
Network Programmability Industry Job Roles Evolution and Certifications:
Traditional Networking Infrastructure > Network Programmability Roles > Network Programmability Certifications and Curriculum
Who Moved my CLI? - Coding to save network admin time:
One skill applies to many tasks:
Network Administration In most environments Today:
Typo in the pasted config? Start from scratch
Challenges:
New Opportunities:
Use cases:
Script usage guidance:
Simple Use Cases:
1. Application Monitoring:
#!/usr/bin/env python
import socket
import time
from cisco import *
from argparse import ArgumentParser
parser = ArgumentParser('Server health monitor')
parser.add_argument('-s', '--server', help='IP address of server to monitor', required=True)
parser.add_argument('-p', '--port', help='TCP port to poll', type=int, required=True)
parser.add_argument('-c', '--commands', help='Commands to run if an interface fails, use ; to separate multiple commands', required=True)
args = parser.parse_args()
connected = False
while True:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if sock.connect_ex((socket.gethostbyname(args.server), int(args.port))) == 0:
connected = True
sock.close()
except socket.error:
connected = False
if connected == False:
with open('servermon.log', 'a') as f:
f.write('The server %s failed on port %s at time %s. Debug output below:' % (args.server, args.port, time.asctime()))
for cmd in args.commands.split(';'):
f.write(cli(cmd)[1])
time.sleep(30)
R1# python servermon.an -s 10.9.46.202 -p 23 -c "show int vlan 20:show proc cpu"
R1# show file bootflash:servermon.log
#!/usr/bin/env python
from cisco import *
from argparse import ArgumentParser
parser = ArgumentParser('Supercommand')
parser.add_argument('ip')
args = parser.parse_args()
ip = args.ip
for arp in CLI('show ip arp %s' % (ip), do_print=False).get_output():
if ip in arp: break
else:
raise Exception('Unable to find %s in ARP output' % ip)
ip, timer, mac, interface = arp.split()
for cam in CLI('show mac address-table address %s' % (mac), do_print=False).get_output():
if mac in cam: break
else:
raise Exception('Unable to find %s in CAM output' % mac)
cam_fields = cam.split()
if cam_fields[0] == '*': cam_fields.pop(0)
vlan, mac, entrytype, age, secure, ntfy, port = cam_fields
for cdp in CLI('show cdp neighbor interface %s' % (port), do_print=False).get_output():
if port in cdp: break
else:
raise Exception('Unable to find %s in CDP output' % port)
print('Here is some information on %s:' % ip)
print(' ' * 4 + 'MAC address: %s' % mac)
print(' ' * 4 + 'Local interface: %s' % port)
print(' ' * 4 + 'VLAN: %s' % vlan)
print(' ' * 4 + 'L3 gateway: %s' % interface)
print(' ' * 4 + 'CDP details: %s' % cdp)
R1(config)# cli alias name supercommand python supercommand.py
R1# supercommand 10.9.46.202
3. Ping a Range:
#!/usr/bin/env python
import re
from cisco import *
from argparse import ArgumentParser
def expandrange(rnge):
if '-' in rnge:
r = rnge.split('-')
return range(int(r[0]), int(r[1])+1)
else:
return [rnge]
parser = ArgumentParser('pingrange')
parser.add_argument('ip')
parser.add_argument('-o', '--options', help='Options to pass to ping, default: count 1', default='count 1')
args = parser.parse_args()
target = args.ip
octets = target.split('.')
for o1 in expandrange(octets[0]):
for o2 in expandrange(octets[1]):
for o3 in expandrange(octets[2]):
for o4 in expandrange(octets[3]):
ip = '%d.%d.%d.%d' % (int(o1),int(o2),int(o3),int(o4))
print('%s - ' % ip),
m = re.search('([0-9\.]+% packet loss)', cli('ping %s %s' % (ip, args.options))[1])
print m.group(0)
R1# python pingrange.py 10.1.1.1-10
Where do I start?
Security for the SDN, by the SDN - Address Security Systematically:
Overview of SDN:
Cisco Open Network Environment (ONE):
Industry's Most Comprehensive Networking Portfolio:
Security Landscape:
Biggest Security Challenges:
The Threat Landscape is evolving:
Anatomy of a Modern Threat:
Network planes:
SSH, TFTP, SNMP, FTP ... and Other Mgmt Protocols
Typical DoS:
SDN DoS:
Network Programmability:
Proactive versus Reactive Applications:
Proactive:
Proactive is a type of application sets configuration parameters for planned network changes.
Reactive:
CLI versus NETCONF Applications:
CLI Applications:
NETCONF Applications:
CLI is a type of interface is available for almost every networking device. While NETCONF and RESTCONF are becoming more common, they are not yet available on many networking devices. XML is a structured data format, not an interface type.
YANG is a data model is used by the NETCONF protocol.
Standalone versus Controller-based Applications:
Standalone Applications:
Controller-based Applications:
External and internal are two varieties of controller-based applications.
Standalone is a type of application communicates directly with a device.
External Support Libraries:
Python code from other sources
Types of Network Programmability:
In general, network programmability is broken down into two high-level categories: device-level programmability and true network-level programmability. Device programmability in and of itself is prone to some of the same scalability challenges as CLI but provides a more reliable and machine-consumable interface to the devices. True network-level programmability treats the network as an object that allows for more advanced solutions that tend to veer toward business use cases. Network-level programmability is enabled by controllers such as the APIC. The APIC controller allows data centre engineers to define policies that describe how the network should function. The controller instantiates these policies in the data centre switches without the need to configure each switch separately.
CLI versus NETCONF:
CLI scripting was the primary approach to making automated configuration changes to the network prior to NETCONF. CLI scripting has several limitations including lack of transaction management, no structured error management, and ever-changing structure and syntax of commands that make scripts fragile and costly to maintain.
Standalone versus Controller-based:
Network programmability applications can be proactive or reactive, they can use CLI or NETCONF; they also can be standalone or controller-based.
Standalone applications have the following characteristics and considerations:
A simple introductory application that uses the pexpect library and pings a network device.
A quick introduction to Python numbers, strings, and variables.
An overview of how code blocks are defined in Python.
A brief look at printing variables using Python commands
The importance of commenting code, and the mechanisms for doing so.
30. hello-device.py
Floats:
Arithmetic operations: +, -, *, /, // (truncation), % (modulus), ** (exponentiation), +=, -=, *=, etc.
Strings:
Other operations: join, replace, duplicate, convert, and others.
Variables, Objects, References:
Code Blocks: Indentation:
Commenting Your Code:
Importance of Comments:
Pro: "Half non-whitespace should comment"Con: "Source code should be self-documenting"
Comments should:
Single-line comments:
Multi-line comments:
PyDoc Auto / Automatically Program Documentation / Auto-Doc Generation / Generating:
In your code:
Generate documentation:
Designing and Implementing Cisco Network Programmability:
Understanding Software-Defined Networking:
What is Software-Defined Networking?:
Software-Defined Networking is:
Software-Defined Networking is NOT:
Traditional versus Software-Defined Networks:
The Traditional Network:
The Network As It Could Be... to an SDN 'Purist':
The Network As It Could Be... In a 'Hybrid SDN':
Why Change?:
Current Industry Trends:
Networking Trends:
Open Source Software:
Programmable Infrastructure:
Platform specific, on-box, automation and scripting mechanisms:
Characteristics of modern programmatic protocols for managing network devices:
Software Defined Networking:
DevOps - Best described by understanding CALMS:
Cisco ACI - Application Centric Infrastructure:
Network Programmability & Automation:
Current Network Operation:
Future Network Operation:
Uses of Network Automation:
Types of Network Automation/programmability techniques can perform:
Network Automation Scenarios:
Data Collection:
Configuration Management Scenarios:
Management Plane:
NMS / End-User <- CLI, (SSH/TELNET), SNMP / NETCONF, RESTCONF, REST -> Network Device: Management Plane, Control Plane, and Data Plane
Why Is Network Automation Different Now?:
Open Source Tools and Enterprise Platforms:
Enterprise Systems Operations:
Enterprise Network Operations:
Open Source Software:
Network Programmability Technology:
Network Automation Workflow:
Configuration Management Workflow [Sample]:
Cisco Platforms and APIs:
Linux Primer for Network Engineers:
Why Learn Linux?
Linux is everywhere - Used in various devices:
cisco@cisco: $ sudo su -
[sudo] password for cisco:
root@cisco: # exit
logout
cisco@cisco: $
Though Linux is pervasive in technology, a network programmability engineer should learn Linux because:
Navigating the Linux File System:
Super User Privileges:
Basic Commands:
Paths and Directories:
cisco@cisco: /scripts$ pwd
/home/cisco/scripts
cisco@cisco: /scripts$ cd cisco
cisco@cisco: /scripts/cisco$ cd /var/log
cisco@cisco: /var/log$ pwd
/var/log
Change Directories:
Linux Distributions:
Debian:
Red Hat Enterprise Linux:
Package Management:
Red Hat Family:
Debian Family:
Working with Files and Directories:
touch
cisco@cisco: $ touch catalyst_config.txt
cisco@cisco: $ ls
catalyst_config.txt cisco Desktop Documents Downloads Templates
cisco@cisco: $ ls -l catalyst_config.txt
-rw-rw-r-- 1 cisco cisco 0 Jun 24 11:50 catalyst_config.txt
Make Directory Commands:
Remove Commands:
Copy and Move Commands:
cisco@cisco: /Nexus9000$ cp file1 file2
cisco@cisco: /Nexus9000$ mv file2 file3
cisco@cisco: /Nexus9000$ ls
file1 file3
cisco@cisco: $ mv class.txt MyClass is moving a file that is called class.txt from its current directory to a directory called MyClass.
Viewing Files Commands:
File Permissions:
Linux operating systems are multi-user
Permissions are based on two factors:
drwxrwxrwx:
cisco@cisco: $ ls -l vlans_script.py
-rw-rw-r-- 1 cisco cisco 0 Sep 12 15:14 vlans_script.py
cisco@cisco: $ chmod u+x vlans_script.py
cisco@cisco: $ ls -l vlans_script.py
-rwxrw-r-- 1 cisco cisco 0 Sep 12 15:14 vlans_script.py
cisco@cisco: $ chmod go+x+w vlans_script.py
cisco@cisco: $ ls -l vlans_script.py
-rwxrwxrwx 1 cisco cisco 0 Sep 12 15:14 vlans_script.py
Linux Processes:
Viewing Running Processes:
cisco@cisco: $ kill 2442
Using the Linux Command Line:
Package Management:
Navigating the Filesystem:
Working with Files and Directories:
Python Foundation for Network Engineers:
Why Learn Python?:
Python 2.x:
Python 3.x:
Using the Dynamic Interpreter (shell):
Writing Python Scripts:
Understanding Python:
Python Helper Utilities and built-in Function:
>>> type('1.1.1.1')
<type 'str'>
>>> dir(str)
['replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split',
'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
## output truncated for brevity ##
>>> help(str.upper)
Writing Idiomatic Python:
Common Python Data Types:
Variable Assignment:
Data Types: Strings:
>>> ipaddr = '10.1.10.1'
>>> hostname = 'nxos1'
>>> hostname = "nxos2"
>>> hostname[4] = '3'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>> os_version = ''
Printing Strings:
>>> interface_config = 'interface Eth1/1\n no switchport'
>>> interface_config
'interface Eth1/1\n no switchport'
>>> print interface_config
interface Eth1/1
no switchport
Concatenate or add one or more strings together:
>>> ipaddr = '10.1.10.1'
>>> mask = '255.255.255.0'
>>> ipmask = ipaddr + ' ' + mask
>>> ipmask
'10.1.10.1 255.255.255.0'
String Built in Methods:
>>> hostname = 'nxos1'
>>> hostname.upper()
'NXOS1'
>>> macaddr = '00:11:22:33:44:55'
>>> macaddr.replace(':', '.')
'00.11.22.33.44.55'
>>> ipaddr.startswith('10')
True
>>> ipaddr = '10.{}.1.1'
>>> ipaddr.format('200')
'10.200.1.1'
>>> ipaddr = '10.4.8.1'
>>> ipaddr.split('.')
['10', '4', '8', '1']
Data Types: Numbers:
>>> 5 * 4
20
>>> 10 - 4
6
>>> 239234 + 4
239238
>>> 10 / 3
3
>>> 10.0 / 3
3.3333333333333335
>>> 10.0 // 3
3.0
Data Types: Booleans:
>>> 9372 > 9396
False
>>> 'nexus' != 'catalyst'
True
>>> 'nexus' in 'nexus 9396'
True
>>> '9372' not in 'nexus 9396'
True
Conditional Statements:
>>> switch = 'catalyst 3850'
>>> if 'catalyst' in switch:
... switch_type = 'catalyst'
... elif 'nexus' in switch:
... switch_type = 'nexus'
... else:
... switch_type = 'unknown'
...
>>> print switch_type
catalyst
Summary:
Create Strings:
Navigate the Built-In Help Features:
Use Built-in Methods of Strings:
Use Conditionals:
Programming the Digital Network Architecture (DNA):
Programming Foundation:
Coding 101 - REST API Basics with APIC-EM:
What is a Web Service?
What is a REST Web Service?
What are the benefits of REST?
REST Is easy to use on any platform
How does this work?
What do I need to know to make a Request?
To construct a request, determine the following information for the API that are calling. Can find this information in the API reference documentation.
About Authentication:
Authentication controls whether a user can access a specific API endpoint and how they can it. For example, one user might have read-only privileges, which they can only make API calls that read data. Another user might have read and change (add, edit, delete) privileges to every endpoint, which means they can make an API call. These access rights are typically-based upon assigned user roles such as Administrator, which grants a user full rights to change data, and User, which grants read-only access.
REST APIs have three common methods to authenticate users:
APIC-EM uses token-based authentication. So the first request need to make creates a token. In APIC-EM, this token is called a service ticket. The controller uses the service ticket to determine which endpoints can access. The service ticket must be included in every API call except the one that creates the ticket.
The steps for using the APIC-EM authentication token are:
How to be a Network Engineer in a Programmable Age:
Meet Carl the Network Engineer:
Networking Skills:
Programming Skills:
The Network...:
The OSI Model of Networking...:
The Four Ages of Networking...:
5 Stages of Grief:
Carl's 3 Step Approach to Network Programmability:
Phase 1:
Phase 2:
Phase 3:
As Needed:
Carl has Embraced Programmability! (and got himself a new shirt :-)):
Core Programming:
"New" Networking Stuff:
Data Formats: Understanding and using JSON, XML and YAML:
Importance of a Data Format:
Know Your Audience:
Common Data Formats in Programming - A human-readable data structure that applications use to store, transfer, and read data:
Common Elements in a Data Format:
"Key" : "Value":
XML Object:
XML List:
Breakdown JSON: JSON - JavaScript Object Notation:
JSON Object:
JSON List:
Simplify YAML: YAML - "YAML Ain't Markup Language":
YAML Object:
YAML List:
APIs are Everywhere... but what are they?:
What is an API?:
"It's a way for two pieces of software to talk to each other"
Application Programming Interface (API)
For a long time... Humans were the only users:
But what about when the user is another software system...:
The API is the User Interface for software systems
APIs are sets of requirements that govern how one application can talk to another.
An API is like an electrical outlet:
What would it be like to power a hair dryer without an outlet?:
The outlet is a service that conforms to specifications:
An API is like ...:
An API (Application Programming Interface) is best thought of as a contract provided by one piece of computer software to another.
APIs help developers create apps that benefit the end user:
- Yelp asks for Map Data > Google Maps - returns map data via API > yelp > Users sees list of restaurants close to them
APIs are often referred to as "an engine of innovation." -- Programmable Web
APIs aren't scary... you already use them:
Command Line Interface (CLI):
Designed for Humans... so more a UI than API but ...:
Simple Network Management Protocol (SNMP):
Other APIs out there:
Simple Object Access Protocol (SOAP):
Representational State Transfer (REST):
XML-RPC and JSON-RPC:
NETCONF (NETwork CONFiguration) Protocol:
RESTCONF Protocol:
HTTP is for more than Web Browsing:
What is REST?: Just Another Use for the HTTP Protocol
Requests and Response, the REST API Flow:
A Look Under the Hood at REST?:
The URI: What are you Requesting?:
http://maps.googleapis.com/maps/api/geocode/json?address=sanjose
HTTP Methods: What to do?:
HTTP Verb | Typical Purpose (CRUD) | Description
Response Status Codes: Did it work?:
Status Code | Status Message | Meaning
Headers: Details and meta-data:
Header | Example Value | Purpose
Data: Sending and Receiving:
{
'title': 'Hamlet',
'author': 'Shakespeare'
}
HTTP Authentication and Security:
Some REST Examples:
The Internet Chuck Norris Database:
DevNet$ curl api.icndb.com/jokes/random
{
"type": "success",
"value": {
"id": 201,
"joke": "Chuck Norris was what Willis was talkin' about.",
"categories": [ ]
}
}
DevNet$ curl api.icndb.com/jokes/random?limitTo=nerdy
{
"type": "success",
"value": {
"id": 537,
"joke": "Each hair in Chuck Norris's beard contributes to making the worlds largest DDOS.",
"categories": [
"nerdy"
]
}
}
Network Programmability with RESTCONF:
The Request:
DevNet$ curl -vk \
-u root:cisco123 \
-H 'accept: application/yang-data+json' \
https://10.10.20.21/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet2
> GET /restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet2 HTTP/1.1
> Host: 10.10.20.21
> User-Agent: curl/7.51.0
> accept: application/yang-data+json
> authorization: Basic dmFncmFudDp2YWdyYW50
The Response - Headers:
< HTTP/1.1 200 OK
< Server: nginx
< Date: Thu, 27 Jul 2017 00:01:52 GMT
< Content-Type: application/yang-data+json
< Transfer-Encoding: chunked
< Connection: close
< Last-Modified: Tue, 25 Jul 2017 19:15:57 GMT
< Cache-Control: private, no-cache, must-revalidate, proxy-revalidate
< Etag: 1501-10157-179272
< Pragma: no-cache
<
The Response - Data:
{
"ietf-interfaces:interface": {
"name": "GigabitEthernet2",
"description": "Wide Area Network",
"type": "iana-if-type:ethernetCsmacd",
"enabled": true,
"ietf-ip:ipv4": {
"address": [
{
"ip": "172.16.0.2",
"netmask": "255.255.255.0"
}
]
},
"ietf-ip:ipv6": {
}
}
}
REST API Tools:
Making REST API Calls with Postman:
Why Postman and How to Get it?:
Postman: Powerful but Simple REST API Client:
Sending an API Request:
API Collections:
Using Environments:
Variables Make Requests Reusable and Flexible:
Variables Make Requests Reusable and Flexible:
Managing Environments:
Setting Environment Variables Dynamically:
"Tests" Enable Dynamic Environment Variables:
Postman to Code!:
You'll eventually want to write some code...:
Full API Request to Code!:
Python Language and Script Basics:
Why Python and How to get it?:
The Zen of Python by Tim Peters:
Why Python for Network Engineers:
How to get Python?
DevNet$ python -version
Python 2.7.12
Breaking Down Python Code:
example1.py:
Fundamentals of Open SDN and OpenFlow:
What is "Open?":
SDN Protocols: > Application Frameworks, Management Systems, Controllers, ...
YANG Modeling Language:
Actual Device Data Modeled in YANG:
YANG and RESTCONF:
Evolution/Evolving of Service Chaining:
Architectural Requirements:
Service Graphs vs. Linear Service Chains:
Example: Business Policy Drives Service Deployment:
First Steps:
Next Generation CCIE:
Ingredients of Hybrid IT:
Bimodal IT Architectures to support Fast IT Business Needs
The pace of change and Networks:
Source: Forrester
Source: Open Computer Project
B-)
Evolving Our Interaction with Network OS:
How > 70% of Config Management is Done Today:
"It's the way real men build real networks."
Ways to Automate Network Components:
Programmability - SDN:
Options for Programming the DC Network:
Requirements of Next-Gen Config Management: RFC 3535 CY 2002:
Result: NETCONF and YANG:
NETCONF (Network Configuration Protocol): NETCONF 1.1:
clnv.s3.amazonaws.com/2015/usa/pdf/BRKACI-2101.pdf
It looks like you're new here. If you want to get involved, click one of these buttons!