Skip to content

Commit 5bee453

Browse files
authored
Merge pull request #335 from opsmill/dga-20250401-prep-20250401
Release 1.10.0
2 parents 0351c74 + 44901c9 commit 5bee453

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2048
-209
lines changed

.vale/styles/spelling-exceptions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ namespace
8585
namespaces
8686
Nautobot
8787
Netbox
88+
Netutils
8889
Newsfragment
8990
Nornir
9091
npm

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang
1111

1212
<!-- towncrier release notes start -->
1313

14+
## [1.10.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.10.0) - 2025-04-01
15+
16+
### Deprecated
17+
18+
- The method `get_by_hfid` on the object Store has been deprecated, use `get(key=[hfid])` instead
19+
- Using a Store without specifying a default branch is now deprecated and will be removed in a future version.
20+
21+
### Added
22+
23+
- All nodes generated by the SDK will now be assigned an `internal_id` (`_internal_id`). This ID has no significance outside of the SDK.
24+
- Jinja2 templating has been refactored to allow for filters within Infrahub. Builtin filters as well as those from Netutils are available.
25+
- The object store has been refactored to support more use cases in the future and it now properly support branches.
26+
27+
### Fixed
28+
29+
- Fix node processing, when using fragment with `prefetch_relationships`. ([#331](https://github.com/opsmill/infrahub-sdk-python/issues/331))
30+
1431
## [1.9.2](https://github.com/opsmill/infrahub-sdk-python/tree/v1.9.2) - 2025-03-26
1532

1633
### Changed

changelog/331.fixed.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Python SDK Templating
3+
---
4+
Filters can be used when defining [computed attributes](https://docs.infrahub.app/guides/computed-attributes) or [Jinja2 Transforms](https://docs.infrahub.app/guides/jinja2-transform) within Infrahub.
5+
6+
## Builtin Jinja2 filters
7+
8+
The following filters are those that are [shipped with Jinja2](https://jinja.palletsprojects.com/en/stable/templates/#list-of-builtin-filters) and enabled within Infrahub. The trusted column indicates if the filter is allowed for use with Infrahub's computed attributes when the server is configured in strict mode.
9+
10+
<!-- vale off -->
11+
| Name | Trusted |
12+
|----------|----------|
13+
{% for filter in builtin %}
14+
| {{ filter.name }} | {% if filter.trusted %}{% else %}{% endif %} |
15+
{% endfor %}
16+
<!-- vale on -->
17+
18+
## Netutils filters
19+
20+
The following Jinja2 filters from <a href="https://netutils.readthedocs.io">Netutils</a> are included within Infrahub.
21+
<!-- vale off -->
22+
| Name | Trusted |
23+
|----------|----------|
24+
{% for filter in netutils %}
25+
| {{ filter.name }} | {% if filter.trusted %}{% else %}{% endif %} |
26+
{% endfor %}
27+
<!-- vale on -->

docs/docs/python-sdk/introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Python SDK
44

55
The Infrahub Python SDK greatly simplifies how you can interact with Infrahub programmatically.
66

7-
## Blog Posts
7+
## Blog posts
88

99
- [Querying Data in Infrahub via the Python SDK](https://www.opsmill.com/querying-data-in-infrahub-via-the-python-sdk/)
1010

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
title: Python SDK Templating
3+
---
4+
Filters can be used when defining [computed attributes](https://docs.infrahub.app/guides/computed-attributes) or [Jinja2 Transforms](https://docs.infrahub.app/guides/jinja2-transform) within Infrahub.
5+
6+
## Builtin Jinja2 filters
7+
8+
The following filters are those that are [shipped with Jinja2](https://jinja.palletsprojects.com/en/stable/templates/#list-of-builtin-filters) and enabled within Infrahub. The trusted column indicates if the filter is allowed for use with Infrahub's computed attributes when the server is configured in strict mode.
9+
10+
<!-- vale off -->
11+
| Name | Trusted |
12+
|----------|----------|
13+
| abs | |
14+
| attr | |
15+
| batch | |
16+
| capitalize | |
17+
| center | |
18+
| count | |
19+
| d | |
20+
| default | |
21+
| dictsort | |
22+
| e | |
23+
| escape | |
24+
| filesizeformat | |
25+
| first | |
26+
| float | |
27+
| forceescape | |
28+
| format | |
29+
| groupby | |
30+
| indent | |
31+
| int | |
32+
| items | |
33+
| join | |
34+
| last | |
35+
| length | |
36+
| list | |
37+
| lower | |
38+
| map | |
39+
| max | |
40+
| min | |
41+
| pprint | |
42+
| random | |
43+
| reject | |
44+
| rejectattr | |
45+
| replace | |
46+
| reverse | |
47+
| round | |
48+
| safe | |
49+
| select | |
50+
| selectattr | |
51+
| slice | |
52+
| sort | |
53+
| string | |
54+
| striptags | |
55+
| sum | |
56+
| title | |
57+
| tojson | |
58+
| trim | |
59+
| truncate | |
60+
| unique | |
61+
| upper | |
62+
| urlencode | |
63+
| urlize | |
64+
| wordcount | |
65+
| wordwrap | |
66+
| xmlattr | |
67+
<!-- vale on -->
68+
69+
## Netutils filters
70+
71+
The following Jinja2 filters from <a href="https://netutils.readthedocs.io">Netutils</a> are included within Infrahub.
72+
<!-- vale off -->
73+
| Name | Trusted |
74+
|----------|----------|
75+
| abbreviated_interface_name | |
76+
| abbreviated_interface_name_list | |
77+
| asn_to_int | |
78+
| bits_to_name | |
79+
| bytes_to_name | |
80+
| canonical_interface_name | |
81+
| canonical_interface_name_list | |
82+
| cidr_to_netmask | |
83+
| cidr_to_netmaskv6 | |
84+
| clean_config | |
85+
| compare_version_loose | |
86+
| compare_version_strict | |
87+
| config_compliance | |
88+
| config_section_not_parsed | |
89+
| delimiter_change | |
90+
| diff_network_config | |
91+
| feature_compliance | |
92+
| find_unordered_cfg_lines | |
93+
| fqdn_to_ip | |
94+
| get_all_host | |
95+
| get_broadcast_address | |
96+
| get_first_usable | |
97+
| get_ips_sorted | |
98+
| get_nist_urls | |
99+
| get_nist_vendor_platform_urls | |
100+
| get_oui | |
101+
| get_peer_ip | |
102+
| get_range_ips | |
103+
| get_upgrade_path | |
104+
| get_usable_range | |
105+
| hash_data | |
106+
| int_to_asdot | |
107+
| interface_range_compress | |
108+
| interface_range_expansion | |
109+
| ip_addition | |
110+
| ip_subtract | |
111+
| ip_to_bin | |
112+
| ip_to_hex | |
113+
| ipaddress_address | |
114+
| ipaddress_interface | |
115+
| ipaddress_network | |
116+
| is_classful | |
117+
| is_fqdn_resolvable | |
118+
| is_ip | |
119+
| is_ip_range | |
120+
| is_ip_within | |
121+
| is_netmask | |
122+
| is_network | |
123+
| is_reversible_wildcardmask | |
124+
| is_valid_mac | |
125+
| longest_prefix_match | |
126+
| mac_normalize | |
127+
| mac_to_format | |
128+
| mac_to_int | |
129+
| mac_type | |
130+
| name_to_bits | |
131+
| name_to_bytes | |
132+
| name_to_name | |
133+
| netmask_to_cidr | |
134+
| netmask_to_wildcardmask | |
135+
| normalise_delimiter_caret_c | |
136+
| paloalto_panos_brace_to_set | |
137+
| paloalto_panos_clean_newlines | |
138+
| regex_findall | |
139+
| regex_match | |
140+
| regex_search | |
141+
| regex_split | |
142+
| regex_sub | |
143+
| sanitize_config | |
144+
| section_config | |
145+
| sort_interface_list | |
146+
| split_interface | |
147+
| uptime_seconds_to_string | |
148+
| uptime_string_to_seconds | |
149+
| version_metadata | |
150+
| vlanconfig_to_list | |
151+
| vlanlist_to_config | |
152+
| wildcardmask_to_netmask | |
153+
<!-- vale on -->

docs/sidebars-python-sdk.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const sidebars: SidebarsConfig = {
3838
label: 'Reference',
3939
items: [
4040
'reference/config',
41+
'reference/templating',
4142
],
4243
},
4344
],

infrahub_sdk/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def _initialize(self) -> None:
281281
self.schema = InfrahubSchema(self)
282282
self.branch = InfrahubBranchManager(self)
283283
self.object_store = ObjectStore(self)
284-
self.store = NodeStore()
284+
self.store = NodeStore(default_branch=self.default_branch)
285285
self.task = InfrahubTaskManager(self)
286286
self.concurrent_execution_limit = asyncio.Semaphore(self.max_concurrent_execution)
287287
self._request_method: AsyncRequester = self.config.requester or self._default_request_method
@@ -840,11 +840,11 @@ async def process_non_batch() -> tuple[list[InfrahubNode], list[InfrahubNode]]:
840840
if populate_store:
841841
for node in nodes:
842842
if node.id:
843-
self.store.set(key=node.id, node=node)
843+
self.store.set(node=node)
844844
related_nodes = list(set(related_nodes))
845845
for node in related_nodes:
846846
if node.id:
847-
self.store.set(key=node.id, node=node)
847+
self.store.set(node=node)
848848
return nodes
849849

850850
def clone(self) -> InfrahubClient:
@@ -1529,7 +1529,7 @@ def _initialize(self) -> None:
15291529
self.schema = InfrahubSchemaSync(self)
15301530
self.branch = InfrahubBranchManagerSync(self)
15311531
self.object_store = ObjectStoreSync(self)
1532-
self.store = NodeStoreSync()
1532+
self.store = NodeStoreSync(default_branch=self.default_branch)
15331533
self.task = InfrahubTaskManagerSync(self)
15341534
self._request_method: SyncRequester = self.config.sync_requester or self._default_request_method
15351535
self.group_context = InfrahubGroupContextSync(self)
@@ -1997,11 +1997,11 @@ def process_non_batch() -> tuple[list[InfrahubNodeSync], list[InfrahubNodeSync]]
19971997
if populate_store:
19981998
for node in nodes:
19991999
if node.id:
2000-
self.store.set(key=node.id, node=node)
2000+
self.store.set(node=node)
20012001
related_nodes = list(set(related_nodes))
20022002
for node in related_nodes:
20032003
if node.id:
2004-
self.store.set(key=node.id, node=node)
2004+
self.store.set(node=node)
20052005
return nodes
20062006

20072007
@overload

0 commit comments

Comments
 (0)