-
Notifications
You must be signed in to change notification settings - Fork 2
/
IOS.py
42 lines (36 loc) · 1.18 KB
/
IOS.py
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
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
from NetDevices.Device import Device
from pexpect import EOF,TIMEOUT
class IOS(Device):
def __init__(self, device):
super().__init__(device)
self.prompt = self.hostname + "#\s?"
async def login(self, prompt=""):
if not prompt:
prompt = self.prompt
await super().login(prompt)
await self._set_terminal_length_zero()
async def _set_terminal_length_zero(self):
self.c.sendline("terminal length 0")
try:
i = await self.c.expect(self.prompt, async_=True)
except EOF:
pass
except TIMEOUT:
print("session timeout")
async def get_config(self):
self.expect_list = []
self.expect_list.append(self.prompt)
result = []
self.c.sendline("show running-config")
try:
i = await self.c.expect(self.expect_list, timeout=30, async_=True)
if i == 0:
result.append(i)
result.append((self.c.before + self.c.after).decode())
except EOF:
pass
except TIMEOUT:
print("session timeout")
return result