DockerNamespace#
- class wattson.networking.namespaces.docker_namespace.DockerNamespace(name: str, logger: Logger | None = None)#
Bases:
Namespace
Methods
Executes a function in this namespace.
Cleans up the networking namespace :return:
Creates a new networking namespace with the specified name
Executes a command in the network namespace
Checks whether the namespace exists :return: True if the namespace exists
from_pid
get_container
Spawns a new process in the network namespace
Moves the given process to this networking namespace.
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: