Commit Graph

2516 Commits

Author SHA1 Message Date
Cole Robinson
f66cca92a9 cli: Make --xml option parsing less special
We can make `--xml` fit the common xml cli option paradigm, which
less us drop a whole bunch of special handling in virt-xml

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-10-01 12:30:34 -04:00
Cole Robinson
76f4599460 virtxml: Don't require options at XML action time
Adjust cli.py `run_parser` and similar functions to take the
parservalue directly, rather than passing in the whole `options`
structure.

This makes it easier to reason about what the virt-xml action
functions are actually working with.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-10-01 12:30:34 -04:00
Cole Robinson
455b38f724 virtxml: Add Action class to track action + option pairs
This adds an Action class which is a container for (most) of the
data we need to perform a virt-xml operation. Basically an instance
of the class represents a pairing like

    --edit 1 --disk path=/foo    or
    --add-device --network wibble,model=virtio
    etc

This is a functional no-op, but it moves the code closer to
an architecture that will allow us to perform multiple actions
with a single virt-xml command.

While doing this, we centralize most of the cli validation that is
scattered around, since it's now easier to do it in one place.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-10-01 12:30:34 -04:00
Cole Robinson
b7c72af73d virtxml: move some functions
Move the validation functions out from amongst the functional XML
editing code, and into their own section. We will be adding more
code alongside in future patches.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-10-01 12:30:34 -04:00
Cole Robinson
de00ff7661 virt-xml: Fix --define with stdin XML
And rework the `refresh-machine-type` testcase to trigger it

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-09-23 10:37:16 -04:00
Cole Robinson
b83a1b0d0f domain: Use KEEP_TPM flag for domain rename
If the VM has implicit TPM state, use the VIR_DOMAIN_UNDEFINE_KEEP_TPM
flag to preserve that state when renaming the VM (if libvirt is new
enough).

The state is stored based on VM UUID and nothing else, and the UUID
is preserved during rename, so we don't need to do any of the same
trickery that's required for nvram duplication.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-09-19 05:48:01 +02:00
Lin Ma
2d94e92d80 guest: Drop the '_' prefix for _add_q35_pcie_controllers
We will use it in domain.py as well.

Signed-off-by: Lin Ma <lma@suse.com>
2024-09-10 13:27:08 -04:00
Cole Robinson
9813dc3b4f capabilities: Exclude a line from code coverage
updated test suite capabilities XML doesn't hit this line anymore.
Just exclude it

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-09-10 13:13:46 -04:00
Andrea Bolognani
2a52d77096 domcapabilities: Add firmware patterns for loongarch64
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2024-09-10 12:56:38 -04:00
Andrea Bolognani
dc603792bf domcapabilities: Add firmware patterns for riscv64
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2024-09-10 12:54:35 -04:00
Andrea Bolognani
5d5da5ff6e domcapabilities: Update comment
Fedora uses the same paths as Gerd's packages these days.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2024-09-10 10:54:53 +02:00
Lin Ma
4782dd1cce cli: Add --disk driver.discard_no_unref=on|off
E.g.
  virt-install \
  ... \
  --disk /tmp/disk0.qcow2,size=16,driver.type=qcow2,driver.discard=unmap,\
  driver.discard_no_unref=on

It results in the following domain xml:
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' discard='unmap' discard_no_unref='on'/>
      <source file='/tmp/disk0.qcow2'/>
      <target dev='vda' bus='virtio'/>
    </disk>

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Lin Ma <lma@suse.de>
2024-09-08 11:25:32 -04:00
Lin Ma
6a65def684 cli: Add --video model.blob=on|off
Libvirt enables blob resources for the virtio video device since 9.2.0.
It accelerates the display path due to less or no copying of pixel data.

E.g.
  virt-install \
  ... \
  --video model.type=virtio,blob=on

It results in the following domain xml:

    <video>
      <model type="virtio" blob="on"/>
    </video>

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Lin Ma <lma@suse.de>
2024-09-08 11:25:32 -04:00
Lin Ma
febddd4b01 cli: Add --memdev target.address_base for virtio-mem and virtio-pmem
Libvirt(since 9.4.0) allows to control this attribute for virtio-{mem,pmem}.
Now add it into virt-install.

Example:
virt-install \
--name test \
--os-variant opensusetumbleweed \
--cdrom /isos/openSUSE-Tumbleweed-DVD-x86_64-Current.iso \
--disk /vms/tw/disk0.qcow2 \
--vcpu 2 \
--cpu cell0.cpus=0,cell0.memory=4194304,\
cell1.cpus=1,cell1.memory=4194304 \
--memory maxMemory=65536,maxMemory.slots=8 \
--memdev model=virtio-mem,\
target.node=0,\
target.block=2048,\
target.size=8192,\
target.requested=2097152,\
target.address_base=0x280000000 \
--memdev model=virtio-pmem,\
source.path=/tmp/virtio_pmem,\
target.size=4096,\
target.address_base=0x480000000

