OS is Debian 10, vagrant provider is libvirt.
vagrant global-status
is supposed to provide information on all vms on a system, but I can see shutoff and running vms in virt-manager that are not listed by vagrant global-status
. I have only used libvirt for Vagrant so I know Vagrant is the culprit.
How do I determine the associated directory/Vagrantfile for each of these vms?
I think this command would do the trick:
find / -name Vagrantfile -exec echo {} \; -exec bash -c 'cd "$(dirname {})" && vagrant status | grep -E shutoff\|running' \; 2>/dev/null
But it seems absurd that something like this would be necessary, and would take a very long time on a large filesystem.
How exactly can I determine the directory for the associated Vagrantfile for each vm? There must be an easier way besides exhaustively searching the filesystem.
Based on the template [1], Vagrant does not seem to keep track of the project directory associated with the VM in libvirt domain metadata.
Internally Vagrant keeps the info about the VM (including the directory) in a JSON file
~/vagrant.d/data/machine-index/index
, check the example [2]I guess it's possible to modify the template to add the directory as a metadata, similar to how Openstack Nova add some metadata to the Guest's libvirt domain, the metadata can be used to get the VM name, Flavor, etc. directly from the compute node without querying Nova.
Obviously this does not apply to the existing VMs prior the change.
[1] https://github.com/vagrant-libvirt/vagrant-libvirt/blob/master/lib/vagrant-libvirt/templates/domain.xml.erb
[2]
For reference, here how the metedata looks in the case of Nova: