Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop to Main #49

Merged
merged 19 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/workflow-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Linting: markdownlint"
uses: DavidAnson/markdownlint-cli2-action@v18
uses: DavidAnson/markdownlint-cli2-action@v19
with:
config: .markdownlint.yaml
globs: |
Expand Down
24 changes: 15 additions & 9 deletions examples/slurpit_to_infrahub/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: from-slurpit
source:
name: slurpitsync
settings:
url: "http://localhost"
api_key: "<API_KEY>"
url: "<URL>"
api_key: "<TOKEN>"

destination:
name: infrahub
Expand All @@ -23,7 +23,7 @@ order: [
"InfraVLAN",
"InfraVRF",
"InfraInterface",
"InfraPrefix",
"InfraPrefix",
"InfraIPAddress"
]

Expand Down Expand Up @@ -129,6 +129,9 @@ schema_mapping:
mapping: Version
- name: file
mapping: File
- name: devices
mapping: hostname
reference: InfraDevice

- name: InfraVLAN
identifiers: ['vlan_id', "name"]
Expand All @@ -141,7 +144,7 @@ schema_mapping:

- name: InfraVRF
identifiers: ["name"]
filters:
filters:
- field: Vrf
operation: is_not_empty
mapping: planning_results.routing-table
Expand All @@ -152,17 +155,20 @@ schema_mapping:
- name: InfraInterface
identifiers: ["device", "name"]
mapping: planning_results.interfaces
fields:
transforms:
- field: desc_string
expression: "{{Description | string}}"
fields:
- name: name
mapping: Interface
- name: description
mapping: Description
mapping: desc_string
- name: mac_address
mapping: MAC_normalized
- name: device
mapping: hostname
reference: InfraDevice

- name: InfraPrefix
identifiers: ['vrf', 'prefix']
mapping: filter_networks
Expand All @@ -174,7 +180,7 @@ schema_mapping:
reference: InfraVRF

