Home » Network Automation with Python: Netmiko, NAPALM และ Nornir
Network Automation with Python: Netmiko, NAPALM และ Nornir
Network Automation with Python: Netmiko, NAPALM และ Nornir
Network Automation คือการใช้ software เพื่อ automate งาน network ที่ทำซ้ำๆ เช่น configuration changes, compliance checks, backup configs และ troubleshooting Python เป็นภาษาที่นิยมที่สุดสำหรับ network automation เพราะมี libraries เฉพาะทางหลายตัวที่รองรับ multi-vendor devices
Network engineer ที่ดูแล devices หลายร้อยถึงหลายพันตัว ไม่สามารถ SSH เข้าไป config ทีละตัวได้ทัน การ automate ช่วยลดเวลา ลด human error และทำให้ configuration consistent ทั้ง network บทความนี้จะเปรียบเทียบ 3 Python libraries หลักสำหรับ network automation
Netmiko vs NAPALM vs Nornir
| คุณสมบัติ |
Netmiko |
NAPALM |
Nornir |
| ประเภท |
SSH library (send commands) |
Abstraction library (vendor-agnostic) |
Automation framework (orchestration) |
| วิธีทำงาน |
SSH เข้าอุปกรณ์ → ส่ง CLI commands |
API/CLI abstraction → structured data |
Inventory + tasks + parallel execution |
| Multi-vendor |
รองรับ 50+ vendors |
รองรับ 10+ vendors (via drivers) |
ใช้ร่วมกับ Netmiko/NAPALM |
| Output |
Raw text (ต้อง parse เอง) |
Structured data (dict/JSON) |
ขึ้นกับ plugin ที่ใช้ |
| Difficulty |
ง่าย (beginner-friendly) |
ปานกลาง |
ปานกลาง-สูง |
| เหมาะกับ |
Quick scripts, simple automation |
Config management, getters |
Large-scale automation |
Netmiko
SSH Library สำหรับ Network Devices
| Feature |
รายละเอียด |
| Connection |
SSH (Paramiko-based) + Telnet |
| Vendors |
Cisco IOS/IOS-XE/NX-OS, Juniper, Arista, HP, FortiGate, MikroTik, etc. |
| send_command() |
ส่ง show command → รับ output (text) |
| send_config_set() |
ส่ง config commands (enter config mode อัตโนมัติ) |
| send_config_from_file() |
ส่ง config จากไฟล์ |
| TextFSM/Genie |
Parse text output เป็น structured data |
| SCP File Transfer |
Upload/download files ผ่าน SCP |
NAPALM
Network Automation and Programmability Abstraction Layer
| Feature |
รายละเอียด |
| Getters |
get_facts(), get_interfaces(), get_bgp_neighbors() → structured JSON |
| Config Management |
load_merge_candidate(), load_replace_candidate() |
| Compare Config |
compare_config() → ดู diff ก่อน apply |
| Commit/Rollback |
commit_config(), rollback() |
| Validation |
compliance_report() → ตรวจสอบ config ตาม template |
| Drivers |
IOS, IOS-XR, NX-OS, Junos, EOS, FortiOS, PANOS |
Nornir
Python Automation Framework
| Feature |
รายละเอียด |
| Inventory |
YAML/SimpleInventory → กำหนด hosts, groups, defaults |
| Tasks |
Python functions ที่ run บนแต่ละ host |
| Plugins |
nornir_netmiko, nornir_napalm, nornir_scrapli |
| Parallel Execution |
Run tasks บนหลาย devices พร้อมกัน (threaded) |
| Filtering |
Filter hosts ตาม group, platform, custom attributes |
| Results |
Structured results per host per task |
เลือก Library ตาม Use Case
| Use Case |
แนะนำ |
เหตุผล |
| Quick script (backup configs) |
Netmiko |
ง่าย เร็ว beginner-friendly |
| Show command + parse output |
Netmiko + TextFSM |
send_command() + structured output |
| Config deployment with rollback |
NAPALM |
compare_config() + commit/rollback |
| Multi-vendor structured data |
NAPALM |
Getters return JSON (vendor-agnostic) |
| Large-scale (100+ devices) |
Nornir |
Parallel execution + inventory management |
| CI/CD pipeline |
Nornir + NAPALM |
Structured, testable, idempotent |
| Event-driven automation |
Netmiko + custom scripts |
Triggered by SNMP traps/syslog |
Other Tools
| Tool |
ประเภท |
เหมาะกับ |
| Ansible (network modules) |
Agentless automation |
Config management, playbooks, non-programmers |
| Scrapli |
SSH library (modern) |
Alternative to Netmiko, async support |
| pyATS/Genie |
Cisco testing framework |
Network testing, parsing, Cisco-focused |
| Terraform (network providers) |
Infrastructure as Code |
Cloud networking, declarative config |
| RESTCONF/NETCONF |
API protocols |
Model-driven (YANG), modern devices |
Getting Started Path
| Level |
เรียนอะไร |
Timeline |
| 1. Python Basics |
Variables, loops, functions, files, modules |
2-4 สัปดาห์ |
| 2. Netmiko |
SSH connections, send commands, parse output |
1-2 สัปดาห์ |
| 3. TextFSM/Genie |
Parse CLI output เป็น structured data |
1 สัปดาห์ |
| 4. NAPALM |
Getters, config management, validation |
1-2 สัปดาห์ |
| 5. Nornir |
Inventory, tasks, plugins, parallel execution |
2 สัปดาห์ |
| 6. RESTCONF/NETCONF |
API-based automation (YANG models) |
2-4 สัปดาห์ |
ทิ้งท้าย: Network Automation = ทักษะที่ต้องมี
Network Automation ไม่ใช่ optional อีกต่อไป เริ่มต้นด้วย Python + Netmiko (ง่ายที่สุด) เพิ่ม NAPALM สำหรับ structured data + config management ใช้ Nornir สำหรับ large-scale automation ค่อยๆ เรียนรู้ทีละ step อย่าพยายามเรียนทุกอย่างพร้อมกัน
อ่านเพิ่มเติมเกี่ยวกับ Ansible Network Automation และ Network Monitoring Tools ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com