DockerNamespace#

class wattson.networking.namespaces.docker_namespace.DockerNamespace(name: str, logger: Logger | None = None)#

Bases: Namespace

Methods

__init__

call

Executes a function in this namespace.

clean

Cleans up the networking namespace :return:

create

Creates a new networking namespace with the specified name

exec

Executes a command in the network namespace

exists

Checks whether the namespace exists :return: True if the namespace exists

from_pid

get_container

popen

Spawns a new process in the network namespace

process_attach

Moves the given process to this networking namespace.

thread_attach

Moves the calling thread to this networking namespace :return:

__init__(name: str, logger: Logger | None = None)#
call(function: Callable, arguments: Tuple | None = None) Any#

Executes a function in this namespace.

Parameters:
  • function (Callable) – The function (callable) to run

  • arguments (Optional[Tuple], optional) – (Optional) parameters to pass to the function (Default value = None)

Returns:

The return value of the called function

Return type:

Any

clean() bool#

Cleans up the networking namespace :return:

create(clean: bool = True) bool#

Creates a new networking namespace with the specified name

Parameters:

clean (bool, optional) – Whether to try to clean any existing namespace with the same name (Default value = True)

exec(command, **kwargs) Tuple[bool, List[str]]#

Executes a command in the network namespace

Parameters:
  • command (Union[str, List[str]]) –

  • **kwargs

exists() bool#

Checks whether the namespace exists :return: True if the namespace exists

popen(cmd: str | List[str], **kwargs) Popen#

Spawns a new process in the network namespace

Parameters:
  • cmd (Union[str, List[str]]) – The cmd to execute

  • **kwargs

Returns:

Popen

Return type:

subprocess.Popen

process_attach(pid: int | None = None)#

Moves the given process to this networking namespace. If no PID is given, moves the current process.

Parameters:

pid (Optional[int], optional) – The PID of the process to attach. None for current process (Default value = None)

thread_attach()#

Moves the calling thread to this networking namespace :return: