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>