sync_task
FMG Sync Task
FMGSyncTask #
Bases: CommonTask
Fortimanager Sync Task
Steps of this task:
- update local repository from remote
- check if there was a change
- check FMG device status list in protected group. If firewalls are not in sync, stop
- download FMG templates and template groups from FMG
- build list of templates to delete from FMG
- build list of templates to upload to FMG
- execute changes in FMG
Attributes:
Name | Type | Description |
---|---|---|
settings |
FMGSyncSettings
|
task settings to use |
fmg |
FMGSync
|
FMG instance |
_changed_templates
staticmethod
#
Determine to be updated templates and template groups
Source code in fortimanager_template_sync/sync_task.py
_delete_templates #
Delete templates and template groups
Parameters:
Name | Type | Description | Default |
---|---|---|---|
templates |
TemplateTree
|
template tree object containing CLI templates/groups to delete |
required |
Source code in fortimanager_template_sync/sync_task.py
_find_unused_templates
staticmethod
#
Find undefined or unused templates or groups in FMG
A template or template group is unused if:
- is not assigned to any device or group
- does not belong to any template-group
Source code in fortimanager_template_sync/sync_task.py
_load_fmg_templates #
Load template data from FMG
Source code in fortimanager_template_sync/sync_task.py
_load_local_repository #
Load files from repository
Source code in fortimanager_template_sync/sync_task.py
_parse_template_data
staticmethod
#
Parse template script text
Expected format for metadata (head comment):
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the template (file name without extension) |
required |
data |
str
|
raw text of the script file |
required |
Source code in fortimanager_template_sync/sync_task.py
_parse_template_groups_data
staticmethod
#
_parse_template_groups_data(name: str, data: str, templates: Optional[List[CLITemplate]] = None) -> CLITemplateGroup
Parse template group file
Source code in fortimanager_template_sync/sync_task.py
_update_fmg_templates #
Update templates and template groups
Source code in fortimanager_template_sync/sync_task.py
_update_local_repository #
Clone or update local repository
Repository is expected in this format:
pre-run/
pre-run1.j2
pre-run2.j2
...
templates/
template1.j2
template2.j2
...
template-groups/
group1.j2
group2.j2
...
Any other files are ignored. All directories are optional, it's not mandatory to have all of them. See docs for additional information.
Returns:
Type | Description |
---|---|
Optional[Repo]
|
Repository with cloned templates |
Source code in fortimanager_template_sync/sync_task.py
run #
Run sync task
Returns:
Type | Description |
---|---|
bool
|
True if sync task succeeded, False otherwise |