A SSH client for systems network automation that uses paramiko.
Project description
Devmiko
A SSH client for systems network automation.
Documentation
Paramiko - SFTPClient
Paramiko - SSHClient
Dependencies
Paramiko
How to install
$ pip install Devmiko
Usage
The client.output holds the full output from all the commands you sent.
SSHClient example
import Devmiko
client = Devmiko.SSHClient(debug=False, filename=None, level='DEBUG')
client.connect('remote_host', username='myusername', password='mypassword')
client.send_command('ls')
client.send_command('sudo su', expect_string=r'^.*Password: $')
client.send_command('mypassword')
print(client.output)
client.disconnect()
Turn on debugging to help you troubleshoot issues with the SSH connection
import Devmiko
client = Devmiko.SSHClient(debug=True, filename='mylogfile.log', level='DEBUG')
You can pass arguments and keyword arguments to the paramiko connection method. Check out the paramiko docs
import Devmiko
client = Devmiko.SSHClient()
client.connect(*args, **kwargs)
How to break out of a prompt? You have to pass the keyword argument expect_string with a regex
import Devmiko
client = Devmiko.SSHClient()
client.connect('remote_host', username='myusername', password='mypassword')
client.send_command('sudo su', expect_string=r'^.*Password: $') # Here we are breaking the prompt at Password:
client.send_command('mypassword')
client.disconnect()
Using Paramiko methods from the Devmiko channel
import Devmiko
import re
client = Devmiko.SSHClient()
client.connect('remote_host', username='myusername', password='mypassword')
client.channel.sendall('ls\n')
output = ''
while True:
temp_output = client.channel.recv(4096).encode('UTF-8')
output += temp_output
if re.search(r'>\s$', temp_output, flags=re.IGNORECASE | re.MULTILINE):
break
print(output)
client.disconnect()
SFTPClient example
For the SFTPClient you need to use the client.channel and use the paramiko methods
import Devmiko
client = Devmiko.SFTPClient()
client.connect('remote_host', username='myusername', password='mypassword')
client.channel.chdir(path='/tmp')
output = client.channel.getcwd()
print(output)
output = client.channel.listdir(path='.')
print(output)
client.channel.get('/tmp/Cleanup.log', 'Downloads/Cleanup.log')
client.disconnect()
Download Files with Progressbar
import Devmiko
client = Devmiko.SFTPClient()
client.connect('remote_host', username='myusername', password='mypassword')
client.get_with_progressbar(remote_file='/tmp/myfile.tar', local_file='Downloads/myfile.tar')
client.disconnect()
Upload Files with Progressbar
import Devmiko
client = Devmiko.SFTPClient()
client.connect('remote_host', username='myusername', password='mypassword')
client.put_with_progressbar(local_file='myfile.tar', remote_file='/tmp/myfile.tar')
client.disconnect()
FTDClient example
The FTDClient include the different Command Line Modes of the FTD so you can enter or switch from mode to mode.
import Devmiko
client = Devmiko.FTDClient(debug=False, filename=None, level='DEBUG')
client.connect('remote_host', username='myusername', password='mypassword')
client.send_command(command='show managers')
client.enter_lina_mode()
client.send_command(command='show run | include hostname')
client.enter_clish_mode()
client.send_command(command='show managers')
client.send_command(command='show failover')
client.enter_diagnostic_cli_mode()
client.send_command(command='show run | include hostname')
client.enter_expert_mode()
client.send_command(command='ls /tmp')
client.enter_regular_mode()
client.send_command(command='show managers')
client.send_command(command='show network')
print(client.output)
client.disconnect()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Devmiko-0.0.1.tar.gz
.
File metadata
- Download URL: Devmiko-0.0.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98c62f8619b2a5cc318c95d7f8704eeb34967af676b1867c5e27354c92f943fd |
|
MD5 | 5b0053b2b80c9e495c13654cc5a457b8 |
|
BLAKE2b-256 | c955fb0190d6ab9ad0d5189e6256669d4c364db7167a69847f45ee3140209425 |
Provenance
File details
Details for the file Devmiko-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: Devmiko-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7de9acaf60897decf1405f93601c2d200064d5a751717a064e8a47480027daf |
|
MD5 | c159666ed09aa418d7c1282aa6c096ff |
|
BLAKE2b-256 | e3440f35b9002687dd806a1f0958c9a28d1b3c7dd0532f449ab8d0de3fa2b665 |