Add per-instance group membership fields on Object Templates#9142
Conversation
Object templates now expose member_of_groups_for_instances and subscriber_of_groups_for_instances. Groups assigned through these are copied onto each object created from the template, while the template's own member_of_groups keeps its existing meaning.
| ("member_of_groups_for_instances", "template_group_member_for_instances"), | ||
| ("subscriber_of_groups_for_instances", "template_group_subscriber_for_instances"), |
There was a problem hiding this comment.
Names are up for debate.
ajtmccarty
left a comment
There was a problem hiding this comment.
functionally looks great
all comments are little naming/docs things
| self.set(name=node_name, schema=schema) | ||
|
|
||
| def _add_template_group_for_instances_relationships( | ||
| self, schema: MainSchemaTypes, changed: bool |
There was a problem hiding this comment.
changed seems like it should be inverted and called duplicate_before_update or something similar
There was a problem hiding this comment.
I changed the var name but did not call it duplicate_before_update because that would imply to do a bunch of not swap to make it behaves as its name would imply; and that would have made this hard to follow (nobody wants to read a var that is the result of a "not of not of not of …").
There was a problem hiding this comment.
good point. name is better now
There was a problem hiding this comment.
- I think we're still in some sort of docs freeze, so this may need to change once that is unfrozen
- personally, I'd say we should try to remove the em-dashes that the LLMs love so much b/c it makes it look like our docs are written by robots and that we are lazy
2550e22 to
02a166e
Compare
FragmentedPacket
left a comment
There was a problem hiding this comment.
Tested locally and using object templates and it successfully added the devices to the group when creating devices from that template.
---
apiVersion: infrahub.app/v1
kind: Object
spec:
kind: CoreStandardGroup
data:
- name: test-group
# Device template — management_address allocated from "Device and Interface IP Pool"
# Includes nested interface template — primary_ip also allocated from the same pool
---
apiVersion: infrahub.app/v1
kind: Object
spec:
kind: TemplateDcimDevice
data:
- template_name: "Standard Device"
management_address_from_resource_pool: "Device and Interface IP Pool"
member_of_groups_for_instances: ["test-group"]
interfaces:
kind: TemplateDcimInterface
data:
- template_name: "Standard Device eth0"
name: eth0
primary_ip_from_resource_pool: "Device and Interface IP Pool"
02a166e to
c420358
Compare
Why
When you set
member_of_groupson an Object Template today, the template node itself becomes a member of the group, but objects created from that template don't inherit the membership. So a template can express "things like this" for attributes and most relationships, but not for groups.This change adds a way to express per-instance group membership on a template, mirroring the
_from_resource_poolsister-field pattern we already use for IPs and number pools.Closes #9094
What changed
Templates now expose two extra relationships:
member_of_groups_for_instancesandsubscriber_of_groups_for_instances. They have kindGENERIC, so adding peers there does not put the template in those groups.At template application time,
NodeTemplateApplierreads the peers from those fields and writes them undermember_of_groups/subscriber_of_groupson the new object. User-supplied groups on the create call still take precedence.The existing
member_of_groupsandsubscriber_of_groupson a template keep their original meaning: they describe the template's own membership and are not propagated to instances.How to test
Checklist
changelog/9094.added.md)docs/docs/topics/object-template.mdx,docs/docs/guides/object-template.mdx,docs/docs/topics/groups.mdx)dev/knowledge/backend/templates.mdadded;architecture.mdandschema-definitions.mdcross-link to it)