It results in the following domain XML snippet:
    <memory model='virtio-mem'>
      <target>
        <size unit='KiB'>8388608</size>
        <node>0</node>
        <block unit='KiB'>2048</block>
        <requested unit='KiB'>2097152</requested>
        <current unit='KiB'>0</current>
        <address base='0x280000000'/>
      </target>
      <alias name='virtiomem0'/>
      <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
    </memory>
    <memory model='virtio-pmem' access='shared'>
      <source>
        <path>/tmp/virtio_pmem</path>
      </source>
      <target>
        <size unit='KiB'>2097152</size>
        <address base='0x480000000'/>
      </target>
      <alias name='virtiopmem0'/>
      <address type='pci' domain='0x0000' bus='0x08' slot='0x00' function='0x0'/>
    </memory>

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Lin Ma <lma@suse.de>
2024-09-08 11:25:32 -04:00
Lin Ma
7a974a3a72 cli: Add --features kvm.pv-ipi.state=on|off
Set kvm pv-ipi feature by --features argument.

E.g. virt-install --features kvm.pv-ipi.state=off
It results in the following domain xml:

 <features>
   <kvm>
     <pv-ipi state='off'/>
   </kvm>
 </features>

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Lin Ma <lma@suse.de>
2024-09-08 11:25:32 -04:00
Cole Robinson
83daac0489 domain: os: treat xenpvh as xen PV
Notably, don't try to add a tablet device, this apparently
doesn't work.

https://github.com/virt-manager/virt-manager/issues/448

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-09-06 15:30:51 -04:00
Pavel Hrdina
74fd503b9e virtinst: enable most Hyper-V features by default
We will not enable hyperv_reset feature as modern Hyper-V versions don't
export it.

We also don't enable hyperv_reenlightenment as it is mostly relevant
when migrating VMs that are running Hyper-V inside and requires other
bits to work correctly.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
169db9dc5f virtinst.support: drop unused conn_hyperv_vapic function
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
9e9dbf735c domain.features: use domcapabilities when setting default Hyper-V features
We will no longer enable hyperv features based on libvirt and QEMU
versions.

Some tests don't use the kvm-x86_64-domcaps-latest so the code will now
not enable Hyper-V features. There are still other test cases that cover
Hyper-V features so instead of mangling with URI for these tests update
test data.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
66bbfa23b2 domain.features: extract setting default hyperv features
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
c279c17e6c domcapabilities: get list of supported Hyper-V features
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
139b0e285b cli: add --features hyperv.avic.state=on/off
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
a06d53596b cli: add --features hyperv.evmcs.state=on/off
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
5afc6919c9 cli: add --features hyperv.ipi.state=on/off
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
e3ec248cff cli: add --features hyperv.tblflush.state=on/off
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
c421ec1b75 cli: add --features hyperv.reenlightenment.state=on/off
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
2786ea5df2 cli: add --features hyperv.frequencies.state=on/off
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
6289a1369b cli: add --features hyperv.stimer.direct.state=on/off
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
1f69795b0a cli: add --features hyperv.stimer.state=on/off
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
d7976a883a cli: add --features hyperv.runtime.state=on/off
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
d2a29245cd cli: add --features hyperv.vpindex.state=on/off
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Pavel Hrdina
ac26945c56 domain.features: reorder Hyper-V features
Follow the table from libvirt documentation [1].

[1] <https://libvirt.org/formatdomain.html#hypervisor-features>

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-09-06 14:15:09 -04:00
Cole Robinson
7e79e064ea Revert virt-xml multiple --edit support
This reverts b34ae0d0c8 and
1fef5d8661.

Playing with this some more I found some deeper problems. For example

```console
[:~/src/virt-manager] (main) $ ./virt-xml test-for-virtxml --connect test://`pwd`/tests/data/testdriver/testsuite.xml --print-diff --edit 1 --video model=FOO --edit 2 --sound model=BAR
--- Original XML
+++ Altered XML
@@ -180,14 +180,14 @@
     <graphics type="vnc" port="-1" autoport="yes">
       <listen type="address"/>
     </graphics>
-    <sound model="sb16"/>
+    <sound model="BAR"/>
     <sound model="es1370"/>
     <sound model="ich6"/>
     <video>
       <model type="vmvga" vram="16384" heads="1" primary="yes"/>
     </video>
     <video>
-      <model type="cirrus" vram="16384" heads="3"/>
+      <model type="FOO" vram="16384" heads="3"/>
     </video>
     <hostdev mode="subsystem" type="usb" managed="yes">
       <source>
```

