[virt-tools-list] [PATCH 2/2] virtinst: Add --sysinfo command line option

Charles Arnold carnold at suse.com
Thu Jul 14 14:06:28 UTC 2016


This option allows adding SMBios information to the guest. Also update
the appropriate classes with test cases.

---
 .../compare/virt-install-singleton-config-2.xml    | 50 ++++++++++++++++
 tests/clitest.py                                   |  3 +
 virtinst/cli.py                                    | 69 ++++++++++++++++++++++
 3 files changed, 122 insertions(+)

diff --git a/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml b/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml
index c50125b..f430568 100644
--- a/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml
+++ b/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml
@@ -36,6 +36,7 @@
     <boot dev="fd"/>
     <boot dev="hd"/>
     <boot dev="network"/>
+    <smbios mode="sysinfo"/>
     <bootmenu enable="no"/>
   </os>
   <idmap>
@@ -122,6 +123,30 @@
   <seclabel type="static" model="selinux" relabel="yes">
     <label>system_u:object_r:svirt_image_t:s0:c100,c200</label>
   </seclabel>
+  <sysinfo type="smbios">
+    <bios>
+      <entry name="date">01/01/1970</entry>
+      <entry name="vendor">Acme LLC</entry>
+      <entry name="version">1.2.3</entry>
+      <entry name="release">10.22</entry>
+    </bios>
+    <system>
+      <entry name="sku">abc-123</entry>
+      <entry name="product">Computer</entry>
+      <entry name="uuid">00000000-1111-2222-3333-444444444444</entry>
+      <entry name="family">Server</entry>
+      <entry name="version">3.2.1</entry>
+      <entry name="serial">123456789</entry>
+      <entry name="manufacturer">Acme Inc.</entry>
+    </system>
+    <baseBoard>
+      <entry name="product">Motherboard</entry>
+      <entry name="location">Chassis</entry>
+      <entry name="version">A01</entry>
+      <entry name="asset">Tag</entry>
+      <entry name="manufacturer">Acme Corp.</entry>
+    </baseBoard>
+  </sysinfo>
   <on_lockfailure>ignore</on_lockfailure>
 </domain>
 <domain type="kvm">
@@ -162,6 +187,7 @@
     <boot dev="fd"/>
     <boot dev="hd"/>
     <boot dev="network"/>
+    <smbios mode="sysinfo"/>
     <bootmenu enable="no"/>
   </os>
   <idmap>
@@ -248,5 +274,29 @@
   <seclabel type="static" model="selinux" relabel="yes">
     <label>system_u:object_r:svirt_image_t:s0:c100,c200</label>
   </seclabel>
+  <sysinfo type="smbios">
+    <bios>
+      <entry name="date">01/01/1970</entry>
+      <entry name="vendor">Acme LLC</entry>
+      <entry name="version">1.2.3</entry>
+      <entry name="release">10.22</entry>
+    </bios>
+    <system>
+      <entry name="sku">abc-123</entry>
+      <entry name="product">Computer</entry>
+      <entry name="uuid">00000000-1111-2222-3333-444444444444</entry>
+      <entry name="family">Server</entry>
+      <entry name="version">3.2.1</entry>
+      <entry name="serial">123456789</entry>
+      <entry name="manufacturer">Acme Inc.</entry>
+    </system>
+    <baseBoard>
+      <entry name="product">Motherboard</entry>
+      <entry name="location">Chassis</entry>
+      <entry name="version">A01</entry>
+      <entry name="asset">Tag</entry>
+      <entry name="manufacturer">Acme Corp.</entry>
+    </baseBoard>
+  </sysinfo>
   <on_lockfailure>ignore</on_lockfailure>
 </domain>
