SSH

Extends expyrimenter.Shell to run commands in a remote host. One parameter was added (the first one), which is the shell SSH arguments (e.g. hostname, user@hostname, -p 2222 user@hostname, etc).

>>> from expyrimenter import SSH
>>> SSH('localhost', 'echo Hello', stdout=True).run()
'Hello'
>>> # You can use try/except
>>> from subprocess import CalledProcessError
>>> try:
>>>     SSH('localhost','wrongcommand').run()
>>> except CalledProcessError as e:
>>>     print("Failed: %s" % e.output)
Failed: bash: wrongcommand: command not found
class expyrimenter.SSH(params, remote_cmd, title=None, stdout=False, stderr=True)[source]

Bases: expyrimenter.shell.Shell

Parameters:
  • params (str) – shell SSH params (at least the hostname).
  • remote_cmd (str) – Command to be run in remote host through SSH.
  • title (str) – A title to be displayed in log outputs. If None, the shell command will be shown.
  • stdout (bool) – Whether or not to display standard output. Default is False.
  • stderr (bool) – Whether or not to display standard error. Default is True.
static await_availability(params, interval=5, max_rand=1)[source]

Periodically tries SSH until it is successful. This function is very useful in cloud environmentes, because there can be a considerable amount of time after a VM is running and before SSH connections are available.

Parameters:
  • params (str) – shell SSH params (at least the hostname).
  • interval (num) – Time in seconds to wait before new trial.
  • max_rand (num) – A float random number between 0 and max_rand will be added to interval.