Class: Vagrant::CopyBox::Command
- Inherits:
-
Object
- Object
- Vagrant::CopyBox::Command
- Defined in:
- lib/vagrant-commit/command.rb
Instance Method Summary collapse
Instance Method Details
#execute ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/vagrant-commit/command.rb', line 117 def execute opts = OptionParser.new do |o| o. = "Usage: vagrant copybox <source> <target>" end # Parse the options argv = (opts) src_boxname, target_boxname = argv if !src_boxname || !target_boxname raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp end collection = Vagrant::BoxCollection.new(@env.boxes_path) box = collection.find(src_boxname, :libvirt, "> 0") provider = box.["provider"] # create necessary files in the boxes path root_dir = @env.boxes_path version = "0" new_box_dir = root_dir.join(target_boxname).join(version).join(provider.to_s) new_box_dir.mkpath new_box_dir.join("metadata.json").open("w") do |f| f.write(()) end new_box_dir.join("Vagrantfile").open("w") do |f| f.write(Vagrantfile()) end src_path = box.directory.join("box.img") target_path = new_box_dir.join("box.img") FileUtils.cp(src_path, target_path) end |
#metadata_json ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/vagrant-commit/command.rb', line 91 def " {\n \"provider\": \"libvirt\",\n \"format\": \"qcow2\",\n \"virtual_size\": 32\n }\n EOF\nend\n" |
#Vagrantfile ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/vagrant-commit/command.rb', line 101 def Vagrantfile " Vagrant.configure(\"2\") do |config|\n config.vm.provider :libvirt do |libvirt|\n libvirt.driver = \"kvm\"\n libvirt.host = \"\"\n libvirt.connect_via_ssh = false\n libvirt.storage_pool_name = \"default\"\n end\n end\n\n user_vagrantfile = File.expand_path('../_include/Vagrantfile', __FILE__)\n load user_vagrantfile if File.exists?(user_vagrantfile)\n EOF\nend\n" |