š¤ 5.1 Model Driven Programmability
What is Model Driven Programmability?
Model Driven Programmability uses standardized data models (YANG) to configure and manage network devices. Instead of CLI commands, you work with structured data models.
YANG Data Models
š Standardized Configuration Models
YANG is a data modeling language for network configuration and state data.
# YANG Model Example
module ietf-interfaces {
namespace "urn:ietf:params:xml:ns:yang:ietf-interfaces";
prefix if;
container interfaces {
list interface {
key "name";
leaf name {
type string;
}
leaf description {
type string;
}
leaf enabled {
type boolean;
default true;
}
}
}
}NETCONF Protocol
š XML-Based Configuration Protocol
NETCONF provides a standardized way to configure network devices using XML over SSH (port 830).
# Python NETCONF Example
from ncclient import manager
with manager.connect(
host='192.168.1.1',
port=830,
username='admin',
password='password',
hostkey_verify=False
) as m:
# Get configuration
config = m.get_config(source='running')
print(config)RESTCONF Protocol
š RESTful API for YANG Models
RESTCONF provides HTTP-based access to YANG data models.
# Python RESTCONF Example
import requests
url = "https://192.168.1.1/restconf/data/ietf-interfaces:interfaces"
headers = {
"Content-Type": "application/yang-data+json",
"Accept": "application/yang-data+json"
}
response = requests.get(url, headers=headers, auth=('admin', 'password'), verify=False)
print(response.json())āļø 5.2 Controller vs Device Management
Overview
Controller-level management uses centralized controllers, while device-level management involves direct device configuration.
Controller-Level Management
šÆ Centralized Control
Controller-level management provides a single pane of glass for network operations.
Benefits
- Centralized View: Single dashboard for entire network
- Policy-Based: Define intent, controller implements
- Automation: Bulk operations across devices
- Simplified: Abstract complexity
# Controller API Example (DNA Center)
import requests
url = "https://dna-center.example.com/dna/intent/api/v1/network-device"
headers = {
"X-Auth-Token": "your_token",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers, verify=False)
devices = response.json()
print(f"Found {len(devices['response'])} devices")Device-Level Management
š§ Direct Device Control
Device-level management provides granular control over individual devices.
Use Cases
- Troubleshooting: Direct access for debugging
- Specific Features: Access device-specific features
- Custom Config: Fine-grained control
- Legacy Devices: Devices not managed by controller
# Device API Example (RESTCONF)
import requests
url = "https://192.168.1.1/restconf/data/ietf-interfaces:interfaces"
headers = {
"Content-Type": "application/yang-data+json",
"Accept": "application/yang-data+json"
}
response = requests.get(url, headers=headers, auth=('admin', 'password'), verify=False)
print(response.json())Comparison Table
| Aspect | Controller-Level | Device-Level |
|---|---|---|
| Scope | Network-wide | Per device |
| Complexity | Simplified | Detailed |
| Speed | Bulk operations | Individual config |
| Best For | Day-to-day operations | Troubleshooting |
š Interactive Python Interpreter
- Write Python code in the editor
- Click "ā¶ Run Code" to execute
- Try sample code buttons