You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/guides/artifact.mdx
+58-15Lines changed: 58 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,56 @@ import ReactPlayer from 'react-player/youtube'
8
8
9
9
:::note
10
10
11
-
This guide has the assumption that you followed the [Creating a Jinja Rendered File (Transform)](./jinja2-transform.mdx) or [Creating a Python transform](./python-transform.mdx) guide as well as [Creating a Group](./groups.mdx) guide
12
-
This is a prerequisite.
11
+
This guide has the assumption that you followed the [Creating a Jinja Rendered File (Transform)](./jinja2-transform.mdx) or [Creating a Python transform](./python-transform.mdx) guide. This is a prerequisite.
13
12
14
13
:::
15
14
16
15
The goal of this guide is to define an artifact for a Jinja rendered Transform or Python transform in Infrahub. We will be using the following steps.
17
16
18
-
1. Creating an artifact definition
19
-
2. Accessing the artifacts
17
+
1. Modifying the schema
18
+
2. Creating a group and adding member nodes
19
+
2. Creating an artifact definition
20
+
3. Accessing the artifacts
21
+
22
+
## Modifying the node schema
23
+
24
+
Before we can generate an artifact for a node, we need to modify the schema. The node will need to inherit from the `CoreArtifactTarget` generic.
25
+
26
+
```yaml
27
+
---
28
+
version: "1.0"
29
+
nodes:
30
+
- name: Device
31
+
namespace: Network
32
+
display_labels:
33
+
- name__value
34
+
inherit_from:
35
+
- CoreArtifactTarget
36
+
attributes:
37
+
- name: name
38
+
kind: Text
39
+
label: Name
40
+
optional: false
41
+
unique: true
42
+
- name: description
43
+
kind: Text
44
+
label: Description
45
+
optional: true
46
+
```
47
+
48
+
We then have to load the modified schema definition into Infrahub.
49
+
50
+
```bash
51
+
infrahubctl schema load /tmp/schema.yml
52
+
```
53
+
54
+
## Creating a group and adding members
55
+
56
+
We need to create a group for every Artifact Definition that we will define. An artifact will be generated for every member that is part of that group.
57
+
58
+
Create a Standard Group with the name `DeviceGroup` and add `NetworkDevice``switch1`, `switch2` and `switch3` as a member.
59
+
60
+
More information can be found in the [Creating a group guide](./groups.mdx).
@@ -26,23 +67,23 @@ The goal of this guide is to define an artifact for a Jinja rendered Transform o
26
67
27
68
In the last step we need to define an Artifact definition, which groups together a [transformation](../topics/transformation.mdx) with a target group and forms the definition of the artifact. Artifact definitions can be created via the frontend, via GraphQL or via a [Git repository](../topics/repository.mdx). In this guide we will be using the Git repository.
28
69
29
-
Add the following contents to the end of the `.infrahub.yml` file at the root of the `tags_render` repository.
70
+
Add the following contents to the end of the `.infrahub.yml` file at the root of the `device_config_render` repository.
30
71
31
72
```yaml
32
73
artifact_definitions:
33
-
- name: "tags_config_file"
34
-
artifact_name: "Tags configuration file"
74
+
- name: "device_configuration"
75
+
artifact_name: "Device configuration file"
35
76
parameters:
36
-
tag: "name__value"
77
+
name: "name__value"
37
78
content_type: "text/plain"
38
-
targets: "TagConfigGroup"
39
-
transformation: "my-transform"
79
+
targets: "DeviceGroup"
80
+
transformation: "device_config_transform"
40
81
```
41
82
42
83
This defines an artifact with the following properties:
43
84
44
85
- **name**: a unique name for the artifact
45
-
- **parameters**: the parameter to pass to the transformation GraphQL query, in this case this we will pass the name of the object (tag) as the tag parameter
86
+
- **parameters**: the parameter to pass to the transformation GraphQL query, in this case this we will pass the name of the object (device) as the name parameter
46
87
- **content type**: the content type for the resulting artifact
47
88
- **targets**: the name of a group of which the members will be a target for this artifact
48
89
- **transformation**: the Jinja2 or Python transformation that should be used
@@ -53,11 +94,11 @@ Commit the changes to the repository and push them to the Git server
The artifact definition will be created in the database, when the Task worker(s) notice the change in the Git repository. The `tags_config_file` should now be visible in the Artifact Definition view in the web interface.
101
+
The artifact definition will be created in the database, when the Task worker(s) notice the change in the Git repository. The `device_configuration` should now be visible in the Artifact Definition view in the web interface.
You can download the artifact by clicking on the `Storage Id` or alternatively through the rest API endpoint `http://<INFRAHUB_HOST:INFRAHUB_PORT>/api/storage/object/<storage_id>`
113
+
You can download the artifact by clicking on the download button, or by using the REST API endpoint `http://<INFRAHUB_HOST:INFRAHUB_PORT>/api/storage/object/<storage_id>`. The `Storage Id` can be copied from the menu next to the artifact name.
Optionally, Infrahub can create a relation between a node and an artifact, by inheriting from the CoreArtifactTarget generic in the schema of the node. This is outside the scope of this guide, since the BuiltinTag node does not inherit from CoreArtifactTarget. More information can be found in the [artifact](../topics/artifact.mdx) topic.
117
+
Alternatively we can access the artifact of an object, by navigating to the object detail view. Navigate to device `switch1`'s detail page, from the *Artifacts* tab you can access all the artifacts that were generated for this object.
Copy file name to clipboardExpand all lines: docs/docs/guides/generator.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,7 +104,7 @@ We provide `convert_query_response` option to be toggled to be able to access ob
104
104
105
105
This allows you to manage the returned data with helper methods on the SDK objects such as `save`, `fetch`, etc. on the returned data rather than having to build a payload to send back to Infrahub to manage the objects.
106
106
107
-
Read more on the [Infrahub Python SDK](../python-sdk).
107
+
Read more on the [Infrahub Python SDK]($(local_base_url_1)python-sdk).
0 commit comments