aboutsummaryrefslogtreecommitdiff
path: root/contrib/python/podman
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2018-06-27 21:37:42 -0700
committerJhon Honce <jhonce@redhat.com>2018-07-13 11:29:28 -0700
commit44b523c946c88e540b50d7ba59f441b5f8e0bad0 (patch)
tree744c09508b139c1aca3d7fc995fad7ff354e3667 /contrib/python/podman
parent14a6d51a8432fc0c3324fec02e8729d3032f2af2 (diff)
downloadpodman-44b523c946c88e540b50d7ba59f441b5f8e0bad0.tar.gz
podman-44b523c946c88e540b50d7ba59f441b5f8e0bad0.tar.bz2
podman-44b523c946c88e540b50d7ba59f441b5f8e0bad0.zip
remote python client for podman
* Use podman library for access * Verbose error checking * Planned windows and macosx ports Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'contrib/python/podman')
-rw-r--r--contrib/python/podman/libs/errors.py17
-rw-r--r--contrib/python/podman/libs/tunnel.py18
2 files changed, 24 insertions, 11 deletions
diff --git a/contrib/python/podman/libs/errors.py b/contrib/python/podman/libs/errors.py
index c28afd940..b98210481 100644
--- a/contrib/python/podman/libs/errors.py
+++ b/contrib/python/podman/libs/errors.py
@@ -5,14 +5,21 @@ from varlink import VarlinkError
class VarlinkErrorProxy(VarlinkError):
"""Class to Proxy VarlinkError methods."""
- def __init__(self, obj):
+ def __init__(self, message, namespaced=False):
"""Construct proxy from Exception."""
- self._obj = obj
+ super().__init__(message.as_dict(), namespaced)
+ self._message = message
self.__module__ = 'libpod'
- def __getattr__(self, item):
- """Return item from proxied Exception."""
- return getattr(self._obj, item)
+ def __getattr__(self, method):
+ """Return attribute from proxied Exception."""
+ if hasattr(self._message, method):
+ return getattr(self._message, method)
+
+ try:
+ return self._message.parameters()[method]
+ except KeyError:
+ raise AttributeError('No such attribute: {}'.format(method))
class ContainerNotFound(VarlinkErrorProxy):
diff --git a/contrib/python/podman/libs/tunnel.py b/contrib/python/podman/libs/tunnel.py
index 42fd3356b..9effdff6c 100644
--- a/contrib/python/podman/libs/tunnel.py
+++ b/contrib/python/podman/libs/tunnel.py
@@ -1,5 +1,6 @@
"""Cache for SSH tunnels."""
import collections
+import logging
import os
import subprocess
import threading
@@ -96,9 +97,15 @@ class Tunnel(object):
def bore(self, id):
"""Create SSH tunnel from given context."""
+ ssh_opts = '-nNT'
+ if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
+ ssh_opts += 'v'
+ else:
+ ssh_opts += 'q'
+
cmd = [
'ssh',
- '-nNTq',
+ ssh_opts,
'-L',
'{}:{}'.format(self.context.local_socket,
self.context.remote_socket),
@@ -106,15 +113,14 @@ class Tunnel(object):
self.context.identity_file,
'ssh://{}@{}'.format(self.context.username, self.context.hostname),
]
-
- if os.environ.get('PODMAN_DEBUG'):
- cmd.append('-vvv')
+ logging.debug('Tunnel cmd "{}"'.format(' '.join(cmd)))
self._tunnel = subprocess.Popen(cmd, close_fds=True)
- for i in range(5):
+ for i in range(10):
+ # TODO: Make timeout configurable
if os.path.exists(self.context.local_socket):
break
- time.sleep(1)
+ time.sleep(0.5)
else:
raise TimeoutError('Failed to create tunnel using: {}'.format(
' '.join(cmd)))