-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdcli_lib.py
More file actions
51 lines (45 loc) · 1.47 KB
/
mdcli_lib.py
File metadata and controls
51 lines (45 loc) · 1.47 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
46
47
48
49
50
51
"""
mdcli lib for developers
@author: hwx1045592
@time: 2023-4-20
"""
from netmiko import ConnectHandler
from config import huawei, mdcli
class MdcliLib():
"""
some utilities of mdcli operations
"""
def __init__(self):
# init connect
self.net_connect = ConnectHandler(**huawei)
# step in mdcli mode
self.authenticate()
def authenticate(self):
command = 'switch md-cli'
output = self.net_connect.send_command_timing(command)
if "Username" in output:
# print("Starting type username...")
mdcliuser = mdcli['mdcliusername']
output += self.net_connect.send_command_timing(f"{mdcliuser}\n")
if "Password:" in output:
# print("Starting type Password...")
mdclipassword = mdcli['mdclipassword']
output += self.net_connect.send_command_timing(f"{mdclipassword}\n")
def display(self, command):
res = ''
if isinstance(command, list):
for c in command:
res += self.net_connect.send_command(c)
else:
res += self.net_connect.send_command(command)
return res
def curd(self, command):
res = ''
if isinstance(command, list):
for c in command:
res += self.net_connect.send_command(c)
else:
res += self.net_connect.send_command(command)
return res
def __del__(self):
self.net_connect.disconnect()