From 047658537052b0e7df68ef3402d740366c4c69c9 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Tue, 22 Oct 2024 09:03:02 -0400 Subject: [PATCH] dynamic annotations --- salt/hypervisor/pillar.sls | 5 +++ .../hypervisor/hypervisor.yaml | 35 +++++++++++++++++++ .../dynamic_annotations/hypervisor/init.sls | 5 +++ .../hypervisor/soc_hypervisor.yaml.jinja | 12 +++++++ 4 files changed, 57 insertions(+) diff --git a/salt/hypervisor/pillar.sls b/salt/hypervisor/pillar.sls index e69de29bb..92c1cbfec 100644 --- a/salt/hypervisor/pillar.sls +++ b/salt/hypervisor/pillar.sls @@ -0,0 +1,5 @@ +soc_hypervisor_pillar: + file.managed: + - name: /opt/so/saltstack/local/pillar/hypervisor/soc_hypervisor.sls + - source: salt://hypervisor/pillar.map.jinja + - template: jinja diff --git a/salt/soc/dynamic_annotations/hypervisor/hypervisor.yaml b/salt/soc/dynamic_annotations/hypervisor/hypervisor.yaml index e69de29bb..f52779e9c 100644 --- a/salt/soc/dynamic_annotations/hypervisor/hypervisor.yaml +++ b/salt/soc/dynamic_annotations/hypervisor/hypervisor.yaml @@ -0,0 +1,35 @@ +hypervisor: + hosts: + defaultHost: + add_guest: + description: Add a new guest to the hypervisor. + forcedType: "[]string" + global: True + multiline: True + guests: + defaultGuest: + copper: + description: Copper nics + forcedType: "[]int" + global: True + multiline: True + sfp: + description: sfp nics + forcedType: string + global: True + multiline: True + disks: + description: disk + forcedType: "[]int" + global: True + multiline: True + cpu: + description: cpu + forcedType: int + global: True + multiline: True + memory: + description: mem + forcedType: int + global: True + multiline: True diff --git a/salt/soc/dynamic_annotations/hypervisor/init.sls b/salt/soc/dynamic_annotations/hypervisor/init.sls index e69de29bb..74db9d9a2 100644 --- a/salt/soc/dynamic_annotations/hypervisor/init.sls +++ b/salt/soc/dynamic_annotations/hypervisor/init.sls @@ -0,0 +1,5 @@ +hypervisor_annotation: + file.managed: + - name: /opt/so/saltstack/default/salt/hypervisor/soc_hypervisor.yaml + - source: salt://soc/dynamic_annotations/hypervisor/soc_hypervisor.yaml.jinja + - template: jinja diff --git a/salt/soc/dynamic_annotations/hypervisor/soc_hypervisor.yaml.jinja b/salt/soc/dynamic_annotations/hypervisor/soc_hypervisor.yaml.jinja index e69de29bb..f96b3ea13 100644 --- a/salt/soc/dynamic_annotations/hypervisor/soc_hypervisor.yaml.jinja +++ b/salt/soc/dynamic_annotations/hypervisor/soc_hypervisor.yaml.jinja @@ -0,0 +1,12 @@ +{% import_yaml 'soc/dynamic_annotations/hypervisor/hypervisor.yaml' as ANNOTATION %} +{% set HYPERVISORS = salt['pillar.get']('hypervisor:nodes', {}) %} + +{% set TEMPLATE = ANNOTATION.hypervisor.hosts.pop('defaultHost') %} +{# remove defaultGuest so that it is not shown in Grid Configuration UI #} +{% do TEMPLATE['guests'].pop('defaultGuest') %} + +{% for hypervisor in HYPERVISORS.hypervisor %} +{% do ANNOTATION.hypervisor.hosts.update({hypervisor: TEMPLATE}) %} +{% endfor %} + +{{ ANNOTATION | yaml(False) }}