fmg
FMG API for humans
FMG #
Bases: FMGBase
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/fmg.py
add #
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#
>>> 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"
... }
... }
>>> with FMG(**settings) as fmg:
... fmg.add(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")
>>> with FMG(**settings) as fmg:
... fmg.add(address)
Returns:
Type | Description |
---|---|
FMGResponse
|
Result of operation |
Source code in pyfortinet/fmg_api/fmg.py
delete #
Delete operation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
Union[dict[str, str], FMGObject]
|
dict or object to delete |
required |
Examples:
Low-level - dict#
>>> settings = {...}
>>> address_request = {
... "url": "/pm/config/global/obj/firewall/address/test-address",
... }
>>> with FMG(**settings) as fmg:
... fmg.delete(address_request)
High-level - obj#
>>> from pyfortinet.fmg_api.firewall import Address
>>> settings = {...}
>>> address = Address(name="test-address")
>>> with FMG(**settings) as fmg:
... fmg.delete(address)
Returns:
Type | Description |
---|---|
FMGResponse
|
Result of operation |
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], Type[FMGObject]], filters: FILTER_TYPE = None, scope: Optional[str] = None, fields: Optional[List[str]] = None, loadsub: bool = True, options: Optional[List[GetOption]] = None) -> FMGResponse
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#
>>> address_request = {
... "url": "/pm/config/global/obj/firewall/address",
... "filter": [ ["name", "==", "test-address"] ],
... "fields": [ "name", "subnet" ]
...}
>>> settings = {...}
>>> with FMG(**settings) as fmg:
... fmg.get(address_request)
High-level - obj#
>>> from pyfortinet.fmg_api.firewall import Address
>>> from pyfortinet.fmg_api.common import F
>>> settings = {...}
>>> with FMG(**settings) as fmg:
... addresses = fmg.get(Address, F(name__like="test-%") & F(subnet="test-subnet"))
Returns:
Type | Description |
---|---|
FMGResponse
|
response object with data |
Source code in pyfortinet/fmg_api/fmg.py
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 |
|
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: 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 |
Other Parameters:
Name | Type | Description |
---|---|---|
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/fmg.py
set #
Set operation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
Union[dict[str, Any], FMGObject]
|
Update operation's data structure |
required |
Examples:
Low-level - dict#
>>> 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"
... }
... }
>>> with FMGBase(**settings) as fmg:
... fmg.set(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")
>>> with FMGBase(**settings) as fmg:
... fmg.set(address)
Returns:
Type | Description |
---|---|
FMGResponse
|
Result of operation |
Source code in pyfortinet/fmg_api/fmg.py
update #
Update operation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
Union[dict[str, Any], FMGObject]
|
Update operation's data structure |
required |
Examples:
Low-level - dict#
>>> 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"
... }
... }
>>> with FMGBase(**settings) as fmg:
... fmg.update(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")
>>> with FMGBase(**settings) as fmg:
... fmg.update(address)
Returns:
Type | Description |
---|---|
FMGResponse
|
Result of operation |