====== Netzwerkmanangement ======
===== Netconf & YANG =====
* http://www.netconfcentral.org/netconf_docs
* https://keepingitclassless.net/2015/03/sdn-protocols-part-5-netconf/
* http://www.seguesoft.com/yang-primer
* [[https://communities.cisco.com/community/developer/dna/blog/2017/01/04/next-generation-network-device-programming-part1|Getting Started with NETCONF/YANG – Part 1 (Cisco)]]
* https://trac.ietf.org/trac/netconf
* https://www.juniper.net/techpubs/en_US/junos/topics/task/operational/netconf-session-request-sending.html
* https://www.juniper.net/techpubs/en_US/junos/topics/task/operational/netconf-requesting-configuration-committed-and-device-info.html
* https://www.juniper.net/techpubs/en_US/junos/topics/task/operational/netconf-yang-rpcs-custom-retrieving-operational-information.html
==== RFCs ====
* [[https://tools.ietf.org/html/rfc6020| RFC 6020: YANG - A Data Modeling Language for
the Network Configuration Protocol (NETCONF)]]
* [[https://tools.ietf.org/html/rfc6244| RFC 6244: An Architecture for
Network Management Using NETCONF and YANG]]
==== Tools ====
* https://github.com/CiscoDevNet/yang-explorer
==== MQTT-Netconf-YANG Bridge ====
**LED-Color: blue**
mosquitto_pub -d -h localhost -p 1883 -t "yang/config" -m '{
"device":{ "description": "MQTT-Device identified by UUID",
"uuid":{ "type": "string", "value": "F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD" },
"device-category":{ "description": "Identifies the device category", "type": "string", "value":"L-LAMP" } },
"rpc": { "set_color_blue": { "description": "RPC call that sets the LED Color to blue",
"mqtt-command": "BLUE", "input": { "uuid": { "description": "Sends request to device specified by uuid", "type": "string" } } },
"switch_off": { "description": "Switches the LIFX-Led off", "mqtt-command": "OFF" } } }'
{
"device":{
"description":"MQTT-Device identified by UUID",
"uuid":{
"type":"string",
"value":"F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD"
},
"device-category":{
"description":"Identifies the device category",
"type":"string",
"value":"L-LAMP"
}
},
"rpc":{
"set_color_blue":{
"description":"RPC call that sets the LED Color to blue",
"mqtt-command":"BLUE",
"input":{
"uuid":{
"description":"Sends request to device specified by uuid",
"type":"string"
}
}
},
"switch_off":{
"description":"Switches the LIFX-Led off",
"mqtt-command":"OFF"
}
}
}
**LED-Color: green**
mosquitto_pub -d -h localhost -p 1883 -t "yang/config" -m '{ "device":{ "description": "MQTT-Device identified by UUID",
"uuid":{ "type": "string", "value": "F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD" },
"device-category":{ "description": "Identifies the device category", "type": "string", "value":"L-LAMP" } },
"rpc": { "set_color_green": { "description": "RPC call that sets the LED Color to green",
"mqtt-command": "GREEN", "input": { "uuid": { "description": "Sends request to device specified by uuid",
"type": "string" } } }, "switch_off": { "description": "Switches the LIFX-Led off", "mqtt-command": "OFF" } } }'
{
"device":{
"description":"MQTT-Device identified by UUID",
"uuid":{
"type":"string",
"value":"F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD"
},
"device-category":{
"description":"Identifies the device category",
"type":"string",
"value":"L-LAMP"
}
},
"rpc":{
"set_color_green":{
"description":"RPC call that sets the LED Color to green",
"mqtt-command":"GREEN",
"input":{
"uuid":{
"description":"Sends request to device specified by uuid",
"type":"string"
}
}
},
"switch_off":{
"description":"Switches the LIFX-Led off",
"mqtt-command":"OFF"
}
}
}
**LED-Color: green + blue**
mosquitto_pub -d -h localhost -p 1883 -t "yang/config" -m '{
"device":{ "description": "MQTT-Device identified by UUID", "uuid":{ "type": "string", "value": "F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD" }, "device-category":{ "description": "Identifies the device category", "type": "string", "value":"L-LAMP" } },
"rpc": {
"set_color_blue": { "description": "RPC call that sets the LED Color to blue", "mqtt-command": "BLUE", "input": { "uuid": { "description": "Sends request to device specified by uuid", "type": "string" } } },
"set_color_green": { "description": "RPC call that sets the LED Color to green", "mqtt-command": "GREEN", "input": { "uuid": { "description": "Sends request to device specified by uuid", "type": "string" } } },
"switch_off": { "description": "Switches the LIFX-Led off", "mqtt-command": "OFF" } } }'
{
"device":{
"description":"MQTT-Device identified by UUID",
"uuid":{
"type":"string",
"value":"F97dfF79-8A12-4F4F-8F69-6B8F3C2EdadDD"
},
"device-category":{
"description":"Identifies the device category",
"type":"string",
"value":"L-LAMP"
}
},
"rpc":{
"set_color_blue":{
"description":"RPC call that sets the LED Color to blue",
"mqtt-command":"BLUE",
"input":{
"uuid":{
"description":"Sends request to device specified by uuid",
"type":"string"
}
}
},
"set_color_green":{
"description":"RPC call that sets the LED Color to green",
"mqtt-command":"GREEN",
"input":{
"uuid":{
"description":"Sends request to device specified by uuid",
"type":"string"
}
}
},
"switch_off":{
"description":"Switches the LIFX-Led off",
"mqtt-command":"OFF"
}
}
}
m = manager.connect_ssh("localhost", port=44555, username="Thomas", password="admin",allow_agent=False,hostkey_verify=False,look_for_keys=False)
n = xml_.to_ele('')
m.dispatch(n)
n = xml_.to_ele('')
n = xml_.to_ele('12345')
n = xml_.to_ele('12345')
n = xml_.to_ele('1fff')
:!: **ACHTUNG:** Server stürzt ab, wenn kein UUID tag angegeben wird.
Setup in iTerm: (''cd /Users/Thomas/LIFX/demo''):
* Links: ''mqtt/LIFX bridge (./mqtt)''
* Mitte: ''mqtt_publisher (send json)''
* Rechts: ''mqtt_subscriber (mosquitto_sub -d -h localhost -p 1883 -t "#")''
* Unten: ''/usr/local/sbin/mosquitto -c ./mqtt.conf''
==== Terminal: ====
**Virtenv starten:**
source python-virtenv/bin/activate
**NETCONF/MQTT bridge:**
python -i netconf_Server.py # Achtung: MQTT Broker muss vorher gestartet sein!
**ncclient:**
from ncclient import manager
from ncclient import xml_
for capability in m.server_capabilities:
... print(capability)
m = manager.connect_ssh('ios-xe-mgmt.cisco.com', port=10000, username="root", password='C!sc0123',allow_agent=False,hostkey_verify=False,look_for_keys=False)