Commit Graph

786 Commits

Author SHA1 Message Date
y-hashida
b8c2f14435
Allow non drvfs on wsl environment (#1755) 2023-09-07 15:42:51 +01:00
Kristupas Antanavicius
574de06f4f
Poweroff domain on vagrant halt -f (#1766)
`vagrant halt -f` is supposed to poweroff the domain without attempting
graceful shutdown. Before, `vagrant halt -f` was attempting to send ACPI
and waiting for timeout before actually powering off the domain.

Fix a bug where ACPI timeout code would cause an exception to be thrown,
instead of setting :result to false and proceeding to poweroff the
domain.

The before behaviour:

`vagrant halt`:
    - attempt graceful shutdown (/sbin/shutdown)
        ERROR: next action
    - attempt sending ACPI (domain.shutdown)
        ERROR: timeout exception

`vagrant halt -f`:
    - attempt sending ACPI (domain.shutdown)
        ERROR: timeout exception

The after behaviour:

`vagrant halt`:
    - attempt graceful shutdown (/sbin/shutdown)
        ERROR: next action
    - attempt sending ACPI (domain.shutdown)
        ERROR: next action
    - poweroff the machine (domain.poweroff)
        ERROR: hopefully never

`vagrant halt -f`:
    - poweroff the machine (domain.poweroff)
        ERROR: hopefully never

Fixes #1765
2023-08-29 20:43:01 +01:00
Darragh Bailey
1ebfacf979
Adjust groups to reduce test dependencies (#1748)
Switch around the groups defined in the Gemfile to allow execution
without installing additional tools that are useful for development but
not needed for testing or packaging.
2023-08-15 11:19:09 +00:00
Darragh Bailey
889b13d636
Handle nic model type updating during start (#1747)
Start domain added some support to update the nic model type if it
changed to avoid needing to completely destroy and recreate the domain.
Additionally support for setting the management network nic model type
was added, however the default value did not correctly reflect expected.

This updates `management_network_model_type` to default to
`nic_model_type`, which in turn defaults to `virtio`. This has now been
moved from the create network interfaces action into the config object
to allow chained resolving. This should ensure that setting
`nic_model_type` will correctly cause all networks to use the model
unless explicitly specified to use a different model.

Additionally the start domain action for updating the interfaces has
been modified to loop over all interfaces and all configured adapters in
the order they should have been added. This allows for checking whether
the model type needs to be updated based on the
`management_network_model_type` config option for the first network,
assuming the management network has been attached, and otherwise to fall
back to the default from `nic_model_type` for all other interfaces.

Finally ensure the iommu attribute is removed from the nic driver if
the model type is switched to anything other virtio to avoid issues with
attempting to enable invalid settings.

Fixes: #1743
2023-06-20 15:46:05 +01:00
Darragh Bailey
99ac328621
Support iface_name setting for management network (#1739)
Allow setting the interface name that appears on the host for the
management network interface in the guest. This allows for more complex
networking layouts by allowiing matching against devices for vlan
configurations.

Fixes: #1701
2023-05-01 13:12:14 +00:00
Holger Finger
cb051a8277
specify qcow2 compatibility version to not use very old 0.10 fallback (#1731)
Libvirt creates qcow2 volumes with very old `compat` version `0.10` if
no `compat` version is specified in the xml (see
[here](https://libvirt.org/formatstorage.html#id11)). It seems libvirt
has backwards compatibility reasons to still use `0.10` if nothing is
specified in the xml.

Unfortunately this has the effect that VMs created by vagrant-libvirt
are using the 10 year old `0.10` qcow2 version, instead of the `1.1`
version that has **better performance and stability fixes**.
This is even happening when the backing file of the vagrant box is in
compat `1.1` format.

This is the `qemu-img info` of the backing file provided by the vagrant
box:
```
# qemu-img info /var/lib/libvirt/images/vagrant_box_image_0_box.img
[...]
Format specific information:
    compat: 1.1
    [...]
```
Although the backing file provided by the box is using compat `1.1`, the
created volume by vagrant-libvirt has only compat `0.1` as shown here:
```
# qemu-img info /var/lib/libvirt/images/vagrant-01-test_default.img
[...]
backing file: /var/lib/libvirt/images/vagrant_box_image_0_box.img
Format specific information:
    compat: 0.10
    [...]
```

With this MR, the volume of the VM will use the same `compat` version as
provided by the backing image of the vagrant box.
If `qemu-img info` does not return a `compat` flag, it falls back to the
very old `0.10` version.
2023-04-22 14:03:21 +01:00
kdunn926
f6126464f1
Feature: Allow specifying type for primary disk (#1729)
This PR has changes to allow specifying the `type` for
`disk_driver`, rather than hardcoding it to `qcow2`.
2023-04-22 13:43:38 +01:00
Conner Crosby
9e7d0f3ec8
Fix duplicate provisioning of running VMs (#1722)
Remove duplicate inclusion of Provision middleware when up is called
on an running machine resulting in a double provision.

Includes a unit test update to ensure expected actions are only called
once as well as a regression for calling up on a running machine.

Fixes #1710.
2023-02-16 18:13:31 +00:00
Bart Kus
2213314a5c Add a validator to prevent conflicting clock configs
This is a second layer of protection, to make the behavior minimally
surprising for the user.  The implementation of clock_* handlers follows
a precedence decision order in case of conflict, but that shouldn't be
relied on as the only layer of defense against bad configs.
2023-02-01 10:40:15 -08:00
Bart Kus
78e46979e0 Add feature-complete /domain/clock support
Feature reference: https://libvirt.org/formatdomain.html#time-keeping
2023-01-26 00:47:15 -08:00
Darragh Bailey
6b907ab6e0
Use append to a truncated file to retain owner (#1677)
Change the default behaviour when logging output from the console to a
file to ensure the file is pre-created and unless append is explicitly
set to true in the source config, truncate the file. Combined with
having the domain template default to enabling append, this causes
libvirt/qemu to not attempt to create the file and thus retains the
owner/group and permissions of the original file.

Relates-to: #1385
2023-01-22 21:22:29 +00:00
Arjen Verstoep
81ea287835
Make NIC model type for management interface configurable (#1711)
This change adds a configuration option for setting the NIC model type for
the management interface, which defaults to `virtio` (the current value)

The context for this change is that I was having severe speed issues
with `virtio` (which have now disappeared, probably after a QEMU update)
and the `e1000e` NIC was doing much better.
2023-01-22 15:23:47 +00:00
Babacar TALL
c9cb598d70 [Fix] forward_ports.rb@redirect_port: no implicit conversion of String into Array (TypeError) 2023-01-19 17:20:42 +00:00
Arjen Verstoep
98e674d270
Fix issue where "iommu" was configured for non-virtio network devices (#1702)
When setting the `model_type` of a network to something else than
`virtio`, the `iommu` parameter was still set for the device which isn't
allowed.

The if-statement for setting the parameter was looking at the default NIC
model type (in `@nic_model_type`) instead of final, configured value in `@model_type`.
2023-01-19 15:29:55 +00:00
Mamoru TASAKA
578d3ae429 Set empty host when nil on finalize_from_uri
With ruby3.2, URI.parse now sets empty host instead of nil via:
dd5118f852

Adjust test case so, also with ruby <= 3.1, forcely set empty string for host
when nil to make finalize_from_uri behavior consistent between different
host ruby versions.
2023-01-19 17:07:39 +09:00
Yevgeniy Kuksenko
ee06cd0a22
Support setting mtu on public interfaces (#1700)
Setting mtu on management and private interfaces is supported. It should
also be supported on public interfaces.
2022-12-23 11:10:33 +00:00
Darragh Bailey
d8c8d3d85f
Support setting iface name for target dev on private networks (#1692)
Allow for iface_name to be set on public_network configurations to
control the name of the interface created by libvirt. This overrides the
default that would be created automatically, but cannot use a reserved
name as it will be ignored.

Closes: #799
2022-12-11 11:21:34 +00:00
Darragh Bailey
1741ee2f6d
Use configured_networks helper in validate (#1695)
Switch to configured networks helper in validate to ensure that that the
validation checks the final list of networks that will be used, not just
those initial configured.

This will help ensure the management network is validated in addition to
the user specified networks.
2022-12-09 17:10:33 +00:00
Darragh Bailey
7a8306745b
Handle autoport when port explicit set (#1693)
Better handle setting the autoport value when the port is explicitly set
to ensure that the XML sent to update the VM is correct and will be the
XML that is reflected in the defined machine.

By prioritizing checking if the port is provided, graphics_autoport =
"yes" is ignored.

Fixes: #1687
2022-12-09 07:48:08 +00:00
Darragh Bailey
e0b17b34f5
Ensure iommu XML is only set for virtio nics (#1690)
Skip setting iommu option on the drive unless it's for virtio model type
nics.

Fixes: #1688
2022-12-04 16:19:43 +00:00
Darragh Bailey
431cf867ba
Handle pmsuspended resume and add state translation message (#1686)
Ensure there is a translation message for state and call the correct
wakeup depending on which form of suspend/pause the machine is in.

Closes: #1200
2022-12-03 08:05:58 +00:00
Darragh Bailey
612eb67f5f
Correct destroy method call logic (#1684)
Actual implementation of the flags behaviour was different than the code
expected. Update to use the correct behaviour.
2022-12-02 00:08:12 +00:00
Darragh Bailey
6bbde74be0
Ensure acceptance tests are executed (#1680)
Ensure the acceptance tests are actually executed and resolve any issues
that have crept in since they were not running as expected.

Call the ResolveDiskSettings on reload to ensure that the start domain
action will have all of the necessary configuration for any additional
storage disks added.

Tidy up create domain output when disks are attached.

Fixes: #1678
2022-11-23 17:33:10 +00:00
Darragh Bailey
f25a375d18
Clear and create forwarded ports on suspend/resume (#1679)
Ensure forwarded ports are cleared on suspend and recreated on resume.
Included tests to exercise the entire up/start behaviour to ensure the
expected actions are called in various scenarios, moving config validate
to only occur at the entrypoints and dropping it from being called
during start. Also eliminate a duplicate SetupComplete call.

Fixes: #1115
2022-11-23 13:44:32 +00:00
Uli Fahrer
0363459bec
feat: add websocket graphics config (#1672)
This adds websocket functionality for VNC. The websocket attribute may 
be used to specify the port to listen on (with -1 meaning 
auto-allocation and autoport having no effect due to security reasons).
2022-11-21 11:05:51 +00:00
Bram de Greve
6c4b7758aa
Adding disk_address_type option. (#954)
This patch allows to specify the virtio-mmio address type, which is
needed for debian guests on virt machines that don't support the PCI
address type.

See also 
https://translatedcode.wordpress.com/2016/11/03/installing-debian-on-qemus-32-bit-arm-virt-board/
where it is explicitly said to use `virtio-blk-device` and
`virtio-net-device` instead of `virtio-blk-pci` and `virtio-net-pci`, for
that reason.

Apparently, libvirt will use the `virtio-blk-pci` and `virtio-net-pci`
by default. By setting address type to `virtio-mmio`, it uses
`virtio-blk-device` instead. It seems not necessary to do the same for
the network controller, since libvirt will also use `virtio-net-device`
if the disk address type is set to `virtio-mmio`.

While this should help with ARM machines, it won't solve all issues
as some machines will boot perfectly with the existing defaults
provided the correct loader binary is used.

Relates-to: #1608
2022-11-14 12:52:22 +00:00
Darragh Bailey
df41f6f037
Ensure default public_network :dev shown on error (#1670)
During validation ensure that the default value for public network
devices is selected and shown on error if it's not one of the host
devices that are currently discovered.
2022-11-10 18:49:46 +00:00
Darragh Bailey
980db1049a
Adding SEV support (#1664)
Secure Encryption Virtualization is supported by libvirt and this
change adds support for vagrant-libvirt to enable it.

It requires a UEFI base box and needs a combination of options to be
configured for it to work.

Co-authored-by: PELLET Norman <norman.pellet@csem.ch>
Co-authored-by: MUNTANÉ CALVO Enric <emc@csem.ch>
Co-authored-by: Darragh Bailey <daragh.bailey@gmail.com>
Closes: #1372
2022-11-10 12:22:37 +00:00
Darragh Bailey
4fe53477b2
Support running tests in parallel (#1667)
To allow for faster execution of the unit tests locally, allow running
them in parallel.
2022-11-08 16:28:32 +00:00
Darragh Bailey
d384e63235
Reject cpu features enabled without model (#1658)
Recent Libvirt will silently drop cpu features set without a model
defined. Ensure this scenario is flagged as being invalid up front.

Fixes: #996
2022-11-04 17:21:42 +00:00
Darragh Bailey
554166cdc7
Fix list networks being read-only (#1651)
Change driver list of networks returned to only be read-only when using
qemu session, to allow for VMs using the system context to be able to
restart any networks needed.
2022-11-02 16:01:49 +00:00
Darragh Bailey
ddb6dbd076
Avoid setting cpu element on unsupported architectures (#1633)
The CPU element to manage the mode, model, features (including nested),
is only available on some architectures. To allow this plugin to
generate XML valid for other architectures such as RISC-V, the CPU
element needs to be optional and only enabled when the architecture
specified supports it.

Include checks in the validation section to help prevent the setting of
an unsupported architecture with any of the CPU features that require
the CPU element to be available.

Fixes: #1538
2022-10-30 14:29:21 +00:00
Darragh Bailey
a12054f2ad
Validate provided synced_folders types for access (#1644)
Reject any 9p synced folders that the user does not have read access to
the host path where using qemu sessions. This is because the VM will
launched with the user permissions instead of system permissions and
will fail to come up if trying to add a path that is not readable to be
mounted into the guest.

Additionally flag that virtiofs may not be supported with qemu sessions,
but do not reject in case support is added in the future.

Fixes: #1430
2022-10-14 14:25:18 +01:00
Darragh Bailey
1048e72dac
Tidy UI output on create (#1643)
Skip emitting items that are not set by default where possible.
2022-10-13 15:00:12 +00:00
Darragh Bailey
e87de89855
Use provided ssh port for machine (#1641)
To allow for a different ssh port to be used when connecting to a
machine for NFS setup, use the port provided in the ssh_info hash
with a fallback to the default ssh port.

This may allow NFS mounting into Windows guests once support is added to
vagrant itself to handle NFS installation.

Fixes: #1640
2022-10-13 13:28:25 +01:00
Darragh Bailey
a8ab0040ff
Disable graphics autoport attr when using spice (#1636)
If the graphics type is set to spice, then skip setting the autoport as
the attribute will be discarded by libvirt causing it to appear as
though not all of the XML sent to start the domain was accepted.
2022-10-11 18:12:32 +01:00
Darragh Bailey
59c7d9f18e
Use same list_all_networks and filter (#1638)
Ensure the same filtering for networks supported by vagrant-libvirt is
done for both driver and util by moving to call the same function with
filtering.

This avoids calls for the list of host devices from failing to parse
some networks that are not supported.

Fixes: #599
2022-10-11 17:54:41 +01:00
Oded Arbel
d38e130f47
Floppy support (#1334)
Add support for attaching 1 or 2 floppy drives to the VM using "vfd"
image files.
2022-10-08 10:59:06 +00:00
Who? Me?!
35e3730abf
Add vcpupin support (#1007)
Support tuning to pin which host CPUs the vCPUs will be pinned to.
2022-10-08 12:14:08 +02:00
Darragh Bailey
414aef131d
Ignore networks that cannot be used (#1628)
If the network does not have a bridge name, ignore it and move onto the
next one. This allows for hostdev networks to exist without breaking.

Includes some rudimentary testing to exercise the lookup code along with
a small bit of refactoring based on the realisation that there is no
need to lookup the network information twice as it is available if the
list_all_networks API is used.

Fixes: #599
2022-10-05 13:58:37 +00:00
Darragh Bailey
f5b70bc074
Query host interfaces directly as libvirt may not include them (#1627)
On some distros the libvirt does not appear to always return all of the
host interfaces. Switch to using 'ip -j link show' to read them directly
from the system in order to ensure all devices are read.

Refactor the driver tests to better isolate between test setup for the
different sets of functions and avoid accidental setting of
configuration details that may not be obvious.

Fixes: #1624
2022-10-05 13:29:44 +00:00
Darragh Bailey
624df5d8ed
Select better defaults when graphics type is spice (#1625)
Reduce the number of other graphics settings that need to be adjusted
once the type has been set to spice by defaulting the remaining options
to ones better suited for spice, in addition to adding the required
channel automatically.

Fixes: #1482
2022-10-02 21:43:37 +01:00
Darragh Bailey
54853d1d3d
Report graphics port after resolving (#1622)
Allow libvirt to start the domain before reading back the XML to
retrieve the port assigned automatically for subsequent graphics access
when autoport is enabled.

Fixes: #992
2022-10-01 13:59:36 +00:00
Darragh Bailey
7813ad3740
Emit default for bootmenu to be off (#1621)
Ensure the bootmenu is disabled by default. When not specified it will
default to the hypervisor default behaviour, however this is not
necessarily defined consistently across different distros. Therefore for
a consistent behaviour, simply ensure it is always configured to be off,
unless explicitly required to be enabled when the boot order is
configured.

Fixes: #947
2022-09-30 22:36:21 +01:00
Darragh Bailey
3599fd7600
Ensure explicit setting of inputs respected (#1619)
Make sure that explicit defining of input devices prevents injection of
the default mouse using ps/2 entry.

Fixes: #1092
2022-09-30 17:06:59 +01:00
Darragh Bailey
6dd3aba4b9
Remove remaining tabs from template (#1614) 2022-09-28 23:40:32 +01:00
Darragh Bailey
997fbc7faf
Replace 9p synced folder :owner with :access (#1571)
The 9p synced folder option :owner is better named as :access, which is
documented by 9p and less likely to cause confusion on the expected
behaviour as it does not control the owner of the files.

Relates-To: #378
2022-09-28 19:13:41 +00:00
Darragh Bailey
6f2674eec6
Remove need to pass machine and domain around in driver (#1579)
The driver is created with a specific machine instance, use this in
stead of requiring a specific instance be passed in. Apply the same
approach to domain where possible which allows the same get ip address
function to be called with and without a domain being passed in to save
lookup during loops.
2022-09-28 17:40:32 +00:00
Darragh Bailey
f111842dbe
Handle different attribute and element ordering (#1592)
Normalise the XML to ensure the attributes for both documents have the
same ordering to prevent excessive noise when differences are detected.
Additionally sort various elements based on attributes that make
ordering irrelevant to allow for simpler comparison using xmlsimple.

Closes: #1583
2022-09-22 17:14:49 +01:00
Rui Lopes
f6992fd848
fix qemu_use_agent to work with windows guests (#1599)
When using `qemu_use_agent = true`, the provisioning of a Windows
machine was faling to get the IP address with the error:

```
`get_ipaddress_from_qemu_agent': undefined method `downcase' for nil:NilClass (NoMethodError)
```

```plain
Traceback (most recent call last):
	18: from /opt/vagrant/embedded/gems/2.3.0/gems/logging-2.3.1/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
	17: from /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/lib/vagrant/action/builtin/wait_for_communicator.rb:16:in `block in call'
	16: from /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/plugins/communicators/winrm/communicator.rb:31:in `wait_for_ready'
	15: from /opt/vagrant/embedded/lib/ruby/2.7.0/timeout.rb:110:in `timeout'
	14: from /opt/vagrant/embedded/lib/ruby/2.7.0/timeout.rb:33:in `catch'
	13: from /opt/vagrant/embedded/lib/ruby/2.7.0/timeout.rb:33:in `catch'
	12: from /opt/vagrant/embedded/lib/ruby/2.7.0/timeout.rb:33:in `block in catch'
	11: from /opt/vagrant/embedded/lib/ruby/2.7.0/timeout.rb:95:in `block in timeout'
	10: from /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/plugins/communicators/winrm/communicator.rb:37:in `block in wait_for_ready'
	 9: from /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/plugins/communicators/winrm/helper.rb:21:in `winrm_info'
	 8: from /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/plugins/communicators/winrm/helper.rb:35:in `winrm_address'
	 7: from /opt/vagrant/embedded/gems/2.3.0/gems/vagrant-2.3.0/lib/vagrant/machine.rb:452:in `ssh_info'
	 6: from /home/rgl/.vagrant.d/gems/2.7.6/gems/vagrant-libvirt-0.10.7/lib/vagrant-libvirt/provider.rb:58:in `ssh_info'
	 5: from /home/rgl/.vagrant.d/gems/2.7.6/gems/vagrant-libvirt-0.10.7/lib/vagrant-libvirt/provider.rb:98:in `state'
	 4: from /home/rgl/.vagrant.d/gems/2.7.6/gems/vagrant-libvirt-0.10.7/lib/vagrant-libvirt/driver.rb:194:in `state'
	 3: from /home/rgl/.vagrant.d/gems/2.7.6/gems/vagrant-libvirt-0.10.7/lib/vagrant-libvirt/driver.rb:103:in `get_domain_ipaddress'
	 2: from /home/rgl/.vagrant.d/gems/2.7.6/gems/vagrant-libvirt-0.10.7/lib/vagrant-libvirt/driver.rb:242:in `get_ipaddress_from_qemu_agent'
	 1: from /home/rgl/.vagrant.d/gems/2.7.6/gems/vagrant-libvirt-0.10.7/lib/vagrant-libvirt/driver.rb:242:in `each'
/home/rgl/.vagrant.d/gems/2.7.6/gems/vagrant-libvirt-0.10.7/lib/vagrant-libvirt/driver.rb:243:in `block in get_ipaddress_from_qemu_agent': undefined method `downcase' for nil:NilClass (NoMethodError)
```

This is due to Windows qemu-ga reporting interfaces that do not have a
`hardware-address`. For example, the `Loopback Pseudo-Interface 1` does
not have it:

```console
$ virsh qemu-agent-command openwrt-vagrant-windows '{"execute":"guest-network-get-interfaces"}' --pretty
{
  "return": [
    {
      "name": "Ethernet 2",
      "ip-addresses": [
        {
          "ip-address-type": "ipv4",
          "ip-address": "10.0.20.11",
          "prefix": 24
        }
      ],
      "statistics": {
        "tx-packets": 3090,
        "tx-errs": 0,
        "rx-bytes": 50713786,
        "rx-dropped": 0,
        "rx-packets": 35116,
        "rx-errs": 0,
        "tx-bytes": 744040,
        "tx-dropped": 0
      },
      "hardware-address": "08:00:27:00:00:0b"
    },
    {
      "name": "Loopback Pseudo-Interface 1",
      "ip-addresses": [
        {
          "ip-address-type": "ipv6",
          "ip-address": "::1",
          "prefix": 128
        },
        {
          "ip-address-type": "ipv4",
          "ip-address": "127.0.0.1",
          "prefix": 8
        }
      ],
      "statistics": {
        "tx-packets": 0,
        "tx-errs": 0,
        "rx-bytes": 0,
        "rx-dropped": 0,
        "rx-packets": 0,
        "rx-errs": 0,
        "tx-bytes": 0,
        "tx-dropped": 0
      }
    }
  ]
}
```

With this change, the IP address can now be found without errors:

```plain
...
    windows: WinRM address: 10.0.20.11:5985
    windows: WinRM username: vagrant
...
```
2022-09-22 10:40:17 +00:00