OK, it’s a bit ugly. Three separate salt files. They could probably all be called from one .top file.
The first needs to be run in the dom0 environment. This isn’t quite the file I used; I have a fairly elaborate process for setting up the names of the VMs–I’ve elided that, it’s not really relevant.
Basically, this first file takes the dvm template (deb11m-net-wifi-dvmt) and temporarily makes it an ordinary AppVM, but. Also the virtualization mode must be set to hvm since it’s going to diddle directly with a device, shortly.
After being made “not a template” the device is attached to deb11m-net-wifi-dvmt and “provides network” is set to true. So now, the erstwhile dvm-template is just like the normal sys-net.
{% if grains['nodename'] == 'dom0' %}
{% set namestem = 'net-wifi' %}
{% set vmname = 'deb11m-net-wifi-dvmt' %}
dvmt-{{namestem}}-detemplatize:
qvm.prefs:
- name: {{vmname}}
- template_for_dispvms: false
- virt_mode: hvm
{% set ndevices = salt['cmd.shell']('qvm-pci ls ' + vmname + ' | wc -l') %}
{% if ndevices != '1' %}
dvm-{{namestem}}-devices-attach:
cmd.run:
- name: 'qvm-pci attach --persistent {{vmname}} dom0:00_14.3'
{% endif %}
dvm-{{namestem}}-provides-network-true:
cmd.run:
- name: 'qvm-prefs {{vmname}} provides_network True'
{% endif %}
This next one needs to be run on target deb11m-net-wifi-dvmt (change the name of course if yours is named something different).
The first thing it does is pause for a couple of seconds. That’s because it takes a short amount of time for the wifi adapter to actually kick on. Without this delay there will simply be a nasty error message and an exit.
Then start the network manager, now that it has a wifi controller to talk to.
But it still takes some time before connecting the two, so another delay.
Then connect to the driver. After this, the appvm named deb11m-net-wifi-dvmt shuts down, knowing
how to connect to the wifi controller.
{% set namestem = 'net-wifi' %}
{% set vmname = 'deb11m-net-wifi-dvmt' %}
{% if grains['nodename'] == vmname %}
dvmt-{{namestem}}-start-network-manager-wait-first:
cmd.run:
- name: 'sleep 2'
- order: 1
dvmt-{{namestem}}-start-network-manager:
cmd.run:
- name: '/sbin/NetworkManager'
- order: 2
dvmt-{{namestem}}-connect-to-wifi-wait-first:
cmd.run:
- name: 'sleep 15'
- order: 3
dvmt-{{namestem}}-connect-to-wifi:
cmd.run:
- name: 'nmcli d wifi connect TMOBILE-9855 password XXXXXXXXXXX'
- order: 4
{% endif %}
The next salt file simply reverses the first one, turning off provides network, resetting the virtual mode, making the VM a dvm template. However, since this runs in dom0, it must wait for the net qube to shut down.
{% if grains['nodename'] == 'dom0' %}
{% set namestem = 'net-wifi' %}
{% set vmname = deb11m-net-wifi-dvmt' %}
dvm-{{namestem}}-shut-down-train:
cmd.run:
- name: 'qvm-shutdown --wait {{vmname}}'
dvm-{{namestem}}-provides-network-false:
cmd.run:
- name: 'qvm-prefs {{vmname}} provides_network False'
dvm-{{namestem}}-devices-detach-train:
cmd.run:
- name: 'qvm-pci detach {{vmname}} dom0:00_14.3'
dvmt-{{namestem}}-dvmt-unprefs-train:
qvm.prefs:
- name: {{vmname}}
- template_for_dispvms: true
- virt_mode: pvh
{% endif %}