async_fmg
FMG API for humans
AsyncFMG #
Bases: AsyncFMGBase
FMG API for humans
Goal of this class to provide easy access to FMG features. This extends the base class capabilities with easy to use methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settings |
Settings
|
FortiManager settings |
None
|
Other Parameters:
Name | Type | Description |
---|---|---|
base_url |
str
|
Base URL to access FMG (e.g.: https://myfmg/jsonrpc) |
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
|
Connection timeout for requests 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/async_fmg.py
add
async
#
Add operation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
Union[dict[str, Any], FMGObject]
|
Add operation's data structure or object |
required |
Examples:
Low-level - dict#
>>> import asyncio
>>> settings = {...}
>>> address_request = {
... "url": "/pm/config/global/obj/firewall/address",
... "data": {
... "name": "test-address",
... "associated-interface": "inside",
... "obj-type": "ip",
... "type": "ipmask",
... "start-ip": "10.0.0.1/24"
... }
... }
>>> async def add_request(request: dict[str,Any]):
... async with AsyncFMG(**settings) as fmg:
... return await fmg.add(address_request)
>>> asyncio.run(add_request(address_request))
High-level - obj#
>>> from pyfortinet.fmg_api.firewall import Address
>>> settings = {...}
>>> address = Address(name="test-address", associated_interface="inside", obj_type="ip",
... type="ipmask", start_ip="10.0.0.1/24")
>>> async def add_request(addr):
... async with AsyncFMG(**settings) as fmg:
... return await fmg.add(addr)
>>> asyncio.run(add_request(address))
Returns:
Type | Description |
---|---|
AsyncFMGResponse
|
Result of operation |
Source code in pyfortinet/fmg_api/async_fmg.py
delete
async
#
Delete operation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
Union[dict[str, str], FMGObject]
|
dict or object to delete |
required |
Examples:
Low-level - dict#
>>> import asyncio
>>> settings = {...}
>>> address_request = {
... "url": "/pm/config/global/obj/firewall/address/test-address",
... }
>>> async def delete_address(address_request):
... async with AsyncFMG(**settings) as fmg:
... await fmg.delete(address_request)
>>> asyncio.run(delete_address(address_request))
High-level - obj#
>>> from pyfortinet.fmg_api.firewall import Address
>>> settings = {...}
>>> address = Address(name="test-address")
>>> async def delete_address(addr):
... async with AsyncFMG(**settings) as fmg:
... return await fmg.delete(addr)
>>> asyncio.run(delete_address(address))
Returns:
Type | Description |
---|---|
AsyncFMGResponse
|
Result of operation |
Source code in pyfortinet/fmg_api/async_fmg.py
exec
async
#
Execute on FMG
Source code in pyfortinet/fmg_api/async_fmg.py
get
async
#
get(request: Union[dict[str, Any], Type[FMGObject]], filters: FILTER_TYPE = None, scope: Optional[str] = None, fields: Optional[List[str]] = None, loadsub: bool = True, options: Optional[List[GetOption]] = None) -> AsyncFMGResponse
Get info from FMG
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
Union[dict[str, Any], Type[FMGObject]]
|
Get operation's data structure |
required |
scope |
Optional[str]
|
Scope where the object is searched (defaults to FMG setting on connection) |
None
|
filters |
FILTER_TYPE
|
Filter expression |
None
|
fields |
Optional[List[str]]
|
Fields to return (default: None means all fields) |
None
|
loadsub |
bool
|
Load sub objects |
True
|
options |
Optional[List[GetOption]]
|
API request options |
None
|
Examples:
Low-level - dict#
>>> import asyncio
>>> address_request = {
... "url": "/pm/config/global/obj/firewall/address",
... "filter": [ ["name", "==", "test-address"] ],
... "fields": [ "name", "subnet" ]
...}
>>> settings = {...}
>>> async def get_address(request: dict[str, Any]):
... async with AsyncFMG(**settings) as fmg:
... return await fmg.get(address_request)
>>> asyncio.run(get_address())
High-level - obj#
>>> import asyncio
>>> from pyfortinet.fmg_api.firewall import Address
>>> from pyfortinet.fmg_api.common import F
>>> settings = {...}
>>> async def get_address():
... async with AsyncFMG(**settings) as fmg:
... return await fmg.get(Address, F(name__like="test-%") & F(subnet="test-subnet"))
>>> asyncio.run(get_address())
Returns:
Type | Description |
---|---|
AsyncFMGResponse
|
response object with data |
Source code in pyfortinet/fmg_api/async_fmg.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 |
|
get_adom_list
async
#
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/async_fmg.py
get_obj #
get_obj(obj: Union[Type[FMGObject], Type[FMGExecObject], AnyFMGObject], **kwargs: Dict[str, Any]) -> AnyFMGObject
Get an object and tie it to this FMG
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Union[Type[FMGObject], Type[FMGExecObject], AnyFMGObject]
|
Any type or instance of FMGObject or FMGExecObject |
required |
kwargs |
Dict[str, Any]
|
fields for the new object initialization |
{}
|
Returns:
Type | Description |
---|---|
AnyFMGObject
|
New object, tied to this FMG |
Source code in pyfortinet/fmg_api/async_fmg.py
set
async
#
Set operation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
Union[dict[str, Any], FMGObject]
|
Update operation's data structure |
required |
Examples:
Low-level - dict#
>>> import asyncio
>>> settings = {...}
>>> address_request = {
... "url": "/pm/config/global/obj/firewall/address",
... "data": {
... "name": "test-address",
... "associated-interface": "inside",
... "obj-type": "ip",
... "type": "ipmask",
... "start-ip": "10.0.0.1/24"
... }
... }
>>> async def set_address(request):
... async with AsyncFMG(**settings) as fmg:
... return await fmg.set(request)
>>> asyncio.run(set_address(address_request))
High-level - obj#
>>> from pyfortinet.fmg_api.firewall import Address
>>> settings = {...}
>>> address = Address(name="test-address", associated_interface="inside", obj_type="ip",
... type="ipmask", start_ip="10.0.0.1/24")
>>> async def set_address(request):
... async with AsyncFMG(**settings) as fmg:
... return await fmg.set(request)
>>> asyncio.run(set_address(address))
Returns:
Type | Description |
---|---|
AsyncFMGResponse
|
Result of operation |
Source code in pyfortinet/fmg_api/async_fmg.py
update
async
#
Update operation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
Union[dict[str, Any], FMGObject]
|
Update operation's data structure |
required |
Examples:
Low-level - dict#
>>> import asyncio
>>> settings = {...}
>>> address_request = {
... "url": "/pm/config/global/obj/firewall/address",
... "data": {
... "name": "test-address",
... "associated-interface": "inside",
... "obj-type": "ip",
... "type": "ipmask",
... "start-ip": "10.0.0.1/24"
... }
... }
>>> async def update_address(request):
... async with AsyncFMG(**settings) as fmg:
... return await fmg.update(request)
>>> asyncio.run(update_address(address_request))
High-level - obj#
>>> from pyfortinet.fmg_api.firewall import Address
>>> settings = {...}
>>> address = Address(name="test-address", associated_interface="inside", obj_type="ip",
... type="ipmask", start_ip="10.0.0.1/24")
>>> async def update_address(addr):
... async with AsyncFMG(**settings) as fmg:
... return await fmg.update(addr)
>>> asyncio.run(update_address(address))
Returns:
Type | Description |
---|---|
AsyncFMGResponse
|
Result of operation |