2011-09-13 21:53:02 +00:00
|
|
|
from . import run
|
2011-05-31 21:33:00 +00:00
|
|
|
|
|
|
|
class Remote(object):
|
|
|
|
"""
|
|
|
|
A connection to a remote host.
|
|
|
|
|
|
|
|
This is a higher-level wrapper around Paramiko's `SSHClient`.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# for unit tests to hook into
|
2011-05-31 21:59:10 +00:00
|
|
|
_runner = staticmethod(run.run)
|
2011-05-31 21:33:00 +00:00
|
|
|
|
|
|
|
def __init__(self, name, ssh, shortname=None):
|
|
|
|
self.name = name
|
|
|
|
self._shortname = shortname
|
|
|
|
self.ssh = ssh
|
|
|
|
|
|
|
|
@property
|
|
|
|
def shortname(self):
|
|
|
|
name = self._shortname
|
|
|
|
if name is None:
|
|
|
|
name = self.name
|
|
|
|
return name
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.shortname
|
|
|
|
|
2011-06-06 22:12:13 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return '{classname}(name={name!r})'.format(
|
|
|
|
classname=self.__class__.__name__,
|
|
|
|
name=self.name,
|
|
|
|
)
|
|
|
|
|
2011-05-31 21:33:00 +00:00
|
|
|
def run(self, **kwargs):
|
|
|
|
"""
|
|
|
|
This calls `orchestra.run.run` with our SSH client.
|
|
|
|
|
|
|
|
TODO refactor to move run.run here?
|
|
|
|
"""
|
2011-06-03 21:44:29 +00:00
|
|
|
r = self._runner(client=self.ssh, **kwargs)
|
|
|
|
r.remote = self
|
|
|
|
return r
|