VPN

async OPNsenseClient.get_openvpn()

Return OpenVPN server and client status information.

Returns:

Mapping with servers and clients

keyed by UUID. Server entries combine instance, provider, session, route, tunnel-address, DNS, status, byte-counter, and connected-client data when available. With the default throw_errors=False, returns None when the sessions endpoint is unavailable or its rows are missing or malformed. A known missing (404) inventory endpoint is treated as empty. A forbidden (403) instance inventory reports Status Access through result_access(), with servers from sessions, no enabled fields, and an empty clients inventory. Provider export and instance details are skipped under Status Access. Without an instance denial, the inventory reads must succeed or report absence for this method to return a Configuration Access result. A transient failure or malformed inventory returns None. A forbidden provider inventory only omits its enrichment. Route-derived clients and connected_clients are omitted when routes cannot be fetched or have missing or malformed rows, rather than reporting zero clients. When self._throw_errors is True, a failed request raises OPNsenseError instead, specifically OPNsensePrivilegeMissing for a forbidden (403) endpoint. A known missing (404) instance or provider endpoint still allows partial results. Structurally malformed required payloads return None rather than raising.

Return type:

MutableMapping[str, Any] | None

async OPNsenseClient.get_wireguard()

Return WireGuard server and client status information.

Returns:

Mapping with servers and clients

keyed by UUID under Configuration Access. Entries combine configured tunnel addresses, peer links, enabled state, interface names, handshake status, byte counters, and connected peer counts where available. With the default throw_errors=False, returns None when the summary endpoint is unavailable or its rows are missing or malformed. A forbidden (403) client or server configuration endpoint reports Status Access through result_access() even when the other configuration inventory fails or is malformed. Without a denial, both inventories must be readable or missing (404) for this method to return a result. Under Status Access, entries come from the status summary, are keyed by key_hash with uuid=None, and omit enabled, tunnel_addresses and dns_servers. When interfaces share a server key, the server status is up if any interface is up, down if every interface is down, or None otherwise. The server takes its name and interface from a row that supports that status, choosing the first interface name in lexical order among ties. At either level, key_hash is the first 16 lowercase hex characters of the SHA-256 of the public key string as reported by the Router. A configured entry without a public key has key_hash=None. A valid empty summary under Configuration Access still reports configured peers as disconnected with zero counters. When self._throw_errors is True, request failures can raise OPNsenseError, specifically OPNsensePrivilegeMissing for a forbidden (403) endpoint. A known missing (404) endpoint is treated as empty for the clients and servers configuration inventories. An empty list for either configuration inventory means none are configured and yields an empty mapping. Structurally malformed required payloads, including a non-empty inventory list, return None regardless of error mode.

Return type:

MutableMapping[str, Any] | None

async OPNsenseClient.toggle_vpn_instance(vpn_type, clients_servers, uuid, toggle_on_off=None)

Toggle a VPN instance and retry known unapplied changes.

WireGuard reads state before toggling because firmware through 26.7.9 ignores its target path, then best-effort corrects a mismatched result. A per-service client lock serializes this client’s toggles, but independent clients and external writers can still race. Known saved changes are retained only on this client and retried by a later matching request; transport failures can leave remote apply state unknown. If the caller cancels after a VPN POST dispatch, the call waits for its response before propagating cancellation so an acknowledged save can be tracked. Closing the client can cancel the queue worker before the response arrives. If OPNsense saved the change, the client may not track it, and a later matching request can skip the service reconfigure.

Parameters:
  • vpn_type (str) – VPN implementation to toggle: openvpn, wireguard or ipsec.

  • clients_servers (str) – WireGuard collection containing the instance; use clients or servers. IPsec uses connections and OpenVPN ignores this value.

  • uuid (str) – VPN instance UUID.

  • toggle_on_off (str | None) – on or off for an explicit state, or None or toggle to flip the current state.

Returns:

True when the toggle and service apply succeeded. A flip uses

the save reply’s changed field to decide whether to apply. An explicit target requires confirmation of the requested state. A matching explicit target returns True without a service reconfigure unless this client tracks an earlier unapplied save. False when the toggle or apply cannot be confirmed, for an unknown VPN type or collection, for an empty WireGuard UUID, or when an error was suppressed. With throw_errors enabled, an invalid toggle_on_off raises OPNsenseInvalidArgument and transport errors raise OPNsenseError. Supported requests that reach the VPN runner raise asyncio.CancelledError if the client is closing or shutdown interrupts the operation. A completed service apply can still report success during shutdown.

Return type:

bool

async OPNsenseClient.get_ipsec()

Return IPsec phase 1 (IKE) connection status information.

Returns:

Mapping with connections keyed by the

IKE connection UUID. Entries combine the connection description, IKE version, local and remote addresses and identities, the connected state, install age, routing state, and byte and packet counters reported by the OPNsense IPsec sessions API. enabled comes from the IPsec connections configuration: it is None for sessions without a configured connection under Configuration Access and the key is omitted when the configuration reports an unrecognized value. With the default throw_errors=False, returns None when the connections configuration cannot be read this time, so a partial inventory cannot be mistaken for a complete one. A known missing (404) connections endpoint allows session-only results with Configuration Access. A forbidden (403) connections endpoint reports Status Access through result_access() and includes only phase 1 connections and phase 2 children visible in sessions, without enabled fields. Child configuration is skipped under Status Access. A forbidden child configuration endpoint on its own only removes configured-only children from the result. Configured connections without a session, including disabled ones, are reported as disconnected. children holds phase 2 status keyed by child UUID, with install_time as the age of the oldest installed SA. A transient phase 2 read failure or a decoded phase 2 response without a valid rows list omits children. Under Configuration Access, a transient or structurally malformed child configuration reply also omits children. Invalid JSON from the child configuration endpoint makes this method return None by default and raise OPNsenseError when self._throw_errors is True. Returns None when the phase 1 sessions endpoint is unavailable or its rows are missing or malformed. A valid empty session list still reports configured connections and children as disconnected with zero counters. When self._throw_errors is True, request failures can raise OPNsenseError, specifically OPNsensePrivilegeMissing for a forbidden (403) endpoint. A known missing (404) connections configuration endpoint still allows session-only results. Structurally malformed phase 1 or connections configuration payloads return None regardless of error mode.

Return type:

MutableMapping[str, Any] | None

Access reporting

class aiopnsense.Access(*values)[source]

Access level detected from the Router’s responses.

STATUS = 'status'
CONFIGURATION = 'configuration'
class aiopnsense.AccessDict(data, *, access)[source]

Dictionary result that carries its reported access level.

access

Detected access level.

Type:

Access

Initialize a dictionary result.

Parameters:
  • data (Mapping[K, V]) – Result entries.

  • access (Access) – Detected access level.

class aiopnsense.AccessList(data, *, access)[source]

List result that carries its reported access level.

access

Detected access level.

Type:

Access

Initialize a list result.

Parameters:
  • data (Iterable[T]) – Result items.

  • access (Access) – Detected access level.

aiopnsense.result_access(result)[source]

Read the access level attached to a result.

Parameters:

result (object) – Data returned by a getter.

Returns:

Reported level, or None if the result does not carry one.

Callers can handle an unreported level as Configuration Access. Deep copying and pickling preserve the level. Plain copies made with dict(), list() or JSON serialization discard it.

Return type:

Access | None