Blob Blame History Raw
From ffa0e4e8e438319cb3c8856d1d7f48a8864afe2e Mon Sep 17 00:00:00 2001
Message-Id: <ffa0e4e8e438319cb3c8856d1d7f48a8864afe2e@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Tue, 13 Nov 2018 16:18:08 +0100
Subject: [PATCH] virt-xml: Start using --os-variant

From: Andrea Bolognani <abologna@redhat.com>

The option only works with --add-device for the time being,
so we prevent its use in all other cases.

It would be nice to have it work with --build-xml too, but
in that case the user would have to provide some extra
information that in the case of --add-device we can figure
out from the existing guest, and it's not entirely clear
whether that would even be that useful, so for now we're
not considering that case at all.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
(cherry picked from commit d2d103a334e3beeb8e108137f50adee2e5c0e5fc)

https://bugzilla.redhat.com/show_bug.cgi?id=1649406

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
 .../virt-xml-kvm-add-disk-os-from-cmdline.xml      | 11 ++++++++++-
 .../virt-xml-kvm-add-network-os-from-cmdline.xml   | 11 ++++++++++-
 virt-xml                                           | 14 ++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/tests/cli-test-xml/compare/virt-xml-kvm-add-disk-os-from-cmdline.xml b/tests/cli-test-xml/compare/virt-xml-kvm-add-disk-os-from-cmdline.xml
index e5e4bd62..cf872c1c 100644
--- a/tests/cli-test-xml/compare/virt-xml-kvm-add-disk-os-from-cmdline.xml
+++ b/tests/cli-test-xml/compare/virt-xml-kvm-add-disk-os-from-cmdline.xml
@@ -1,10 +1,19 @@
+   </description>
+   <metadata>
+     <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
+-      <libosinfo:os id="http://fedoraproject.org/fedora/unknown"/>
++      <libosinfo:os id="http://microsoft.com/win/me"/>
+     </libosinfo:libosinfo>
+   </metadata>
+   <memory unit="KiB">409600</memory>
+@@
      <panic model="s390"/>
      <panic model="pseries"/>
      <panic model="hyperv"/>
 +    <disk type="file" device="disk">
 +      <driver name="qemu" type="qcow2"/>
 +      <source file="/dev/default-pool/testvol1.img"/>
-+      <target dev="vdaf" bus="virtio"/>
++      <target dev="hdd" bus="ide"/>
 +    </disk>
    </devices>
    <seclabel type="dynamic" model="selinux" relabel="yes"/>
diff --git a/tests/cli-test-xml/compare/virt-xml-kvm-add-network-os-from-cmdline.xml b/tests/cli-test-xml/compare/virt-xml-kvm-add-network-os-from-cmdline.xml
index c834c936..8d278e7a 100644
--- a/tests/cli-test-xml/compare/virt-xml-kvm-add-network-os-from-cmdline.xml
+++ b/tests/cli-test-xml/compare/virt-xml-kvm-add-network-os-from-cmdline.xml
@@ -1,10 +1,19 @@
+   </description>
+   <metadata>
+     <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
+-      <libosinfo:os id="http://fedoraproject.org/fedora/unknown"/>
++      <libosinfo:os id="http://microsoft.com/win/me"/>
+     </libosinfo:libosinfo>
+   </metadata>
+   <memory unit="KiB">409600</memory>
+@@
      <panic model="s390"/>
      <panic model="pseries"/>
      <panic model="hyperv"/>
 +    <interface type="bridge">
 +      <source bridge="eth0"/>
 +      <mac address="00:11:22:33:44:55"/>
-+      <model type="virtio"/>
++      <model type="e1000"/>
 +    </interface>
    </devices>
    <seclabel type="dynamic" model="selinux" relabel="yes"/>
diff --git a/virt-xml b/virt-xml
index 65d9b55f..39abd297 100755
--- a/virt-xml
+++ b/virt-xml
@@ -56,6 +56,13 @@ def get_diff(origxml, newxml):
     return ret
 
 
+def set_distro_variant(options, guest):
+    if options.distro_variant is None:
+        return
+
+    guest.set_os_name(options.distro_variant)
+
+
 def get_domain_and_guest(conn, domstr):
     try:
         int(domstr)
@@ -175,6 +182,8 @@ def action_edit(guest, options, parserclass):
             fail(_("'--edit %s' doesn't make sense with --%s, "
                    "just use empty '--edit'") %
             (options.edit, parserclass.cli_arg_name))
+    if options.distro_variant is not None:
+        fail(_("--os-variant is not supported with --edit"))
 
     return cli.parse_option_strings(options, guest, inst, update=True)
 
@@ -182,6 +191,7 @@ def action_edit(guest, options, parserclass):
 def action_add_device(guest, options, parserclass):
     if not parserclass.prop_is_list(guest):
         fail(_("Cannot use --add-device with --%s") % parserclass.cli_arg_name)
+    set_distro_variant(options, guest)
     devs = cli.parse_option_strings(options, guest, None)
     devs = util.listify(devs)
     for dev in devs:
@@ -193,6 +203,8 @@ def action_remove_device(guest, options, parserclass):
     if not parserclass.prop_is_list(guest):
         fail(_("Cannot use --remove-device with --%s") %
              parserclass.cli_arg_name)
+    if options.distro_variant is not None:
+        fail(_("--os-variant is not supported with --remove-device"))
 
     devs = _find_objects_to_edit(guest, "remove-device",
         getattr(options, parserclass.cli_arg_name)[-1], parserclass)
@@ -207,6 +219,8 @@ def action_build_xml(conn, options, parserclass):
     if not parserclass.propname:
         fail(_("--build-xml not supported for --%s") %
              parserclass.cli_arg_name)
+    if options.distro_variant is not None:
+        fail(_("--os-variant is not supported with --build-xml"))
 
     guest = virtinst.Guest(conn)
     inst = parserclass.lookup_prop(guest)
-- 
2.19.2