common
Common objects
OP
module-attribute
#
OP = {'eq': '==', 'neq': '!=', 'lt': '<', 'le': '<=', 'gt': '>', 'ge': '>=', 'or': '&', 'in': 'in', 'contain': 'contain', 'like': 'like', 'not_like': '!like', 'glob': 'glob', 'not_glob': '!glob'}
ComplexFilter #
ComplexFilter(a: Union[ComplexFilter, FilterList, F], op: Literal['||', '&&'], b: Union[ComplexFilter, FilterList, F])
Complex handling of filters and their operator
Source code in pyfortinet/fmg_api/common.py
F #
Filter class that allows us to define a single filter for an object
Argument format is {field}={value} or {field}__{operator}={value} Only one argument can be passed!
Filter object can be used at FMG.get
method
Attributes:
Name | Type | Description |
---|---|---|
negate |
bool
|
If true the filter is negated |
source |
str
|
The source is the API attribute we are looking at |
op |
str
|
The operator for the search |
targets |
str
|
The target is the value we are searching for |
Source code in pyfortinet/fmg_api/common.py
generate #
Generate API filter list
Source code in pyfortinet/fmg_api/common.py
FilterList #
FilterList(*members: Union[F, FilterList])
List of F objects
Source code in pyfortinet/fmg_api/common.py
Scope #
Specify scope for an object
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Scope name (e.g. firewall name or group name) |
vdom |
str
|
VDOM if applicable |
text_to_filter #
text_to_filter(text: str) -> FILTER_TYPE
Text to filter object
Format of the text follows the OP
definition!
This is a simple text to filter object converter. It does not support more complex logic.
Simple field comparisons with and/or and ,
operators are supported. ,
means a simple or
between same
type fields.
structure::
fname fop fvalue OP fname fop fvalue OP ...
---------------- ----------------
F token F token
Examples:
simple F filter
inversing
simple or function
>>> text_to_filter('name eq host_1, name eq host_2').generate()
[['name', '==', 'host_1'], ['name', '==', 'host_2']]
more complex filter
>>> text_to_filter('name eq host_1 and conf_status eq insync').generate()
[['name', '==', 'host_1'], '&&', ['conf_status', '==', 'insync']]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
Text to parse |
required |
Returns:
Name | Type | Description |
---|---|---|
FILTER_TYPE |
FILTER_TYPE
|
Filter object which can be used in FMG.get calls |
Raises: ValueError: text cannot be parsed