hfortix_fortios.Transaction
- class hfortix_fortios.Transaction(client, timeout=60, vdom=None, auto_commit=True, auto_abort=True)[source]
FortiOS batch transaction manager.
Supports atomic multi-request operations with automatic commit/abort. Available in FortiOS 6.4.0+.
Transaction changes are cached and not applied until committed. Use abort() to rollback all changes.
- transaction_id
Unique transaction ID assigned by FortiOS
- is_active
Whether transaction is currently active
- is_committed
Whether transaction has been committed
- is_aborted
Whether transaction has been aborted
Examples
>>> # Automatic mode (default) >>> with fgt.transaction() as txn: ... fgt.api.cmdb.system.interface.post(name="vlan10", ...) ... fgt.api.cmdb.firewall.policy.post(srcintf=[{"name": "vlan10"}], ...) ... # Auto-commits on success, auto-aborts on exception
>>> # Review before commit >>> with fgt.transaction(auto_commit=False) as txn: ... fgt.api.cmdb.system.interface.post(...) ... cached = txn.show() # Inspect what will be committed ... if confirm(cached): ... txn.commit() ... else: ... txn.abort()
>>> # Manual error handling >>> with fgt.transaction(auto_abort=False) as txn: ... try: ... fgt.api.cmdb.system.interface.post(...) ... except Exception as e: ... log_error(e) ... txn.abort()
Note
Multiple transactions can run simultaneously if they don’t modify same tables
Nested transactions are not supported
Transactions expire after timeout if not committed
Some tables may not support transactions
- __init__(client, timeout=60, vdom=None, auto_commit=True, auto_abort=True)[source]
Initialize transaction.
- Parameters:
client (
FortiOS) – FortiOS client instancetimeout (
int) – Transaction timeout in seconds (default 60)vdom (
str|None) – VDOM for transaction (uses client default if None)auto_commit (
bool) – Auto-commit on context exit if no errors (default True)auto_abort (
bool) – Auto-abort on exception (default True)
Methods
__init__(client[, timeout, vdom, ...])Initialize transaction.
abort()Abort transaction and rollback all changes.
commit()Commit transaction and apply all cached changes.
rollback()Alias for abort() - rollback all transaction changes.
show()Show cached commands (FortiOS 7.4.1+).
start()Start transaction.
Attributes
Check if transaction has been aborted.
Check if transaction is active (started but not committed/aborted).
Check if transaction has been committed.
Get transaction ID.