dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.58k stars 456 forks source link

Enhancement: add SMBIOS tags support #1051

Open Tulux opened 9 months ago

Tulux commented 9 months ago

A quick and portable way to transmit information such as strings to guest is using SMBIOS tables.

Can be implemented in a simple way by using a list that would fill the OEM section: smbios = ['string1', 'string2'] which would be converted to:

<sysinfo type="smbios">
  <oemStrings>
    <entry>string1</entry>
    <entry>string2</entry>
  </oemStrings>
</sysinfo>

Or by using a mix of dict/list: smbios = {'system':{'manufacturer':'Fedora'}} Which would be converted to:

<system>
  <entry name='manufacturer'>Fedora</entry>
</system>
Tulux commented 9 months ago

Quick work-around to set OEM strings from list:

Terraform part:

  xml {
    xslt = templatefile("${path.module}/smbios.xsl.tftpl", {"oemstrings": ["hello", "world"]})
  }

XSLT/template smbios.xsl.tftpl part:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:template match="node()|@*">
      <xsl:copy>
         <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
   </xsl:template>

  <xsl:template match="/domain/os">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
            <xsl:element name ="smbios">
                <xsl:attribute name="mode">sysinfo</xsl:attribute>
            </xsl:element>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="/domain">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
            <xsl:element name ="sysinfo">
                <xsl:attribute name="type">smbios</xsl:attribute>
                <xsl:element name="oemStrings">
                    %{ for oemstring in oemstrings ~}
                    <xsl:element name="entry">${oemstring}</xsl:element>
                    %{ endfor ~}
                </xsl:element>
            </xsl:element>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
scabala commented 3 weeks ago

Hi, thanks for the report and workaround. Could you provide a little bigger example XML using dict (the second one in first post)?

Tulux commented 2 weeks ago

Hello,

Actually it was only a suggestion, I am only using lists in my projects.

Florent

scabala commented 2 weeks ago

That's fine, I was just curious how it looks like in entirety.