vagrant-libvirt / vagrant-libvirt

Vagrant provider for libvirt.
https://vagrant-libvirt.github.io/vagrant-libvirt/
MIT License
2.32k stars 500 forks source link

have libvirt.name = "libvirt_name_here" ability #1763

Open LuisBL opened 1 year ago

LuisBL commented 1 year ago

Is your feature request related to a problem? Please describe.

I have the following Vagrantfile

$ cat Vagrantfile
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt'

Vagrant.configure("2") do |config|
  config.vm.box = "debian/bullseye64"
  config.vm.provider :libvirt do |libvirt|
    # libvirt.name = "deb11_main"
    libvirt.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
    libvirt.memory = 2048
    libvirt.cpus = 2
  end
$

With the bellow versions:

$ vagrant plugin list 
vagrant-faster (0.2.0, global)
vagrant-hostsupdater (1.2.4, global)
vagrant-libvirt (0.12.2, global)
$ 

Describe the solution you'd like I would like to be able to name to name the libvirt VM e.g. # libvirt.name = "deb11_main" so I would be able to see with:

$ virsh list --all
 Id   Name                                  State
------------------------------------------------------
 -    deb11_ansible_vm_test_ansible_roles   shut off
 -    deb11_main                         shut off
$ 

Additional context I thought this was available but when i try it I get:

$ vagrant up
Bringing machine 'default' up with 'libvirt' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:

Libvirt Provider:
* The following settings shouldn't exist: name
$
electrofelix commented 4 months ago

name is a VirtualBox provider option, don't know if it exists on any other provider. Vagrant does provide a standard way to set a guest name though, which is supported config.vm.define "deb11_main", combined with a provider option to set the prefix to an empty value using libvirt.default_prefix = "" will get you what you want.

Combining those into the example snippet you shared:

Vagrant.configure("2") do |config|
  config.vm.box = "debian/bullseye64"
  config.vm.define "deb11_main"
  config.vm.provider :libvirt do |libvirt|
    libvirt.default_prefix = ""
    libvirt.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
    libvirt.memory = 2048
    libvirt.cpus = 2
  end
end