Nornir - 고성능 네트워크 자동화 프레임워크
개요
Nornir은 순수 Python으로 작성된 네트워크 자동화 프레임워크로, 멀티스레드를 활용하여 대규모 네트워크 환경에서 빠른 성능을 제공합니다.
주요 특징
1. 순수 Python
- YAML 대신 Python 코드로 작성
- IDE 자동완성 지원
- 디버깅 용이
2. 멀티스레딩
from nornir import InitNornir
from nornir_netmiko.tasks import netmiko_send_command
nr = InitNornir(config_file="config.yaml")
# 모든 장비에 병렬로 명령 실행
result = nr.run(
task=netmiko_send_command,
command_string="show version"
)
# 100대 장비를 20초 안에 처리!
3. 플러그인 아키텍처
- nornir-netmiko: SSH 연결
- nornir-napalm: NAPALM 통합
- nornir-scrapli: 고성능 SSH
- nornir-jinja2: 템플릿 렌더링
설치 및 설정
pip install nornir nornir-netmiko nornir-utils
inventory 설정 (hosts.yaml)
---
router1:
hostname: 192.168.1.1
platform: cisco_ios
groups:
- cisco_routers
router2:
hostname: 192.168.1.2
platform: cisco_ios
groups:
- cisco_routers
실전 예제
1. 기본 명령 실행
from nornir import InitNornir
from nornir_netmiko.tasks import netmiko_send_command
from nornir_utils.plugins.functions import print_result
nr = InitNornir(config_file="config.yaml")
result = nr.run(
task=netmiko_send_command,
command_string="show ip interface brief"
)
print_result(result)
2. 설정 배포
from nornir_netmiko.tasks import netmiko_send_config
def configure_interface(task):
config = [
f"interface {task.host['interface']}",
f"description {task.host['description']}",
"no shutdown"
]
result = task.run(
task=netmiko_send_config,
config_commands=config
)
return result
result = nr.run(task=configure_interface)
성능 비교
100대 장비에서 "show version" 실행:
- Ansible: ~5분
- Nornir: ~20초
장점
✓ 매우 빠른 성능 (멀티스레드) ✓ Pure Python (IDE 지원, 디버깅) ✓ 유연한 데이터 처리 ✓ 작은 메모리 사용량
단점
✗ Python 개발 지식 필요 ✗ 작은 커뮤니티 ✗ Ansible보다 적은 플러그인
링크
- GitHub: https://github.com/nornir-automation/nornir
- 문서: https://nornir.readthedocs.io/