Compare commits

...

4 commits
0.1.0 ... main

Author SHA1 Message Date
b3421c11b4 Add PyPi installation instructions
All checks were successful
CI / ci (push) Successful in 27s
2025-02-24 12:10:56 +01:00
000349be67 Add Changelog.md
All checks were successful
CI / ci (push) Successful in 28s
2025-02-19 18:29:49 +01:00
99b4c75371 Update README.md
All checks were successful
CI / ci (push) Successful in 57s
2025-02-19 13:30:07 +01:00
4b7342c5d7 Make method private
All checks were successful
CI / ci (push) Successful in 56s
2025-02-19 13:21:50 +01:00
4 changed files with 27 additions and 13 deletions

7
Changelog.md Normal file
View file

@ -0,0 +1,7 @@
# pfsense-netbox-sync
## [Unreleased]
## [0.1.0]
- Initial release.

View file

@ -10,6 +10,12 @@ corresponding DNS entries on pfSense DNS resolver.
## Installation ## Installation
This package is available on PyPi. You can install it using pip.
```
$ pip install pfsense-netbox-sync
```
## Configuration ## Configuration
### On NetBox ### On NetBox
@ -44,7 +50,7 @@ The following env variables will need to be set:
You can then execute the script using the following command: You can then execute the script using the following command:
``` ```
PF_API_URL=xx PF_API_USER=xx PF_API_PASS=xx NB_API_URL=xx NB_API_TOKEN=xx python3 -m app PF_API_URL=xx PF_API_USER=xx PF_API_PASS=xx NB_API_URL=xx NB_API_TOKEN=xx python3 -m pfsense_netbox_sync
``` ```
The script will indicate any change made. The script will indicate any change made.

View file

@ -14,7 +14,7 @@ import urllib3
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
def fetch_netbox_host_overrides(nb_api: pynetbox.api) -> dict: def _fetch_netbox_host_overrides(nb_api: pynetbox.api) -> dict:
""" """
Fetch and build a list of host override from a NetBox instance Fetch and build a list of host override from a NetBox instance
:param nb_api: the NetBox API client :param nb_api: the NetBox API client
@ -42,7 +42,7 @@ def fetch_netbox_host_overrides(nb_api: pynetbox.api) -> dict:
return nb_host_overrides return nb_host_overrides
def fetch_pfsense_host_overrides() -> dict: def _fetch_pfsense_host_overrides() -> dict:
""" """
Fetch and build a list of host override from a pfSense instance Fetch and build a list of host override from a pfSense instance
:return: the list of host overrides mapped by their hostname :return: the list of host overrides mapped by their hostname
@ -70,7 +70,7 @@ def fetch_pfsense_host_overrides() -> dict:
return pf_host_overrides return pf_host_overrides
def compute_host_overrides_changes( def _compute_host_overrides_changes(
netbox_host_overrides: dict, netbox_host_overrides: dict,
pfsense_host_overrides: dict, pfsense_host_overrides: dict,
) -> (List[dict], List[dict], List[dict]): ) -> (List[dict], List[dict], List[dict]):
@ -120,7 +120,7 @@ def process_new_host_overrides(host_overrides: List[dict]):
sys.exit(1) sys.exit(1)
def process_changed_host_overrides(pf_host_overrides: dict, host_overrides: List[dict]): def _process_changed_host_overrides(pf_host_overrides: dict, host_overrides: List[dict]):
""" """
Process the changed host overrides. This will update them into the pfSense instance Process the changed host overrides. This will update them into the pfSense instance
:param pf_host_overrides: the actual host overrides coming from the pfSense instance :param pf_host_overrides: the actual host overrides coming from the pfSense instance
@ -149,7 +149,7 @@ def process_changed_host_overrides(pf_host_overrides: dict, host_overrides: List
sys.exit(1) sys.exit(1)
def process_deleted_host_overrides(host_overrides: List[dict]): def _process_deleted_host_overrides(host_overrides: List[dict]):
""" """
Process the deleted host overrides. This will delete them from the pfSense instance Process the deleted host overrides. This will delete them from the pfSense instance
:param host_overrides: the deleted host overrides :param host_overrides: the deleted host overrides
@ -182,13 +182,13 @@ def main():
) )
# First, built the host overrides using Netbox as source # First, built the host overrides using Netbox as source
nb_host_overrides = fetch_netbox_host_overrides(nb_api) nb_host_overrides = _fetch_netbox_host_overrides(nb_api)
# Then fetch the actual host overrides from pfSense API # Then fetch the actual host overrides from pfSense API
pf_host_overrides = fetch_pfsense_host_overrides() pf_host_overrides = _fetch_pfsense_host_overrides()
# Compute the changes # Compute the changes
(new_host_overrides, changed_host_overrides, deleted_host_overrides) = compute_host_overrides_changes( (new_host_overrides, changed_host_overrides, deleted_host_overrides) = _compute_host_overrides_changes(
nb_host_overrides, nb_host_overrides,
pf_host_overrides, pf_host_overrides,
) )
@ -207,19 +207,19 @@ def main():
process_new_host_overrides(new_host_overrides) process_new_host_overrides(new_host_overrides)
# Then process the changed host overrides # Then process the changed host overrides
process_changed_host_overrides(pf_host_overrides, changed_host_overrides) _process_changed_host_overrides(pf_host_overrides, changed_host_overrides)
# Once it's done, re-fetch the actual host overrides from pfSense API (because the ID may have changed) # Once it's done, re-fetch the actual host overrides from pfSense API (because the ID may have changed)
pf_host_overrides = fetch_pfsense_host_overrides() pf_host_overrides = _fetch_pfsense_host_overrides()
# Re-compute the changes (only for the deleted this time) # Re-compute the changes (only for the deleted this time)
(_, _, deleted_host_overrides) = compute_host_overrides_changes( (_, _, deleted_host_overrides) = _compute_host_overrides_changes(
nb_host_overrides, nb_host_overrides,
pf_host_overrides, pf_host_overrides,
) )
# Finally process the deleted host overrides # Finally process the deleted host overrides
process_deleted_host_overrides(deleted_host_overrides) _process_deleted_host_overrides(deleted_host_overrides)
# Finally restart the DNS resolver # Finally restart the DNS resolver
r = requests.post( r = requests.post(

View file

@ -25,6 +25,7 @@ dependencies = [
[project.urls] [project.urls]
Homepage = "https://git.creekorful.cloud/creekorful/pfsense-netbox-sync" Homepage = "https://git.creekorful.cloud/creekorful/pfsense-netbox-sync"
Issues = "https://git.creekorful.cloud/creekorful/pfsense-netbox-sync/issues" Issues = "https://git.creekorful.cloud/creekorful/pfsense-netbox-sync/issues"
Changelog = "https://git.creekorful.cloud/creekorful/pfsense-netbox-sync/src/branch/main/Changelog.md"
[project.scripts] [project.scripts]
pfnbsync = "pfsense_netbox_sync:main" pfnbsync = "pfsense_netbox_sync:main"