Namespace#

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

Bases: object

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

file_get_contents

file_put_contents

from_pid

get_namespaces

loopback_up

Sets the loopback interface in the namespace up :return:

popen

Spawns a new process in the network namespace

process_attach

Moves the given process to this networking namespace.

set_name_servers

thread_attach

Moves the calling thread to this networking namespace :return:

Attributes

NAMESPACE_PATH_ETC

NAMESPACE_PATH_RUN

NAMESPACE_PATH_VAR

is_network_namespace

__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: str | List[str], **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

loopback_up() bool#

Sets the loopback interface in the namespace up :return:

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: