⚡
FLASH SALE
— 30% OFF Yearly Network Automation Memberships! Use code
SALE30
at checkout. Offer ends August 20th.
➜ Sign up here
Training
Bootcamp
Courses
Tech Sessions
Resources
Blog
Tips
GitHub
YouTube
Newsletter
Playgrounds
Pricing
Sign In
Become Member
TTP Parser
Validate and test the parsing of your TTP templates
Tools
J2 Renderer
TTP Parser
TextFSM Parser
XPath Tester
Members Only
JMESPath Validator
JSON Schema Validator
Data Format Converter
TTP Template
"""Common data model that will be used by the source and target adapters""" from os import getenv from typing import List, Optional, TypedDict from nautobot.ipam.models import IPAddress # from diffsync.enum import DiffSyncModelFlags from nautobot_firewall_models.models import ( AddressObject, AddressObjectGroup, FQDN, IPRange, PolicyRule, ServiceObject, ServiceObjectGroup, Zone, ) from nautobot_ssot.contrib import NautobotModel from nautobot_ssot.contrib.typeddicts import TagDict FORTIMANAGER_NAUTOBOT_NAMESPACE: str | None = getenv("FORTIMANAGER_NAUTOBOT_NAMESPACE") class SourceServiceGroupsDict(TypedDict): name: str class SourceServicesDict(TypedDict): name: str class SourceAddressGroupsDict(TypedDict): name: str class SourceAddressesDict(TypedDict): name: str class PolicyRuleDiffSyncModel(NautobotModel): """Diffsync model for syncing of Policy Rules.""" _model = PolicyRule _modelname = "policy_rule" _identifiers = ("name",) _attributes = ( "description", "tags", "status__name", "action", "source_addresses", "source_address_groups", "source_zone__name", "source_services", "source_service_groups", ) name: str description: str status__name: str tags: List[TagDict] = [] action: str source_addresses: List[SourceAddressesDict] = [] source_address_groups: List[SourceAddressGroupsDict] = [] source_zone__name: Optional[str] source_services: List[SourceServicesDict] = [] source_service_groups: List[SourceServiceGroupsDict] = [] class ServiceObjectGroupDict(TypedDict): name: str class ServiceObjectGroupDiffSyncModel(NautobotModel): """Diffsync model for syncing service objects groups.""" _model = ServiceObjectGroup _modelname = "service_object_group" _identifiers = ("name",) _attributes = ("description", "tags", "status__name", "service_objects") name: str description: str status__name: str tags: List[TagDict] = [] service_objects: List[ServiceObjectGroupDict] = [] class AddressObjectGroupDict(TypedDict): name: str class AddressObjectGroupDiffSyncModel(NautobotModel): """Model used to store Address Objects (Firewal Data Model).""" _model = AddressObjectGroup _modelname = "address_object_group" _identifiers = ("name",) _attributes = ( "description", "tags", "status__name", "address_objects", ) name: str description: str status__name: str tags: List[TagDict] = [] address_objects: List[AddressObjectGroupDict] = [] class AddressObjectDiffSyncModel(NautobotModel): """Model used to store Address Objects (Firewal Data Model).""" _model = AddressObject _modelname = "address_object" _identifiers = ("name",) _attributes = ( "fqdn__name", "status__name", "ip_address__host", "ip_address__mask_length", "ip_range__start_address", "ip_range__end_address", "description", "tags", ) name: str status__name: str fqdn__name: Optional[str] = None ip_address__host: Optional[str] = None ip_address__mask_length: Optional[int] = None ip_range__start_address: Optional[str] = None ip_range__end_address: Optional[str] = None description: str tags: list[TagDict] = [] class IPAddressDiffSyncModel(NautobotModel): """ Model to store IPAddresses """ _model = IPAddress _modelname = "ip_address" _identifiers = ("host", "mask_length", "parent__namespace__name") _attributes = ("description", "tags", "status__name") host: str parent__namespace__name: str description: str tags: list[TagDict] = [] mask_length: int status__name: str def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Returns only IPs within Namespace = FortiManager @classmethod def get_queryset(cls): return IPAddress.objects.filter(parent__namespace__name=FORTIMANAGER_NAUTOBOT_NAMESPACE) class FQDNDiffSyncModel(NautobotModel): _model = FQDN _modelname = "fqdn" _identifiers = ("name",) _attributes = ("description", "status__name") name: str description: str status__name: str class IPRangeDiffSyncModel(NautobotModel): """Diffsync model for syncing IP range objects. Inside the nautobot firewall app vrf is vrf is defined as a key if it exists, We're not currently building VRFs in Nautobot so I'm skipping this. """ _model = IPRange _modelname = "ip_range" _identifiers = ("start_address", "end_address") _attributes = ("status__name", "description") start_address: str end_address: str status__name: str description: str class ZoneDiffSyncModel(NautobotModel): _model = Zone _modelname = "zone" _identifiers = ("name",) _attributes = ("status__name", "description") name: str description: str status__name: str class ServiceDiffSyncModel(NautobotModel): """Diffsync model for syncing service objects. Some basic service types are predefined inside the app (eg HTTP(s)) so we tag the objects we're managing. """ _model = ServiceObject _modelname = "service" _identifiers = ("ip_protocol", "name") _attributes = ("status__name", "port", "description", "tags") ip_protocol: str name: str status__name: str description: str port: Optional[str] = "" tags: List[TagDict] = [] # def __init__(self, *args, **kwargs): # super().__init__(*args, **kwargs) # self.model_flags = DiffSyncModelFlags.SKIP_UNMATCHED_DST # Returns only IPs within Namespace = FortiManager @classmethod def get_queryset(cls): return ServiceObject.objects.filter(tags__name="Fortimanager")
0
/ 20000
Raw Text
NAM
0
/ 20000
Result
[ {} ]
Parse
Share
Auto-Sync