- name: InfraIPAddress
identifiers: ["address", 'prefix']
identifiers: ["address", 'ip_prefix']
mapping: filter_interfaces
transforms:
- field: dev_int
Expand All @@ -187,6 +193,6 @@ schema_mapping:
- name: interface
mapping: dev_int
reference: InfraInterface
- name: prefix
- name: ip_prefix
mapping: vrf_prefix
reference: InfraPrefix
4 changes: 2 additions & 2 deletions examples/slurpit_to_infrahub/infrahub/sync_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from .sync_models import (
InfraDevice,
InfraHardwareInfo,
InfraInterface,
InfraIPAddress,
InfraInterface,
InfraPlatform,
InfraPrefix,
InfraVersion,
InfraVLAN,
InfraVRF,
InfraVersion,
LocationGeneric,
OrganizationGeneric,
TemplateDeviceType,
Expand Down
20 changes: 5 additions & 15 deletions examples/slurpit_to_infrahub/infrahub/sync_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

from __future__ import annotations

from typing import Any

from infrahub_sync.adapters.infrahub import InfrahubModel


# -------------------------------------------------------
# AUTO-GENERATED FILE, DO NOT MODIFY
# This file has been generated with the command `infrahub-sync generate`
Expand All @@ -24,7 +24,6 @@ class InfraDevice(InfrahubModel):
local_id: str | None = None
local_data: Any | None = None


class InfraHardwareInfo(InfrahubModel):
_modelname = "InfraHardwareInfo"
_identifiers = ("device", "serial")
Expand All @@ -39,10 +38,9 @@ class InfraHardwareInfo(InfrahubModel):
local_id: str | None = None
local_data: Any | None = None


class InfraIPAddress(InfrahubModel):
_modelname = "InfraIPAddress"
_identifiers = ("address", "prefix")
_identifiers = ("address", "ip_prefix")
_attributes = ("interface",)
address: str
interface: str | None = None
Expand All @@ -51,7 +49,6 @@ class InfraIPAddress(InfrahubModel):
local_id: str | None = None
local_data: Any | None = None


class InfraInterface(InfrahubModel):
_modelname = "InfraInterface"
_identifiers = ("device", "name")
Expand All @@ -64,7 +61,6 @@ class InfraInterface(InfrahubModel):
local_id: str | None = None
local_data: Any | None = None


class InfraPlatform(InfrahubModel):
_modelname = "InfraPlatform"
_identifiers = ("name",)
Expand All @@ -74,7 +70,6 @@ class InfraPlatform(InfrahubModel):
local_id: str | None = None
local_data: Any | None = None


class InfraPrefix(InfrahubModel):
_modelname = "InfraPrefix"
_identifiers = ("vrf", "prefix")
Expand All @@ -85,7 +80,6 @@ class InfraPrefix(InfrahubModel):
local_id: str | None = None
local_data: Any | None = None


class InfraVLAN(InfrahubModel):
_modelname = "InfraVLAN"
_identifiers = ("vlan_id", "name")
Expand All @@ -96,7 +90,6 @@ class InfraVLAN(InfrahubModel):
local_id: str | None = None
local_data: Any | None = None


class InfraVRF(InfrahubModel):
_modelname = "InfraVRF"
_identifiers = ("name",)
Expand All @@ -106,22 +99,21 @@ class InfraVRF(InfrahubModel):
local_id: str | None = None
local_data: Any | None = None


class InfraVersion(InfrahubModel):
_modelname = "InfraVersion"
_identifiers = ("version",)
_attributes = ("file",)
_attributes = ("devices", "file")
version: str
devices: list[str] | None = []
file: str | None = None

local_id: str | None = None
local_data: Any | None = None


class LocationGeneric(InfrahubModel):
_modelname = "LocationGeneric"
_identifiers = ("name",)
_attributes = ("description", "number", "street", "zipcode", "country", "phonenumber", "city", "county", "state")
_attributes = ("description", "number", "street", "city", "county", "state", "zipcode", "country", "phonenumber")
name: str
description: str | None = None
number: str | None = None
Expand All @@ -136,7 +128,6 @@ class LocationGeneric(InfrahubModel):
local_id: str | None = None
local_data: Any | None = None


class OrganizationGeneric(InfrahubModel):
_modelname = "OrganizationGeneric"
_identifiers = ("name",)
Expand All @@ -147,7 +138,6 @@ class OrganizationGeneric(InfrahubModel):
local_id: str | None = None
local_data: Any | None = None


class TemplateDeviceType(InfrahubModel):
_modelname = "TemplateDeviceType"
_identifiers = ("name",)
Expand Down
4 changes: 2 additions & 2 deletions examples/slurpit_to_infrahub/slurpitsync/sync_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from .sync_models import (
InfraDevice,
InfraHardwareInfo,
InfraInterface,
InfraIPAddress,
InfraInterface,
InfraPlatform,
InfraPrefix,
InfraVersion,
InfraVLAN,
InfraVRF,
InfraVersion,
LocationGeneric,
OrganizationGeneric,
TemplateDeviceType,
Expand Down
20 changes: 5 additions & 15 deletions examples/slurpit_to_infrahub/slurpitsync/sync_models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

from __future__ import annotations

from typing import Any

from infrahub_sync.adapters.slurpitsync import SlurpitsyncModel


# -------------------------------------------------------
# AUTO-GENERATED FILE, DO NOT MODIFY
# This file has been generated with the command `infrahub-sync generate`
Expand All @@ -24,7 +24,6 @@ class InfraDevice(SlurpitsyncModel):
local_id: str | None = None
local_data: Any | None = None


class InfraHardwareInfo(SlurpitsyncModel):
_modelname = "InfraHardwareInfo"
_identifiers = ("device", "serial")
Expand All @@ -39,10 +38,9 @@ class InfraHardwareInfo(SlurpitsyncModel):
local_id: str | None = None
local_data: Any | None = None


class InfraIPAddress(SlurpitsyncModel):
_modelname = "InfraIPAddress"
_identifiers = ("address", "prefix")
_identifiers = ("address", "ip_prefix")
_attributes = ("interface",)
address: str
interface: str | None = None
Expand All @@ -51,7 +49,6 @@ class InfraIPAddress(SlurpitsyncModel):
local_id: str | None = None
local_data: Any | None = None


class InfraInterface(SlurpitsyncModel):
_modelname = "InfraInterface"
_identifiers = ("device", "name")
Expand All @@ -64,7 +61,6 @@ class InfraInterface(SlurpitsyncModel):
local_id: str | None = None
local_data: Any | None = None


class InfraPlatform(SlurpitsyncModel):
_modelname = "InfraPlatform"
_identifiers = ("name",)
Expand All @@ -74,7 +70,6 @@ class InfraPlatform(SlurpitsyncModel):
local_id: str | None = None
local_data: Any | None = None


class InfraPrefix(SlurpitsyncModel):
_modelname = "InfraPrefix"
_identifiers = ("vrf", "prefix")
Expand All @@ -85,7 +80,6 @@ class InfraPrefix(SlurpitsyncModel):
local_id: str | None = None
local_data: Any | None = None


class InfraVLAN(SlurpitsyncModel):
_modelname = "InfraVLAN"
_identifiers = ("vlan_id", "name")
Expand All @@ -96,7 +90,6 @@ class InfraVLAN(SlurpitsyncModel):
local_id: str | None = None
local_data: Any | None = None


class InfraVRF(SlurpitsyncModel):
_modelname = "InfraVRF"
_identifiers = ("name",)
Expand All @@ -106,22 +99,21 @@ class InfraVRF(SlurpitsyncModel):
local_id: str | None = None
local_data: Any | None = None


class InfraVersion(SlurpitsyncModel):
_modelname = "InfraVersion"
_identifiers = ("version",)
_attributes = ("file",)
_attributes = ("devices", "file")
version: str
devices: list[str] | None = []
file: str | None = None

local_id: str | None = None
local_data: Any | None = None


class LocationGeneric(SlurpitsyncModel):
_modelname = "LocationGeneric"
_identifiers = ("name",)
_attributes = ("description", "number", "street", "zipcode", "country", "phonenumber", "city", "county", "state")
_attributes = ("description", "number", "street", "city", "county", "state", "zipcode", "country", "phonenumber")
name: str
description: str | None = None
number: str | None = None
Expand All @@ -136,7 +128,6 @@ class LocationGeneric(SlurpitsyncModel):
local_id: str | None = None
local_data: Any | None = None


class OrganizationGeneric(SlurpitsyncModel):
_modelname = "OrganizationGeneric"
_identifiers = ("name",)
Expand All @@ -147,7 +138,6 @@ class OrganizationGeneric(SlurpitsyncModel):
local_id: str | None = None
local_data: Any | None = None


class TemplateDeviceType(SlurpitsyncModel):
_modelname = "TemplateDeviceType"
_identifiers = ("name",)
Expand Down
4 changes: 3 additions & 1 deletion infrahub_sync/adapters/infrahub.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def update_node(node: InfrahubNodeSync, attrs: dict) -> InfrahubNodeSync:
for existing_id in existing_only:
attr.remove(existing_id)

attr.fetch()
for new_id in new_only:
attr.add(new_id)

Expand Down Expand Up @@ -215,7 +216,8 @@ def infrahub_node_to_diffsync(self, node: InfrahubNodeSync) -> dict:
elif rel_schema.cardinality == "many":
values = []
rel_manager = getattr(node, rel_schema.name)
for peer in rel_manager:
rel_manager.fetch()
for peer in rel_manager.peers:
peer_node = self.client.store.get(key=peer.id, kind=rel_schema.peer)
peer_data = self.infrahub_node_to_diffsync(node=peer_node)
peer_model = getattr(self, rel_schema.peer)
Expand Down
Loading
Loading