vagrant-lxc 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd1975bccf20eba75300c481bdf0278fe909151c
4
- data.tar.gz: 6d9d53e02972c5f080aec5f26a750066d695bd57
3
+ metadata.gz: 0a4f7310beee8c22199a005050da4b4e7ec6d4ce
4
+ data.tar.gz: 8a821d1fd168ca8b76ceb56842c919140f411e75
5
5
  SHA512:
6
- metadata.gz: 7e7803f41a9bb9b45c2656e38711a7180b700f5e11d96d07a2b28c04009f3fc3fc72f63c985a6ade6af446914f7a2e0aa09308d7cbddfa90b24bc03fd88ad3ea
7
- data.tar.gz: 3e5ad8c62617b4e385773ff4fec76b14005c53304e4302bd487094cdd77bc0838bc47cbbfec5c4dc9d2b3094111ac4336e157fbffacc736e168cad0c75fc981d
6
+ metadata.gz: a60f7cc7e0a0539f779bb8a3f5c957521d59d43692cb56c511713f60d47d995e951398a83c5e87460842daffbae1e26d438534361881d0bac2c78b411a6c5824
7
+ data.tar.gz: 6f464caf8224f223e234eff0b1346336b7d27044d8dd7f242e5abdf33d484d57121954d44602826ea2c4682910575d9573ed771cefbe1b7591c7aab34c3e31bc
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## 0.1.0
2
+
3
+ - Support for chef added to base quantal64 box
4
+ - Puppet upgraded to 3.1.1 on base quantal64 box
5
+ - Port forwarding support added [#6](https://github.com/fgrehm/vagrant-lxc/issues/6)
6
+
7
+ ## Previous
8
+
9
+ The changelog began with version 0.1.0 so any changes prior to that
10
+ can be seen by checking the tagged releases and reading git commit
11
+ messages.
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  GIT
2
2
  remote: https://github.com/mitchellh/vagrant.git
3
- revision: 327ca544efdd6a0d0988509152a369fdb09c904d
3
+ revision: 87613ec9392d4660ffcb1d5755307136c06af08c
4
4
  specs:
5
- vagrant (1.1.1.dev)
5
+ vagrant (1.1.4)
6
6
  childprocess (~> 0.3.7)
7
7
  erubis (~> 2.7.0)
8
8
  i18n (~> 0.6.0)
9
9
  json (>= 1.5.1, < 1.8.0)
10
10
  log4r (~> 1.1.9)
11
- net-scp (~> 1.0.4)
12
- net-ssh (~> 2.2.2)
11
+ net-scp (~> 1.1.0)
12
+ net-ssh (~> 2.6.6)
13
13
 
14
14
  PATH
15
15
  remote: .
16
16
  specs:
17
- vagrant-lxc (0.0.3.dev)
17
+ vagrant-lxc (0.1.0)
18
18
 
19
19
  GEM
20
20
  remote: https://rubygems.org/
@@ -24,7 +24,7 @@ GEM
24
24
  coderay (1.0.9)
25
25
  diff-lcs (1.2.1)
26
26
  erubis (2.7.0)
27
- ffi (1.4.0)
27
+ ffi (1.6.0)
28
28
  guard (1.6.2)
29
29
  listen (>= 0.6.0)
30
30
  lumberjack (>= 1.0.2)
@@ -36,45 +36,45 @@ GEM
36
36
  guard (~> 1.1)
37
37
  guard-ctags-bundler (0.1.6)
38
38
  guard (>= 1.1)
39
- guard-rspec (2.5.0)
39
+ guard-rspec (2.5.1)
40
40
  guard (>= 1.1)
41
41
  rspec (~> 2.11)
42
42
  i18n (0.6.4)
43
43
  json (1.7.7)
44
44
  listen (0.7.3)
45
45
  log4r (1.1.10)
46
- lumberjack (1.0.2)
46
+ lumberjack (1.0.3)
47
47
  method_source (0.8.1)
48
- multi_json (1.6.1)
49
- net-scp (1.0.4)
50
- net-ssh (>= 1.99.1)
51
- net-ssh (2.2.2)
48
+ multi_json (1.7.2)
49
+ net-scp (1.1.0)
50
+ net-ssh (>= 2.6.5)
51
+ net-ssh (2.6.6)
52
52
  pry (0.9.12)
53
53
  coderay (~> 1.0.5)
54
54
  method_source (~> 0.8)
55
55
  slop (~> 3.4)
56
- rake (10.0.3)
56
+ rake (10.0.4)
57
57
  rb-inotify (0.9.0)
58
58
  ffi (>= 0.5.0)
59
59
  rspec (2.13.0)
60
60
  rspec-core (~> 2.13.0)
61
61
  rspec-expectations (~> 2.13.0)
62
62
  rspec-mocks (~> 2.13.0)
63
- rspec-core (2.13.0)
63
+ rspec-core (2.13.1)
64
64
  rspec-expectations (2.13.0)
65
65
  diff-lcs (>= 1.1.3, < 2.0)
66
66
  rspec-fire (1.1.3)
67
67
  rspec (~> 2.11)
68
68
  rspec-mocks (2.13.0)
69
- rspec-spies (2.1.3)
69
+ rspec-spies (2.1.4)
70
70
  rspec (~> 2.0)
71
71
  simplecov (0.7.1)
72
72
  multi_json (~> 1.0)
73
73
  simplecov-html (~> 0.7.1)
74
74
  simplecov-html (0.7.1)
75
- slop (3.4.3)
75
+ slop (3.4.4)
76
76
  terminal-table (1.4.5)
77
- thor (0.17.0)
77
+ thor (0.18.0)
78
78
 
79
79
  PLATFORMS
80
80
  ruby
data/README.md CHANGED
@@ -1,29 +1,28 @@
1
- # vagrant-lxc
1
+ # vagrant-lxc [![Build Status](https://travis-ci.org/fgrehm/vagrant-lxc.png?branch=master)](https://travis-ci.org/fgrehm/vagrant-lxc) [![Gem Version](https://badge.fury.io/rb/vagrant-lxc.png)](http://badge.fury.io/rb/vagrant-lxc) [![Code Climate](https://codeclimate.com/github/fgrehm/vagrant-lxc.png)](https://codeclimate.com/github/fgrehm/vagrant-lxc)
2
2
 
3
- [![Build Status](https://travis-ci.org/fgrehm/vagrant-lxc.png?branch=master)](https://travis-ci.org/fgrehm/vagrant-lxc)
4
-
5
- Highly experimental Linux Containers support for Vagrant 1.1.
3
+ Experimental Linux Containers support for Vagrant > 1.1.
6
4
 
7
5
 
8
6
  ## Dependencies
9
7
 
10
- Vagrant >= 1.1.0, the `lxc` package and a Kernel [higher than 3.5.0-17.28](#help-im-unable-to-restart-containers),
8
+ Vagrant >= 1.1.0, `lxc` and `redir` packages and a Kernel [higher than 3.5.0-17.28](#help-im-unable-to-restart-containers),
11
9
  which on Ubuntu 12.10 means something like:
12
10
 
13
11
  ```
14
12
  sudo apt-get update && sudo apt-get dist-upgrade
15
- sudo apt-get install lxc
16
- wget "http://files.vagrantup.com/packages/67bd4d30f7dbefa7c0abc643599f0244986c38c8/vagrant_`uname -m`.deb" -O /tmp/vagrant.deb
13
+ sudo apt-get install lxc redir
14
+ wget "http://files.vagrantup.com/packages/87613ec9392d4660ffcb1d5755307136c06af08c/vagrant_`uname -m`.deb" -O /tmp/vagrant.deb
17
15
  sudo dpkg -i /tmp/vagrant.deb
18
16
  ```
19
17
 
20
18
 
21
- ## What is currently supported?
19
+ ## What is currently supported? (v0.1.0)
22
20
 
23
21
  * Vagrant's `up`, `halt`, `reload`, `destroy`, and `ssh` commands
24
22
  * Shared folders
25
- * Provisioning with shell scripts and puppet (should work with chef but I [haven't had the chance](https://github.com/fgrehm/vagrant-lxc/issues/37) to set it up on the base box)
23
+ * Provisioning
26
24
  * Setting container's host name
25
+ * Port forwarding
27
26
 
28
27
  *Please refer to the [closed issues](https://github.com/fgrehm/vagrant-lxc/issues?labels=&milestone=&page=1&state=closed)
29
28
  for the most up to date list.*
@@ -31,11 +30,13 @@ for the most up to date list.*
31
30
 
32
31
  ## Current limitations
33
32
 
34
- * Port forwarding does not work [yet](https://github.com/fgrehm/vagrant-lxc/issues/6)
33
+ * Port forwarding collision detection
35
34
  * A hell lot of `sudo`s
36
35
  * Only a [single ubuntu box supported](boxes), I'm still [figuring out what should go
37
36
  on the .box file](https://github.com/fgrehm/vagrant-lxc/issues/4)
38
37
  * "[works on my machine](https://github.com/fgrehm/vagrant-lxc/issues/20)" (TM)
38
+ * [Does not tell you if dependencies are not met](https://github.com/fgrehm/vagrant-lxc/issues/11)
39
+ (will probably just throw up some random error)
39
40
  * + bunch of other [core features](https://github.com/fgrehm/vagrant-lxc/issues?labels=core&milestone=&page=1&state=open)
40
41
  and some known [bugs](https://github.com/fgrehm/vagrant-lxc/issues?labels=bug&page=1&state=open)
41
42
 
@@ -51,9 +52,11 @@ vagrant plugin install vagrant-lxc
51
52
  After that you can create a `Vagrantfile` like the one below and run `vagrant up --provider=lxc`:
52
53
 
53
54
  ```ruby
55
+ Vagrant.require_plugin 'vagrant-lxc'
56
+
54
57
  Vagrant.configure("2") do |config|
55
58
  config.vm.box = "lxc-quantal64"
56
- config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-03-10.box'
59
+ config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-03-26.box'
57
60
 
58
61
  # Share an additional folder to the guest Container. The first argument
59
62
  # is the path on the host to the actual folder. The second argument is
@@ -3,6 +3,7 @@
3
3
  # This is the code extracted from /usr/share/lxc/templates/lxc-ubuntu
4
4
  # that comes with Ubuntu 12.10 which is responsible for downloading the
5
5
  # rootfs files / packages
6
+ # It also installs puppet and chef on the container
6
7
 
7
8
  set -e
8
9
 
@@ -21,8 +22,8 @@ cleanup()
21
22
  write_sourceslist()
22
23
  {
23
24
  # $1 => path to the rootfs
24
- # $2 => architecture we want to add
25
25
 
26
+ # TODO: Mirrors sometimes are giving us some 404s
26
27
  MIRROR=${MIRROR:-mirror://mirrors.ubuntu.com/mirrors.txt}
27
28
  SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.ubuntu.com/ubuntu}
28
29
 
@@ -35,7 +36,7 @@ EOF
35
36
 
36
37
  download_ubuntu()
37
38
  {
38
- packages=vim,ssh,curl,wget,bash-completion,manpages,puppet
39
+ packages=vim,ssh,curl,wget,bash-completion,manpages,man-db,psmisc
39
40
  echo "installing packages: $packages"
40
41
 
41
42
  trap cleanup EXIT SIGHUP SIGINT SIGTERM
@@ -101,3 +102,19 @@ if [ -d "${cache}/rootfs-${arch}" ]; then
101
102
  fi
102
103
 
103
104
  download_ubuntu $cache $arch $release
105
+
106
+ rootfs="${cache}/rootfs-${arch}"
107
+
108
+ echo "installing puppet"
109
+ wget http://apt.puppetlabs.com/puppetlabs-release-precise.deb -O "${rootfs}/tmp/puppetlabs-release-${release}.deb"
110
+ chroot $rootfs dpkg -i "/tmp/puppetlabs-release-${release}.deb"
111
+ chroot $rootfs apt-get update
112
+ chroot $rootfs apt-get install puppet -y
113
+
114
+ echo "installing chef"
115
+ cat > $rootfs/tmp/install-chef.sh << EOF
116
+ #!/bin/sh
117
+ curl -L https://www.opscode.com/chef/install.sh -k | sudo bash
118
+ EOF
119
+ chmod +x $rootfs/tmp/install-chef.sh
120
+ chroot $rootfs /tmp/install-chef.sh
@@ -1,7 +1,7 @@
1
1
  # -*- mode: ruby -*-
2
2
  # vi: set ft=ruby :
3
3
 
4
- def local_cache(box_name)
4
+ def local_apt_cache(box_name)
5
5
  cache_dir = File.join(File.expand_path(Vagrant::Environment::DEFAULT_HOME),
6
6
  'cache',
7
7
  'apt',
@@ -11,6 +11,16 @@ def local_cache(box_name)
11
11
  cache_dir
12
12
  end
13
13
 
14
+ def local_gem_cache(box_name)
15
+ cache_dir = File.join(File.expand_path(Vagrant::Environment::DEFAULT_HOME),
16
+ 'cache',
17
+ 'gems',
18
+ 'source',
19
+ box_name)
20
+ FileUtils.mkdir_p(cache_dir) unless File.exists? cache_dir
21
+ cache_dir
22
+ end
23
+
14
24
  Vagrant.require_plugin 'vagrant-lxc'
15
25
 
16
26
  Vagrant.configure("2") do |config|
@@ -18,28 +28,29 @@ Vagrant.configure("2") do |config|
18
28
 
19
29
  config.vm.synced_folder "../", "/vagrant", name: 'vagrant-root'
20
30
 
21
- cache_dir = local_cache(config.vm.box)
22
- config.vm.synced_folder cache_dir, "/var/cache/apt/archives", name: "vagrant-cache"
31
+ cache_dir = local_apt_cache(config.vm.box)
32
+ config.vm.synced_folder cache_dir, "/var/cache/apt/archives", name: "vagrant-apt-cache"
33
+
34
+ cache_dir = local_gem_cache(config.vm.box)
35
+ config.vm.synced_folder cache_dir, "/home/vagrant/gems/cache", name: "vagrant-gem-cache"
23
36
 
24
37
  config.vm.define :vbox do |vb_config|
25
38
  vb_config.vm.box_url = "https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box"
26
39
  vb_config.vm.hostname = 'vbox'
27
40
 
28
41
  vb_config.vm.provider :virtualbox do |vb|
29
- # Configure VM to use 1.5gb of ram and 3 cpus
42
+ # Configure VM to use 1.5gb of ram and 2 cpus
30
43
  vb.customize [
31
44
  "modifyvm", :id,
32
45
  "--memory", '1536',
33
- "--cpus", '4'
46
+ "--cpus", '2'
34
47
  ]
35
48
  end
36
-
37
- vb_config.vm.provision :shell, :path => 'shell-provisioning/upgrade-kernel'
38
49
  end
39
50
 
40
51
  config.vm.define :lxc do |lxc_config|
41
52
  lxc_config.vm.hostname = 'lxc-dev-box'
42
- lxc_config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-03-10.box'
53
+ lxc_config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-03-26.box'
43
54
 
44
55
  lxc_config.vm.provider :lxc do |lxc|
45
56
  # Required to boot nested containers
@@ -47,6 +58,8 @@ Vagrant.configure("2") do |config|
47
58
  end
48
59
  end
49
60
 
61
+ config.vm.provision :shell, :path => 'shell-provisioning/upgrade-kernel'
62
+
50
63
  config.vm.provision :puppet do |puppet|
51
64
  puppet.manifests_path = "."
52
65
  puppet.manifest_file = "site.pp"
data/development/site.pp CHANGED
@@ -20,7 +20,8 @@ exec {
20
20
 
21
21
  # Install dependencies
22
22
  package {
23
- [ 'libffi-dev', 'bsdtar', 'exuberant-ctags', 'ruby1.9.1-dev', 'htop', 'git', 'build-essential' ]:
23
+ [ 'libffi-dev', 'bsdtar', 'exuberant-ctags', 'ruby1.9.1-dev', 'htop', 'git',
24
+ 'build-essential', 'redir' ]:
24
25
  ensure => 'installed'
25
26
  ;
26
27
 
data/example/Vagrantfile CHANGED
@@ -15,7 +15,7 @@ Vagrant.require_plugin 'vagrant-lxc'
15
15
 
16
16
  Vagrant.configure("2") do |config|
17
17
  config.vm.box = "quantal64"
18
- config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-03-10.box'
18
+ config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-03-26.box'
19
19
  config.vm.hostname = 'lxc-quantal64'
20
20
 
21
21
  config.vm.synced_folder "/tmp", "/vagrant_data"
@@ -0,0 +1,47 @@
1
+ module Vagrant
2
+ module LXC
3
+ module Action
4
+ class ClearForwardedPorts
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new("vagrant::lxc::action::clear_forwarded_ports")
8
+ end
9
+
10
+ def call(env)
11
+ @env = env
12
+
13
+ if redir_pids.any?
14
+ env[:ui].info I18n.t("vagrant.actions.vm.clear_forward_ports.deleting")
15
+ redir_pids.each do |pid|
16
+ next unless is_redir_pid?(pid)
17
+ @logger.debug "Killing pid #{pid}"
18
+ system "sudo pkill -9 -P #{pid}"
19
+ end
20
+
21
+ remove_redir_pids
22
+ end
23
+
24
+ @app.call env
25
+ end
26
+
27
+ protected
28
+
29
+ def redir_pids
30
+ @redir_pids = Dir[@env[:machine].data_dir.join('pids').to_s + "/redir_*.pid"].map do |file|
31
+ File.read(file).strip.chomp
32
+ end
33
+ end
34
+
35
+ def is_redir_pid?(pid)
36
+ `ps -o cmd= #{pid}`.strip.chomp =~ /redir/
37
+ end
38
+
39
+ def remove_redir_pids
40
+ Dir[@env[:machine].data_dir.join('pids').to_s + "/redir_*.pid"].each do |file|
41
+ File.delete file
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,83 @@
1
+ module Vagrant
2
+ module LXC
3
+ module Action
4
+ class ForwardPorts
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new("vagrant::lxc::action::forward_ports")
8
+ end
9
+
10
+ def call(env)
11
+ @env = env
12
+
13
+ # Continue, we need the VM to be booted in order to grab its IP
14
+ @app.call env
15
+
16
+ # Get the ports we're forwarding
17
+ env[:forwarded_ports] = compile_forwarded_ports(env[:machine].config)
18
+
19
+ # Warn if we're port forwarding to any privileged ports
20
+ env[:forwarded_ports].each do |fp|
21
+ if fp[:host] <= 1024
22
+ env[:ui].warn I18n.t("vagrant.actions.vm.forward_ports.privileged_ports")
23
+ break
24
+ end
25
+ end
26
+
27
+ env[:ui].info I18n.t("vagrant.actions.vm.forward_ports.forwarding")
28
+ forward_ports
29
+ end
30
+
31
+ def forward_ports
32
+ @container_ip = @env[:machine].provider.container.assigned_ip
33
+
34
+ @env[:forwarded_ports].each do |fp|
35
+ message_attributes = {
36
+ # TODO: Add support for multiple adapters
37
+ :adapter => 'eth0',
38
+ :guest_port => fp[:guest],
39
+ :host_port => fp[:host]
40
+ }
41
+
42
+ # TODO: Remove adapter from logging
43
+ @env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry",
44
+ message_attributes))
45
+
46
+ redir_pid = redirect_port(fp[:host], fp[:guest])
47
+ store_redir_pid(fp[:host], redir_pid)
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def compile_forwarded_ports(config)
54
+ mappings = {}
55
+
56
+ config.vm.networks.each do |type, options|
57
+ if type == :forwarded_port
58
+ mappings[options[:host]] = options
59
+ end
60
+ end
61
+
62
+ mappings.values
63
+ end
64
+
65
+ def redirect_port(host, guest)
66
+ redir_cmd = "sudo redir --laddr=127.0.0.1 --lport=#{host} --cport=#{guest} --caddr=#{@container_ip}"
67
+
68
+ @logger.debug "Forwarding port with `#{redir_cmd}`"
69
+ fork { exec redir_cmd }
70
+ end
71
+
72
+ def store_redir_pid(host_port, redir_pid)
73
+ data_dir = @env[:machine].data_dir.join('pids')
74
+ data_dir.mkdir unless data_dir.directory?
75
+
76
+ data_dir.join("redir_#{host_port}.pid").open('w') do |pid_file|
77
+ pid_file.write(redir_pid)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,13 +1,17 @@
1
+ # TODO: Remove base action
1
2
  require 'vagrant-lxc/action/base_action'
2
3
 
4
+ # TODO: Use require_relative
3
5
  require 'vagrant-lxc/action/boot'
4
6
  require 'vagrant-lxc/action/check_created'
5
7
  require 'vagrant-lxc/action/check_running'
8
+ require 'vagrant-lxc/action/clear_forwarded_ports'
6
9
  require 'vagrant-lxc/action/create'
7
10
  require 'vagrant-lxc/action/created'
8
11
  require 'vagrant-lxc/action/destroy'
9
12
  require 'vagrant-lxc/action/disconnect'
10
13
  require 'vagrant-lxc/action/forced_halt'
14
+ require 'vagrant-lxc/action/forward_ports'
11
15
  require 'vagrant-lxc/action/handle_box_metadata'
12
16
  require 'vagrant-lxc/action/is_running'
13
17
  require 'vagrant-lxc/action/network'
@@ -21,9 +25,10 @@ module Vagrant
21
25
  # machine back up with the new configuration.
22
26
  def self.action_reload
23
27
  Vagrant::Action::Builder.new.tap do |b|
24
- # b.use CheckLXC
28
+ # b.use CheckDependencies
25
29
  b.use Vagrant::Action::Builtin::Call, Created do |env1, b2|
26
30
  if !env1[:result]
31
+ # TODO: Implement our own MessageNotCreated
27
32
  b2.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotCreated
28
33
  next
29
34
  end
@@ -52,10 +57,10 @@ module Vagrant
52
57
  # b.use ClearSharedFolders
53
58
  b.use ShareFolders
54
59
  b.use Network
55
- # b.use ForwardPorts
56
60
  b.use Vagrant::Action::Builtin::SetHostname
57
61
  # b.use SaneDefaults
58
62
  # b.use Customize
63
+ b.use ForwardPorts
59
64
  b.use Boot
60
65
  end
61
66
  end
@@ -63,16 +68,18 @@ module Vagrant
63
68
  # This action just runs the provisioners on the machine.
64
69
  def self.action_provision
65
70
  Vagrant::Action::Builder.new.tap do |b|
66
- # b.use CheckLXC
71
+ # b.use CheckDependencies
67
72
  b.use Vagrant::Action::Builtin::ConfigValidate
68
73
  b.use Vagrant::Action::Builtin::Call, Created do |env1, b2|
69
74
  if !env1[:result]
75
+ # TODO: Implement our own MessageNotCreated
70
76
  b2.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotCreated
71
77
  next
72
78
  end
73
79
 
74
80
  b2.use Vagrant::Action::Builtin::Call, IsRunning do |env2, b3|
75
81
  if !env2[:result]
82
+ # TODO: Implement our own MessageNotRunning
76
83
  b3.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotRunning
77
84
  next
78
85
  end
@@ -88,7 +95,7 @@ module Vagrant
88
95
  # A precondition of this action is that the container exists.
89
96
  def self.action_start
90
97
  Vagrant::Action::Builder.new.tap do |b|
91
- # b.use CheckLXC
98
+ # b.use CheckDependencies
92
99
  b.use Vagrant::Action::Builtin::ConfigValidate
93
100
  b.use Vagrant::Action::Builtin::Call, IsRunning do |env, b2|
94
101
  # If the VM is running, then our work here is done, exit
@@ -103,7 +110,7 @@ module Vagrant
103
110
  # container, configuring metadata, and booting.
104
111
  def self.action_up
105
112
  Vagrant::Action::Builder.new.tap do |b|
106
- # b.use CheckLXC
113
+ # b.use CheckDependencies
107
114
  b.use Vagrant::Action::Builtin::ConfigValidate
108
115
  b.use Vagrant::Action::Builtin::Call, Created do |env, b2|
109
116
  # If the VM is NOT created yet, then do the setup steps
@@ -121,16 +128,19 @@ module Vagrant
121
128
  # the virtual machine, gracefully or by force.
122
129
  def self.action_halt
123
130
  Vagrant::Action::Builder.new.tap do |b|
124
- # b.use CheckLXC
131
+ # b.use CheckDependencies
125
132
  b.use Vagrant::Action::Builtin::Call, Created do |env, b2|
126
133
  if env[:result]
134
+ # TODO: If vagrant >=...
127
135
  b2.use Disconnect
136
+ b2.use ClearForwardedPorts
128
137
  b2.use Vagrant::Action::Builtin::Call, Vagrant::Action::Builtin::GracefulHalt, :stopped, :running do |env2, b3|
129
138
  if !env2[:result] && env2[:machine].provider.state.running?
130
139
  b3.use ForcedHalt
131
140
  end
132
141
  end
133
142
  else
143
+ # TODO: Implement our own MessageNotCreated
134
144
  b2.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotCreated
135
145
  end
136
146
  end
@@ -141,9 +151,10 @@ module Vagrant
141
151
  # freeing the resources of the underlying virtual machine.
142
152
  def self.action_destroy
143
153
  Vagrant::Action::Builder.new.tap do |b|
144
- # b.use CheckLXC
154
+ # b.use CheckDependencies
145
155
  b.use Vagrant::Action::Builtin::Call, Created do |env1, b2|
146
156
  if !env1[:result]
157
+ # TODO: Implement our own MessageNotCreated
147
158
  b2.use VagrantPlugins::ProviderVirtualBox::Action::MessageNotCreated
148
159
  next
149
160
  end
@@ -167,7 +178,7 @@ module Vagrant
167
178
  # This is the action that will exec into an SSH shell.
168
179
  def self.action_ssh
169
180
  Vagrant::Action::Builder.new.tap do |b|
170
- # b.use CheckLXC
181
+ # b.use CheckDependencies
171
182
  b.use CheckCreated
172
183
  # b.use CheckAccessible
173
184
  b.use CheckRunning
@@ -178,7 +189,7 @@ module Vagrant
178
189
  # This is the action that will run a single SSH command.
179
190
  def self.action_ssh_run
180
191
  Vagrant::Action::Builder.new.tap do |b|
181
- # b.use CheckLXC
192
+ # b.use CheckDependencies
182
193
  b.use CheckCreated
183
194
  # b.use CheckAccessible
184
195
  b.use CheckRunning
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module LXC
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -1,17 +1,24 @@
1
1
  if ENV['COVERAGE']
2
2
  require 'simplecov'
3
3
  SimpleCov.start do
4
- # This can probably go away once we stop using vagrant as submodule
5
4
  add_filter { |source_file| source_file.filename =~ /\/spec\/support/ }
6
5
  end
7
6
  end
8
7
 
9
8
  require 'bundler/setup'
10
9
 
10
+ require 'i18n'
11
+
11
12
  require 'rspec-spies'
12
13
 
13
14
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
14
15
 
16
+ # If we should verify constant names, eager loads
17
+ if ENV['VERIFY_CONSTANT_NAMES']
18
+ require 'vagrant-lxc/plugin'
19
+ require 'vagrant-lxc/provider'
20
+ end
21
+
15
22
  require 'rspec/fire'
16
23
  RSpec::Fire.configure do |config|
17
24
  config.verify_constant_names = ENV['VERIFY_CONSTANT_NAMES'] == '1'
@@ -8,6 +8,12 @@ module UnitExampleGroup
8
8
  Object.any_instance.stub(:`) { |*args, &block|
9
9
  UnitExampleGroup.prevent_system_calls(*args, &block)
10
10
  }
11
+ Object.any_instance.stub(:exec) { |*args, &block|
12
+ UnitExampleGroup.prevent_system_calls(*args, &block)
13
+ }
14
+ Object.any_instance.stub(:fork) { |*args, &block|
15
+ UnitExampleGroup.prevent_system_calls(*args, &block)
16
+ }
11
17
  require 'vagrant/util/subprocess'
12
18
  Vagrant::Util::Subprocess.stub(:execute) { |*args, &block|
13
19
  UnitExampleGroup.prevent_system_calls(*args, &block)
@@ -22,6 +28,7 @@ module UnitExampleGroup
22
28
  Somehow your code under test is trying to execute a command on your system,
23
29
  please stub it out or move your spec code to an acceptance spec.
24
30
 
31
+ Block: #{block.inspect}
25
32
  Command: "#{args.join(' ')}"
26
33
  MSG
27
34
  end
@@ -0,0 +1,42 @@
1
+ require 'unit_helper'
2
+
3
+ require 'vagrant-lxc/action/clear_forwarded_ports'
4
+
5
+ describe Vagrant::LXC::Action::ClearForwardedPorts do
6
+ let(:app) { mock(:app, call: true) }
7
+ let(:env) { {machine: machine, ui: stub(info: true)} }
8
+ let(:machine) { mock(:machine, data_dir: data_dir) }
9
+ let!(:data_dir) { Pathname.new(Dir.mktmpdir) }
10
+ let(:pids_dir) { data_dir.join('pids') }
11
+ let(:pid) { 'a-pid' }
12
+ let(:pid_cmd) { 'redir' }
13
+
14
+ subject { described_class.new(app, env) }
15
+
16
+ before do
17
+ pids_dir.mkdir
18
+ pids_dir.join('redir_1234.pid').open('w') { |f| f.write(pid) }
19
+ subject.stub(system: true, :` => pid_cmd)
20
+ subject.call(env)
21
+ end
22
+
23
+ after { FileUtils.rm_rf data_dir.to_s }
24
+
25
+ it 'removes all files under pid directory' do
26
+ Dir[pids_dir.to_s + "/redir_*.pid"].should be_empty
27
+ end
28
+
29
+ context 'with a valid redir pid' do
30
+ it 'kills known processes' do
31
+ subject.should have_received(:system).with("sudo pkill -9 -P #{pid}")
32
+ end
33
+ end
34
+
35
+ context 'with an invalid pid' do
36
+ let(:pid_cmd) { 'sudo ls' }
37
+
38
+ it 'does not kill the process' do
39
+ subject.should_not have_received(:system).with("sudo pkill -9 -P #{pid}")
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ require 'unit_helper'
2
+
3
+ require 'vagrant-lxc/action/forward_ports'
4
+
5
+ describe Vagrant::LXC::Action::ForwardPorts do
6
+ let(:app) { mock(:app, call: true) }
7
+ let(:env) { {machine: machine, ui: stub(info: true)} }
8
+ let(:machine) { mock(:machine) }
9
+ let!(:data_dir) { Pathname.new(Dir.mktmpdir) }
10
+ let(:networks) { [[:other_config, {}], [:forwarded_port, {guest: guest_port, host: host_port}]] }
11
+ let(:host_port) { 8080 }
12
+ let(:guest_port) { 80 }
13
+ let(:provider) { fire_double('Vagrant::LXC::Provider', container: container) }
14
+ let(:container) { fire_double('Vagrant::LXC::Container', assigned_ip: container_ip) }
15
+ let(:container_ip) { '10.0.1.234' }
16
+ let(:pid) { 'a-pid' }
17
+
18
+ subject { described_class.new(app, env) }
19
+
20
+ before do
21
+ machine.stub_chain(:config, :vm, :networks).and_return(networks)
22
+ machine.stub(provider: provider, data_dir: data_dir)
23
+
24
+ subject.stub(exec: true)
25
+ subject.stub(:fork) { |&block| block.call; pid }
26
+ subject.call(env)
27
+ end
28
+
29
+ after { FileUtils.rm_rf data_dir.to_s }
30
+
31
+ it 'forwards ports using redir' do
32
+ subject.should have_received(:exec).with(
33
+ "sudo redir --laddr=127.0.0.1 --lport=#{host_port} --cport=#{guest_port} --caddr=#{container_ip}"
34
+ )
35
+ end
36
+
37
+ it "stores redir pids on machine's data dir" do
38
+ pid_file = data_dir.join('pids', "redir_#{host_port}.pid").read
39
+ pid_file.should == pid
40
+ end
41
+ end
data/tasks/boxes.rake CHANGED
@@ -12,6 +12,7 @@ namespace :boxes do
12
12
  sh 'rm -f boxes/quantal64/rootfs.tar.gz'
13
13
  sh 'cd boxes/quantal64 && sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs-amd64/*'
14
14
  sh "cd boxes/quantal64 && sudo chown #{ENV['USER']}:#{ENV['USER']} rootfs.tar.gz && tar -czf ../output/lxc-quantal64.box ./* --exclude=rootfs-amd64 --exclude=download-ubuntu"
15
+ sh 'cd boxes/quantal64 && sudo rm -rf rootfs-amd64'
15
16
  end
16
17
  end
17
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-lxc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Rehm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-19 00:00:00.000000000 Z
11
+ date: 2013-03-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Linux Containers provider for Vagrant
14
14
  email:
@@ -21,6 +21,7 @@ files:
21
21
  - .rspec
22
22
  - .travis.yml
23
23
  - .vimrc
24
+ - CHANGELOG.md
24
25
  - Gemfile
25
26
  - Gemfile.lock
26
27
  - Guardfile
@@ -45,11 +46,13 @@ files:
45
46
  - lib/vagrant-lxc/action/boot.rb
46
47
  - lib/vagrant-lxc/action/check_created.rb
47
48
  - lib/vagrant-lxc/action/check_running.rb
49
+ - lib/vagrant-lxc/action/clear_forwarded_ports.rb
48
50
  - lib/vagrant-lxc/action/create.rb
49
51
  - lib/vagrant-lxc/action/created.rb
50
52
  - lib/vagrant-lxc/action/destroy.rb
51
53
  - lib/vagrant-lxc/action/disconnect.rb
52
54
  - lib/vagrant-lxc/action/forced_halt.rb
55
+ - lib/vagrant-lxc/action/forward_ports.rb
53
56
  - lib/vagrant-lxc/action/handle_box_metadata.rb
54
57
  - lib/vagrant-lxc/action/is_running.rb
55
58
  - lib/vagrant-lxc/action/network.rb
@@ -66,6 +69,8 @@ files:
66
69
  - spec/fixtures/sample-ifconfig-output
67
70
  - spec/spec_helper.rb
68
71
  - spec/support/unit_example_group.rb
72
+ - spec/unit/action/clear_forwarded_ports_spec.rb
73
+ - spec/unit/action/forward_ports_spec.rb
69
74
  - spec/unit/action/handle_box_metadata_spec.rb
70
75
  - spec/unit/container/cli_spec.rb
71
76
  - spec/unit/container_spec.rb
@@ -101,6 +106,8 @@ test_files:
101
106
  - spec/fixtures/sample-ifconfig-output
102
107
  - spec/spec_helper.rb
103
108
  - spec/support/unit_example_group.rb
109
+ - spec/unit/action/clear_forwarded_ports_spec.rb
110
+ - spec/unit/action/forward_ports_spec.rb
104
111
  - spec/unit/action/handle_box_metadata_spec.rb
105
112
  - spec/unit/container/cli_spec.rb
106
113
  - spec/unit/container_spec.rb