Skip to content

Support starting from an existing image known to LXD.

Cesar Enrique Garcia requested to merge cquike/vagrant-lxd:existing_image into master

This PR tries to solve issue #10. It adds a new config option called "image" that should be set to an existing image known to LXD.

The option can be set in the user Vagrantfile or in the Vagrantfile of the box itself:

In the first case the user Vagrantfile might look like this:

Vagrant.configure('2') do |config|
    config.vm.box = "dummy"
    config.vm.provider 'lxd' do |lxd|
        lxd.image = 'lxd_existing_image'
    end
end

Note that still the user needs to specify the box name, even if it is not used.

In the second case, a box under the $VAGRANT_HOME/boxes directory might look like this:

$VAGRANT_HOME/boxes
  |-lxd_existing_image
      |-1.0.0
          |-lxd
             |-Vagrantfile

where Vagrantfile is

Vagrant.configure('2') do |config|
    config.vm.provider 'lxd' do |lxd|
        lxd.image = 'lxd_existing_image'
    end
end

Please note that this is my first contribution to vagrant and my first ruby code programming, so there might be significant improvements. However the code seems at least to work.

A couple of possible enhancements:

  • Add a lxd command to create a box from an existing image. This could create the structure mentioned above.
  • Avoid having to create a lxc subdirectory under the box directories. I understand this is needed when using the lxc underlying format, but in case of using an existing lxd image this is redundant.
Edited by Evan Hanson

Merge request reports