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

Update infrahub-sdk v1.0.0 #129

Merged
merged 5 commits into from
Nov 4, 2024
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
2 changes: 1 addition & 1 deletion .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extends: default
ignore: |
/.venv
/examples
/tests/**/output*
/tests/**
changelogs/changelog.yaml

rules:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
version: "3.4"
x-args:
&args
PYTHON_VER: ${PYTHON_VER}
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/artifact_fetch_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:trim:

.. meta::
:antsibull-docs: 2.13.1
:antsibull-docs: 2.15.0

.. Anchors

Expand All @@ -22,7 +22,7 @@ opsmill.infrahub.artifact_fetch module -- Fetch the content of an artifact from
.. Collection note

.. note::
This module is part of the `opsmill.infrahub collection <https://galaxy.ansible.com/ui/repo/published/opsmill/infrahub/>`_ (version 1.1.0).
This module is part of the `opsmill.infrahub collection <https://galaxy.ansible.com/ui/repo/published/opsmill/infrahub/>`_ (version 1.2.2).

It is not included in ``ansible-core``.
To check whether it is installed, run :code:`ansible-galaxy collection list`.
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/environment_variables.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:orphan:

.. meta::
:antsibull-docs: 2.13.1
:antsibull-docs: 2.15.0

.. _list_of_collection_env_vars:

Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/index.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.. meta::
:antsibull-docs: 2.13.1
:antsibull-docs: 2.15.0


.. _plugins_in_opsmill.infrahub:

Opsmill.Infrahub
================

Collection version 1.1.0
Collection version 1.2.2

.. contents::
:local:
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/install_role.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:trim:

.. meta::
:antsibull-docs: 2.13.1
:antsibull-docs: 2.15.0

.. Anchors

Expand All @@ -20,7 +20,7 @@ opsmill.infrahub.install role -- Install Infrahub
.. Collection note

.. note::
This role is part of the `opsmill.infrahub collection <https://galaxy.ansible.com/ui/repo/published/opsmill/infrahub/>`_ (version 1.1.0).
This role is part of the `opsmill.infrahub collection <https://galaxy.ansible.com/ui/repo/published/opsmill/infrahub/>`_ (version 1.2.2).

It is not included in ``ansible-core``.
To check whether it is installed, run :code:`ansible-galaxy collection list`.
Expand Down
53 changes: 34 additions & 19 deletions docs/plugins/inventory_inventory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:trim:

.. meta::
:antsibull-docs: 2.13.1
:antsibull-docs: 2.15.0

.. Anchors

Expand All @@ -22,7 +22,7 @@ opsmill.infrahub.inventory inventory -- Infrahub inventory source (using GraphQL
.. Collection note

.. note::
This inventory plugin is part of the `opsmill.infrahub collection <https://galaxy.ansible.com/ui/repo/published/opsmill/infrahub/>`_ (version 1.1.0).
This inventory plugin is part of the `opsmill.infrahub collection <https://galaxy.ansible.com/ui/repo/published/opsmill/infrahub/>`_ (version 1.2.2).

It is not included in ``ansible-core``.
To check whether it is installed, run :code:`ansible-galaxy collection list`.
Expand Down Expand Up @@ -207,7 +207,7 @@ Parameters

- INI entry:

.. code-block::
.. code-block:: ini

[inventory]
cache = false
Expand Down Expand Up @@ -259,14 +259,14 @@ Parameters

- INI entries:

.. code-block::
.. code-block:: ini

[defaults]
fact_caching_connection = VALUE



.. code-block::
.. code-block:: ini

[inventory]
cache_connection = VALUE
Expand Down Expand Up @@ -324,14 +324,14 @@ Parameters

- INI entries:

.. code-block::
.. code-block:: ini

[defaults]
fact_caching = memory



.. code-block::
.. code-block:: ini

[inventory]
cache_plugin = memory
Expand Down Expand Up @@ -389,14 +389,29 @@ Parameters

- INI entries:

.. code-block::
.. code-block:: ini

[default]
fact_caching_prefix = ansible_inventory_


Removed in: version 2.16 of ansible.builtin


Why: Fixes typing error in INI section name

Alternative: Use the 'defaults' section instead



.. code-block:: ini

[defaults]
fact_caching_prefix = ansible_inventory_



.. code-block::
.. code-block:: ini

[inventory]
cache_prefix = ansible_inventory_
Expand Down Expand Up @@ -454,14 +469,14 @@ Parameters

- INI entries:

.. code-block::
.. code-block:: ini

[defaults]
fact_caching_timeout = 3600



.. code-block::
.. code-block:: ini

[inventory]
cache_timeout = 3600
Expand Down Expand Up @@ -644,7 +659,7 @@ Parameters

The default value when the host variable's value is an empty string.

This option is mutually exclusive with :ansopt:`opsmill.infrahub.inventory#inventory:keyed\_groups[].trailing\_separator`.
This option is mutually exclusive with :literal:`trailing\_separator`.


.. raw:: html
Expand Down Expand Up @@ -880,9 +895,9 @@ Parameters

<div class="ansible-option-indent-desc"></div><div class="ansible-option-cell">

Set this option to :ansval:`False` to omit the :ansopt:`opsmill.infrahub.inventory#inventory:keyed\_groups[].separator` after the host variable when the value is an empty string.
Set this option to :emphasis:`False` to omit the :literal:`separator` after the host variable when the value is an empty string.

This option is mutually exclusive with :ansopt:`opsmill.infrahub.inventory#inventory:keyed\_groups[].default\_value`.
This option is mutually exclusive with :literal:`default\_value`.


.. rst-class:: ansible-option-line
Expand Down Expand Up @@ -1265,7 +1280,7 @@ Parameters

<div class="ansible-option-cell">

If :ansval:`yes` make invalid entries a fatal error, otherwise skip and continue.
If :literal:`yes` make invalid entries a fatal error, otherwise skip and continue.

Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default.

Expand Down Expand Up @@ -1417,7 +1432,7 @@ Parameters

- INI entry:

.. code-block::
.. code-block:: ini

[inventory_plugins]
use_extra_vars = false
Expand Down Expand Up @@ -1513,10 +1528,10 @@ Examples
InfraDevice:
include:
- name
- platform
- primary_address
- platform.ansible_network_os
- primary_address.address
- site.name
- interfaces
- site

compose:
hostname: name
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/lookup_lookup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:trim:

.. meta::
:antsibull-docs: 2.13.1
:antsibull-docs: 2.15.0

.. Anchors

Expand All @@ -22,7 +22,7 @@ opsmill.infrahub.lookup lookup -- Queries and returns elements from Infrahub (us
.. Collection note

.. note::
This lookup plugin is part of the `opsmill.infrahub collection <https://galaxy.ansible.com/ui/repo/published/opsmill/infrahub/>`_ (version 1.1.0).
This lookup plugin is part of the `opsmill.infrahub collection <https://galaxy.ansible.com/ui/repo/published/opsmill/infrahub/>`_ (version 1.2.2).

It is not included in ``ansible-core``.
To check whether it is installed, run :code:`ansible-galaxy collection list`.
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/query_graphql_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:trim:

.. meta::
:antsibull-docs: 2.13.1
:antsibull-docs: 2.15.0

.. Anchors

Expand All @@ -22,7 +22,7 @@ opsmill.infrahub.query_graphql module -- Queries and returns elements from Infra
.. Collection note

.. note::
This module is part of the `opsmill.infrahub collection <https://galaxy.ansible.com/ui/repo/published/opsmill/infrahub/>`_ (version 1.1.0).
This module is part of the `opsmill.infrahub collection <https://galaxy.ansible.com/ui/repo/published/opsmill/infrahub/>`_ (version 1.2.2).

It is not included in ``ansible-core``.
To check whether it is installed, run :code:`ansible-galaxy collection list`.
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace: opsmill
name: infrahub

# The version of the collection. Must be compatible with semantic versioning
version: 1.2.0
version: 1.2.2

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
6 changes: 3 additions & 3 deletions plugins/inventory/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@
InfraDevice:
include:
- name
- platform
- primary_address
- platform.ansible_network_os
- primary_address.address
- site.name
- interfaces
- site

compose:
hostname: name
Expand Down
3 changes: 0 additions & 3 deletions plugins/module_utils/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

try:
from infrahub_sdk.exceptions import (
FilterNotFoundError,
GraphQLError,
SchemaNotFoundError,
ServerNotReachableError,
Expand Down Expand Up @@ -39,8 +38,6 @@ def wrapper(*args, **kwargs):
raise Exception(f"An error occurred while executing the GraphQL Query {kwargs}")
except SchemaNotFoundError:
raise Exception(f"Unable to find the schema {kwargs}")
except FilterNotFoundError:
raise Exception(f"Filters not Found {kwargs}")
except ServerNotReachableError:
raise Exception("Server not Reacheable")
except ServerNotResponsiveError:
Expand Down
15 changes: 13 additions & 2 deletions plugins/module_utils/infrahub_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def __init__(
@handle_infrahub_exceptions
def fetch_single_artifact(
self,
filters: Optional[Dict[str, str]] = None,
filters: Dict[str, str],
branch: Optional[str] = None,
) -> List[InfrahubNodeSync]:
"""
Retrieve all artifact content

Parameters:
filters (Optional[Dict[str, str]]): Dict of filters to apply on the query
artifact (Optional[Dict[str, str]]): Dict of filters to apply on the query
branch (Optional[str]): Name of the branch to query from. Defaults to default_branch.

Returns:
Expand Down Expand Up @@ -129,6 +129,8 @@ def fetch_artifacts(
def fetch_single_node( # noqa: PLR0917
self,
kind: str,
id: Optional[str] = None,
hfid: Optional[list[str]] = None,
include: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
filters: Optional[Dict[str, str]] = None,
Expand All @@ -140,6 +142,8 @@ def fetch_single_node( # noqa: PLR0917

Parameters:
kind (str): kind of the nodes to query
id (Optional[str]): ID of the node to retrieve
hfid (Optional[List[str]]): HFID of the node to retrieve
include (Optional[List[str]]): list of attributes/relationship to retrieve
exclude (Optional[List[str]]): list of attributes/relationship to ignore
filters (Optional[Dict[str, str]]): Dict of filters to apply on the query
Expand All @@ -149,11 +153,18 @@ def fetch_single_node( # noqa: PLR0917
Returns:
InfrahubNodeSync: Single Infrahub Node
"""
if id:
filters["ids"] = [id]
if hfid:
filters["hfid"] = hfid

if not filters:
raise Exception("At least one filter must be provided")

node = self.client.get(
kind=kind,
id=id,
hfid=hfid,
include=include,
populate_store=True,
exclude=exclude,
Expand Down
Loading
Loading