Sha256: 1085fa4785d714da7acbdcd7c9f1c167e9e78dab16355330b3a63d08dde52b31

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

module Vagrant
  module LXC
    module Action
      class Create
        def initialize(app, env)
          @app = app
        end

        def call(env)
          config = env[:machine].provider_config
          container_name = config.container_name

          case container_name
            when :machine
              container_name = env[:machine].name.to_s
            when String
              # Nothing to do here, move along...
            else
              container_name = "#{env[:root_path].basename}_#{env[:machine].name}"
              container_name.gsub!(/[^-a-z0-9_]/i, "")
              # milliseconds + random number suffix to allow for simultaneous
              # `vagrant up` of the same box in different dirs
              container_name << "_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}"
          end

          env[:machine].provider.driver.create(
            container_name,
            config.backingstore,
            config.backingstore_options,
            env[:lxc_template_src],
            env[:lxc_template_config],
            env[:lxc_template_opts]
          )

          env[:machine].id = container_name

          @app.call env
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-lxc-1.0.1 lib/vagrant-lxc/action/create.rb
vagrant-lxc-1.0.0 lib/vagrant-lxc/action/create.rb
vagrant-lxc-1.0.0.alpha.3 lib/vagrant-lxc/action/create.rb
vagrant-lxc-1.0.0.alpha.2 lib/vagrant-lxc/action/create.rb