Class: Vagrant::LXC::Action::Create
- Inherits:
-
Object
- Object
- Vagrant::LXC::Action::Create
- Defined in:
- lib/vagrant-lxc/action/create.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #generate_container_name(env) ⇒ Object
-
#initialize(app, env) ⇒ Create
constructor
A new instance of Create.
Constructor Details
#initialize(app, env) ⇒ Create
Returns a new instance of Create.
5 6 7 |
# File 'lib/vagrant-lxc/action/create.rb', line 5 def initialize(app, env) @app = app end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vagrant-lxc/action/create.rb', line 9 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 = generate_container_name(env) end backingstore = config.backingstore if backingstore.nil? backingstore = config.privileged ? "best" : "dir" end driver = env[:machine].provider.driver = env[:lxc_template_opts] if driver.supports_new_config_format if env[:lxc_box_config] driver.update_config_keys(env[:lxc_box_config]) end else ['--oldconfig'] = '' end driver.create( container_name, backingstore, config., env[:lxc_template_src], env[:lxc_template_config], ) driver.update_config_keys env[:machine].id = container_name @app.call env end |
#generate_container_name(env) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vagrant-lxc/action/create.rb', line 50 def generate_container_name(env) 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)}" # Trim container name to 64 chars, keeping "randomness" trim_point = container_name.size > 64 ? -64 : -(container_name.size) container_name[trim_point..-1] end |