How do you determine the location of a Vagrantfile from virt-manager?
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]
cat .\index | python -m json.tool
{
"version": 1,
"machines": {
"4f9bf5cd740f409c867553c19c52a81c": {
"local_data_path": "C:/Vagrant-Machines/bionic-vm/.vagrant",
"name": "default",
"provider": "hyperv",
"state": "running",
"vagrantfile_name": null,
"vagrantfile_path": "C:/Vagrant-Machines/bionic-vm",
"updated_at": null,
"extra_data": {
"box": {
"name": "hashicorp/bionic64",
"provider": "hyperv",
"version": "1.0.282"
}
}
}
}
}
For reference, here how the metedata looks in the case of Nova:
virsh dumpxml instance-0033dd00 | head
<domain type='kvm' id='93'>
<name>instance-0033dd00</name>
<uuid>XXXXXXXXXXXXXXXXXXX</uuid>
<metadata>
<nova:instance xmlns:nova="http://openstack.org/xmlns/libvirt/nova/1.0">
<nova:package version="17.0.13"/>
<nova:name>VM-NAME</nova:name>
<nova:creationTime>2021-05-11 10:50:49</nova:creationTime>
<nova:flavor name="m1.small">
<nova:memory>16384</nova:memory>