Skip to content

Release 1.10.0 #335

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

Merged
merged 12 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .vale/styles/spelling-exceptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace
namespaces
Nautobot
Netbox
Netutils
Newsfragment
Nornir
npm
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang

<!-- towncrier release notes start -->

## [1.10.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.10.0) - 2025-04-01

### Deprecated

- The method `get_by_hfid` on the object Store has been deprecated, use `get(key=[hfid])` instead
- Using a Store without specifying a default branch is now deprecated and will be removed in a future version.

### Added

- All nodes generated by the SDK will now be assigned an `internal_id` (`_internal_id`). This ID has no significance outside of the SDK.
- Jinja2 templating has been refactored to allow for filters within Infrahub. Builtin filters as well as those from Netutils are available.
- The object store has been refactored to support more use cases in the future and it now properly support branches.

### Fixed

- Fix node processing, when using fragment with `prefetch_relationships`. ([#331](https://github.com/opsmill/infrahub-sdk-python/issues/331))

## [1.9.2](https://github.com/opsmill/infrahub-sdk-python/tree/v1.9.2) - 2025-03-26

### Changed
Expand Down
1 change: 0 additions & 1 deletion changelog/331.fixed.md

This file was deleted.

27 changes: 27 additions & 0 deletions docs/_templates/sdk_template_reference.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Python SDK Templating
---
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.

## Builtin Jinja2 filters

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.

<!-- vale off -->
| Name | Trusted |
|----------|----------|
{% for filter in builtin %}
| {{ filter.name }} | {% if filter.trusted %}✅{% else %}❌{% endif %} |
{% endfor %}
<!-- vale on -->

## Netutils filters

The following Jinja2 filters from <a href="https://netutils.readthedocs.io">Netutils</a> are included within Infrahub.
<!-- vale off -->
| Name | Trusted |
|----------|----------|
{% for filter in netutils %}
| {{ filter.name }} | {% if filter.trusted %}✅{% else %}❌{% endif %} |
{% endfor %}
<!-- vale on -->
2 changes: 1 addition & 1 deletion docs/docs/python-sdk/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Python SDK

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

## Blog Posts
## Blog posts

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

Expand Down
153 changes: 153 additions & 0 deletions docs/docs/python-sdk/reference/templating.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
---
title: Python SDK Templating
---
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.

## Builtin Jinja2 filters

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.

<!-- vale off -->
| Name | Trusted |
|----------|----------|
| abs | ✅ |
| attr | ❌ |
| batch | ❌ |
| capitalize | ✅ |
| center | ✅ |
| count | ✅ |
| d | ✅ |
| default | ✅ |
| dictsort | ❌ |
| e | ✅ |
| escape | ✅ |
| filesizeformat | ✅ |
| first | ✅ |
| float | ✅ |
| forceescape | ✅ |
| format | ✅ |
| groupby | ❌ |
| indent | ✅ |
| int | ✅ |
| items | ❌ |
| join | ✅ |
| last | ✅ |
| length | ✅ |
| list | ✅ |
| lower | ✅ |
| map | ❌ |
| max | ✅ |
| min | ✅ |
| pprint | ❌ |
| random | ❌ |
| reject | ❌ |
| rejectattr | ❌ |
| replace | ✅ |
| reverse | ✅ |
| round | ✅ |
| safe | ❌ |
| select | ❌ |
| selectattr | ❌ |
| slice | ✅ |
| sort | ❌ |
| string | ✅ |
| striptags | ✅ |
| sum | ✅ |
| title | ✅ |
| tojson | ❌ |
| trim | ✅ |
| truncate | ✅ |
| unique | ❌ |
| upper | ✅ |
| urlencode | ✅ |
| urlize | ❌ |
| wordcount | ✅ |
| wordwrap | ✅ |
| xmlattr | ❌ |
<!-- vale on -->

## Netutils filters

The following Jinja2 filters from <a href="https://netutils.readthedocs.io">Netutils</a> are included within Infrahub.
<!-- vale off -->
| Name | Trusted |
|----------|----------|
| abbreviated_interface_name | ✅ |
| abbreviated_interface_name_list | ✅ |
| asn_to_int | ✅ |
| bits_to_name | ✅ |
| bytes_to_name | ✅ |
| canonical_interface_name | ✅ |
| canonical_interface_name_list | ✅ |
| cidr_to_netmask | ✅ |
| cidr_to_netmaskv6 | ✅ |
| clean_config | ✅ |
| compare_version_loose | ✅ |
| compare_version_strict | ✅ |
| config_compliance | ✅ |
| config_section_not_parsed | ✅ |
| delimiter_change | ✅ |
| diff_network_config | ✅ |
| feature_compliance | ✅ |
| find_unordered_cfg_lines | ✅ |
| fqdn_to_ip | ❌ |
| get_all_host | ❌ |
| get_broadcast_address | ✅ |
| get_first_usable | ✅ |
| get_ips_sorted | ✅ |
| get_nist_urls | ✅ |
| get_nist_vendor_platform_urls | ✅ |
| get_oui | ✅ |
| get_peer_ip | ✅ |
| get_range_ips | ✅ |
| get_upgrade_path | ✅ |
| get_usable_range | ✅ |
| hash_data | ✅ |
| int_to_asdot | ✅ |
| interface_range_compress | ✅ |
| interface_range_expansion | ✅ |
| ip_addition | ✅ |
| ip_subtract | ✅ |
| ip_to_bin | ✅ |
| ip_to_hex | ✅ |
| ipaddress_address | ✅ |
| ipaddress_interface | ✅ |
| ipaddress_network | ✅ |
| is_classful | ✅ |
| is_fqdn_resolvable | ❌ |
| is_ip | ✅ |
| is_ip_range | ✅ |
| is_ip_within | ✅ |
| is_netmask | ✅ |
| is_network | ✅ |
| is_reversible_wildcardmask | ✅ |
| is_valid_mac | ✅ |
| longest_prefix_match | ✅ |
| mac_normalize | ✅ |
| mac_to_format | ✅ |
| mac_to_int | ✅ |
| mac_type | ✅ |
| name_to_bits | ✅ |
| name_to_bytes | ✅ |
| name_to_name | ✅ |
| netmask_to_cidr | ✅ |
| netmask_to_wildcardmask | ✅ |
| normalise_delimiter_caret_c | ✅ |
| paloalto_panos_brace_to_set | ✅ |
| paloalto_panos_clean_newlines | ✅ |
| regex_findall | ❌ |
| regex_match | ❌ |
| regex_search | ❌ |
| regex_split | ❌ |
| regex_sub | ❌ |
| sanitize_config | ✅ |
| section_config | ✅ |
| sort_interface_list | ✅ |
| split_interface | ✅ |
| uptime_seconds_to_string | ✅ |
| uptime_string_to_seconds | ✅ |
| version_metadata | ✅ |
| vlanconfig_to_list | ✅ |
| vlanlist_to_config | ✅ |
| wildcardmask_to_netmask | ✅ |
<!-- vale on -->
1 change: 1 addition & 0 deletions docs/sidebars-python-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const sidebars: SidebarsConfig = {
label: 'Reference',
items: [
'reference/config',
'reference/templating',
],
},
],
Expand Down
12 changes: 6 additions & 6 deletions infrahub_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
self.schema = InfrahubSchema(self)
self.branch = InfrahubBranchManager(self)
self.object_store = ObjectStore(self)
self.store = NodeStore()
self.store = NodeStore(default_branch=self.default_branch)
self.task = InfrahubTaskManager(self)
self.concurrent_execution_limit = asyncio.Semaphore(self.max_concurrent_execution)
self._request_method: AsyncRequester = self.config.requester or self._default_request_method
Expand Down Expand Up @@ -840,11 +840,11 @@
if populate_store:
for node in nodes:
if node.id:
self.store.set(key=node.id, node=node)
self.store.set(node=node)
related_nodes = list(set(related_nodes))
for node in related_nodes:
if node.id:
self.store.set(key=node.id, node=node)
self.store.set(node=node)
return nodes

def clone(self) -> InfrahubClient:
Expand Down Expand Up @@ -1529,7 +1529,7 @@
self.schema = InfrahubSchemaSync(self)
self.branch = InfrahubBranchManagerSync(self)
self.object_store = ObjectStoreSync(self)
self.store = NodeStoreSync()
self.store = NodeStoreSync(default_branch=self.default_branch)
self.task = InfrahubTaskManagerSync(self)
self._request_method: SyncRequester = self.config.sync_requester or self._default_request_method
self.group_context = InfrahubGroupContextSync(self)
Expand Down Expand Up @@ -1997,11 +1997,11 @@
if populate_store:
for node in nodes:
if node.id:
self.store.set(key=node.id, node=node)
self.store.set(node=node)
related_nodes = list(set(related_nodes))
for node in related_nodes:
if node.id:
self.store.set(key=node.id, node=node)
self.store.set(node=node)

Check warning on line 2004 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L2004

Added line #L2004 was not covered by tests
return nodes

@overload
Expand Down
Loading