virtinstall: Set VM name earlier so disks are named correctly

We need to change the flow from

  * parse all the strings
  * set capabilities defaults
  * build installer
  * fill in all guest defaults

To

  * parse boot and metadata strings
  * set capabilities defaults
  * build installer
  * set --name default
  * parse all the remaining strings
  * fill in all guest defaults

Because --disk parsing depends on --name for some path generation.
So this fixes --disk names when --name is implicitly specified by
--install or --osinfo

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2022-08-03 11:44:46 -04:00
parent 02e6abad48
commit 5e48307e9d
10 changed files with 33 additions and 20 deletions

View File

@ -23,7 +23,7 @@
<emulator>/usr/bin/qemu-system-aarch64</emulator>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/var/lib/libvirt/images/disk.qcow2"/>
<source file="/var/lib/libvirt/images/fedora22.qcow2"/>
<target dev="vda" bus="virtio"/>
</disk>
<controller type="scsi" model="virtio-scsi">

View File

@ -29,7 +29,7 @@
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/var/lib/libvirt/images/disk.qcow2"/>
<source file="/var/lib/libvirt/images/vm1.qcow2"/>
<target dev="sda" bus="sata"/>
</disk>
<controller type="usb" model="ich9-ehci1"/>

View File

@ -27,7 +27,7 @@
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/var/lib/libvirt/images/disk.qcow2"/>
<source file="/var/lib/libvirt/images/vm1.qcow2"/>
<target dev="hda" bus="ide"/>
</disk>
<controller type="usb" model="ich9-ehci1"/>

View File

@ -20,7 +20,7 @@
<devices>
<emulator>/usr/bin/test-hv</emulator>
<disk type="file" device="disk">
<source file="/var/lib/libvirt/images/disk.qcow2"/>
<source file="/var/lib/libvirt/images/vm1.qcow2"/>
<target dev="hda" bus="ide"/>
</disk>
<disk type="file" device="cdrom">
@ -72,7 +72,7 @@
<devices>
<emulator>/usr/bin/test-hv</emulator>
<disk type="file" device="disk">
<source file="/var/lib/libvirt/images/disk.qcow2"/>
<source file="/var/lib/libvirt/images/vm1.qcow2"/>
<target dev="hda" bus="ide"/>
</disk>
<disk type="file" device="cdrom">

View File

@ -33,7 +33,7 @@
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/tmp/.local/share/libvirt/images/disk.qcow2"/>
<source file="/tmp/.local/share/libvirt/images/fedora21.qcow2"/>
<target dev="vda" bus="virtio"/>
</disk>
<disk type="file" device="cdrom">
@ -106,7 +106,7 @@
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/tmp/.local/share/libvirt/images/disk.qcow2"/>
<source file="/tmp/.local/share/libvirt/images/fedora21.qcow2"/>
<target dev="vda" bus="virtio"/>
</disk>
<disk type="file" device="cdrom">

View File

@ -246,7 +246,7 @@
</disk>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/var/lib/libvirt/images/disk.qcow2"/>
<source file="/var/lib/libvirt/images/fedora.qcow2"/>
<target dev="vdc" bus="virtio"/>
</disk>
<disk type="block" device="lun" sgio="filtered" rawio="yes">
@ -293,7 +293,7 @@
<auth username="admin">
<secret type="ceph" uuid="f65cc5a8-b77b-4254-9030-d50a528fb456"/>
</auth>
<source protocol="rbd" name="rbd-sourcename/disk">
<source protocol="rbd" name="rbd-sourcename/fedora">
<host name="ceph-mon-1.example.com" port="6789"/>
<host name="ceph-mon-2.example.com" port="6789"/>
<host name="ceph-mon-3.example.com" port="6789"/>
@ -392,13 +392,13 @@
</disk>
<disk type="file" device="disk">
<driver name="qemu" type="raw" discard="unmap"/>
<source file="/var/lib/libvirt/images/disk.img"/>
<source file="/var/lib/libvirt/images/fedora.img"/>
<target dev="vdp" bus="virtio"/>
<transient shareBacking="yes"/>
</disk>
<disk type="block" device="disk">
<driver name="qemu" type="raw" cache="none" discard="unmap" io="native"/>
<source dev="/dev/pool-logical/disk"/>
<source dev="/dev/pool-logical/fedora"/>
<target dev="vdq" bus="virtio"/>
</disk>
<disk type="dir" device="disk">

View File

@ -32,7 +32,7 @@
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/var/lib/libvirt/images/disk.qcow2"/>
<source file="/var/lib/libvirt/images/openbsd4.9.qcow2"/>
<target dev="hda" bus="ide"/>
</disk>
<controller type="usb" model="ich9-ehci1"/>

View File

@ -38,7 +38,7 @@
</disk>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/var/lib/libvirt/images/disk.qcow2"/>
<source file="/var/lib/libvirt/images/fedora27.qcow2"/>
<target dev="vdb" bus="virtio"/>
</disk>
<controller type="usb" model="qemu-xhci" ports="15"/>
@ -112,7 +112,7 @@
</disk>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/var/lib/libvirt/images/disk.qcow2"/>
<source file="/var/lib/libvirt/images/fedora27.qcow2"/>
<target dev="vdb" bus="virtio"/>
</disk>
<controller type="usb" model="qemu-xhci" ports="15"/>

View File

@ -37,12 +37,12 @@
</disk>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/pool-dir/disk.qcow2"/>
<source file="/pool-dir/fedora.qcow2"/>
<target dev="vdb" bus="virtio"/>
</disk>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/pool-dir/disk-1.qcow2"/>
<source file="/pool-dir/fedora-1.qcow2"/>
<target dev="vdc" bus="virtio"/>
</disk>
<disk type="file" device="disk">
@ -168,7 +168,7 @@
</disk>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" discard="unmap"/>
<source file="/var/lib/libvirt/images/disk.qcow2"/>
<source file="/var/lib/libvirt/images/fedora.qcow2"/>
<target dev="vdg" bus="virtio"/>
</disk>
<disk type="file" device="disk">

View File

@ -463,13 +463,15 @@ def build_installer(options, guest, installdata):
return installer
def set_cli_defaults(options, guest):
def set_cli_default_name(guest):
if not guest.name:
default_name = virtinst.Guest.generate_name(guest)
cli.print_stdout(_("Using default --name {vm_name}").format(
vm_name=default_name))
guest.name = default_name
def set_cli_defaults(options, guest):
if guest.os.is_container():
if not memory_specified(guest):
mbram = 1024
@ -618,8 +620,14 @@ def _build_options_guest(conn, options):
# Fill in guest from the command line content
set_explicit_guest_options(options, guest)
cli.run_all_parsers(options, guest)
cli.parse_xmlcli(guest, options)
# We do these two parser bit early, since Installer setup will
# depend on them, but delay the rest to later, since things like
# disk naming can depend on Installer operations
cli.run_parser(options, guest, cli.ParserBoot)
options.boot = None
cli.run_parser(options, guest, cli.ParserMetadata)
options.metadata = None
# Call set_capabilities_defaults explicitly here rather than depend
# on set_defaults calling it. Installer setup needs filled in values.
@ -646,6 +654,11 @@ def build_guest_instance(conn, options):
installer_detect_distro(guest, installer, osdata)
if not options.reinstall:
# We want to fill in --name before we do disk parsing, since
# default disk paths are generated based on VM name
set_cli_default_name(guest)
cli.run_all_parsers(options, guest)
cli.parse_xmlcli(guest, options)
set_cli_defaults(options, guest)
installer.set_install_defaults(guest)