LBHG 0G@BG J . . , JB ) 8J GL • y U T cspSa w • i kS St hegvS wlr • ms Sa wclg mugd m • LOHJD 0G@BG J - 1 7-0 ( ) • /. je nSw 8 JBG@ • hegvS a o / a o • .H GBLP , LBNBLB • 4, 71 mu ro • L7I .H BG@ .HIPJB@AL 7.2 AGH HE LBHG , JB G
! • +! • !3! • 04$ - 2 • mp • U S r • e h I • s U t - 2 • mp C • mp • Cl • s • e h uT • ianmph • U 5)(*) • % *,. ! • !$~*,. "/2 ! • 04*,. 5)(() • % (! • !(! • 04( • '- 016 - 2 • Cl O H • Co c gl • T S T yT • Ac gl I 53 ., .21 8 - 5 8 2 510 81
L 0 - A E A H 1 0 0 • nr R OU S y y • aLi S y y • h L S y ,G y • L L SsMUy y • m S L TS glctuxo • L S • L S y • 0/ / A E PS p R R g ABHC E I / 2 .7 A A E A D C 8 /
T O GU ) OT s E gE gtET GU nrle 5 8 1 9 88 9 T O GU U T T O GU , N h E I - O . gE & E 2 A l E 7 A 68 A 03 E - NANOG71:Network Automation: past, present, and future ( Slide, Movie) .!3+ %,3+ *)-& ! "#$4 105'/ ( 2 '/ 2 ?
0 A 8 : 8 , Psp RI h Rr cR Pr ,. UaP . 0 . ,. UaP R c Ry t cR Py . y Oc o cR Plg Ry t cR Py Oc o . lg Ry t . y . nmy Oc o A . 8 C 8: lg Ry t . nmy Oc o A . 8 C B lg Ry t . my
I - v e Rpsd nR • mp Rf U Xa b P -nR Y • mp Rf l kR b P .L H I M 8b • r R P 0 tce Y • hio U P I C P U • v g y g 3N A M IJ ( • mp Rf P3N A eu Sa 1 3 0 b t if ml T
H • r u T p pe I ch S yH • io ml S r u }O U H ( - C 8A ) 20-. 26 8 1 : A ,;6 4 num = 1 if num == 1: print(“Hello JANOG!!!”) $ python3 sample.py Hello JANOG!!! • io ml • s CA8 a p S CA8 g n {t O H I 4; :6 C
list Jinja2 (2.9.6) . . . $ pip install jinja2 HI 0 HI C U HI S O T () *& venvvirtualenv",* # pip %'( ( $+)! ) https://docs.python.jp/3/library/venv.html
80 # datetime import datetime # datetime datetime now now = datetime.datetime.now() print(now) $ python3 sample_library.py 2017-11-15 14:25:56.360603 sample_library.py 1 2 2 HA C I
o • J . H J F A AI EI H F EHA O F • J . CE N I H J F # N I EIH HJ F • ig la R Tt m d d Xc S r n R e r n m • . • / E 1 : 2 F 5NHEJ 5 6 : ( F 0E I 4 :# F 6 : , F 4 : ( ( F • Tp o Uhe RsTx T n o c a d S • di aR S • . J. H J F A AI EI H F NJJI EHA O F # H JI # CN H ) 0IJP EC ( - 4 03 HI#:IFN EIH / E 4H
t A • hkca NS mX mnA • N sO c LM uA • u hkca w Mo e C O CA • ,(.( ,3 6 • OmX mn • ) 2 ,3 :6 3: 23 :2 3 :1 : 1 1 3 :6 ,) NAPALM Cisco Router Juniper Router Cisco Juniper get_network_driver(”iosxr") get_facts()[‘os_version’] 12.1X47-D15.4 get_network_driver("junos") get_facts()[‘os_version’]
mnot U O T r t • i wh ah mnot U T S1 cuH T g g e ( -=> 8A ) 20-.3 2 8 = 1= A = , 4 Hostname: vsrx Model: firefly-perimeter JUNOS Software Release [12.1X47-D15.4] 12.1X47-D15.4
P ) J 37 )( 2 <html> <body> <h1> {{ title }} </h1> <p> {{ body }} </p> </body> </html> title = “Web page 1” body = “Hello! World!” {{ }} : {% if %} : if {% endif %} {% for in %} : for {% endfor %} {# #} : [ (Jinja2)] HTML
8A - host_info: mgnt_ipaddress: 192.168.33.3 hostname: vsrx1 os : junos username: user1 password: password1 if_info: if_name: ge-0/0/2 if_address_ipv4: 192.168.35.1 if_subnet_ipv4: 30 if_description: AS65002_peer .g ST IO MP LO U YH . ST a 1 C e ei IO MP l he c he ei import yaml # YAML file = open("sample_yaml.yml", "r") # file YAML router_info = yaml.load(file) print(router_info['host_info']['hostname’]) print(router_info[‘if_info'][‘if_name’]) sample_yaml.yml sample_yaml.py $ python3 sample_yaml.py vsrx1 ge-0/0/2
,-3 2658 1 A 6 5 . 5 $ python –-version Python 2.7.14 $ python2 --version Python 2.7.14 $ python3 --version Python 3.6.3 ae h pt 0CA8 I gi 1T P S 1 uT P CA8 CA8 CA8 ) U ic ae h rn l H
C M/ PPP CIH I IPH I M • 4 57 57 lk • C M/ I M I M )).- . (A( . ) , • 1 H 57 , lk • C M/ I M I M . ) -A . ..,, ( • gUdh XW qawb lk S utsp6082 oms XrnT ( 1I C - 385129 8 CHI 7I O IHM 0 3H
H • r u T p pe I ch S yH • io ml S r u }O U H ( - C 8A ) 20-. 2 58 1 : A ,; 54 5 $ vi sample.py num = 1 if num == 1: print(“Hello JANOG!!!”) $ python3 sample.py Hello JANOG!!! • io ml • s CA8 a p S CA8 g n {t O H I
=A 7 ,= a = 1 # a: int b = 1.1 # b: float print(a) print(b) print(‘-----’) c = a + b # c: float print(c) $ python3 sample_number.py 1 1.1 ----- 2.1 IH S IH 1 T2 U O (Cint a;float b;)" ! ( # ) A 7 =C 57
c = “text” # ‘“ $(,# d = "" #)-%+&0 #Python3 ! Unicode+&0 " #Python2 !ASCII u"" .'*/ print(c) print(d) $ python3 sample_string.py text = 52 8 = 0 S1 T C U C I H I H O
python3 sample_if.py num is two num = 2 if num == 1: print("num is one") elif num == 2: print("num is two") else: print("num is the others") 1 8 0 A U T c ,A 6 PCmU T Tai 21 PleH _ f O gI Ch Sfn
H IA C O U # router_list = [”router_A”, ”router_B”] # router_list router_name for router_name in router_list: print(router_name) $ python3 sample_for_2.py router_A router_B # # range(3) = 0,1,2 for num in range(3): print(num) $ python3 sample_for_1.py 0 1 2 H IA TS O U sample_for_1.py sample_for_2.py
open("sample_read.txt", "r") text = file1.read() # ! print(text) file1.close() # :"w", :"a" file2 = open("sample_write.txt", "w") file2.write("Good!") file2.close() $ python3 sample_file.py Hello JANOG! from sample_read.txt How are you feeling? sample_file.py [ : sample_read.txt] Hello JANOG! from sample_read.txt How are you feeling? [ : sample_write.txt] Good! C I C HA 3 ., .21 8 - 6 8 2 10 81
, 2 $ pip3 list Jinja2 (2.9.6) . . . $ pip3 install jinja2 S H HOI C 7 71 H HOI C HOI C T H U () *& venvvirtualenv",* # pip %'( ( $+)! ) https://docs.python.jp/3/library/venv.html
$ pip2 --version pip 9.0.1 from /Library/Frameworks/Python.framework/Versions /2.7/lib/python2.7/site-packages (python 2.7) $ pip3 --version pip 9.0.1 from /Library/Frameworks/Python.framework/Versions /3.6/lib/python3.6/site-packages (python 3.6) c m H go- O i ,.srOT S P a I tnlh H e U () : pip Python setuptools pip http://www.lifewithpython.com/2012/11/Python-package-setuptools-pip.html A8 a up C , 0 32 . 7 83 21 2
# datetime import datetime # datetime datetime now now = datetime.datetime.now() print(now) $ python3 sample_library.py 2017-11-15 14:25:56.360603 sample_library.py 1 2 72 HA C I
P ) J 7 )( 2 <html> <body> <h1> {{ title }} </h1> <p> {{ body }} </p> </body> </html> title = “Web page 1” body = “Hello! World!” {{ }} : {% if %} : if {% endif %} {% for in %} : for {% endfor %} {# #} : [ (Jinja2)] HTML
def add(x, y): sum = x + y return sum sample_unittest.py C O I C I import unittest import sample_unittest class TestSample(unittest.TestCase): def test_add(self): actual = sample_unittest.add(1,2) expected = 3 self.assertEqual(actual, expected) if __name__ == "__main__": unittest.main() tests/test_sample_unittest.py ├── sample_unittest.py └── tests └── test_sample_unittest.py H A
DCcU c • 1E C2 0 • T X bhSki O P2 H DC e ag • 8C D A8G • WcaP bhol a • , H , H-I , H08 • pmjUh We bh a • C CG F A . DE F H L .41 - 4 CD DAIH DCG F 8 .C
N-NDE M .ELAMD ABQ • l a0 2a r ty o a f vt kh • -IQCN - 2: -IQCN b ri oc • 60 ri oc • l a- 2a r a f vt kh • AGPAMR SMIOEP T : • 0IRHSB AGPAMR SMNQ 0SEQR • w m AGPAMRa IPE Wg e • AGPAMR -IQCN 2 :T • w m : RNN BNV 8APR 2 : AGPAMR SICJ RAPR • w m 2 :T AGPAMRg d • AGPAMR +PIQRA T • w m QIMG T UIRH AGPAMR AMD IPRSA ,NV )( -NOWPIGHR X ) 2 -1 ECHMN N SRINMQ +LEPICA 2MC
IOS / IOS-XE One Platform Kit (OnePK) C, Java, Python ASR1000: 3.12 -3.17(EoL) YANG Development Kit(YDK) Python, C++ 16.5.1 later IOS-XR One Platform Kit (OnePK) C, Java, Python ASR900: 5.1.2 - 5.3.3(EoL) ASR9000: 5.1.1 - 5.3.3(EoL) YANG Development Kit(YDK) Python, C++ 6.0.0 later NX-OS One Platform Kit (OnePK) C, Java, Python Nexus9000: all version Nexus6000: - 7.2(EoL) NX-API Web GUI, HTTP/HTTPS Nexus9000: all version Nexus7000: 7.2(0)D1(1) later Nesus6000: 7.2(0)N1(1) later Juniper JUNOS PyEZ Python 11.4 later Juniper Extension Toolkit(JET) Python 16.2 later Extreme (ex-Brocade) Network OS PyNOS Python 5.0.1 later Arista EOS pyeapi, rbeapi, goeapi Python, Ruby, Go 4.1.2 later EOS SDK C++, Python all version O 8 , 8 9 S 8 ,
nC • /43X r ST L l C • r i Xe s H C D xIp • . 1 : 9 9 - Cisco Router SSH/Telnet show version (Cisco Command) Juniper Router SSH/Telnet show version (Juniper Command) Hostname: vsrx Model: firefly-perimeter JUNOS Software Release [12.1X47-D15.4] . . . i E ( X i E 7), 0 ) X Thu Jan 18 02:03:05.771 UTC Cisco IOS XR Software, Version 6.2.1.23I Copyright (c) 2013-2016 by Cisco Systems, Inc. . . .
okM v C • mec P o o C • Pn u r eX s NO L wC • w mec O i C • ) . , . 9 • o o • ) 4 . A 1 4 46 3 3: 3 : A . 2 ( NAPALM Cisco Router Juniper Router Cisco Juniper get_network_driver(”iosxr") get_facts()[‘os_version’] 12.1X47-D15.4 get_network_driver("junos") get_facts()[‘os_version’]
o • J . H J F A AI EI H F EHA O F • J . CE N I H J F # N I EIH HJ F • ig la R Tt m d d Xc S r n R e r n m • . • / E 1 : ) 2 F 5NHEJ 5 6 : ( F 0E I 4 :# 9 F 6 : F 4 : ( ) ( F • Tp o Uhe RsTx T n o c a d S • di aR S • . J. H J F A AI EI H F NJJI EHA O F # H JI # CN H - 0IJP EC ( , 4 0 HI#:IFN EIH / E 4H
: O i O : • ln e N . N W As 9 A N : b a S : • t 9 i kc N A W: • . , N A : N : • ) 6 3 2 8 8 1 ( Ansible (playbook) Cisco Router Juniper Router Ansible iosxr Module Ansible junos Module iosxr-facts debug: var=ansible_net_version junos-facts debug: var=ansible_net_version 12.1X47-D15.4
_ i y ol HRRO NC AM I E CNL AM I E ARE R I R NF MERUNPJ LN S E HRL • O A NNJ wx 5 kh v • y ol • : • 2 : 2 : 9 : : . : /( /NPRI : 2 SLN EMNTN ERTI NP OEM UIRCH P MAMCE T 8AMN :PN N • • krfh knsga t • ,M I E im CNPE LN S E 0A AV LN S E k • im,MI E v -NO PIGHR X ) 2 -1 ECHMN :N SRINM ,LEPICA 2MC
• , 8 A • h p t P u • l m imn • -- m imn • oc m imn • oc e o • t u O U A UH C P IS O • T s t C y P I • T t P I m imn • T a g I • T I uO I 3 . .21 8 - 8 2 10 81