Skip to content

Commit

Permalink
issue #510: add mitogen_container_name= variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
dw committed Feb 1, 2019
1 parent d763570 commit 01840fd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
30 changes: 24 additions & 6 deletions ansible_mitogen/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ def _connect_docker(spec):
'method': 'docker',
'kwargs': {
'username': spec.remote_user(),
'container': spec.remote_addr(),
'container': (
spec.mitogen_container_name() or
spec.remote_addr()
),
'python_path': spec.python_path(),
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
}
Expand All @@ -137,7 +140,10 @@ def _connect_kubectl(spec):
return {
'method': 'kubectl',
'kwargs': {
'pod': spec.remote_addr(),
'pod': (
spec.mitogen_container_name() or
spec.remote_addr()
),
'python_path': spec.python_path(),
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
'kubectl_path': spec.mitogen_kubectl_path(),
Expand All @@ -154,7 +160,10 @@ def _connect_jail(spec):
'method': 'jail',
'kwargs': {
'username': spec.remote_user(),
'container': spec.remote_addr(),
'container': (
spec.mitogen_container_name() or
spec.remote_addr()
),
'python_path': spec.python_path(),
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
}
Expand All @@ -168,7 +177,10 @@ def _connect_lxc(spec):
return {
'method': 'lxc',
'kwargs': {
'container': spec.remote_addr(),
'container': (
spec.mitogen_container_name() or
spec.remote_addr()
),
'python_path': spec.python_path(),
'lxc_attach_path': spec.mitogen_lxc_attach_path(),
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
Expand All @@ -183,7 +195,10 @@ def _connect_lxd(spec):
return {
'method': 'lxd',
'kwargs': {
'container': spec.remote_addr(),
'container': (
spec.mitogen_container_name() or
spec.remote_addr()
),
'python_path': spec.python_path(),
'lxc_path': spec.mitogen_lxc_path(),
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
Expand All @@ -205,7 +220,10 @@ def _connect_setns(spec, kind=None):
return {
'method': 'setns',
'kwargs': {
'container': spec.remote_addr(),
'container': (
spec.mitogen_container_name() or
spec.remote_addr()
),
'username': spec.remote_user(),
'python_path': spec.python_path(),
'kind': kind or spec.mitogen_kind(),
Expand Down
13 changes: 13 additions & 0 deletions ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ def mitogen_ssh_debug_level(self):
The SSH debug level.
"""

@abc.abstractmethod
def mitogen_container_name(self):
"""
Highest precedence variable for specifying the name of a container to
connect to.
"""

@abc.abstractmethod
def extra_args(self):
"""
Expand Down Expand Up @@ -398,6 +405,9 @@ def mitogen_machinectl_path(self):
def mitogen_ssh_debug_level(self):
return self._connection.get_task_var('mitogen_ssh_debug_level')

def mitogen_container_name(self):
return self._connection.get_task_var('mitogen_container_name')

def extra_args(self):
return self._connection.get_extra_args()

Expand Down Expand Up @@ -577,5 +587,8 @@ def mitogen_machinectl_path(self):
def mitogen_ssh_debug_level(self):
return self._host_vars.get('mitogen_ssh_debug_level')

def mitogen_container_name(self):
return self._host_vars.get('mitogen_container_name')

def extra_args(self):
return [] # TODO

1 comment on commit 01840fd

@cloudnull
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This all works in a local test environment consisting of 10 host machines, 3 of which have lxc/nspawn containers running within them.

Please sign in to comment.