updates + ad requriements
This commit is contained in:
parent
255b2bd4ef
commit
5113aef8c2
19
conn/core.py
19
conn/core.py
@ -87,8 +87,12 @@ class node:
|
||||
logfile = re.sub(r'\$\{date (.*)}',now.strftime(dateconf.group(1)), logfile)
|
||||
return logfile
|
||||
|
||||
def _logclean(self, logfile):
|
||||
t = open(logfile, "r").read().replace("\n","",1).replace("\a","")
|
||||
def _logclean(self, logfile, var = False):
|
||||
if var == False:
|
||||
t = open(logfile, "r").read()
|
||||
else:
|
||||
t = logfile
|
||||
t = t.replace("\n","",1).replace("\a","")
|
||||
t = t.replace('\n\n', '\n')
|
||||
t = re.sub('.\[K', '', t)
|
||||
while True:
|
||||
@ -98,10 +102,13 @@ class node:
|
||||
t = tb
|
||||
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/ ]*[@-~])')
|
||||
t = ansi_escape.sub('', t)
|
||||
if var == False:
|
||||
d = open(logfile, "w")
|
||||
d.write(t)
|
||||
d.close()
|
||||
return
|
||||
else:
|
||||
return t
|
||||
|
||||
def interact(self, missingtext = False):
|
||||
connect = self._connect()
|
||||
@ -116,7 +123,7 @@ class node:
|
||||
if "logfile" in dir(self):
|
||||
self._logclean(self.logfile)
|
||||
|
||||
def run(self, commands,*, folder = '', prompt = '>$|#$|\$.$'):
|
||||
def run(self, commands,*, folder = '', prompt = '>$|#$|\$.$', stdout = False):
|
||||
connect = self._connect()
|
||||
if connect == True:
|
||||
output = ''
|
||||
@ -127,18 +134,20 @@ class node:
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
else:
|
||||
self.child.expect(prompt)
|
||||
print(self.child.sendline(commands))
|
||||
self.child.sendline(commands)
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
self.child.expect(prompt)
|
||||
output = output + self.child.before.decode() + self.child.after.decode()
|
||||
if folder == '':
|
||||
if stdout == True:
|
||||
print(output)
|
||||
else:
|
||||
with open(folder + "/" + self.unique, "w") as f:
|
||||
f.write(output)
|
||||
f.close()
|
||||
self._logclean(folder + "/" + self.unique)
|
||||
|
||||
self.output = output
|
||||
return output
|
||||
|
||||
|
||||
|
||||
|
3
conn/requirements.txt
Normal file
3
conn/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
pexpect~=4.8.0
|
||||
pycryptodome~=3.14.1
|
||||
PyYAML~=6.0
|
18
test.py
18
test.py
@ -17,13 +17,17 @@ conf = conn.configfile("test.yaml")
|
||||
# print(yaml.dump(conf.profiles))
|
||||
# conf.saveconfig("test.yaml")
|
||||
# ***
|
||||
xr=conn.node("xr@home", **conf.connections["home"]["xr"], config=conf)
|
||||
ios=conn.node("ios@home", **conf.connections["home"]["ios"], config=conf)
|
||||
norman = conn.node("norman@home", **conf.connections["home"]["norman"], config=conf)
|
||||
eve = conn.node("eve@home", **conf.connections["home"]["eve"], config=conf)
|
||||
# xr=conn.node("xr@home", **conf.connections["home"]["xr"], config=conf)
|
||||
# ios=conn.node("ios@home", **conf.connections["home"]["ios"], config=conf)
|
||||
# norman = conn.node("norman@home", **conf.connections["home"]["norman"], config=conf)
|
||||
# eve = conn.node("eve@home", **conf.connections["home"]["eve"], config=conf)
|
||||
router228 = conn.node("router228@bbva", **conf.connections["bbva"]["router228"], config=conf)
|
||||
# router228.interact()
|
||||
router228.run(["term len 0","show ip int br"])
|
||||
# xr.run(["term len 0","show ip bgp", "show ip bgp summ"], folder="test")
|
||||
# ios.run(["term len 0","show ip bgp", "show ip bgp summ"], folder="test")
|
||||
# ios.run(["term len 0","show ip bgp", "show ip bgp summ"])
|
||||
# norman.run(["ls -la", "pwd"], folder = "test")
|
||||
# eve.run(["ls -la", "pwd"], folder = "test")
|
||||
xr.interact()
|
||||
# test = eve.run(["ls -la", "pwd"])
|
||||
print(router228.output)
|
||||
# xr.interact()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user