Skip to content

Commit ec44d06

Browse files
authored
Merge pull request #81 from opsmill/copilot/fix-80
Add GenericRestApiAdapter
2 parents b9c76a3 + f058cdd commit ec44d06

File tree

19 files changed

+845
-439
lines changed

19 files changed

+845
-439
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: from-peeringdb
3+
source:
4+
name: genericrestapi
5+
settings:
6+
url: "https://www.peeringdb.com"
7+
api_endpoint: "api"
8+
auth_method: "none" # PeeringDB allows public access (beware rate limits)
9+
response_key_pattern: "data" # PeeringDB wraps lists under "data"
10+
11+
12+
destination:
13+
name: infrahub
14+
settings:
15+
url: "http://localhost:8000"
16+
17+
# Optional: Skip objects in the source that don't exist in the destination (prevents creation)
18+
dyffsync_flags: ["SKIP_UNMATCHED_SRC"]
19+
20+
order: ["InfraAutonomousSystem"]
21+
22+
schema_mapping:
23+
- name: InfraAutonomousSystem
24+
mapping: net # PeeringDB resource
25+
identifiers: ["asn"] # needed to match/merge objects
26+
fields:
27+
- name: asn # minimal id field
28+
mapping: asn
29+
- name: name
30+
mapping: name
31+
- name: irr_as_set
32+
mapping: irr_as_set
33+
- name: ipv4_max_prefixes
34+
mapping: info_prefixes4
35+
- name: ipv6_max_prefixes
36+
mapping: info_prefixes6

examples/peeringdb_to_infrahub/genenericrestapi/__init__.py

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from infrahub_sync.adapters.genenericrestapi import GenenericrestapiAdapter
2+
3+
from .sync_models import (
4+
InfraAutonomousSystem,
5+
InfraBGPCommunity,
6+
InfraBGPPeerGroup,
7+
InfraBGPRoutingPolicy,
8+
InfraIXP,
9+
InfraIXPConnection,
10+
IpamIPAddress,
11+
OrganizationProvider,
12+
)
13+
14+
15+
# -------------------------------------------------------
16+
# AUTO-GENERATED FILE, DO NOT MODIFY
17+
# This file has been generated with the command `infrahub-sync generate`
18+
# All modifications will be lost the next time you reexecute this command
19+
# -------------------------------------------------------
20+
class GenenericrestapiSync(GenenericrestapiAdapter):
21+
InfraAutonomousSystem = InfraAutonomousSystem
22+
InfraBGPPeerGroup = InfraBGPPeerGroup
23+
IpamIPAddress = IpamIPAddress
24+
OrganizationProvider = OrganizationProvider
25+
InfraBGPCommunity = InfraBGPCommunity
26+
InfraBGPRoutingPolicy = InfraBGPRoutingPolicy
27+
InfraIXP = InfraIXP
28+
InfraIXPConnection = InfraIXPConnection
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
5+
from infrahub_sync.adapters.genenericrestapi import GenenericrestapiModel
6+
7+
8+
# -------------------------------------------------------
9+
# AUTO-GENERATED FILE, DO NOT MODIFY
10+
# This file has been generated with the command `infrahub-sync generate`
11+
# All modifications will be lost the next time you reexecute this command
12+
# -------------------------------------------------------
13+
class InfraAutonomousSystem(GenenericrestapiModel):
14+
_modelname = "InfraAutonomousSystem"
15+
_identifiers = ("asn",)
16+
_attributes = (
17+
"organization",
18+
"affiliated",
19+
"irr_as_set",
20+
"name",
21+
"ipv4_max_prefixes",
22+
"description",
23+
"ipv6_max_prefixes",
24+
)
25+
asn: int
26+
affiliated: bool | None = None
27+
irr_as_set: str | None = None
28+
name: str
29+
ipv4_max_prefixes: int | None = None
30+
description: str | None = None
31+
ipv6_max_prefixes: int | None = None
32+
organization: str | None = None
33+
34+
local_id: str | None = None
35+
local_data: Any | None = None
36+
37+
38+
class InfraBGPPeerGroup(GenenericrestapiModel):
39+
_modelname = "InfraBGPPeerGroup"
40+
_identifiers = ("name",)
41+
_attributes = ("bgp_communities", "import_policies", "export_policies", "description", "status")
42+
name: str
43+
description: str | None = None
44+
status: str | None = None
45+
bgp_communities: list[str] | None = []
46+
import_policies: list[str] | None = []
47+
export_policies: list[str] | None = []
48+
49+
local_id: str | None = None
50+
local_data: Any | None = None
51+
52+
53+
class IpamIPAddress(GenenericrestapiModel):
54+
_modelname = "IpamIPAddress"
55+
_identifiers = ("address",)
56+
_attributes = ("description",)
57+
description: str | None = None
58+
address: str
59+
60+
local_id: str | None = None
61+
local_data: Any | None = None
62+
63+
64+
class OrganizationProvider(GenenericrestapiModel):
65+
_modelname = "OrganizationProvider"
66+
_identifiers = ("name",)
67+
_attributes = ()
68+
name: str
69+
70+
local_id: str | None = None
71+
local_data: Any | None = None
72+
73+
74+
class InfraBGPCommunity(GenenericrestapiModel):
75+
_modelname = "InfraBGPCommunity"
76+
_identifiers = ("name",)
77+
_attributes = ("description", "label", "community_type", "value")
78+
name: str
79+
description: str | None = None
80+
label: str | None = None
81+
community_type: str | None = None
82+
value: str
83+
84+
local_id: str | None = None
85+
local_data: Any | None = None
86+
87+
88+
class InfraBGPRoutingPolicy(GenenericrestapiModel):
89+
_modelname = "InfraBGPRoutingPolicy"
90+
_identifiers = ("name",)
91+
_attributes = ("bgp_communities", "address_family", "policy_type", "label", "weight", "description")
92+
address_family: int
93+
policy_type: str
94+
label: str | None = None
95+
weight: int | None = 1000
96+
name: str
97+
description: str | None = None
98+
bgp_communities: list[str] | None = []
99+
100+
local_id: str | None = None
101+
local_data: Any | None = None
102+
103+
104+
class InfraIXP(GenenericrestapiModel):
105+
_modelname = "InfraIXP"
106+
_identifiers = ("name",)
107+
_attributes = ("export_policies", "bgp_communities", "import_policies", "status", "description")
108+
status: str | None = "enabled"
109+
name: str
110+
description: str | None = None
111+
export_policies: list[str] | None = []
112+
bgp_communities: list[str] | None = []
113+
import_policies: list[str] | None = []
114+
115+
local_id: str | None = None
116+
local_data: Any | None = None
117+
118+
119+
class InfraIXPConnection(GenenericrestapiModel):
120+
_modelname = "InfraIXPConnection"
121+
_identifiers = ("name",)
122+
_attributes = (
123+
"internet_exchange_point",
124+
"ipv4_address",
125+
"ipv6_address",
126+
"status",
127+
"peeringdb_netixlan",
128+
"vlan",
129+
"description",
130+
)
131+
name: str
132+
status: str | None = "enabled"
133+
peeringdb_netixlan: int | None = None
134+
vlan: int | None = None
135+
description: str | None = None
136+
internet_exchange_point: str
137+
ipv4_address: str | None = None
138+
ipv6_address: str | None = None
139+
140+
local_id: str | None = None
141+
local_data: Any | None = None

