2013-03-03 05:24:05 +00:00
|
|
|
module Vagrant
|
|
|
|
module LXC
|
|
|
|
module Action
|
2013-04-02 00:05:19 +00:00
|
|
|
class Create
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
2013-03-03 05:24:05 +00:00
|
|
|
def call(env)
|
2014-02-02 20:35:48 +00:00
|
|
|
container_name = env[:machine].provider_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, "")
|
2014-02-02 21:42:32 +00:00
|
|
|
# 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)}"
|
2014-01-01 21:54:27 +00:00
|
|
|
end
|
2013-04-05 06:10:38 +00:00
|
|
|
|
|
|
|
env[:machine].provider.driver.create(
|
|
|
|
container_name,
|
|
|
|
env[:lxc_template_src],
|
2013-06-06 03:04:59 +00:00
|
|
|
env[:lxc_template_config],
|
2013-04-05 06:10:38 +00:00
|
|
|
env[:lxc_template_opts]
|
|
|
|
)
|
|
|
|
|
|
|
|
env[:machine].id = container_name
|
2013-03-29 05:17:34 +00:00
|
|
|
|
2013-03-03 05:24:05 +00:00
|
|
|
@app.call env
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|