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