nord.vpn
¶
Tools for starting and supervising OpenVPN clients.
-
nord.vpn.
run
(config, username, password, dns_servers=())[source]¶ Run an OpenVPN client until it dies and return the exit code.
Optionally provide DNS servers that will replace the contents of ‘/etc/resolv.conf’ for the duration of the client.
Parameters: - config (str) – The contents of the OpenVPN config file.
- password (username,) – Credentials for the OpenVPN connection.
- dns_servers (tuple of str, optional) – IP addresses of DNS servers with which to populate ‘/etc/resolv.conv’ when the VPN is up.
-
nord.vpn.
start
(config, username, password)[source]¶ Start an OpenVPN client with the given configuration.
Parameters: - config (str) – The contents of the OpenVPN config file.
- password (username,) – Credentials for the OpenVPN connection.
Returns: proc
Return type: asyncio.subprocess.Process
Raises: - PermissionError if we cannot use ‘sudo’ without a password.
- OpenVPNError if the OpenVPN process does not start correctly.
- LockError if a lock could not be obtained for the lockfile.
Notes
Obtains a lock on a global lockfile before launching an OpenVPN client in a subprocess. The lock is released when the process dies.
-
nord.vpn.
supervise
(proc)[source]¶ Supervise a process.
This coroutine supervises a process and writes its stdout to a logger until it dies, or until the coroutine is cancelled, when the process will be killed.
Parameters: proc (asyncio.subprocess.Process) – Returns: returncode – ‘proc.returncode’. Return type: int