This program displays the hostname, serial number, and OS version of a device. The “get_facts” command includes all of these details. We need to modify the parameters so that it displays the result as per our requirements.
Complete program for displaying hostname, serial number and os version
from napalm import get_network_driver
import json
driver = get_network_driver('ios')
with driver('131.226.217.143','developer','C1sco12345') as device:
output = json.dumps(device.get_facts())
result = json.loads(output)
print('Serial Number : ',result['serial_number'])
print('Hostname : ',result['hostname'])
print('OS version : ',result['os_version'])
Output
Serial Number : 9ESGOBARV9D
Hostname : csr1000v-1
OS version : Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.1a, RELEASE SOFTWARE (fc3)
Process finished with exit code 0