Skip to content

OpenVPN Interface

The OpenVPN Interface is used to create secure point-to-point or site-to-site connections.

OpenVPNInterface

Provides a pure Python OpenVPN server interface for HIL testing

Methods:

Name Description
__enter__

Context manager entry

__exit__

Context manager exit

__init__

Initialize OpenVPN server interface.

cleanup

Clean up server resources

generate_client_config

Generate client configuration that can connect to the OpenVPN server.

get_http_url

Get the HTTP server URL.

get_server_info

Get server information

get_vpn_ip

Get the server's IP address on the VPN network.

save_client_config

Generate and save client configuration to file.

setup_server

Generate all certificates and configuration files for OpenVPN server

start_server

Start the OpenVPN server

stop_server

Stop the OpenVPN server

__enter__()

Context manager entry

__exit__(exc_type, exc_val, exc_tb)

Context manager exit

__init__(server_ip='127.0.0.1', server_port=1194, network='10.8.0.0', netmask='255.255.255.0', work_dir=None, auto_detect_location=True, country=None, state=None, locality=None)

Initialize OpenVPN server interface.

Parameters:

Name Type Description Default
server_ip str

IP address the server will bind to (use "127.0.0.1" for auto-detection)

'127.0.0.1'
server_port int

Port the server will listen on

1194
network str

VPN network address

'10.8.0.0'
netmask str

VPN network mask

'255.255.255.0'
work_dir Optional[str]

Working directory for certificates and configs

None
auto_detect_location bool

Auto-detect location for certificate attributes (default: True)

True
country Optional[str]

Country code for certificate attributes (overrides auto-detection)

None
state Optional[str]

State/province for certificate attributes (overrides auto-detection)

None
locality Optional[str]

City/locality for certificate attributes (overrides auto-detection)

None

cleanup()

Clean up server resources

generate_client_config(client_name, server_address=None)

Generate client configuration that can connect to the OpenVPN server.

Parameters:

Name Type Description Default
client_name str

Name for the client certificate

required
server_address Optional[str]

Server address for client config (auto-detected if not provided)

None

Returns:

Type Description
str

Client configuration as string

get_http_url()

Get the HTTP server URL.

get_server_info()

Get server information

get_vpn_ip()

Get the server's IP address on the VPN network.

save_client_config(client_name, output_path, server_address=None)

Generate and save client configuration to file.

Parameters:

Name Type Description Default
client_name str

Name for the client certificate

required
output_path str

Path to save the client configuration

required
server_address Optional[str]

Server address for client config

None

Returns:

Type Description
str

Path to saved configuration file

setup_server(generate_fresh_dh=False)

Generate all certificates and configuration files for OpenVPN server

Parameters:

Name Type Description Default
generate_fresh_dh bool

If True, generate fresh DH parameters (slow). If False, use pre-generated ones (fast).

False

start_server()

Start the OpenVPN server

stop_server()

Stop the OpenVPN server