Package: jumpssh
JumpSSH:Python module to run commands on remote serversCopyright:Copyright (c) 2017 Amadeus sasLicense:MITDocumentation:https://jumpssh.readthedocs.ioDevelopment:https://github.com/AmadeusITGroup/JumpSSHWhatJumpSSHis a module for Python 2.7+/3.5+ that can be used to run commands on remote servers through a gateway.It is based onparamiko library.
It provides the ability to execute commands on hosts that are not directly accessible but only through one or
more servers.
Script does not need to be uploaded on a remote server and can be run locally.Several authentication methods are supported (password, ssh key).Commands can be run through several jump servers before reaching the remote server.
No need to establish a session for each command, a single ssh session can run as many command as you want,
including parallel queries, and you will get result for each command independently.So, why another python library to setup remote server through ssh ? Here is a quick comparison with the most known existing python librariesParamiko: provide very good implementation of SSHv2 protocol in python but with a low level api a bit complexAnsible: require more configuration and understanding to start.
Moreover, support of bastion host is done with modification of local ssh config to use ProxyCommand, and this is
needed for each bastion host.Fabric: use of jump server is much easier than Ansible thanks to ‘env.gateway’ parameter, but does not allow jump through several servers.InstallationTo install JumpSSH, simply:$pipinstalljumpsshExamplesestablish ssh session with a remote host through a gateway:>>>fromjumpsshimportSSHSession# establish ssh connection between your local machine and the jump server>>>gateway_session=SSHSession('gateway.example.com',...'my_user',password='my_password').open()# from jump server, establish connection with a remote server>>>remote_session=gateway_session.get_remote_session('remote.example.com',...password='my_password2')run commands on remote host:# command will be executed remotely and output will be returned locally and printed>>>print(remote_session.get_cmd_output('ls -lta'))total28drwxr-xr-x.412rootroot12288Mar2114:25..drwx------.2my_usermy_user28Mar619:25.sshdrwx------.3my_usermy_user70Mar619:25.-rw-r--r--.1my_usermy_user18Jul122016.bash_logout-rw-r--r--.1my_usermy_user193Jul122016.bash_profile-rw-r--r--.1my_usermy_user231Jul122016.bashrc# get exit code of the remotely executed command (here to check if a package is installed)>>>remote_session.get_exit_code('yum list installed package_name')0remote rest api usage:# calling rest api on remote host that is only accessible from the gateway>>>fromjumpsshimportRestSshClient>>>rest_client=RestSshClient(gateway_session)# syntax is similar to requests library (http://docs.python-requests.org)>>>http_response=rest_client.get('http://remote.example.com/helloworld')>>>http_response.status_code200>>>http_response.textu'Hello, World!'remote files operations:# check if remote path exists>>>remote_session.exists('/path/to/a/file')True# copy file from local machine to remote host through gateway>>>remote_session.put('/local/path/to/a/file','/remote/path/to/the/file')# create file on remote host from local content>>>remote_session.file('/remote/path/to/the/file',...content='remote file content',permissions='600')# download remote file on local machine from remote host through gateway>>>remote_session.get('/remote/path/to/the/file','/local/path/')Testsjumpssh tests require docker, checkdocker documentationfor how to install it
depending on your OS.
it also requires few python packages. To install them, run:$pipinstall-rrequirements_dev.txtTo run the test suite, clone the repository and run:$pytest-svtests/or simply:$toxContributingBug ReportsBug reports are hugely important! Before you raise one, though,
please check through theGitHub issues,
both open and closed, to confirm that the bug hasn’t been reported before.Feature RequestsIf you think a feature is missing and could be useful in this module, feel free to raise a feature request through theGitHub issuesCode ContributionsWhen contributing code, please followthis project-agnostic contribution guide.