summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-03-10 09:10:22 +0100
committerAnton Khirnov <anton@khirnov.net>2020-03-10 09:11:01 +0100
commitdcf78b00979f0e17bb6102069ae33c93045da388 (patch)
treeb60c2e3d9542f93524de9eac09a45135996ed9ff
parent00bf9f3eafff6f29b4fcf18d7c1f2ab2b1310c16 (diff)
targets: add __str__ methods to targets
Allows to easily get a descriptive string for a target.
-rwxr-xr-xexample.py2
-rw-r--r--lbup/targets.py10
2 files changed, 11 insertions, 1 deletions
diff --git a/example.py b/example.py
index 8cd5c31..ba3e09c 100755
--- a/example.py
+++ b/example.py
@@ -14,7 +14,7 @@ tgts = (
def list_targets(tgts):
for tgt in tgts:
- sys.stdout.write('%s\n' % tgt.name)
+ sys.stdout.write('%s\n %s\n' % (tgt.name, str(tgt)))
# parse the commandline
parser = argparse.ArgumentParser()
diff --git a/lbup/targets.py b/lbup/targets.py
index 0d3ffe8..8f30ae5 100644
--- a/lbup/targets.py
+++ b/lbup/targets.py
@@ -52,6 +52,9 @@ class Target(ABC):
else:
self._logger = logger
+ def __str__(self):
+ return "Target{%s/%s}" % (self.dirs, self.excludes)
+
def _log_command(self, name, retcode, stdout, stderr):
self._logger.debug('%s finished with return code %d' % (name, retcode))
@@ -138,6 +141,9 @@ class TargetSSH(Target):
super().__init__(name, dirs, excludes, logger)
+ def __str__(self):
+ return "%s{SSH:%s}" % (super().__str__(), str(self._remote))
+
def _paramiko_exec_cmd(self, client, cmd):
self._logger.debug('Client %s: executing command: %s' % (client, cmd))
@@ -203,6 +209,10 @@ class TargetSSHLXCLVM(TargetSSH):
super().__init__(name, dirs, excludes, logger, target_remote, target_remote_bupdir)
+ def __str__(self):
+ return "%s{LXC:%s/%s@[%s]}{LVM:%s}" % (super().__str__(), self._lxc_containername,
+ self._lxc_username, str(self._parent_remote), self._snapshot_size)
+
def save(self, data_dir):
with contextlib.ExitStack() as stack:
parent = stack.enter_context(_ssh_client.SSHConnection(self._parent_remote))