2013-03-02 15:17:04 +00:00
|
|
|
require 'vagrant-lxc/action/base_action'
|
|
|
|
|
|
|
|
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
|
|
|
|
template_name = metadata['template-name']
|
|
|
|
|
2013-03-02 19:39:49 +00:00
|
|
|
after_create = metadata['after-create-script'] ?
|
|
|
|
box.directory.join(metadata['after-create-script']).to_s :
|
|
|
|
nil
|
|
|
|
|
2013-03-02 15:17:04 +00:00
|
|
|
metadata.merge!(
|
2013-03-02 19:39:49 +00:00
|
|
|
'template-name' => "vagrant-#{box.name}-#{template_name}",
|
2013-03-03 02:12:26 +00:00
|
|
|
'lxc-cache-path' => box.directory.to_s,
|
2013-03-02 19:39:49 +00:00
|
|
|
'after-create-script' => after_create
|
2013-03-02 15:17:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Prepends "lxc-" to the template file so that `lxc-create` is able to find it
|
|
|
|
dest = LXC_TEMPLATES_PATH.join("lxc-#{metadata['template-name']}").to_s
|
|
|
|
src = box.directory.join(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}"])
|
|
|
|
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|