Class: Vagrant::LXC::Action::HandleBoxMetadata
- Inherits:
-
Object
- Object
- Vagrant::LXC::Action::HandleBoxMetadata
- Defined in:
- lib/vagrant-lxc/action/handle_box_metadata.rb
Overview
Prepare arguments to be used for lxc-create
Constant Summary collapse
- SUPPORTED_VERSIONS =
[2, 3]
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ HandleBoxMetadata
constructor
A new instance of HandleBoxMetadata.
- #rootfs_tarball ⇒ Object
- #template_config_file ⇒ Object
- #template_opts ⇒ Object
- #template_src ⇒ Object
- #validate_box ⇒ Object
Constructor Details
#initialize(app, env) ⇒ HandleBoxMetadata
Returns a new instance of HandleBoxMetadata.
7 8 9 10 |
# File 'lib/vagrant-lxc/action/handle_box_metadata.rb', line 7 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant::lxc::action::handle_box_metadata") end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-lxc/action/handle_box_metadata.rb', line 12 def call(env) @env = env @box = @env[:machine].box @env[:ui].info I18n.t("vagrant.actions.vm.import.importing", :name => @env[:machine].box.name) @logger.debug 'Validating box contents' validate_box @logger.debug 'Setting box options on environment' @env[:lxc_template_opts] = template_opts @env[:lxc_template_src] = template_src if template_config_file.exist? @env[:lxc_template_config] = template_config_file.to_s end @app.call env end |
#rootfs_tarball ⇒ Object
50 51 52 |
# File 'lib/vagrant-lxc/action/handle_box_metadata.rb', line 50 def rootfs_tarball @rootfs_tarball ||= @box.directory.join('rootfs.tar.gz').to_s end |
#template_config_file ⇒ Object
37 38 39 |
# File 'lib/vagrant-lxc/action/handle_box_metadata.rb', line 37 def template_config_file @template_config_file ||= @box.directory.join('lxc.conf') end |
#template_opts ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/vagrant-lxc/action/handle_box_metadata.rb', line 41 def template_opts @template_opts ||= @box..fetch('template-opts', {}).dup.merge!( '--tarball' => rootfs_tarball, # TODO: Deprecate this, the rootfs should be ready for vagrant-lxc # SSH access at this point '--auth-key' => Vagrant.source_root.join('keys', 'vagrant.pub')..to_s ) end |
#template_src ⇒ Object
33 34 35 |
# File 'lib/vagrant-lxc/action/handle_box_metadata.rb', line 33 def template_src @template_src ||= @box.directory.join('lxc-template').to_s end |
#validate_box ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/vagrant-lxc/action/handle_box_metadata.rb', line 54 def validate_box unless SUPPORTED_VERSIONS.include? @box..fetch('version').to_i raise Errors::IncompatibleBox.new name: @box.name, found: @box..fetch('version').to_i, supported: SUPPORTED_VERSIONS.join(' and ') 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 end |