Created
December 16, 2015 01:57
-
-
Save TechplexEngineer/56435b53c580d0f0d554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import paramiko, time | |
| def run_commands(ip_address, user, password, commandList, platform='', buffer=5000): | |
| """ this function runs the specified commands on the node and returns a | |
| list with unfiltered results. | |
| """ | |
| print "Configuring " + ip_address | |
| remote_conn_pre = paramiko.SSHClient() | |
| remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
| remote_conn_pre.connect(ip_address, username=user, password=password) | |
| remote_conn = remote_conn_pre.invoke_shell() | |
| if platform == "cisco": | |
| remote_conn.send("enable\n") | |
| time.sleep(1) | |
| remote_conn.send(password+'\n') | |
| time.sleep(1) | |
| commands = commandList.split('\n') | |
| for com in commands: | |
| remote_conn.send(com+'\n') | |
| time.sleep(1) | |
| output = remote_conn.recv(buffer) | |
| #print output | |
| if __name__ == '__main__': | |
| run_commands('50.1.1.1', 'vyos', 'vyos', 'configure\nexit') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment