vagrant-lxc-2.1-patch 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +31 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +10 -0
  5. data/.vimrc +1 -0
  6. data/BOXES.md +47 -0
  7. data/CHANGELOG.md +510 -0
  8. data/CONTRIBUTING.md +24 -0
  9. data/Gemfile +24 -0
  10. data/Guardfile +7 -0
  11. data/LICENSE.txt +22 -0
  12. data/README.md +187 -0
  13. data/Rakefile +3 -0
  14. data/lib/vagrant-lxc.rb +10 -0
  15. data/lib/vagrant-lxc/action.rb +234 -0
  16. data/lib/vagrant-lxc/action/boot.rb +42 -0
  17. data/lib/vagrant-lxc/action/clear_forwarded_ports.rb +56 -0
  18. data/lib/vagrant-lxc/action/compress_rootfs.rb +30 -0
  19. data/lib/vagrant-lxc/action/create.rb +57 -0
  20. data/lib/vagrant-lxc/action/destroy.rb +18 -0
  21. data/lib/vagrant-lxc/action/destroy_confirm.rb +17 -0
  22. data/lib/vagrant-lxc/action/fetch_ip_with_lxc_info.rb +43 -0
  23. data/lib/vagrant-lxc/action/forced_halt.rb +20 -0
  24. data/lib/vagrant-lxc/action/forward_ports.rb +121 -0
  25. data/lib/vagrant-lxc/action/gc_private_network_bridges.rb +47 -0
  26. data/lib/vagrant-lxc/action/handle_box_metadata.rb +94 -0
  27. data/lib/vagrant-lxc/action/prepare_nfs_settings.rb +64 -0
  28. data/lib/vagrant-lxc/action/prepare_nfs_valid_ids.rb +19 -0
  29. data/lib/vagrant-lxc/action/private_networks.rb +46 -0
  30. data/lib/vagrant-lxc/action/setup_package_files.rb +60 -0
  31. data/lib/vagrant-lxc/action/warn_networks.rb +25 -0
  32. data/lib/vagrant-lxc/command/root.rb +58 -0
  33. data/lib/vagrant-lxc/command/sudoers.rb +97 -0
  34. data/lib/vagrant-lxc/config.rb +73 -0
  35. data/lib/vagrant-lxc/driver.rb +288 -0
  36. data/lib/vagrant-lxc/driver/cli.rb +166 -0
  37. data/lib/vagrant-lxc/errors.rb +62 -0
  38. data/lib/vagrant-lxc/plugin.rb +51 -0
  39. data/lib/vagrant-lxc/provider.rb +101 -0
  40. data/lib/vagrant-lxc/provider/cap/public_address.rb +17 -0
  41. data/lib/vagrant-lxc/sudo_wrapper.rb +104 -0
  42. data/lib/vagrant-lxc/synced_folder.rb +72 -0
  43. data/lib/vagrant-lxc/version.rb +5 -0
  44. data/locales/en.yml +82 -0
  45. data/scripts/lxc-template +171 -0
  46. data/scripts/pipework +422 -0
  47. data/spec/Vagrantfile +26 -0
  48. data/spec/fixtures/sample-ip-addr-output +2 -0
  49. data/spec/spec_helper.rb +35 -0
  50. data/spec/support/.gitkeep +0 -0
  51. data/spec/unit/action/clear_forwarded_ports_spec.rb +43 -0
  52. data/spec/unit/action/compress_rootfs_spec.rb +29 -0
  53. data/spec/unit/action/forward_ports_spec.rb +117 -0
  54. data/spec/unit/action/handle_box_metadata_spec.rb +126 -0
  55. data/spec/unit/action/setup_package_files_spec.rb +83 -0
  56. data/spec/unit/driver/cli_spec.rb +263 -0
  57. data/spec/unit/driver_spec.rb +268 -0
  58. data/spec/unit/support/unit_example_group.rb +38 -0
  59. data/spec/unit_helper.rb +17 -0
  60. data/tasks/spec.rake +40 -0
  61. data/templates/sudoers.rb.erb +129 -0
  62. data/vagrant-lxc.gemspec +20 -0
  63. data/vagrant-spec.config.rb +24 -0
  64. metadata +119 -0
