Skip to content

Commit 83a3898

Browse files
authored
bug: Allow optional mapping (#101)
* bug: allow optional mapping to fix error on static reference * linter
1 parent 75c4183 commit 83a3898

File tree

35 files changed

+295
-41
lines changed

35 files changed

+295
-41
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""ACI sync adapter module."""
1+
"""ACI sync adapter module."""

examples/aci_to_infrahub/aci/sync_models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
from __future__ import annotations
22

3-
from typing import Any, List
3+
from typing import Any
44

55
from infrahub_sync.plugin_loader import PluginLoader
6+
67
# Load model class dynamically at runtime (honor adapters_path, safe fallback)
78
try:
8-
99
_loader = PluginLoader.from_env_and_args()
1010

11-
1211
_spec = "aci"
1312

1413
_ModelBaseClass = _loader.resolve(_spec, default_class_candidates=("Model",))
1514
except Exception:
1615
# Fallback: use DiffSyncModel to avoid import-time failure
1716
from diffsync import DiffSyncModel as _FallbackModel
17+
1818
_ModelBaseClass = _FallbackModel
1919

20+
2021
# -------------------------------------------------------
2122
# AUTO-GENERATED FILE, DO NOT MODIFY
2223
# This file has been generated with the command `infrahub-sync generate`
@@ -36,6 +37,7 @@ class DcimPhysicalDevice(_ModelBaseClass):
3637
local_id: str | None = None
3738
local_data: Any | None = None
3839

40+
3941
class DcimPhysicalInterface(_ModelBaseClass):
4042
_modelname = "DcimPhysicalInterface"
4143
_identifiers = ("device", "name")
@@ -47,6 +49,7 @@ class DcimPhysicalInterface(_ModelBaseClass):
4749
local_id: str | None = None
4850
local_data: Any | None = None
4951

52+
5053
class LocationBuilding(_ModelBaseClass):
5154
_modelname = "LocationBuilding"
5255
_identifiers = ("name",)
@@ -58,6 +61,7 @@ class LocationBuilding(_ModelBaseClass):
5861
local_id: str | None = None
5962
local_data: Any | None = None
6063

64+
6165
class LocationMetro(_ModelBaseClass):
6266
_modelname = "LocationMetro"
6367
_identifiers = ("name",)
@@ -68,6 +72,7 @@ class LocationMetro(_ModelBaseClass):
6872
local_id: str | None = None
6973
local_data: Any | None = None
7074

75+
7176
class OrganizationCustomer(_ModelBaseClass):
7277
_modelname = "OrganizationCustomer"
7378
_identifiers = ("name", "customer_id")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""Infrahub sync adapter module."""
1+
"""Infrahub sync adapter module."""

examples/aci_to_infrahub/infrahub/sync_models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
from __future__ import annotations
22

3-
from typing import Any, List
3+
from typing import Any
44

55
from infrahub_sync.plugin_loader import PluginLoader
6+
67
# Load model class dynamically at runtime (honor adapters_path, safe fallback)
78
try:
8-
99
_loader = PluginLoader.from_env_and_args()
1010

11-
1211
_spec = "infrahub"
1312

1413
_ModelBaseClass = _loader.resolve(_spec, default_class_candidates=("Model",))
1514
except Exception:
1615
# Fallback: use DiffSyncModel to avoid import-time failure
1716
from diffsync import DiffSyncModel as _FallbackModel
17+
1818
_ModelBaseClass = _FallbackModel
1919

20+
2021
# -------------------------------------------------------
2122
# AUTO-GENERATED FILE, DO NOT MODIFY
2223
# This file has been generated with the command `infrahub-sync generate`
@@ -36,6 +37,7 @@ class DcimPhysicalDevice(_ModelBaseClass):
3637
local_id: str | None = None
3738
local_data: Any | None = None
3839

40+
3941
class DcimPhysicalInterface(_ModelBaseClass):
4042
_modelname = "DcimPhysicalInterface"
4143
_identifiers = ("device", "name")
@@ -47,6 +49,7 @@ class DcimPhysicalInterface(_ModelBaseClass):
4749
local_id: str | None = None
4850
local_data: Any | None = None
4951

52+
5053
class LocationBuilding(_ModelBaseClass):
5154
_modelname = "LocationBuilding"
5255
_identifiers = ("name",)
@@ -58,6 +61,7 @@ class LocationBuilding(_ModelBaseClass):
5861
local_id: str | None = None
5962
local_data: Any | None = None
6063

64+
6165
class LocationMetro(_ModelBaseClass):
6266
_modelname = "LocationMetro"
6367
_identifiers = ("name",)
@@ -68,6 +72,7 @@ class LocationMetro(_ModelBaseClass):
6872
local_id: str | None = None
6973
local_data: Any | None = None
7074

75+
7176
class OrganizationCustomer(_ModelBaseClass):
7277
_modelname = "OrganizationCustomer"
7378
_identifiers = ("name", "customer_id")

examples/custom_adapter/custom_adapter_src/custom_adapter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self, filepath: str | None = None) -> None:
4848
print(f"DEBUG: Loaded mock database from {filepath}")
4949
except (FileNotFoundError, json.JSONDecodeError) as e:
5050
print(f"DEBUG: Failed to load mock database from {filepath}: {e}")
51+
5152
def get_all_nodes(self, model: str) -> list[dict[str, Any]]:
5253
"""Get all nodes of a specific model from the mock database.
5354

examples/custom_adapter/infrahub/sync_models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3-
from typing import Any, List
3+
from typing import Any
44

55
from infrahub_sync.plugin_loader import PluginLoader
6+
67
# Load model class dynamically at runtime (honor adapters_path, safe fallback)
78
try:
89
_loader = PluginLoader.from_env_and_args(adapter_paths=[])
@@ -13,8 +14,10 @@
1314
except Exception:
1415
# Fallback: use DiffSyncModel to avoid import-time failure
1516
from diffsync import DiffSyncModel as _FallbackModel
17+
1618
_ModelBaseClass = _FallbackModel
1719

20+
1821
# -------------------------------------------------------
1922
# AUTO-GENERATED FILE, DO NOT MODIFY
2023
# This file has been generated with the command `infrahub-sync generate`

examples/custom_adapter/mockdb/sync_models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3-
from typing import Any, List
3+
from typing import Any
44

55
from infrahub_sync.plugin_loader import PluginLoader
6+
67
# Load model class dynamically at runtime (honor adapters_path, safe fallback)
78
try:
89
_loader = PluginLoader.from_env_and_args(adapter_paths=[])
@@ -13,8 +14,10 @@
1314
except Exception:
1415
# Fallback: use DiffSyncModel to avoid import-time failure
1516
from diffsync import DiffSyncModel as _FallbackModel
17+
1618
_ModelBaseClass = _FallbackModel
1719

20+
1821
# -------------------------------------------------------
1922
# AUTO-GENERATED FILE, DO NOT MODIFY
2023
# This file has been generated with the command `infrahub-sync generate`

examples/device42_to_infrahub/genericrestapi/sync_models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3-
from typing import Any, List
3+
from typing import Any
44

55
from infrahub_sync.plugin_loader import PluginLoader
6+
67
# Load model class dynamically at runtime (honor adapters_path, safe fallback)
78
try:
89
_loader = PluginLoader.from_env_and_args(adapter_paths=[])
@@ -13,8 +14,10 @@
1314
except Exception:
1415
# Fallback: use DiffSyncModel to avoid import-time failure
1516
from diffsync import DiffSyncModel as _FallbackModel
17+
1618
_ModelBaseClass = _FallbackModel
1719

20+
1821
# -------------------------------------------------------
1922
# AUTO-GENERATED FILE, DO NOT MODIFY
2023
# This file has been generated with the command `infrahub-sync generate`
@@ -29,6 +32,7 @@ class BuiltinTag(_ModelBaseClass):
2932
local_id: str | None = None
3033
local_data: Any | None = None
3134

35+
3236
class LocationSite(_ModelBaseClass):
3337
_modelname = "LocationSite"
3438
_identifiers = ("name",)
@@ -39,6 +43,7 @@ class LocationSite(_ModelBaseClass):
3943
local_id: str | None = None
4044
local_data: Any | None = None
4145

46+
4247
class OrganizationTenant(_ModelBaseClass):
4348
_modelname = "OrganizationTenant"
4449
_identifiers = ("name",)

examples/device42_to_infrahub/infrahub/sync_models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3-
from typing import Any, List
3+
from typing import Any
44

55
from infrahub_sync.plugin_loader import PluginLoader
6+
67
# Load model class dynamically at runtime (honor adapters_path, safe fallback)
78
try:
89
_loader = PluginLoader.from_env_and_args(adapter_paths=[])
@@ -13,8 +14,10 @@
1314
except Exception:
1415
# Fallback: use DiffSyncModel to avoid import-time failure
1516
from diffsync import DiffSyncModel as _FallbackModel
17+
1618
_ModelBaseClass = _FallbackModel
1719

20+
1821
# -------------------------------------------------------
1922
# AUTO-GENERATED FILE, DO NOT MODIFY
2023
# This file has been generated with the command `infrahub-sync generate`
@@ -29,6 +32,7 @@ class BuiltinTag(_ModelBaseClass):
2932
local_id: str | None = None
3033
local_data: Any | None = None
3134

35+
3236
class LocationSite(_ModelBaseClass):
3337
_modelname = "LocationSite"
3438
_identifiers = ("name",)
@@ -39,6 +43,7 @@ class LocationSite(_ModelBaseClass):
3943
local_id: str | None = None
4044
local_data: Any | None = None
4145

46+
4247
class OrganizationTenant(_ModelBaseClass):
4348
_modelname = "OrganizationTenant"
4449
_identifiers = ("name",)

examples/infrahub_to_peering-manager/infrahub/sync_models.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3-
from typing import Any, List
3+
from typing import Any
44

55
from infrahub_sync.plugin_loader import PluginLoader
6+
67
# Load model class dynamically at runtime (honor adapters_path, safe fallback)
78
try:
89
_loader = PluginLoader.from_env_and_args(adapter_paths=[])
@@ -13,8 +14,10 @@
1314
except Exception:
1415
# Fallback: use DiffSyncModel to avoid import-time failure
1516
from diffsync import DiffSyncModel as _FallbackModel
17+
1618
_ModelBaseClass = _FallbackModel
1719

20+
1821
# -------------------------------------------------------
1922
# AUTO-GENERATED FILE, DO NOT MODIFY
2023
# This file has been generated with the command `infrahub-sync generate`
@@ -35,6 +38,7 @@ class InfraAutonomousSystem(_ModelBaseClass):
3538
local_id: str | None = None
3639
local_data: Any | None = None
3740

41+
3842
class InfraBGPPeerGroup(_ModelBaseClass):
3943
_modelname = "InfraBGPPeerGroup"
4044
_identifiers = ("name",)
@@ -49,6 +53,7 @@ class InfraBGPPeerGroup(_ModelBaseClass):
4953
local_id: str | None = None
5054
local_data: Any | None = None
5155

56+
5257
class InfraBGPCommunity(_ModelBaseClass):
5358
_modelname = "InfraBGPCommunity"
5459
_identifiers = ("name",)
@@ -62,6 +67,7 @@ class InfraBGPCommunity(_ModelBaseClass):
6267
local_id: str | None = None
6368
local_data: Any | None = None
6469

70+
6571
class InfraBGPRoutingPolicy(_ModelBaseClass):
6672
_modelname = "InfraBGPRoutingPolicy"
6773
_identifiers = ("name",)
@@ -77,6 +83,7 @@ class InfraBGPRoutingPolicy(_ModelBaseClass):
7783
local_id: str | None = None
7884
local_data: Any | None = None
7985

86+
8087
class InfraIXP(_ModelBaseClass):
8188
_modelname = "InfraIXP"
8289
_identifiers = ("name",)
@@ -91,6 +98,7 @@ class InfraIXP(_ModelBaseClass):
9198
local_id: str | None = None
9299
local_data: Any | None = None
93100

101+
94102
class InfraIXPConnection(_ModelBaseClass):
95103
_modelname = "InfraIXPConnection"
96104
_identifiers = ("name",)

0 commit comments

Comments
 (0)