sciurus/vagrant-mutate

Support boxes with slash in name

sciurus opened this issue · 15 comments

Support boxes with slash in name
> vagrant box list
ubuntu/trusty64      (virtualbox, 14.04)
> vagrant mutate ubuntu/trusty64 libvirt
Vagrant-mutate can not download from Vagrant Cloud for you.

I don't understand this error message. I have already downloaded the box. There seems to be an assumption that any box name with a / in it needs to be downloaded from vagrantcloud.com, but that's not always the case.

elsif box_arg =~ /\//

If you already downloaded the box, pass vagrant-mutate the path to the box file. For example, if the file name is trusty64.box and it's in the current directory, run vagrant mutate trusty64.box libvirt.

The box file does not have to be in the current directory. The slash is only interpreted to refer Vagrant Cloud if a file at that path does not exist. For example, if you saved the box to your Downloads directory then vagrant mutate ~/Downloads/trusty64.box libvirt would work.

I was too quick to respond; on re-reading I see you meant that you had a box already loaded in vagrant's box path that has / in the name. I haven't seen this before, so thanks for reporting the issue. What is the source of this box and how did you load it? What is the output of find ~/.vagrant.d/boxes/ ? That info will help me determine how vagrant-mutate can support this.

Thanks for the quick response! In my Vagrantfile I just have config.vm.box = 'ubuntu/trusty64' which is a new feature in Vagrant v1.5. Please see the "Box Shortnames" section in this http://www.vagrantup.com/blog/feature-preview-vagrant-1-5-boxes-2-0.html blog post. I could have also downloaded the box with vagrant box add ubuntu/trusty64. Both are effectively the same.

> find .vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/
.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/
.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/14.04
.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/14.04/virtualbox
.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/14.04/virtualbox/box.ovf
.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/14.04/virtualbox/metadata.json
.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/14.04/virtualbox/box-disk1.vmdk
.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/14.04/virtualbox/Vagrantfile
.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/metadata_url

Thanks. I knew I had to handle versioned boxes (#51) but I hadn't considered that forward slash was now part of the box name. I'll need to handle both of these issues to support boxes from vagrant cloud.

Any news/progress on this @sciurus?

Although I'd like to fix this and #51, working on it is low on my priorities. Anyone is welcome to take a crack at them!

Workaround is to supply box URL.

$ vagrant mutate https://vagrantcloud.com/cloud-team/boxes/ubuntu-server-14.04.1-32bit/versions/1.0/providers/virtualbox.box kvm

Once box is downloaded and mutated find the box name.

$ vagrant box list
cloud-team/ubuntu-server-14.04.1-32bit    (virtualbox, 1.0)
virtualbox                                (kvm, 0)

Finally add box name to Vagrantfile

  config.vm.box = "virtualbox"

On a side note it will be nice to have option to give a name to the mutaded box.

@schkovich if you want to set the name now, rename $HOME/.vagrant.d/boxes/virtualbox.

Anyone doing some work on this ? I looked into the vagrant code how adding a box is implemented, because re-using some of the function could help.
Things that should be added :

  • support vagrant cloud both local boxes as download the boxes
    --> for download defaults will be latest version and virtualbox provider
    --> add options to force version
    --> download metadata.json from cloud when needed
    --> add target name for converted box, and also versioning

Will try to get this added and do a PR when I got something.
Using vagrant 1.7.2
Also, any tips are welcome, my ruby is very green ...

I'm not actively developing vagrant-mutate anymore; it does what I need it to do, and I don't have much free time.

I'm glad to provide guidance and review to anyone who wants to work on it.

I will give a try. Will keep you informed about my progress/ troubles :)

Have just submitted PR #67 which add's initial support for VagrantCloud box names.

Would welcome some testing from other users.
It works for the various scenarios I've tried, but the more the merrier :)

That's fantastic @fatmcgav; many thanks for your effort! I'm quite busy now (started a new job last month, moved into a new apartment this weekend) but I promise to review #67 as soon as I can dedicate the time.

I give it a try. 👍