-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_netmiko_example.py
More file actions
45 lines (34 loc) · 1.41 KB
/
api_netmiko_example.py
File metadata and controls
45 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Learning Series: Network Programmability Basics
Module: Programming Fundamentals
Lesson: Python Part 3
Author: Hank Preston <hapresto@cisco.com>
api_netmiko_example.py
Illustrate the following concepts:
- Making CLI calls using netmiko library
- Intended to be entered into an interactive
interpreter
"""
import logging
# Specify to log to a file, specify the format for the message and the date format and the logging level
logging.basicConfig(filename='mylog.log',format='%(asctime)s %(levelname)s: %(message)s',datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.DEBUG)
# Log some messages
logging.debug('This is a debug message. You should see this in the file.')
logging.info('This is an info message. You should see this in the file.')
logging.warning('This is a warning message. You should see this in the file.')
from netmiko import ConnectHandler
from pprint import pprint
try:
router = {"device_type": "cisco_ios",
"host": "10.10.20.4",
"user": "cisco",
"pass": "cisco_1234!"}
net_connect = ConnectHandler(ip=router["host"],
username=router["user"],
password=router["pass"],
device_type=router["device_type"])
interface_cli = net_connect.send_command("show run int Gig1")
pprint(interface_cli)
logging.info(interface_cli)
except Exception as e:
logging.error(e)