Browse Source

add box specific bootstrap options in metadata.

master
Georg Hopp 9 years ago
parent
commit
c60e1bf073
  1. 3
      example_box/metadata.json
  2. 2
      gentoo.json
  3. BIN
      gentoo_001_lxd.box
  4. 0
      gentoo_box/README.md
  5. 23
      gentoo_box/metadata.json
  6. 0
      gentoo_box/vagrant.pub
  7. 3
      lib/vagrant/lxd/action.rb
  8. 40
      lib/vagrant/lxd/action/bootstrap.rb
  9. 6
      lib/vagrant/lxd/driver.rb

3
example_box/metadata.json

@ -1,3 +0,0 @@
{
"provider": "lxd"
}

2
gentoo.json

@ -9,7 +9,7 @@
"name": "lxd",
"url": "file:///data/ghopp/projects/vagrant/vagrant-lxd/gentoo_001_lxd.box",
"checksum_type": "sha1",
"checksum": "4f3d7bfe034fe9fb82179992fdc6803b6f96abfb"
"checksum": "9cf9ffd2c840680672a329a87abcd056b021d130"
}
]
}

BIN
gentoo_001_lxd.box

0
example_box/README.md → gentoo_box/README.md

23
gentoo_box/metadata.json

@ -0,0 +1,23 @@
{
"provider": "lxd",
"bootstrap": {
"hostname": {
"exec": [
["sed", "-i", "s/-lxc //", "/etc/init.d/hostname"],
["sed", "-i", "s/LXC_NAME/<%= hostname %>/", "/etc/conf.d/hostname"],
["sed", "-i", "s/<%= container %>/<%= hostname %>/", "/etc/hostname"],
["sed", "-i", "s/<%= container %>/<%= hostname %>/", "/etc/hosts"]
]
},
"packages": {
"exec": [
["emerge", "--update", "sudo"]
]
},
"sudo": {
"exec": [
["echo", "vagrant ALL=(ALL) NOPASSWD: ALL", ">>/etc/sudoers"]
]
}
}
}

0
example_box/vagrant.pub → gentoo_box/vagrant.pub

3
lib/vagrant/lxd/action.rb

@ -7,6 +7,7 @@ module Vagrant
module Lxd
module Action
action_root = Pathname.new(File.expand_path("../action", __FILE__))
autoload :Bootstrap, action_root.join("bootstrap")
autoload :Create, action_root.join("create")
autoload :EnsureImage, action_root.join("ensure_image")
autoload :EnsureSsh, action_root.join("ensure_ssh")
@ -31,11 +32,13 @@ module Vagrant
end
b.use action_start
b.use EnsureSsh
b.use Bootstrap
end
end
def self.action_start
Vagrant::Action::Builder.new.tap do |b|
b.use Bootstrap
b.use EnsureStarted
end
end

40
lib/vagrant/lxd/action/bootstrap.rb

@ -0,0 +1,40 @@
require 'erb'
module Vagrant
module Lxd
module Action
class Bootstrap
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::lxd::action::bootstrap")
end
def call(env)
driver = env[:machine].provider.driver
bs_data = env[:machine].box.metadata["bootstrap"]
bs_data.each do |name, actions|
env[:ui].info "--- Bootstrap #{name} ---", :prefix => false
actions.each do |action, data|
# right now I do not handle differnet actions just return if
# action is not "exec".
next if action != "exec"
container = driver.name
hostname = env[:machine].name
data.each do |d|
d.collect! { |element| ERB.new(element).result(binding) }
driver.exec(*d)
env[:ui].info "--- #{d.inspect} ---", :prefix => false
end
end
end
@app.call(env)
end
end
end
end
end
# vim: set et ts=2 sw=2:

6
lib/vagrant/lxd/driver.rb

@ -155,7 +155,7 @@ module Vagrant
begin
@bridge = YAML.load(execute("network", "show", "vagrantbr0"))
rescue
execute("network", "create", "vagrantbr0")
execute("network", "create", "vagrantbr0", "dns.mode=dynamic")
end
end
@bridge
@ -191,6 +191,10 @@ module Vagrant
end
end
def exec(*command)
execute("exec", @name, "--", *command)
end
# Taken from Virtualbox provider and modified in some parts.
# Execute the given subcommand for Lxc and return the output.
def execute(*command, &block)

Loading…
Cancel
Save