def execute_ssh_command(self, command):
"""Executes command on switch.
Args:
command(str): ssh command to execute
"""
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Make connection and create shell.
client.connect(self.ipaddr, self._sshtun_port, self.ssh_user, self.ssh_user_pass)
shell = client.invoke_shell()
# Execute command and get results.
_, stdout, stderr = client.exec_command(command)
data = self._read_command_output(stdout, stderr, 'both')
# Close connection.
shell.close()
client.close()
return data
评论列表
文章目录