Commit c60e1bf0730634c943e67ab55f2f4c2ccc4eb6f2
1 parent
e391d9ba
add box specific bootstrap options in metadata.
Showing
9 changed files
with
72 additions
and
5 deletions
example_box/metadata.json
deleted
100644 → 0
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | "name": "lxd", |
10 | 10 | "url": "file:///data/ghopp/projects/vagrant/vagrant-lxd/gentoo_001_lxd.box", |
11 | 11 | "checksum_type": "sha1", |
12 | - "checksum": "4f3d7bfe034fe9fb82179992fdc6803b6f96abfb" | |
12 | + "checksum": "9cf9ffd2c840680672a329a87abcd056b021d130" | |
13 | 13 | } |
14 | 14 | ] |
15 | 15 | } | ... | ... |
No preview for this file type
gentoo_box/metadata.json
0 → 100644
1 | +{ | |
2 | + "provider": "lxd", | |
3 | + "bootstrap": { | |
4 | + "hostname": { | |
5 | + "exec": [ | |
6 | + ["sed", "-i", "s/-lxc //", "/etc/init.d/hostname"], | |
7 | + ["sed", "-i", "s/LXC_NAME/<%= hostname %>/", "/etc/conf.d/hostname"], | |
8 | + ["sed", "-i", "s/<%= container %>/<%= hostname %>/", "/etc/hostname"], | |
9 | + ["sed", "-i", "s/<%= container %>/<%= hostname %>/", "/etc/hosts"] | |
10 | + ] | |
11 | + }, | |
12 | + "packages": { | |
13 | + "exec": [ | |
14 | + ["emerge", "--update", "sudo"] | |
15 | + ] | |
16 | + }, | |
17 | + "sudo": { | |
18 | + "exec": [ | |
19 | + ["echo", "vagrant ALL=(ALL) NOPASSWD: ALL", ">>/etc/sudoers"] | |
20 | + ] | |
21 | + } | |
22 | + } | |
23 | +} | ... | ... |
... | ... | @@ -7,6 +7,7 @@ module Vagrant |
7 | 7 | module Lxd |
8 | 8 | module Action |
9 | 9 | action_root = Pathname.new(File.expand_path("../action", __FILE__)) |
10 | + autoload :Bootstrap, action_root.join("bootstrap") | |
10 | 11 | autoload :Create, action_root.join("create") |
11 | 12 | autoload :EnsureImage, action_root.join("ensure_image") |
12 | 13 | autoload :EnsureSsh, action_root.join("ensure_ssh") |
... | ... | @@ -31,11 +32,13 @@ module Vagrant |
31 | 32 | end |
32 | 33 | b.use action_start |
33 | 34 | b.use EnsureSsh |
35 | + b.use Bootstrap | |
34 | 36 | end |
35 | 37 | end |
36 | 38 | |
37 | 39 | def self.action_start |
38 | 40 | Vagrant::Action::Builder.new.tap do |b| |
41 | + b.use Bootstrap | |
39 | 42 | b.use EnsureStarted |
40 | 43 | end |
41 | 44 | end | ... | ... |
lib/vagrant/lxd/action/bootstrap.rb
0 → 100644
1 | +require 'erb' | |
2 | + | |
3 | +module Vagrant | |
4 | + module Lxd | |
5 | + module Action | |
6 | + class Bootstrap | |
7 | + def initialize(app, env) | |
8 | + @app = app | |
9 | + @logger = Log4r::Logger.new("vagrant::lxd::action::bootstrap") | |
10 | + end | |
11 | + | |
12 | + def call(env) | |
13 | + driver = env[:machine].provider.driver | |
14 | + bs_data = env[:machine].box.metadata["bootstrap"] | |
15 | + | |
16 | + bs_data.each do |name, actions| | |
17 | + env[:ui].info "--- Bootstrap #{name} ---", :prefix => false | |
18 | + actions.each do |action, data| | |
19 | + # right now I do not handle differnet actions just return if | |
20 | + # action is not "exec". | |
21 | + next if action != "exec" | |
22 | + | |
23 | + container = driver.name | |
24 | + hostname = env[:machine].name | |
25 | + data.each do |d| | |
26 | + d.collect! { |element| ERB.new(element).result(binding) } | |
27 | + driver.exec(*d) | |
28 | + env[:ui].info "--- #{d.inspect} ---", :prefix => false | |
29 | + end | |
30 | + end | |
31 | + end | |
32 | + | |
33 | + @app.call(env) | |
34 | + end | |
35 | + end | |
36 | + end | |
37 | + end | |
38 | +end | |
39 | + | |
40 | +# vim: set et ts=2 sw=2: | ... | ... |
... | ... | @@ -155,7 +155,7 @@ module Vagrant |
155 | 155 | begin |
156 | 156 | @bridge = YAML.load(execute("network", "show", "vagrantbr0")) |
157 | 157 | rescue |
158 | - execute("network", "create", "vagrantbr0") | |
158 | + execute("network", "create", "vagrantbr0", "dns.mode=dynamic") | |
159 | 159 | end |
160 | 160 | end |
161 | 161 | @bridge |
... | ... | @@ -191,6 +191,10 @@ module Vagrant |
191 | 191 | end |
192 | 192 | end |
193 | 193 | |
194 | + def exec(*command) | |
195 | + execute("exec", @name, "--", *command) | |
196 | + end | |
197 | + | |
194 | 198 | # Taken from Virtualbox provider and modified in some parts. |
195 | 199 | # Execute the given subcommand for Lxc and return the output. |
196 | 200 | def execute(*command, &block) | ... | ... |
Please
register
or
login
to post a comment