vagrant-lxc 0.6.3 → 0.6.4

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: 990ef5aede9667e2cb3b0abab7eb851da17d7b28
4
- data.tar.gz: 969e6045235f3d9e12e942f8ee10244c4c3a5834
3
+ metadata.gz: da07b6b0d3b29fc7b29cb7433180abc52e31a900
4
+ data.tar.gz: 8502aefc759fef3438c3d8ef6cc8ebcaa9385080
5
5
  SHA512:
6
- metadata.gz: fca22e79ad331aa2e7ae48bd9ccc13c7497b0a79cb83d4aa292ae74492bf70905734b2b564812644b8cf950d54b230b7025b4f50fe4340ea070c0f6d376d2f09
7
- data.tar.gz: d2a5421b294892a96bf8a777e35501a3b8a0e1b589bdf076f91982b8783357b79f9223cf1736c700291052c30856b1ab870f71aa3770504f299ff2f820648fc1
6
+ metadata.gz: 55d597dd781cc4d7d4c2e20a8ea666f166aa3dbbdf6f8b0ac7ba3ebf1c6fbfad054f086d4e02dcc320cafe983bf75f22cacaaae943fb3d4f82b4f75e48620ff4
7
+ data.tar.gz: 1907baa7cc4833b121b43a76320360cd6ea836ebc6c6ade118fd821ca9cc2ed89dbe58afd0c24590e2f84936f68205a840332fcef78c094b687aa578bd8664dc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [0.6.4](https://github.com/fgrehm/vagrant-lxc/compare/v0.6.3...v0.6.4) (Oct 27, 2013)
2
+
3
+ IMPROVEMENTS:
4
+
5
+ - Make `lxc-template` compatible with Ubuntu 13.10 [#150](https://github.com/fgrehm/vagrant-lxc/issues/150)
6
+
7
+ BUG FIXES:
8
+
9
+ - Fix force halt for hosts that do not have `lxc-shutdown` around (like Ubuntu 13.10) [#150](https://github.com/fgrehm/vagrant-lxc/issues/150)
10
+
1
11
  ## [0.6.3](https://github.com/fgrehm/vagrant-lxc/compare/v0.6.2...v0.6.3) (Oct 12, 2013)
2
12
 
3
13
  IMPROVEMENTS:
data/Gemfile.lock CHANGED
@@ -26,7 +26,7 @@ GIT
26
26
  PATH
27
27
  remote: .
28
28
  specs:
29
- vagrant-lxc (0.6.3)
29
+ vagrant-lxc (0.6.4)
30
30
 
31
31
  GEM
32
32
  remote: https://rubygems.org/
@@ -0,0 +1,159 @@
1
+ #!/bin/bash
2
+
3
+ # set -x
4
+ set -e
5
+
6
+ # Script used to build OpenMandriva base vagrant-lxc containers, currently limited to
7
+ # host's arch
8
+ #
9
+ # USAGE:
10
+ # $ cd boxes && sudo ./build-openmandriva-box.sh OPENMANDRIVA_RELEASE BOX_ARCH
11
+ #
12
+ # TODO: scripts for install CHEF, PUPPET, SALT, BABUSHKA
13
+ # To enable Chef or any other configuration management tool pass '1' to the
14
+ # corresponding env var:
15
+ # $ CHEF=1 sudo -E ./build-openmandriva-box.sh OPENMANDRIVA_RELEASE BOX_ARCH
16
+ # $ PUPPET=1 sudo -E ./build-openmandriva-box.sh OPENMANDRIVA_RELEASE BOX_ARCH
17
+ # $ SALT=1 sudo -E ./build-openmandriva-box.sh OPENMANDRIVA_RELEASE BOX_ARCH
18
+ # $ BABUSHKA=1 sudo -E ./build-openmandriva-box.sh OPENMANDRIVA_RELEASE BOX_ARCH
19
+
20
+ ##################################################################################
21
+ # 0 - Initial setup and sanity checks
22
+
23
+ TODAY=$(date -u +"%Y-%m-%d")
24
+ NOW=$(date -u)
25
+ RELEASE=${1:-"openmandriva2013.0"}
26
+ ARCH=${2:-"x86_64"}
27
+ PKG=vagrant-lxc-${RELEASE}-${ARCH}-${TODAY}.box
28
+ WORKING_DIR=/tmp/vagrant-lxc-${RELEASE}
29
+ VAGRANT_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"
30
+ ROOTFS=/var/lib/lxc/${RELEASE}-base/${RELEASE}-base/rootfs
31
+
32
+ # Providing '1' will enable these tools
33
+ CHEF=${CHEF:-0}
34
+ PUPPET=${PUPPET:-0}
35
+ SALT=${SALT:-0}
36
+ BABUSHKA=${BABUSHKA:-0}
37
+
38
+ # Path to files bundled with the box
39
+ CWD=`readlink -f .`
40
+ LXC_TEMPLATE=${CWD}/common/lxc-template-openmandriva
41
+ LXC_CONF=${CWD}/common/lxc.conf
42
+ METATADA_JSON=${CWD}/common/metadata.json
43
+
44
+ # Set up a working dir
45
+ mkdir -p $WORKING_DIR
46
+
47
+ if [ -f "${WORKING_DIR}/${PKG}" ]; then
48
+ echo "Found a box on ${WORKING_DIR}/${PKG} already!"
49
+ exit 1
50
+ fi
51
+
52
+ ##################################################################################
53
+ # 1 - Create the base container
54
+
55
+ if $(lxc-ls | grep -q "${RELEASE}-base"); then
56
+ echo "Base container already exists, please remove it with \`lxc-destroy -n ${RELEASE}-base\`!"
57
+ exit 1
58
+ else
59
+ export SUITE=$RELEASE
60
+ lxc-create -n ${RELEASE}-base -t openmandriva -- -R ${RELEASE} --arch ${ARCH}
61
+ fi
62
+
63
+
64
+ ######################################
65
+ # 2 - Fix some known issues
66
+
67
+ # Fixes some networking issues
68
+ cat /etc/resolv.conf > ${ROOTFS}/etc/resolv.conf
69
+
70
+ ##################################################################################
71
+ # 3 - Prepare vagrant user
72
+ chroot ${ROOTFS} su -c 'useradd --create-home -s /bin/bash vagrant'
73
+
74
+ # echo -n 'vagrant:vagrant' | chroot ${ROOTFS} chpasswd
75
+ chroot ${ROOTFS} su -c "echo -n 'vagrant:vagrant' | chpasswd"
76
+
77
+
78
+ ##################################################################################
79
+ # 4 - Setup SSH access and passwordless sudo
80
+
81
+ # Configure SSH access
82
+ mkdir -p ${ROOTFS}/home/vagrant/.ssh
83
+ echo $VAGRANT_KEY > ${ROOTFS}/home/vagrant/.ssh/authorized_keys
84
+ chroot ${ROOTFS} chown -R vagrant: /home/vagrant/.ssh
85
+
86
+ chroot ${ROOTFS} urpmi sudo --auto
87
+ chroot ${ROOTFS} usermod -a -G wheel vagrant
88
+
89
+ # Enable passwordless sudo for users under the "sudo" group
90
+ cp ${ROOTFS}/etc/sudoers{,.orig}
91
+ sed -i 's/Defaults requiretty/\# Defaults requiretty/' ${ROOTFS}/etc/sudoers
92
+ sed -i 's/\#%wheel/\%wheel/' ${ROOTFS}/etc/sudoers
93
+ sed -i 's/\# %wheel/\%wheel/' ${ROOTFS}/etc/sudoers
94
+ # sed -i -e \
95
+ # 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' \
96
+ # ${ROOTFS}/etc/sudoers
97
+
98
+
99
+ ##################################################################################
100
+ # 5 - Add some goodies and update packages
101
+
102
+ PACKAGES=(vim curl wget man bash-completion openssh-server openssh-clients tar)
103
+ chroot ${ROOTFS} urpmi ${PACKAGES[*]} --auto
104
+ chroot ${ROOTFS} urpmi.update -a
105
+
106
+
107
+ ##################################################################################
108
+ # 6 - Configuration management tools
109
+
110
+ if [ $CHEF = 1 ]; then
111
+ ./common/install-chef $ROOTFS
112
+ fi
113
+
114
+ if [ $PUPPET = 1 ]; then
115
+ ./common/install-puppet $ROOTFS
116
+ fi
117
+
118
+ if [ $SALT = 1 ]; then
119
+ ./common/install-salt $ROOTFS
120
+ fi
121
+
122
+ if [ $BABUSHKA = 1 ]; then
123
+ ./common/install-babushka $ROOTFS
124
+ fi
125
+
126
+
127
+ ##################################################################################
128
+ # 7 - Free up some disk space
129
+
130
+ rm -rf ${ROOTFS}/tmp/*
131
+ # chroot ${ROOTFS} urpmi clean metadata
132
+
133
+
134
+ ##################################################################################
135
+ # 8 - Build box package
136
+
137
+ # Compress container's rootfs
138
+ cd $(dirname $ROOTFS)
139
+ tar --numeric-owner -czf /tmp/vagrant-lxc-${RELEASE}/rootfs.tar.gz ./rootfs/*
140
+
141
+ # Prepare package contents
142
+ cd $WORKING_DIR
143
+ cp $LXC_TEMPLATE lxc-template
144
+ cp $LXC_CONF .
145
+ cp $METATADA_JSON .
146
+ chmod +x lxc-template
147
+ sed -i "s/<TODAY>/${NOW}/" metadata.json
148
+
149
+ # Vagrant box!
150
+ tar -czf $PKG ./*
151
+
152
+ chmod +rw ${WORKING_DIR}/${PKG}
153
+ mkdir -p ${CWD}/output
154
+ mv ${WORKING_DIR}/${PKG} ${CWD}/output
155
+
156
+ # Clean up after ourselves
157
+ rm -rf ${WORKING_DIR}
158
+
159
+ echo "The base box was built successfully to ${CWD}/output/${PKG}"
@@ -40,8 +40,8 @@ extract_rootfs()
40
40
  rootfs=$3
41
41
 
42
42
  echo "Extracting $tarball ..."
43
- mkdir -p $(dirname $rootfs)
44
- (cd `dirname $rootfs` && tar xfz $tarball)
43
+ mkdir -p $rootfs
44
+ (cd $rootfs && tar xfz $tarball --strip-components=2)
45
45
  return 0
46
46
  }
47
47
 
@@ -0,0 +1,225 @@
1
+ #!/bin/bash
2
+
3
+ # This is a modified version of /usr/share/lxc/templates/lxc-openmandriva
4
+ # that comes with OpenMandriva changed to suit vagrant-lxc needs
5
+
6
+ #
7
+ # template script for generating openmandriva container for LXC
8
+ #
9
+
10
+ #
11
+ # lxc: linux Container library
12
+
13
+ # Authors:
14
+ # Alexander Khryukin <alexander@mezon.ru>
15
+ # Vokhmin Alexey V <avokhmin@gmail.com>
16
+
17
+ # This library is free software; you can redistribute it and/or
18
+ # modify it under the terms of the GNU Lesser General Public
19
+ # License as published by the Free Software Foundation; either
20
+ # version 2.1 of the License, or (at your option) any later version.
21
+
22
+ # This library is distributed in the hope that it will be useful,
23
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ # Lesser General Public License for more details.
26
+
27
+ # You should have received a copy of the GNU Lesser General Public
28
+ # License along with this library; if not, write to the Free Software
29
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30
+
31
+
32
+ set -e
33
+
34
+ if [ -r /etc/default/lxc ]; then
35
+ . /etc/default/lxc
36
+ fi
37
+
38
+ extract_rootfs()
39
+ {
40
+ tarball=$1
41
+ arch=$2
42
+ rootfs=$3
43
+
44
+ echo "Extracting $tarball ..."
45
+ mkdir -p $(dirname $rootfs)
46
+ (cd `dirname $rootfs` && tar xfz $tarball)
47
+ return 0
48
+ }
49
+
50
+ install_openmandriva()
51
+ {
52
+ rootfs=$1
53
+ release=$2
54
+ tarball=$3
55
+ mkdir -p /var/lock/subsys/
56
+
57
+ (
58
+ flock -x 200
59
+ if [ $? -ne 0 ]; then
60
+ echo "Cache repository is busy."
61
+ return 1
62
+ fi
63
+
64
+ extract_rootfs $tarball $arch $rootfs
65
+ if [ $? -ne 0 ]; then
66
+ echo "Failed to copy rootfs"
67
+ return 1
68
+ fi
69
+
70
+ return 0
71
+
72
+ ) 200>/var/lock/subsys/lxc
73
+
74
+ return $?
75
+ }
76
+
77
+ copy_configuration()
78
+ {
79
+ path=$1
80
+ rootfs=$2
81
+ name=$3
82
+
83
+ grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
84
+
85
+ # if there is exactly one veth network entry, make sure it has an
86
+ # associated hwaddr.
87
+ nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
88
+ if [ $nics -eq 1 ]; then
89
+ grep -q "^lxc.network.hwaddr" $path/config || sed -i -e "/^lxc\.network\.type[ \t]*=[ \t]*veth/a lxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')" $path/config
90
+ fi
91
+
92
+ if [ $? -ne 0 ]; then
93
+ echo "Failed to add configuration"
94
+ return 1
95
+ fi
96
+
97
+ return 0
98
+ }
99
+
100
+ post_process()
101
+ {
102
+ rootfs=$1
103
+
104
+ # rmdir /dev/shm for containers that have /run/shm
105
+ # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
106
+ # get bind mounted to the host's /run/shm. So try to rmdir
107
+ # it, and in case that fails move it out of the way.
108
+ if [ ! -L $rootfs/dev/shm ] && [ -d $rootfs/run/shm ] && [ -e $rootfs/dev/shm ]; then
109
+ mv $rootfs/dev/shm $rootfs/dev/shm.bak
110
+ ln -s /run/shm $rootfs/dev/shm
111
+ fi
112
+ }
113
+
114
+ usage()
115
+ {
116
+ cat <<EOF
117
+ usage:
118
+ $1 -n|--name=<container_name>
119
+ [-p|--path=<path>] [-c|--clean] [-R|--release=<openmandriva2013.0/rosa2012.1/cooker/ release>]
120
+ [-4|--ipv4=<ipv4 address>] [-6|--ipv6=<ipv6 address>]
121
+ [-g|--gw=<gw address>] [-d|--dns=<dns address>]
122
+ [-P|--profile=<name of the profile>] [--rootfs=<path>]
123
+ [-A|--arch=<arch of the container>]
124
+ [-T|--tarball <tarball path>]
125
+ [-S|--auth-key <auth-key path>]
126
+ [-h|--help]
127
+ Mandatory args:
128
+ -n,--name container name, used to as an identifier for that container from now on
129
+ Optional args:
130
+ -p,--path path to where the container rootfs will be created, defaults to /var/lib/lxc. The container config will go under /var/lib/lxc in that case
131
+ -c,--clean clean the cache
132
+ -R,--release openmandriva2013.0/cooker/rosa2012.1 release for the new container. if the host is OpenMandriva, then it will default to the host's release.
133
+ -4,--ipv4 specify the ipv4 address to assign to the virtualized interface, eg. 192.168.1.123/24
134
+ -6,--ipv6 specify the ipv6 address to assign to the virtualized interface, eg. 2003:db8:1:0:214:1234:fe0b:3596/64
135
+ -g,--gw specify the default gw, eg. 192.168.1.1
136
+ -G,--gw6 specify the default gw, eg. 2003:db8:1:0:214:1234:fe0b:3596
137
+ -d,--dns specify the DNS server, eg. 192.168.1.2
138
+ -P,--profile Profile name is the file name in /etc/lxc/profiles contained packages name for install to cache.
139
+ -A,--arch Define what arch the container will be [i586,x86_64,armv7l,armv7hl]
140
+ ---rootfs rootfs path
141
+ -h,--help print this help
142
+ EOF
143
+ return 0
144
+ }
145
+
146
+ options=$(getopt -o hp:n:P:cR:4:6:g:d:A:S:T: -l help,rootfs:,path:,name:,profile:,clean:,release:,ipv4:,ipv6:,gw:,dns:,arch:,auth-key:,tarball: -- "$@")
147
+ if [ $? -ne 0 ]; then
148
+ usage $(basename $0)
149
+ exit 1
150
+ fi
151
+ eval set -- "$options"
152
+
153
+ # doesn't use
154
+ release=${release:-"cooker"}
155
+
156
+ hostarch=$(uname -m)
157
+ while true
158
+ do
159
+ case "$1" in
160
+ -h|--help) usage $0 && exit 0;;
161
+ -p|--path) path=$2; shift 2;;
162
+ --rootfs) rootfs_path=$2; shift 2;;
163
+ -n|--name) name=$2; shift 2;;
164
+ -P|--profile) profile=$2; shift 2;;
165
+ -c|--clean) clean=$2; shift 2;;
166
+ -R|--release) release=$2; shift 2;;
167
+ -T|--tarball) tarball=$2; shift 2;;
168
+ -S|--auth-key) auth_key=$2; shift 2;;
169
+ -A|--arch) arch=$2; shift 2;;
170
+ -4|--ipv4) ipv4=$2; shift 2;;
171
+ -6|--ipv6) ipv6=$2; shift 2;;
172
+ -g|--gw) gw=$2; shift 2;;
173
+ -d|--dns) dns=$2; shift 2;;
174
+ --) shift 1; break ;;
175
+ *) break ;;
176
+ esac
177
+ done
178
+
179
+ arch=${arch:-$hostarch}
180
+ if [ $hostarch = "i586" -a $arch = "x86_64" ]; then
181
+ echo "can't create x86_64 container on i586"
182
+ exit 1
183
+ fi
184
+
185
+ if [ -z "$path" ]; then
186
+ echo "'path' parameter is required"
187
+ exit 1
188
+ fi
189
+
190
+ if [ "$(id -u)" != "0" ]; then
191
+ echo "This script should be run as 'root'"
192
+ exit 1
193
+ fi
194
+
195
+ # detect rootfs
196
+ config="$path/config"
197
+ # if $rootfs exists here, it was passed in with --rootfs
198
+ if [ -z "$rootfs" ]; then
199
+ if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
200
+ rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
201
+ else
202
+ rootfs=$path/rootfs
203
+ fi
204
+ fi
205
+
206
+ install_openmandriva $rootfs $release $tarball
207
+ if [ $? -ne 0 ]; then
208
+ echo "failed to install openmandriva $release"
209
+ exit 1
210
+ fi
211
+
212
+ copy_configuration $path $rootfs $name $arch
213
+ if [ $? -ne 0 ]; then
214
+ echo "failed write configuration file"
215
+ exit 1
216
+ fi
217
+
218
+ post_process $rootfs $release
219
+
220
+ echo ""
221
+ echo "##"
222
+ echo "# The default user is 'vagrant' with password 'vagrant'!"
223
+ echo "# Use the 'sudo' command to run tasks as root in the container."
224
+ echo "##"
225
+ echo ""
@@ -1,43 +1,43 @@
1
1
  module Vagrant
2
2
  module LXC
3
3
  module Action
4
- class FetchIpWithLxcAttach
5
- # Include this so we can use `Subprocess` more easily.
6
- include Vagrant::Util::Retryable
4
+ class FetchIpWithLxcAttach
5
+ # Include this so we can use `Subprocess` more easily.
6
+ include Vagrant::Util::Retryable
7
7
 
8
- def initialize(app, env)
9
- @app = app
10
- @logger = Log4r::Logger.new("vagrant::lxc::action::fetch_ip_with_lxc_attach")
11
- end
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant::lxc::action::fetch_ip_with_lxc_attach")
11
+ end
12
12
 
13
- def call(env)
14
- env[:machine_ip] ||= assigned_ip(env)
15
- rescue LXC::Errors::NamespacesNotSupported
16
- @logger.info 'The `lxc-attach` command available does not support the --namespaces parameter, falling back to dnsmasq leases to fetch container ip'
17
- ensure
18
- @app.call(env)
19
- end
13
+ def call(env)
14
+ env[:machine_ip] ||= assigned_ip(env)
15
+ rescue LXC::Errors::NamespacesNotSupported
16
+ @logger.info 'The `lxc-attach` command available does not support the --namespaces parameter, falling back to dnsmasq leases to fetch container ip'
17
+ ensure
18
+ @app.call(env)
19
+ end
20
20
 
21
- def assigned_ip(env)
22
- driver = env[:machine].provider.driver
23
- ip = ''
24
- retryable(:on => LXC::Errors::ExecuteError, :tries => 10, :sleep => 3) do
25
- unless ip = get_container_ip_from_ip_addr(driver)
26
- # retry
27
- raise LXC::Errors::ExecuteError, :command => "lxc-attach"
28
- end
21
+ def assigned_ip(env)
22
+ driver = env[:machine].provider.driver
23
+ ip = ''
24
+ retryable(:on => LXC::Errors::ExecuteError, :tries => 10, :sleep => 3) do
25
+ unless ip = get_container_ip_from_ip_addr(driver)
26
+ # retry
27
+ raise LXC::Errors::ExecuteError, :command => "lxc-attach"
29
28
  end
30
- ip
31
29
  end
30
+ ip
31
+ end
32
32
 
33
- # From: https://github.com/lxc/lxc/blob/staging/src/python-lxc/lxc/__init__.py#L371-L385
34
- def get_container_ip_from_ip_addr(driver)
35
- output = driver.attach '/sbin/ip', '-4', 'addr', 'show', 'scope', 'global', 'eth0', namespaces: 'network'
36
- if output =~ /^\s+inet ([0-9.]+)\/[0-9]+\s+/
37
- return $1.to_s
38
- end
33
+ # From: https://github.com/lxc/lxc/blob/staging/src/python-lxc/lxc/__init__.py#L371-L385
34
+ def get_container_ip_from_ip_addr(driver)
35
+ output = driver.attach '/sbin/ip', '-4', 'addr', 'show', 'scope', 'global', 'eth0', namespaces: 'network'
36
+ if output =~ /^\s+inet ([0-9.]+)\/[0-9]+\s+/
37
+ return $1.to_s
39
38
  end
40
39
  end
41
40
  end
42
41
  end
43
42
  end
43
+ end
@@ -84,7 +84,8 @@ module Vagrant
84
84
  def forced_halt
85
85
  @logger.info('Shutting down container...')
86
86
  @cli.transition_to(:stopped) { |c| c.shutdown }
87
- rescue CLI::TargetStateNotReached
87
+ # REFACTOR: Do not use exception to control the flow
88
+ rescue CLI::TargetStateNotReached, CLI::ShutdownNotSupported
88
89
  @cli.transition_to(:stopped) { |c| c.stop }
89
90
  end
90
91
 
@@ -10,6 +10,7 @@ module Vagrant
10
10
  attr_accessor :name
11
11
 
12
12
  class TransitionBlockNotProvided < RuntimeError; end
13
+ class ShutdownNotSupported < RuntimeError; end
13
14
  class TargetStateNotReached < RuntimeError
14
15
  def initialize(target_state, state)
15
16
  msg = "Target state '#{target_state}' not reached, currently on '#{state}'"
@@ -72,7 +73,12 @@ module Vagrant
72
73
  end
73
74
 
74
75
  def shutdown
75
- run :shutdown, '--name', @name
76
+ if system('which lxc-shutdown > /dev/null')
77
+ run :shutdown, '--name', @name
78
+ else
79
+ # REFACTOR: Do not use exception to control the flow
80
+ raise ShutdownNotSupported
81
+ end
76
82
  end
77
83
 
78
84
  def attach(*cmd)
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module LXC
3
- VERSION = "0.6.3"
3
+ VERSION = "0.6.4"
4
4
  end
5
5
  end
@@ -103,13 +103,19 @@ describe Vagrant::LXC::Driver::CLI do
103
103
  subject { described_class.new(sudo_wrapper, name) }
104
104
 
105
105
  before do
106
+ subject.stub(system: true)
106
107
  subject.stub(:run)
107
- subject.shutdown
108
108
  end
109
109
 
110
110
  it 'issues a lxc-shutdown with provided container name' do
111
+ subject.shutdown
111
112
  subject.should have_received(:run).with(:shutdown, '--name', name)
112
113
  end
114
+
115
+ it 'raises a ShutdownNotSupported in case it is not supported' do
116
+ subject.stub(:system).with('which lxc-shutdown > /dev/null').and_return(false)
117
+ expect { subject.shutdown }.to raise_error(described_class::ShutdownNotSupported)
118
+ end
113
119
  end
114
120
 
115
121
  describe 'state' do
@@ -118,6 +118,13 @@ describe Vagrant::LXC::Driver do
118
118
  cli.should_receive(:stop)
119
119
  subject.forced_halt
120
120
  end
121
+
122
+ it 'attempts to force the container to stop in case lxc-shutdown is not supported' do
123
+ cli.stub(:shutdown).and_raise(Vagrant::LXC::Driver::CLI::ShutdownNotSupported)
124
+ cli.should_receive(:transition_to).with(:stopped).twice
125
+ cli.should_receive(:stop)
126
+ subject.forced_halt
127
+ end
121
128
  end
122
129
 
123
130
  describe 'state' do
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.6.3
4
+ version: 0.6.4
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-10-12 00:00:00.000000000 Z
11
+ date: 2013-10-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Linux Containers provider for Vagrant
14
14
  email:
@@ -31,6 +31,7 @@ files:
31
31
  - README.md
32
32
  - Rakefile
33
33
  - boxes/build-debian-box.sh
34
+ - boxes/build-openmandriva-box.sh
34
35
  - boxes/build-ubuntu-box.sh
35
36
  - boxes/common/cleanup
36
37
  - boxes/common/install-babushka
@@ -39,6 +40,7 @@ files:
39
40
  - boxes/common/install-salt
40
41
  - boxes/common/install-salt-debian
41
42
  - boxes/common/lxc-template
43
+ - boxes/common/lxc-template-openmandriva
42
44
  - boxes/common/lxc.conf
43
45
  - boxes/common/metadata.json
44
46
  - development/Vagrantfile