Я пытаюсь установить соединение, используя pexpect с подходом ниже:
child = pexpect.spawn('telnet {console_ip} {console_port}'.format(console_ip=self.obj.get("console_ip"),
console_port=int(self.obj.get("console_port"))))
while True:
index = child.expect(
["Hit 'c' key to stop autoboot:", "prompt#", "ARGUS", "Loading:", ".*login:", "Escape character is",
"Press \[Ctrl+D\] to go to the Suspend Menu", "Please enter your name:"])
if index == 0:
child.sendline("ccccc\n")
elif index == 1:
time.sleep(1)
child.sendline("\r run net \r")
time.sleep(1)
elif index == 2:
time.sleep(1)
child.sendline("\r reset \r")
time.sleep(5)
elif index == 3:
time.sleep(1)
time.sleep(3)
break
elif index == 4:
child.sendline(user_name+"\r")
elif index == 5:
time.sleep(1)
child.sendline(password+"\r")
elif index == 6:
time.sleep(1)
child.sendline("\r")
elif index == 7:
time.sleep(1)
child.sendline("\r")
elif index == 8:
time.sleep(1)
child.sendline("abcde\r")
Я хочу знать, есть ли лучший способ реализовать то же самое с меньшим количеством строк кода.