2013-03-02 15:17:04 +00:00
|
|
|
module Vagrant
|
|
|
|
module LXC
|
|
|
|
module Action
|
|
|
|
# Prepare arguments to be used for lxc-create
|
2013-04-02 00:05:19 +00:00
|
|
|
class HandleBoxMetadata
|
2013-03-02 15:17:04 +00:00
|
|
|
def initialize(app, env)
|
2013-04-02 00:05:19 +00:00
|
|
|
@app = app
|
2013-03-02 15:17:04 +00:00
|
|
|
@logger = Log4r::Logger.new("vagrant::lxc::action::handle_box_metadata")
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2013-04-09 01:06:13 +00:00
|
|
|
@env = env
|
|
|
|
@box = @env[:machine].box
|
2013-03-11 03:13:48 +00:00
|
|
|
|
2013-04-09 01:06:13 +00:00
|
|
|
@env[:ui].info I18n.t("vagrant.actions.vm.import.importing",
|
|
|
|
:name => @env[:machine].box.name)
|
2013-03-02 15:17:04 +00:00
|
|
|
|
2013-04-09 01:06:13 +00:00
|
|
|
@logger.debug 'Validating box contents'
|
|
|
|
validate_box
|
2013-04-05 06:10:38 +00:00
|
|
|
|
2013-04-09 01:06:13 +00:00
|
|
|
@logger.debug 'Setting box options on environment'
|
|
|
|
@env[:lxc_template_opts] = template_opts
|
|
|
|
@env[:lxc_template_src] = template_src
|
|
|
|
|
2013-06-06 03:04:59 +00:00
|
|
|
if template_config_file.exist?
|
|
|
|
@env[:lxc_template_config] = template_config_file.to_s
|
|
|
|
end
|
|
|
|
|
2013-04-09 01:06:13 +00:00
|
|
|
@app.call env
|
|
|
|
end
|
2013-03-08 03:54:15 +00:00
|
|
|
|
2013-04-09 01:06:13 +00:00
|
|
|
def template_src
|
|
|
|
@template_src ||= @box.directory.join('lxc-template').to_s
|
|
|
|
end
|
2013-04-05 06:10:38 +00:00
|
|
|
|
2013-06-06 03:04:59 +00:00
|
|
|
def template_config_file
|
|
|
|
@template_config_file ||= @box.directory.join('lxc.conf')
|
|
|
|
end
|
|
|
|
|
2013-04-09 01:06:13 +00:00
|
|
|
def template_opts
|
|
|
|
@template_opts ||= @box.metadata.fetch('template-opts', {}).dup.merge!(
|
|
|
|
'--tarball' => rootfs_tarball,
|
|
|
|
'--auth-key' => Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s
|
2013-03-08 03:54:15 +00:00
|
|
|
)
|
2013-04-09 01:06:13 +00:00
|
|
|
end
|
2013-03-02 15:17:04 +00:00
|
|
|
|
2013-04-09 01:06:13 +00:00
|
|
|
def rootfs_tarball
|
|
|
|
@rootfs_tarball ||= @box.directory.join('rootfs.tar.gz').to_s
|
|
|
|
end
|
2013-04-05 06:10:38 +00:00
|
|
|
|
2013-04-09 01:06:13 +00:00
|
|
|
def validate_box
|
2013-06-06 03:05:34 +00:00
|
|
|
if @box.metadata.fetch('version').to_i < 2
|
2013-04-09 01:06:13 +00:00
|
|
|
raise Errors::InvalidBoxVersion.new name: @box.name
|
|
|
|
end
|
|
|
|
|
|
|
|
unless File.exists?(template_src)
|
|
|
|
raise Errors::TemplateFileMissing.new name: @box.name
|
|
|
|
end
|
|
|
|
|
|
|
|
unless File.exists?(rootfs_tarball)
|
|
|
|
raise Errors::RootFSTarballMissing.new name: @box.name
|
|
|
|
end
|
2013-03-02 15:17:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|