Commit ecd8be87baca766172c433042df40432385338f7
1 parent
98100c7c
add basic stop and destroy action and provision in up
Showing
4 changed files
with
76 additions
and
0 deletions
| ... | ... | @@ -13,6 +13,8 @@ module Vagrant |
| 13 | 13 | autoload :EnsureSsh, action_root.join("ensure_ssh") |
| 14 | 14 | autoload :EnsureStarted, action_root.join("ensure_started") |
| 15 | 15 | autoload :Network, action_root.join("network") |
| 16 | + autoload :Stop, action_root.join("stop") | |
| 17 | + autoload :Destroy, action_root.join("destroy") | |
| 16 | 18 | |
| 17 | 19 | include Vagrant::Action::Builtin |
| 18 | 20 | |
| ... | ... | @@ -35,6 +37,7 @@ module Vagrant |
| 35 | 37 | b2.use action_start |
| 36 | 38 | end |
| 37 | 39 | end |
| 40 | + b2.use action_provision | |
| 38 | 41 | end |
| 39 | 42 | end |
| 40 | 43 | |
| ... | ... | @@ -50,6 +53,18 @@ module Vagrant |
| 50 | 53 | end |
| 51 | 54 | end |
| 52 | 55 | |
| 56 | + def self.action_halt | |
| 57 | + Vagrant::Action::Builder.new.tap do |b| | |
| 58 | + b.use Stop | |
| 59 | + end | |
| 60 | + end | |
| 61 | + | |
| 62 | + def self.action_destroy | |
| 63 | + Vagrant::Action::Builder.new.tap do |b| | |
| 64 | + b.use Destroy | |
| 65 | + end | |
| 66 | + end | |
| 67 | + | |
| 53 | 68 | def self.action_provision |
| 54 | 69 | Vagrant::Action::Builder.new.tap do |b| |
| 55 | 70 | #b.use CheckAccessible | ... | ... |
lib/vagrant/lxd/action/destroy.rb
0 → 100644
| 1 | +module Vagrant | |
| 2 | + module Lxd | |
| 3 | + module Action | |
| 4 | + class Destroy | |
| 5 | + def initialize(app, env) | |
| 6 | + @app = app | |
| 7 | + @logger = Log4r::Logger.new("vagrant::lxd::action::destroy") | |
| 8 | + end | |
| 9 | + | |
| 10 | + def call(env) | |
| 11 | + driver = env[:machine].provider.driver | |
| 12 | + | |
| 13 | + if driver.container? | |
| 14 | + if driver.state == :running | |
| 15 | + driver.stop | |
| 16 | + end | |
| 17 | + driver.destroy | |
| 18 | + end | |
| 19 | + | |
| 20 | + @app.call(env) | |
| 21 | + end | |
| 22 | + end | |
| 23 | + end | |
| 24 | + end | |
| 25 | +end | |
| 26 | + | |
| 27 | +# vim: set et ts=2 sw=2: | ... | ... |
lib/vagrant/lxd/action/stop.rb
0 → 100644
| 1 | +module Vagrant | |
| 2 | + module Lxd | |
| 3 | + module Action | |
| 4 | + class Stop | |
| 5 | + def initialize(app, env) | |
| 6 | + @app = app | |
| 7 | + @logger = Log4r::Logger.new("vagrant::lxd::action::stop") | |
| 8 | + end | |
| 9 | + | |
| 10 | + def call(env) | |
| 11 | + driver = env[:machine].provider.driver | |
| 12 | + | |
| 13 | + if driver.container? | |
| 14 | + if driver.state == :running | |
| 15 | + driver.stop | |
| 16 | + end | |
| 17 | + end | |
| 18 | + | |
| 19 | + @app.call(env) | |
| 20 | + end | |
| 21 | + end | |
| 22 | + end | |
| 23 | + end | |
| 24 | +end | |
| 25 | + | |
| 26 | +# vim: set et ts=2 sw=2: | ... | ... |
| ... | ... | @@ -128,6 +128,14 @@ module Vagrant |
| 128 | 128 | container_data["state"]["status"].downcase.to_sym |
| 129 | 129 | end |
| 130 | 130 | |
| 131 | + def stop | |
| 132 | + execute "stop", @name | |
| 133 | + end | |
| 134 | + | |
| 135 | + def destroy | |
| 136 | + execute "delete", @name | |
| 137 | + end | |
| 138 | + | |
| 131 | 139 | def get_image(remote) |
| 132 | 140 | return if image? # image already exists |
| 133 | 141 | ... | ... |
Please
register
or
login
to post a comment