There's other weirdness too, though it's mostly strange plays on previous weird behavior

* `--edit --video model=vga --edit --sound model=ich9 --video model=qxl` works
* `--add-device --sound model=foo --video model=bar` was previously rejected but now works
* `--remove-device --video model=vmvga --sound model=sb16` was previously rejected by now works

Fixing all this is not trivial. So I think we need to revert and go back to the drawing board.
2024-08-28 21:09:31 +02:00
Cole Robinson
5fe6dcc6b4 Fix some pylint
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-08-28 11:53:35 -04:00
Daniel P. Berrangé
3559dcd9de virtinst: add properties for AMD SEV-SNP
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2024-08-28 14:38:40 +02:00
Pavel Hrdina
b34ae0d0c8 virt-xml: allow multiple --edit options
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-08-26 12:33:51 -04:00
Pavel Hrdina
cb6636f4bf virtinst: add getter/setter for video model
This makes it easier for users to change video model from QXL to
different model as QXL is special and uses other attributes that are not
supported by any other model. Without this code libvirt would report
error or user would have to request `clearxml`.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-08-26 12:33:51 -04:00
Pavel Hrdina
093d58fbc8 virtinst: add/remove spice devices when updating graphics type
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-08-26 12:33:51 -04:00
Pavel Hrdina
aaf8551914 virtinst: remove spice devices when removing last spice graphics
When Spice graphics is used QEMU creates a Spice server and communicates
with Spice client using multiple channels. These channels are used by
the spice devices as well. Without the Spice graphics defined there is
no use for the other devices. In addition libvirt will report error for
such configuration.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-08-26 12:33:51 -04:00
Pavel Hrdina
2a0aa2d56b virtinst: fix compare for audio devices
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-08-26 12:33:51 -04:00
Pavel Hrdina
ef64949e84 virtinst: unify detection of duplicate console when removing device
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-08-26 12:33:51 -04:00
Cole Robinson
29145b9e93 Fix some pylint
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2024-08-26 11:36:01 -04:00
Pavel Hrdina
90ceb87b7c virt-install: implement passt backend for user network interface
Add new `--network backend.type` attribute, libvirt currently supports
only `passt`. If not network type is specified virt-install will pick
`user` type as it is required for `passt` backend.

This also introduces support to specify portForward and specifying port
range as well.

For more details see [1].

[1] <https://libvirt.org/formatdomain.html#userspace-slirp-or-passt-connection>

Fixes: https://github.com/virt-manager/virt-manager/issues/488
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-08-26 11:27:03 -04:00
Natanael Copa
648f52bde0 virt-install: fix cloud-init ssh keys
Fix the cloud-init config file for --clouduser-ssh key.

Also change ssh_authorized_keys to `ssh_authorized_keys`, and make sure
default user is not deleted when setting ssh key for root.

Fixes commit 22478f307d (virt-install: Add --cloud-init clouduser-ssh-key=)

Resolves: https://github.com/virt-manager/virt-manager/issues/452

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2024-07-25 16:50:34 +02:00
Patrice Lacouture
72a74fb1fb virtinstall: Fix --location and --cloud-init conflict
So far, --cloud-init is ignored when --location is specified.

Resolves: virt-manager#469
2024-07-22 16:08:09 +02:00
taoky
cd8eeaf56d virtinst: disk: Add paths_in_use_by()
conn.fetch_all_vols() is slow, taking ~0.03s every time it's used. When
handling with a large number of paths, its performance is too bad and
could stuck UI for a very long time.

DeviceDisk.paths_in_use_by is added to help handle many paths with
only one call to conn.fetch_all_vols().
2024-07-22 12:42:10 +02:00
Pavel Hrdina
43f581c26c virtinst: add graphics to risc-v virt VMs by default
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-07-02 15:40:51 +02:00
Pavel Hrdina
faebce406b virtinst: add graphics to aarch64 virt VMs by default
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2024-07-02 15:40:51 +02:00
Xianglai Li
ea3cae4dc9 Add some default device support for loongarch
Add adaptations for loongarch with the following features:
Default video Support
UEFI prefer
Usb tablet and usb keyboard
rng and memballoon
sound device
Usb controller

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-06-18 12:09:14 +02:00
Xianglai Li
d2cf01b3eb Add loongarch support
Define the judgment function of
loongarch architecture.

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
2024-06-18 12:09:14 +02:00