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