diff --git a/tests/clitest.py b/tests/clitest.py
index b63a92a..cd0fa1d 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -427,6 +427,9 @@ c.add_compare("""--pxe \
 --memorybacking size=1,unit='G',nodeset='1,2-5',nosharepages=yes,locked=yes \
 --features acpi=off,eoi=on,privnet=on,hyperv_spinlocks=on,hyperv_spinlocks_retries=1234,vmport=off,pmu=off \
 --clock offset=utc,hpet_present=no,rtc_tickpolicy=merge \
+--sysinfo type=0,vendor="Acme LLC",version=1.2.3,date=01/01/1970,release=10.22 \
+--sysinfo type=1,manufacturer="Acme Inc.",product=Computer,version=3.2.1,serial=123456789,uuid=00000000-1111-2222-3333-444444444444,sku=abc-123,family=Server \
+--sysinfo type=2,manufacturer="Acme Corp.",product=Motherboard,version=A01,serial=1234-5678,asset=Tag,location=Chassis \
 --pm suspend_to_mem=yes,suspend_to_disk=no \
 --resource partition=/virtualmachines/production \
 --events on_poweroff=destroy,on_reboot=restart,on_crash=preserve,on_lockfailure=ignore \
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 432640b..8b5f6be 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -67,6 +67,7 @@ from .osxml import OSXML
 from .pm import PM
 from .seclabel import Seclabel
 from .storage import StoragePool, StorageVolume
+from .sysinfo import SYSInfo
 
 
 ##########################
@@ -722,6 +723,13 @@ def add_guest_xml_options(geng):
         help=_("Configure VM lifecycle management policy"))
     geng.add_argument("--resource", action="append",
         help=_("Configure VM resource partitioning (cgroups)"))
+    geng.add_argument("--sysinfo", action="append",
+        help=_("Configure SMBIOS System Information. Ex:\n"
+               "--sysinfo emulate\n"
+               "--sysinfo host\n"
+               "--sysinfo type=0,vendor=Vendor_Inc.,version=1.2.3-abc,...\n"
+               "--sysinfo type=1,manufacturer=System_Corp.,product=codename,...\n"
+               "--sysinfo type=2,manufacturer=Baseboard_Corp.,product=codename,...\n"))
 
 
 def add_boot_options(insg):
@@ -1541,6 +1549,13 @@ class ParserBoot(VirtCLIParser):
     def set_initargs_cb(self, inst, val, virtarg):
         inst.os.set_initargs_string(val)
 
+    def set_smbios_mode_cb(self, inst, val, virtarg):
+        if val.startswith("type="):
+            inst.sysinfo.parse(val)
+            val = "sysinfo"
+        inst.os.smbios_mode = val
+        self.optdict["smbios_mode"] = val
+
     def noset_cb(self, inst, val, virtarg):
         pass
 
@@ -1584,6 +1599,8 @@ ParserBoot.add_arg("os.kernel_args", "kernel_args",
 ParserBoot.add_arg("os.init", "init")
 ParserBoot.add_arg("os.machine", "machine")
 ParserBoot.add_arg("os.initargs", "initargs", cb=ParserBoot.set_initargs_cb)
+ParserBoot.add_arg("os.smbios_mode", "smbios_mode",
+                   can_comma=True, cb=ParserBoot.set_smbios_mode_cb)
 
 # This is simply so the boot options are advertised with --boot help,
 # actual processing is handled by _parse
@@ -1702,6 +1719,58 @@ ParserPM.add_arg("suspend_to_mem", "suspend_to_mem", is_onoff=True)
 ParserPM.add_arg("suspend_to_disk", "suspend_to_disk", is_onoff=True)
 
 
+####################
+# --sysinfo parsing #
+####################
+
+class ParserSYSInfo(VirtCLIParser):
+    cli_arg_name = "sysinfo"
+    objclass = SYSInfo
+    remove_first = "type"
+
+    def set_type_cb(self, inst, val, virtarg):
+        if val == "host" or val == "emulate":
+            self.guest.os.smbios_mode = val
+        elif val.startswith(SYSInfo.SMBIOS_TYPE_BIOS) or \
+             val.startswith(SYSInfo.SMBIOS_TYPE_SYSTEM) or \
+             val.startswith(SYSInfo.SMBIOS_TYPE_BASEBOARD):
+            self.guest.os.smbios_mode = "sysinfo"
+            inst.parse(self.guest, "type=" + val)
+        else:
+            fail(_("Unknown smbios flag '%s'") % val)
+
+    def _parse(self, inst):
+        if self.optstr == "none":
+            self.guest.skip_default_sysinfo = True
+            return
+
+        return VirtCLIParser._parse(self, inst)
+
+_register_virt_parser(ParserSYSInfo)
+# <sysinfo type='smbios'>
+ParserSYSInfo.add_arg("type", "type", cb=ParserSYSInfo.set_type_cb, can_comma=True)
+# <bios> type=0 BIOS Information
+ParserSYSInfo.add_arg("bios.vendor", "bios.vendor")
+ParserSYSInfo.add_arg("bios.version", "bios.version")
+ParserSYSInfo.add_arg("bios.date", "bios.date")
+ParserSYSInfo.add_arg("bios.release", "bios.release")
+# <system> type=1 System Information
+ParserSYSInfo.add_arg("system.manufacturer", "system.manufacturer")
+ParserSYSInfo.add_arg("system.product", "system.product")
+ParserSYSInfo.add_arg("system.version", "system.version")
+ParserSYSInfo.add_arg("system.serial", "system.serial")
+ParserSYSInfo.add_arg("system.uuid", "system.uuid")
+ParserSYSInfo.add_arg("system.sku", "system.sku")
+ParserSYSInfo.add_arg("system.family", "system.family")
+# <baseBoard> type=2 Baseboard (or Module) Information
+ParserSYSInfo.add_arg("baseBoard.manufacturer", "baseBoard.manufacturer")
+ParserSYSInfo.add_arg("baseBoard.product", "baseBoard.product")
+ParserSYSInfo.add_arg("baseBoard.version", "baseBoard.version")
+ParserSYSInfo.add_arg("baseBoard.serial", "baseBoard.serial")
+ParserSYSInfo.add_arg("baseBoard.asset", "baseBoard.asset")
+ParserSYSInfo.add_arg("baseBoard.location", "baseBoard.location")
+
+
 ##########################
 # Guest <device> parsing #
 ##########################
-- 
2.6.6




More information about the virt-tools-list mailing list