2013-03-02 15:17:04 +00:00
|
|
|
module Vagrant
|
|
|
|
module LXC
|
|
|
|
module Action
|
|
|
|
# Prepare arguments to be used for lxc-create
|
|
|
|
class HandleBoxMetadata < BaseAction
|
|
|
|
LXC_TEMPLATES_PATH = Pathname.new("/usr/share/lxc/templates")
|
|
|
|
|
|
|
|
def initialize(app, env)
|
|
|
|
super
|
|
|
|
@logger = Log4r::Logger.new("vagrant::lxc::action::handle_box_metadata")
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
box = env[:machine].box
|
|
|
|
metadata = box.metadata
|
2013-03-02 19:39:49 +00:00
|
|
|
|
2013-03-02 15:17:04 +00:00
|
|
|
metadata.merge!(
|
2013-03-07 05:09:09 +00:00
|
|
|
'template-name' => "vagrant-#{box.name}",
|
|
|
|
'lxc-cache-path' => box.directory.to_s
|
2013-03-02 15:17:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Prepends "lxc-" to the template file so that `lxc-create` is able to find it
|
2013-03-07 05:09:09 +00:00
|
|
|
src = box.directory.join('lxc-template').to_s
|
2013-03-02 15:17:04 +00:00
|
|
|
dest = LXC_TEMPLATES_PATH.join("lxc-#{metadata['template-name']}").to_s
|
|
|
|
|
|
|
|
@logger.debug('Copying LXC template into place')
|
|
|
|
# This should only ask for administrative permission once, even
|
|
|
|
# though its executed in multiple subshells.
|
|
|
|
system(%Q[sudo su root -c "cp #{src} #{dest}"])
|
2013-03-07 05:09:09 +00:00
|
|
|
system(%Q[sudo su root -c "cd #{box.directory} && tar xfz rootfs.tar.gz"])
|
2013-03-02 15:17:04 +00:00
|
|
|
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|