fmg
High-level FortiManager object API.
FMG #
Bases: FMGBase
High-level synchronous FortiManager client.
Accepts configuration models and execution objects, constructs API requests, and returns bound models from high-level GET operations. Dictionary requests remain supported for endpoints without models. Use an authenticated connection context for object operations.
An asynchronous context on FMG yields a separate AsyncFMG client. Use the value
bound by as for requests; custom synchronous methods are not converted to async.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
FMGSettings
|
Connection settings; when supplied, takes precedence over keyword settings |
None
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
base_url |
str
|
Base URL to access FMG (e.g.: https://myfmg) |
username |
str
|
User to authenticate |
password |
str
|
Password for authentication |
adom |
str
|
ADOM to use for this connection |
verify |
bool
|
Verify SSL certificate (REQUESTS_CA_BUNDLE can set accepted CA cert) |
timeout |
float
|
Connect/read inactivity timeout per transport attempt, in seconds |
raise_on_error |
bool
|
Raise exception on error |
discard_on_close |
bool
|
Discard changes after connection close (workspace mode) |
discard_on_error |
bool
|
Discard changes when exception occurs (workspace mode) |
Source code in pyfortinet/fmg_api/fmg.py
add #
add(request: MULTI_REQUEST_ARG) -> FMGResponse
Create configuration objects in FortiManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
MULTI_REQUEST_ARG
|
One model or dictionary, or a nonempty list containing only models or only dictionaries. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FMGResponse |
FMGResponse
|
Operation status; read the object separately to obtain its resulting configuration. |
Notes
This operation writes configuration. Models use API aliases and omit None values. Empty lists are sent explicitly. Batch operations are not a transaction; partial writes may remain after a failure. Check firmware semantics before using SET for a resource.
Examples:
Inside an open connection, with the appropriate target and permissions:
from pyfortinet.fmg_api.firewall import Address
address = Address(name="example-server", subnet="192.0.2.10/32")
response = fmg.add(address)
Source code in pyfortinet/fmg_api/fmg.py
clone #
clone(request: REQUEST_ARG, *, create_task: bool = False, **new: str) -> FMGResponse
Clone one configuration object using new identity values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
REQUEST_ARG
|
Source model or raw clone request dictionary. |
required |
create_task
|
bool
|
Request a background task. Keep the connection open until it finishes. |
False
|
**new
|
str
|
New identity fields, usually name, matching the model's master keys. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
FMGResponse |
FMGResponse
|
Clone operation status, with task metadata when provided by FortiManager. |
Examples:
Inside an open connection, clone an existing address to an unused name:
from pyfortinet.fmg_api.firewall import Address
response = fmg.clone(Address(name="example-server"), name="example-server-copy")
Source code in pyfortinet/fmg_api/fmg.py
close #
Close the synchronous connection; async contexts manage their own connection.
delete #
delete(request: MULTI_REQUEST_ARG) -> FMGResponse
Delete the identified configuration objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
MULTI_REQUEST_ARG
|
One model or dictionary, or a nonempty list containing only models or only dictionaries. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FMGResponse |
FMGResponse
|
Operation status; read the object separately to obtain its resulting configuration. |
Notes
This operation writes configuration. Models use API aliases and omit None values. Empty lists are sent explicitly. Batch operations are not a transaction; partial writes may remain after a failure. Check firmware semantics before using SET for a resource.
Examples:
Inside an open connection, with the appropriate target and permissions:
from pyfortinet.fmg_api.firewall import Address
address = Address(name="example-server")
response = fmg.delete(address)
Source code in pyfortinet/fmg_api/fmg.py
exec #
Execute on FMG
Source code in pyfortinet/fmg_api/fmg.py
get #
get(
request: Union[dict[str, Any], FMGObject, Type[FMGObject]],
filters: Union[str, FILTER_TYPE] = None,
scope: Optional[str] = None,
fields: Optional[List[str]] = None,
loadsub: bool = True,
options: Optional[List[GetOption]] = None,
) -> FMGResponse
Read objects from FortiManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Union[dict[str, Any], FMGObject, Type[FMGObject]]
|
Model class for a collection, initialized model for selection, or raw request dictionary. |
required |
filters
|
Union[str, FILTER_TYPE]
|
Filter expression as text or composed with F. |
None
|
scope
|
Optional[str]
|
Request scope; an explicit model scope takes precedence. |
None
|
fields
|
Optional[List[str]]
|
API field names to request, or None for all fields. |
None
|
loadsub
|
bool
|
Request nested tables. |
True
|
options
|
Optional[List[GetOption]]
|
Additional API GET options. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FMGResponse |
FMGResponse
|
High-level data contains bound models. A successful empty lookup |
FMGResponse
|
has an empty data list and first() returns None. Dictionary requests retain raw results. |
Examples:
Use configured connection settings and handle an empty lookup:
from pyfortinet import FMG
from pyfortinet.fmg_api.common import F
from pyfortinet.fmg_api.firewall import Address
with FMG(**config) as fmg:
response = fmg.get(Address, F(name__like="server%"))
for address in response.data:
print(address.name, address.subnet)
server = (fmg.get(Address(name="server1"))).first()
if server is not None:
print(server.name)
Source code in pyfortinet/fmg_api/fmg.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
get_adom_list #
Gather adoms from FMG
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
FILTER_TYPE
|
filter as list or F object |
None
|
Returns:
| Type | Description |
|---|---|
Optional[List[str]]
|
list of adom strings or None in case of error |
Source code in pyfortinet/fmg_api/fmg.py
get_obj #
get_obj(obj: Union[Type[FMGObject], Type[FMGExecObject], AnyFMGObject], **kwargs: Any) -> AnyFMGObject
Construct or bind a local model to this client without an API request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Union[Type[FMGObject], Type[FMGExecObject], AnyFMGObject]
|
FMGObject or FMGExecObject class, or an existing instance. |
required |
**kwargs
|
Any
|
Initialization fields when obj is a class; ignored for existing instances. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
AnyFMGObject |
AnyFMGObject
|
A new instance for a class argument, or the same bound instance for an object argument. |
Examples:
This method is synchronous for both clients. Creating the model does not create the remote object:
from pyfortinet.fmg_api.firewall import Address
address = fmg.get_obj(Address, name="example-server", subnet="192.0.2.10/32")
Source code in pyfortinet/fmg_api/fmg.py
refresh #
Re-load data from FMG
Source code in pyfortinet/fmg_api/fmg.py
set #
set(request: MULTI_REQUEST_ARG) -> FMGResponse
Submit a FortiManager SET operation for the supplied objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
MULTI_REQUEST_ARG
|
One model or dictionary, or a nonempty list containing only models or only dictionaries. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FMGResponse |
FMGResponse
|
Operation status; read the object separately to obtain its resulting configuration. |
Notes
This operation writes configuration. Models use API aliases and omit None values. Empty lists are sent explicitly. Batch operations are not a transaction; partial writes may remain after a failure. Check firmware semantics before using SET for a resource.
Examples:
Inside an open connection, with the appropriate target and permissions:
from pyfortinet.fmg_api.firewall import Address
address = Address(name="example-server", subnet="192.0.2.10/32")
response = fmg.set(address)
Source code in pyfortinet/fmg_api/fmg.py
update #
update(request: MULTI_REQUEST_ARG) -> FMGResponse
Update supplied non-null configuration fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
MULTI_REQUEST_ARG
|
One model or dictionary, or a nonempty list containing only models or only dictionaries. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FMGResponse |
FMGResponse
|
Operation status; read the object separately to obtain its resulting configuration. |
Notes
This operation writes configuration. Models use API aliases and omit None values. Empty lists are sent explicitly. Batch operations are not a transaction; partial writes may remain after a failure. Check firmware semantics before using SET for a resource.
Examples:
Inside an open connection, with the appropriate target and permissions:
from pyfortinet.fmg_api.firewall import Address
address = Address(name="example-server", comment="Application server")
response = fmg.update(address)