examples/peeringdb_to_infrahub/generic_rest_api/__init__.py

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from infrahub_sync.adapters.generic_rest_api import Generic_Rest_ApiAdapter
2+
3+
from .sync_models import (
4+
InfraAutonomousSystem,
5+
InfraBGPCommunity,
6+
InfraBGPPeerGroup,
7+
InfraBGPRoutingPolicy,
8+
InfraIXP,
9+
InfraIXPConnection,
10+
IpamIPAddress,
11+
OrganizationProvider,
12+
)
13+
14+
15+
# -------------------------------------------------------
16+
# AUTO-GENERATED FILE, DO NOT MODIFY
17+
# This file has been generated with the command `infrahub-sync generate`
18+
# All modifications will be lost the next time you reexecute this command
19+
# -------------------------------------------------------
20+
class Generic_Rest_ApiSync(Generic_Rest_ApiAdapter):
21+
InfraAutonomousSystem = InfraAutonomousSystem
22+
InfraBGPPeerGroup = InfraBGPPeerGroup
23+
IpamIPAddress = IpamIPAddress
24+
OrganizationProvider = OrganizationProvider
25+
InfraBGPRoutingPolicy = InfraBGPRoutingPolicy
26+
InfraBGPCommunity = InfraBGPCommunity
27+
InfraIXP = InfraIXP
28+
InfraIXPConnection = InfraIXPConnection
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
5+
from infrahub_sync.adapters.generic_rest_api import Generic_Rest_ApiModel
6+
7+
8+
# -------------------------------------------------------
9+
# AUTO-GENERATED FILE, DO NOT MODIFY
10+
# This file has been generated with the command `infrahub-sync generate`
11+
# All modifications will be lost the next time you reexecute this command
12+
# -------------------------------------------------------
13+
class InfraAutonomousSystem(Generic_Rest_ApiModel):
14+
_modelname = "InfraAutonomousSystem"
15+
_identifiers = ("asn",)
16+
_attributes = (
17+
"organization",
18+
"affiliated",
19+
"irr_as_set",
20+
"name",
21+
"ipv4_max_prefixes",
22+
"description",
23+
"ipv6_max_prefixes",
24+
)
25+
asn: int
26+
affiliated: bool | None = None
27+
irr_as_set: str | None = None
28+
name: str
29+
ipv4_max_prefixes: int | None = None
30+
description: str | None = None
31+
ipv6_max_prefixes: int | None = None
32+
organization: str | None = None
33+
34+
local_id: str | None = None
35+
local_data: Any | None = None
36+
37+
38+
class InfraBGPPeerGroup(Generic_Rest_ApiModel):
39+
_modelname = "InfraBGPPeerGroup"
40+
_identifiers = ("name",)
41+
_attributes = ("import_policies", "export_policies", "bgp_communities", "description", "status")
42+
name: str
43+
description: str | None = None
44+
status: str | None = None
45+
import_policies: list[str] | None = []
46+
export_policies: list[str] | None = []
47+
bgp_communities: list[str] | None = []
48+
49+
local_id: str | None = None
50+
local_data: Any | None = None
51+
52+
53+
class IpamIPAddress(Generic_Rest_ApiModel):
54+
_modelname = "IpamIPAddress"
55+
_identifiers = ("address",)
56+
_attributes = ("description",)
57+
description: str | None = None
58+
address: str
59+
60+
local_id: str | None = None
61+
local_data: Any | None = None
62+
63+
64+
class OrganizationProvider(Generic_Rest_ApiModel):
65+
_modelname = "OrganizationProvider"
66+
_identifiers = ("name",)
67+
_attributes = ()
68+
name: str
69+
70+
local_id: str | None = None
71+
local_data: Any | None = None
72+
73+
74+
class InfraBGPRoutingPolicy(Generic_Rest_ApiModel):
75+
_modelname = "InfraBGPRoutingPolicy"
76+
_identifiers = ("name",)
77+
_attributes = ("bgp_communities", "label", "description", "policy_type", "weight", "address_family")
78+
name: str
79+
label: str | None = None
80+
description: str | None = None
81+
policy_type: str
82+
weight: int | None = 1000
83+
address_family: int
84+
bgp_communities: list[str] | None = []
85+
86+
local_id: str | None = None
87+
local_data: Any | None = None
88+
89+
90+
class InfraBGPCommunity(Generic_Rest_ApiModel):
91+
_modelname = "InfraBGPCommunity"
92+
_identifiers = ("name",)
93+
_attributes = ("description", "label", "community_type", "value")
94+
name: str
95+
description: str | None = None
96+
label: str | None = None
97+
community_type: str | None = None
98+
value: str
99+
100+
local_id: str | None = None
101+
local_data: Any | None = None
102+
103+
104+
class InfraIXP(Generic_Rest_ApiModel):
105+
_modelname = "InfraIXP"
106+
_identifiers = ("name",)
107+
_attributes = ("export_policies", "bgp_communities", "import_policies", "description", "status")
108+
name: str
109+
description: str | None = None
110+
status: str | None = "enabled"
111+
export_policies: list[str] | None = []
112+
bgp_communities: list[str] | None = []
113+
import_policies: list[str] | None = []
114+
115+
local_id: str | None = None
116+
local_data: Any | None = None
117+
118+
119+
class InfraIXPConnection(Generic_Rest_ApiModel):
120+
_modelname = "InfraIXPConnection"
121+
_identifiers = ("name",)
122+
_attributes = (
123+
"internet_exchange_point",
124+
"ipv4_address",
125+
"ipv6_address",
126+
"status",
127+
"peeringdb_netixlan",
128+
"vlan",
129+
"description",
130+
)
131+
name: str
132+
status: str | None = "enabled"
133+
peeringdb_netixlan: int | None = None
134+
vlan: int | None = None
135+
description: str | None = None
136+
internet_exchange_point: str
137+
ipv4_address: str | None = None
138+
ipv6_address: str | None = None
139+
140+
local_id: str | None = None
141+
local_data: Any | None = None

examples/peeringdb_to_infrahub/genericrestapi/__init__.py

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from infrahub_sync.adapters.genericrestapi import GenericrestapiAdapter
2+
3+
from .sync_models import (
4+
InfraAutonomousSystem,
5+
)
6+
7+
8+
# -------------------------------------------------------
9+
# AUTO-GENERATED FILE, DO NOT MODIFY
10+
# This file has been generated with the command `infrahub-sync generate`
11+
# All modifications will be lost the next time you reexecute this command
12+
# -------------------------------------------------------
13+
class GenericrestapiSync(GenericrestapiAdapter):
14+
InfraAutonomousSystem = InfraAutonomousSystem

0 commit comments

Comments
 (0)