After much effort on python class now my code working as expected.
But I used below code in every place in my script:
buff = ''
while not buff.endswith('#'):
resp = self.remote_conn.recv(9999)
buff += resp
print resp
Any one can please help me to avoid using above code multiple times, in the below code
class Asr:
def __init__(self):
''' SSH connection Establish '''
self.hostname = hostname
self.net_username = net_username
self.net_password = net_password
def remote(self):
self.remote_conn_pre = paramiko.SSHClient()
self.remote_conn_pre.set_missing_host_key_policy(
paramiko.AutoAddPolicy())
self.remote_conn_pre.connect(self.hostname, username=self.net_username, password=self.net_password, look_for_keys=False, allow_agent=False)
self.remote_conn = self.remote_conn_pre.invoke_shell()
def disable_paging(self):
self.remote_conn.send("terminal length 0\n")
def inventory(self):
self.remote()
self.remote_conn.send("\n")
self.remote_conn.send("ping 1.1.1.1\n")
buff = ''
while not buff.endswith('#'):
resp = self.remote_conn.recv(9999)
buff += resp
print resp
self.remote_conn.send("ping 1.1.1.1\n")
buff = ''
while not buff.endswith('#'):
resp = self.remote_conn.recv(9999)
buff += resp
print resp
self.remote_conn.send("ping 1.1.1.1\n")
buff = ''
while not buff.endswith('#'):
resp = self.remote_conn.recv(9999)
buff += resp
print resp
self.remote_conn.close()
def version(self):
self.remote()
self.remote_conn.send("\n")
self.remote_conn.send("ping 1.1.1.1\n")
buff = ''
while not buff.endswith('#'):
resp = self.remote_conn.recv(9999)
buff += resp
print resp
self.disable_paging()
self.remote_conn.send("show inventory\n")
buff = ''
while not buff.endswith('#'):
resp = self.remote_conn.recv(9999)
buff += resp
print resp
self.remote_conn.close()
asr = Asr()
asr.inventory()
asr.version()