VPN
- async OPNsenseClient.get_openvpn()
Return OpenVPN server and client status information.
- Returns:
- Mapping with
serversandclients 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, returnsNonewhen 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 throughresult_access(), with servers from sessions, noenabledfields, and an emptyclientsinventory. 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 returnsNone. A forbidden provider inventory only omits its enrichment. Route-derivedclientsandconnected_clientsare omitted when routes cannot be fetched or have missing or malformed rows, rather than reporting zero clients. Whenself._throw_errorsisTrue, a failed request raisesOPNsenseErrorinstead, specificallyOPNsensePrivilegeMissingfor a forbidden (403) endpoint. A known missing (404) instance or provider endpoint still allows partial results. Structurally malformed required payloads returnNonerather than raising.
- Mapping with
- Return type:
MutableMapping[str, Any] | None
- async OPNsenseClient.get_wireguard()
Return WireGuard server and client status information.
- Returns:
- Mapping with
serversandclients 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, returnsNonewhen the summary endpoint is unavailable or its rows are missing or malformed. A forbidden (403) client or server configuration endpoint reports Status Access throughresult_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 bykey_hashwithuuid=None, and omitenabled,tunnel_addressesanddns_servers. When interfaces share a server key, the server status isupif any interface is up,downif every interface is down, orNoneotherwise. 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_hashis 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 haskey_hash=None. A valid empty summary under Configuration Access still reports configured peers as disconnected with zero counters. Whenself._throw_errorsisTrue, request failures can raiseOPNsenseError, specificallyOPNsensePrivilegeMissingfor 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, returnNoneregardless of error mode.
- Mapping with
- 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,wireguardoripsec.clients_servers (str) – WireGuard collection containing the instance; use
clientsorservers. IPsec usesconnectionsand OpenVPN ignores this value.uuid (str) – VPN instance UUID.
toggle_on_off (str | None) –
onorofffor an explicit state, orNoneortoggleto flip the current state.
- Returns:
- True when the toggle and service apply succeeded. A flip uses
the save reply’s
changedfield to decide whether to apply. An explicit target requires confirmation of the requested state. A matching explicit target returnsTruewithout 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. Withthrow_errorsenabled, an invalidtoggle_on_offraisesOPNsenseInvalidArgumentand transport errors raiseOPNsenseError. Supported requests that reach the VPN runner raiseasyncio.CancelledErrorif the client is closing or shutdown interrupts the operation. A completed service apply can still report success during shutdown.
- Return type:
- async OPNsenseClient.get_ipsec()
Return IPsec phase 1 (IKE) connection status information.
- Returns:
- Mapping with
connectionskeyed 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.
enabledcomes from the IPsec connections configuration: it isNonefor sessions without a configured connection under Configuration Access and the key is omitted when the configuration reports an unrecognized value. With the defaultthrow_errors=False, returnsNonewhen 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 throughresult_access()and includes only phase 1 connections and phase 2 children visible in sessions, withoutenabledfields. 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.childrenholds phase 2 status keyed by child UUID, withinstall_timeas the age of the oldest installed SA. A transient phase 2 read failure or a decoded phase 2 response without a validrowslist omitschildren. Under Configuration Access, a transient or structurally malformed child configuration reply also omitschildren. Invalid JSON from the child configuration endpoint makes this method returnNoneby default and raiseOPNsenseErrorwhenself._throw_errorsisTrue. ReturnsNonewhen 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. Whenself._throw_errorsisTrue, request failures can raiseOPNsenseError, specificallyOPNsensePrivilegeMissingfor a forbidden (403) endpoint. A known missing (404) connections configuration endpoint still allows session-only results. Structurally malformed phase 1 or connections configuration payloads returnNoneregardless of error mode.
- Mapping with
- 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.
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.
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
Noneif 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.
- Reported level, or
- Return type:
Access | None