@@ -0,0 +1,24 @@
1
+ ### Please read before contributing
2
+
3
+ * If you have an issue with base boxes, please create it on https://github.com/fgrehm/vagrant-lxc-base-boxes,
4
+ this repository is for the Vagrant plugin only.
5
+
6
+ * Try not to post questions in the issues tracker. I will probably answer you
7
+ but I'll most likely close the issue right away and will continue the discussion
8
+ with the issue closed. If you have any questions about the plugin, make sure
9
+ you go through the [Wiki](https://github.com/fgrehm/vagrant-lxc/wiki) pages
10
+ first (specially the [Troubleshooting Section](https://github.com/fgrehm/vagrant-lxc/wiki/Troubleshooting))
11
+ and if you still need answers please ask a question on [Stack Overflow](http://stackoverflow.com/questions/tagged/vagrant-lxc)
12
+ using the `vagrant` / `lxc` tag on it so that I get notified :)
13
+
14
+ * Please do a search on the issues tracker before submitting your issue to
15
+ check if it was already reported / fixed.
16
+
17
+ * When reporting a bug, please include **all** information that you can get
18
+ about your environment. Things like vagrant / vagrant-lxc / kernel / lxc /
19
+ distro versions, the list of plugins you have installed, a [gist](https://gist.github.com/)
20
+ with the output of running `VAGRANT_LOG=debug vagrant COMMAND`, the `Vagrantfile`
21
+ you are using and / or base box URL are really useful when tracking down what's
22
+ going on on your side of the globe and will get bonus points :)
23
+
24
+ Thanks!
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v1.8.7'
5
+ gem 'guard'
6
+ gem 'guard-rspec'
7
+ gem 'rb-inotify'
8
+ end
9
+
10
+ group :development, :test do
11
+ gem 'rake', '~> 10.4.2'
12
+ gem 'rspec', '~> 2.99.0'
13
+ gem 'coveralls', '~> 0.7.2', require: (ENV['COVERAGE'] == 'true')
14
+ # The is the ref *just* before we switch to childprocess 0.6, which conflicts with vagrant 1.8 deps.
15
+ gem 'vagrant-spec', git: 'https://github.com/mitchellh/vagrant-spec.git', ref: '5006bc73cd8796465ca09307d4774f8ec8375aa0'
16
+ end
17
+
18
+ group :plugins do
19
+ acceptance = (ENV['ACCEPTANCE'] == 'true')
20
+ gem 'vagrant-cachier', git: 'https://github.com/fgrehm/vagrant-cachier.git', require: !acceptance
21
+ gem 'vagrant-pristine', git: 'https://github.com/fgrehm/vagrant-pristine.git', require: !acceptance
22
+ gem 'vagrant-omnibus', require: !acceptance
23
+ gemspec
24
+ end
@@ -0,0 +1,7 @@
1
+ guard 'rspec', :spec_paths => ["spec/unit"] do
2
+ watch(%r{^spec/unit/.+_spec\.rb$})
3
+ watch(%r{^lib/vagrant-lxc/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
4
+ watch('spec/unit_helper.rb') { "spec/unit" }
5
+ watch('spec/spec_helper.rb') { "spec/unit" }
6
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec/unit" }
7
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013-2014 Fábio Rehm
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,187 @@
1
+ # vagrant-lxc
2
+
3
+ [![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) [![Coverage Status](https://coveralls.io/repos/fgrehm/vagrant-lxc/badge.png?branch=master)](https://coveralls.io/r/fgrehm/vagrant-lxc) [![Gitter chat](https://badges.gitter.im/fgrehm/vagrant-lxc.png)](https://gitter.im/fgrehm/vagrant-lxc)
4
+
5
+ [LXC](http://lxc.sourceforge.net/) provider for [Vagrant](http://www.vagrantup.com/) 1.8+
6
+
7
+ This is a Vagrant plugin that allows it to control and provision Linux Containers
8
+ as an alternative to the built in VirtualBox provider for Linux hosts. Check out
9
+ [this blog post](http://fabiorehm.com/blog/2013/04/28/lxc-provider-for-vagrant/)
10
+ to see it in action.
11
+
12
+ ## Features
13
+
14
+ * Provides the same workflow as the Vagrant VirtualBox provider
15
+ * Port forwarding via [`redir`](https://github.com/troglobit/redir)
16
+ * Private networking via [`pipework`](https://github.com/jpetazzo/pipework)
17
+
18
+ ## Requirements
19
+
20
+ * [Vagrant 1.8+](http://www.vagrantup.com/downloads.html)
21
+ * lxc >=1.0
22
+ * `redir` (if you are planning to use port forwarding)
23
+ * `brctl` (if you are planning to use private networks, on Ubuntu this means `apt-get install bridge-utils`)
24
+
25
+ The plugin is known to work better and pretty much out of the box on Ubuntu 14.04+
26
+ hosts and installing the dependencies on it basically means a
27
+ `apt-get install lxc lxc-templates cgroup-lite redir`. For setting up other
28
+ types of hosts please have a look at the [Wiki](https://github.com/fgrehm/vagrant-lxc/wiki).
29
+
30
+ If you are on a Mac or Windows machine, you might want to have a look at [this](http://the.taoofmac.com/space/HOWTO/Vagrant)
31
+ blog post for some ideas on how to set things up or check out [this other repo](https://github.com/fgrehm/vagrant-lxc-vbox-hosts)
32
+ for a set of Vagrant VirtualBox machines ready for vagrant-lxc usage.
33
+
34
+
35
+ ## Installation
36
+
37
+ ```
38
+ vagrant plugin install vagrant-lxc
39
+ ```
40
+
41
+
42
+ ## Quick start
43
+
44
+ ```
45
+ vagrant init fgrehm/precise64-lxc
46
+ vagrant up --provider=lxc
47
+ ```
48
+
49
+ _More information about skipping the `--provider` argument can be found at the
50
+ "DEFAULT PROVIDER" section of [Vagrant docs](https://docs.vagrantup.com/v2/providers/basic_usage.html)_
51
+
52
+ ## Base boxes
53
+
54
+ Base boxes can be found on [Atlas](https://atlas.hashicorp.com/boxes/search?provider=lxc)
55
+ and some scripts to build your own are available at [fgrehm/vagrant-lxc-base-boxes](https://github.com/fgrehm/vagrant-lxc-base-boxes).
56
+
57
+ If you want to build your own boxes, please have a look at [`BOXES.md`](https://github.com/fgrehm/vagrant-lxc/tree/master/BOXES.md)
58
+ for more information.
59
+
60
+ ## Advanced configuration
61
+
62
+ You can modify container configurations from within your Vagrantfile using the
63
+ [provider block](http://docs.vagrantup.com/v2/providers/configuration.html):
64
+
65
+ ```ruby
66
+ Vagrant.configure("2") do |config|
67
+ config.vm.box = "fgrehm/trusty64-lxc"
68
+ config.vm.provider :lxc do |lxc|
69
+ # Same effect as 'customize ["modifyvm", :id, "--memory", "1024"]' for VirtualBox
70
+ lxc.customize 'cgroup.memory.limit_in_bytes', '1024M'
71
+ end
72
+ end
73
+ ```
74
+
75
+ vagrant-lxc will then write out `lxc.cgroup.memory.limit_in_bytes='1024M'` to the
76
+ container config file (usually kept under `/var/lib/lxc/<container>/config`)
77
+ prior to starting it.
78
+
79
+ For other configuration options, please check the [lxc.conf manpages](http://manpages.ubuntu.com/manpages/precise/man5/lxc.conf.5.html).
80
+
81
+ ### Private Networks
82
+
83
+ Starting with vagrant-lxc 1.1.0, there is some rudimentary support for configuring
84
+ [Private Networks](https://docs.vagrantup.com/v2/networking/private_network.html)
85
+ by leveraging the [pipework](https://github.com/jpetazzo/pipework) project.
86
+
87
+ On its current state, there is a requirement for setting the bridge name that
88
+ will be created and will allow your machine to comunicate with the container
89
+
90
+ For example:
91
+
92
+ ```ruby
93
+ Vagrant.configure("2") do |config|
94
+ config.vm.network "private_network", ip: "192.168.2.100", lxc__bridge_name: 'vlxcbr1'
95
+ end
96
+ ```
97
+
98
+ Will create a new `veth` device for the container and will set up (or reuse)
99
+ a `vlxcbr1` bridge between your machine and the `veth` device. Once the last
100
+ vagrant-lxc container attached to the bridge gets `vagrant halt`ed, the plugin
101
+ will delete the bridge.
102
+
103
+ ### Container naming
104
+
105
+ By default vagrant-lxc will attempt to generate a unique container name
106
+ for you. However, if the container name is important to you, you may use the
107
+ `container_name` attribute to set it explicitly from the `provider` block:
108
+
109
+ ```ruby
110
+ Vagrant.configure("2") do |config|
111
+ config.vm.define "db" do |node|
112
+ node.vm.provider :lxc do |lxc|
113
+ lxc.container_name = :machine # Sets the container name to 'db'
114
+ lxc.container_name = 'mysql' # Sets the container name to 'mysql'
115
+ end
116
+ end
117
+ end
118
+ ```
119
+
120
+ _Please note that there is a 64 chars limit and the container name will be
121
+ trimmed down to that to ensure we can always bring the container up.
122
+
123
+ ### Backingstore options
124
+
125
+ Support for setting `lxc-create`'s backingstore option (`-B` and related) can be
126
+ specified from the provider block and it defaults to `best`, to change it:
127
+
128
+ ```ruby
129
+ Vagrant.configure("2") do |config|
130
+ config.vm.provider :lxc do |lxc|
131
+ lxc.backingstore = 'lvm' # or 'btrfs', 'overlayfs', ...
132
+ # lvm specific options
133
+ lxc.backingstore_option '--vgname', 'schroots'
134
+ lxc.backingstore_option '--fssize', '5G'
135
+ lxc.backingstore_option '--fstype', 'xfs'
136
+ end
137
+ end
138
+ ```
139
+
140
+ ## Unprivileged containers support
141
+
142
+ Since v1.4.0, `vagrant-lxc` gained support for unprivileged containers. For now, since it's a new
143
+ feature, privileged containers are still the default, but you can have your `Vagrantfile` use
144
+ unprivileged containers with the `privileged` flag (which defaults to `true`). Example:
145
+
146
+ ```ruby
147
+ Vagrant.configure("2") do |config|
148
+ config.vm.provider :lxc do |lxc|
149
+ lxc.privileged = false
150
+ end
151
+ end
152
+ ```
153
+
154
+ For unprivileged containers to work with `vagrant-lxc`, you need a properly configured system. On
155
+ some distros, it can be somewhat of a challenge. Your journey to configuring your system can start
156
+ with [Stéphane Graber's blog post about it](https://stgraber.org/2014/01/17/lxc-1-0-unprivileged-containers/).
157
+
158
+ ## Avoiding `sudo` passwords
159
+
160
+ If you're not using unprivileged containers, this plugin requires **a lot** of `sudo`ing To work
161
+ around that, you can use the `vagrant lxc sudoers` command which will create a file under
162
+ `/etc/sudoers.d/vagrant-lxc` whitelisting all commands required by `vagrant-lxc` to run.
163
+
164
+ If you are interested on what will be generated by that command, please check
165
+ [this code](lib/vagrant-lxc/command/sudoers.rb).
166
+
167
+
168
+ ## More information
169
+
170
+ Please refer the [wiki](https://github.com/fgrehm/vagrant-lxc/wiki).
171
+
172
+
173
+ ## Problems / ideas?
174
+
175
+ Please review the [Troubleshooting](https://github.com/fgrehm/vagrant-lxc/wiki/Troubleshooting)
176
+ wiki page + [known bugs](https://github.com/fgrehm/vagrant-lxc/issues?labels=bug&page=1&state=open)
177
+ list if you have a problem and feel free to use the [issue tracker](https://github.com/fgrehm/vagrant-lxc/issues)
178
+ propose new functionality and / or report bugs.
179
+
180
+
181
+ ## Contributing
182
+
183
+ 1. Fork it
184
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
185
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
186
+ 4. Push to the branch (`git push origin my-new-feature`)
187
+ 5. Create new Pull Request
@@ -0,0 +1,3 @@
1
+ Dir['./tasks/**/*.rake'].each { |f| load f }
2
+
3
+ require 'bundler/gem_tasks'
@@ -0,0 +1,10 @@
1
+ require "vagrant-lxc/version"
2
+ require "vagrant-lxc/plugin"
3
+
4
+ module Vagrant
5
+ module LXC
6
+ def self.source_root
7
+ @source_root ||= Pathname.new(File.dirname(__FILE__)).join('..').expand_path
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,234 @@
1
+ require 'vagrant-lxc/action/boot'
2
+ require 'vagrant-lxc/action/clear_forwarded_ports'
3
+ require 'vagrant-lxc/action/create'
4
+ require 'vagrant-lxc/action/destroy'
5
+ require 'vagrant-lxc/action/destroy_confirm'
6
+ require 'vagrant-lxc/action/compress_rootfs'
7
+ require 'vagrant-lxc/action/fetch_ip_with_lxc_info'
8
+ require 'vagrant-lxc/action/forced_halt'
9
+ require 'vagrant-lxc/action/forward_ports'
10
+ require 'vagrant-lxc/action/gc_private_network_bridges'
11
+ require 'vagrant-lxc/action/handle_box_metadata'
12
+ require 'vagrant-lxc/action/prepare_nfs_settings'
13
+ require 'vagrant-lxc/action/prepare_nfs_valid_ids'
14
+ require 'vagrant-lxc/action/private_networks'
15
+ require 'vagrant-lxc/action/setup_package_files'
16
+ require 'vagrant-lxc/action/warn_networks'
17
+
18
+ module Vagrant
19
+ module LXC
20
+ module Action
21
+ # Shortcuts
22
+ Builtin = Vagrant::Action::Builtin
23
+ Builder = Vagrant::Action::Builder
24
+
25
+ # This action is responsible for reloading the machine, which
26
+ # brings it down, sucks in new configuration, and brings the
27
+ # machine back up with the new configuration.
28
+ def self.action_reload
29
+ Builder.new.tap do |b|
30
+ b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2|
31
+ if env1[:result]
32
+ b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
33
+ next
34
+ end
35
+
36
+ b2.use Builtin::ConfigValidate
37
+ b2.use action_halt
38
+ b2.use action_start
39
+ end
40
+ end
41
+ end
42
+
43
+ # This action boots the VM, assuming the VM is in a state that requires
44
+ # a bootup (i.e. not saved).
45
+ def self.action_boot
46
+ Builder.new.tap do |b|
47
+ b.use Builtin::Provision
48
+ b.use Builtin::EnvSet, :port_collision_repair => true
49
+ b.use Builtin::HandleForwardedPortCollisions
50
+ b.use PrepareNFSValidIds
51
+ b.use Builtin::SyncedFolderCleanup
52
+ b.use Builtin::SyncedFolders
53
+ b.use PrepareNFSSettings
54
+ b.use Builtin::SetHostname
55
+ b.use WarnNetworks
56
+ b.use ForwardPorts
57
+ b.use PrivateNetworks
58
+ b.use Boot
59
+ b.use Builtin::WaitForCommunicator
60
+ end
61
+ end
62
+
63
+ # This action just runs the provisioners on the machine.
64
+ def self.action_provision
65
+ Builder.new.tap do |b|
66
+ b.use Builtin::ConfigValidate
67
+ b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2|
68
+ if env1[:result]
69
+ b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
70
+ next
71
+ end
72
+
73
+ b2.use Builtin::Call, Builtin::IsState, :running do |env2, b3|
74
+ if !env2[:result]
75
+ b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_running")
76
+ next
77
+ end
78
+
79
+ b3.use Builtin::Provision
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ # This action starts a container, assuming it is already created and exists.
86
+ # A precondition of this action is that the container exists.
87
+ def self.action_start
88
+ Builder.new.tap do |b|
89
+ b.use Builtin::ConfigValidate
90
+ b.use Builtin::BoxCheckOutdated
91
+ b.use Builtin::Call, Builtin::IsState, :running do |env, b2|
92
+ # If the VM is running, then our work here is done, exit
93
+ next if env[:result]
94
+ b2.use action_boot
95
+ end
96
+ end
97
+ end
98
+
99
+ # This action brings the machine up from nothing, including creating the
100
+ # container, configuring metadata, and booting.
101
+ def self.action_up
102
+ Builder.new.tap do |b|
103
+ b.use Builtin::ConfigValidate
104
+ b.use Builtin::Call, Builtin::IsState, :not_created do |env, b2|
105
+ # If the VM is NOT created yet, then do the setup steps
106
+ if env[:result]
107
+ b2.use Builtin::HandleBox
108
+ b2.use HandleBoxMetadata
109
+ b2.use Create
110
+ end
111
+ end
112
+ b.use action_start
113
+ end
114
+ end
115
+
116
+ # This is the action that is primarily responsible for halting
117
+ # the virtual machine, gracefully or by force.
118
+ def self.action_halt
119
+ Builder.new.tap do |b|
120
+ b.use Builtin::Call, Builtin::IsState, :not_created do |env, b2|
121
+ if env[:result]
122
+ b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
123
+ next
124
+ end
125
+
126
+ b2.use ClearForwardedPorts
127
+ b2.use GcPrivateNetworkBridges
128
+ b2.use Builtin::Call, Builtin::GracefulHalt, :stopped, :running do |env2, b3|
129
+ if !env2[:result]
130
+ b3.use ForcedHalt
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+
137
+ # This is the action that is primarily responsible for completely
138
+ # freeing the resources of the underlying virtual machine.
139
+ def self.action_destroy
140
+ Builder.new.tap do |b|
141
+ b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2|
142
+ if env1[:result]
143
+ b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
144
+ next
145
+ end
146
+
147
+ b2.use Builtin::Call, DestroyConfirm do |env2, b3|
148
+ if env2[:result]
149
+ b3.use Builtin::ConfigValidate
150
+ b3.use Builtin::EnvSet, :force_halt => true
151
+ b3.use action_halt
152
+ b3.use Destroy
153
+ b3.use Builtin::ProvisionerCleanup
154
+ else
155
+ b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.will_not_destroy")
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+ # This action packages the virtual machine into a single box file.
163
+ def self.action_package
164
+ Builder.new.tap do |b|
165
+ b.use Builtin::Call, Builtin::IsState, :not_created do |env1, b2|
166
+ if env1[:result]
167
+ b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
168
+ next
169
+ end
170
+
171
+ b2.use action_halt
172
+ b2.use CompressRootFS
173
+ b2.use SetupPackageFiles
174
+ b2.use Vagrant::Action::General::Package
175
+ end
176
+ end
177
+ end
178
+
179
+ # This action is called to read the IP of the container. The IP found
180
+ # is expected to be put into the `:machine_ip` key.
181
+ def self.action_ssh_ip
182
+ Builder.new.tap do |b|
183
+ b.use Builtin::Call, Builtin::ConfigValidate do |env, b2|
184
+ b2.use FetchIpWithLxcInfo
185
+ end
186
+ end
187
+ end
188
+
189
+ # This is the action that will exec into an SSH shell.
190
+ def self.action_ssh
191
+ Builder.new.tap do |b|
192
+ b.use Builtin::ConfigValidate
193
+ b.use Builtin::Call, Builtin::IsState, :not_created do |env, b2|
194
+ if env[:result]
195
+ b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
196
+ next
197
+ end
198
+
199
+ b2.use Builtin::Call, Builtin::IsState, :running do |env1, b3|
200
+ if !env1[:result]
201
+ b3.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_running")
202
+ next
203
+ end
204
+
205
+ b3.use Builtin::SSHExec
206
+ end
207
+ end
208
+ end
209
+ end
210
+
211
+ # This is the action that will run a single SSH command.
212
+ def self.action_ssh_run
213
+ Builder.new.tap do |b|
214
+ b.use Builtin::ConfigValidate
215
+ b.use Builtin::Call, Builtin::IsState, :not_created do |env, b2|
216
+ if env[:result]
217
+ b2.use Builtin::Message, I18n.t("vagrant_lxc.messages.not_created")
218
+ next
219
+ end
220
+
221
+ b2.use Builtin::Call, Builtin::IsState, :running do |env1, b3|
222
+ if !env1[:result]
223
+ raise Vagrant::Errors::VMNotRunningError
224
+ next
225
+ end
226
+
227
+ b3.use Builtin::SSHRun
228
+ end
229
+ end
230
+ end
231
+ end
232
+ end
233
+ end
234
+ end