Browse Source

add basic stop and destroy action and provision in up

master
Georg Hopp 9 years ago
parent
commit
ecd8be87ba
  1. 15
      lib/vagrant/lxd/action.rb
  2. 27
      lib/vagrant/lxd/action/destroy.rb
  3. 26
      lib/vagrant/lxd/action/stop.rb
  4. 8
      lib/vagrant/lxd/driver.rb

15
lib/vagrant/lxd/action.rb

@ -13,6 +13,8 @@ module Vagrant
autoload :EnsureSsh, action_root.join("ensure_ssh")
autoload :EnsureStarted, action_root.join("ensure_started")
autoload :Network, action_root.join("network")
autoload :Stop, action_root.join("stop")
autoload :Destroy, action_root.join("destroy")
include Vagrant::Action::Builtin
@ -35,6 +37,7 @@ module Vagrant
b2.use action_start
end
end
b2.use action_provision
end
end
@ -50,6 +53,18 @@ module Vagrant
end
end
def self.action_halt
Vagrant::Action::Builder.new.tap do |b|
b.use Stop
end
end
def self.action_destroy
Vagrant::Action::Builder.new.tap do |b|
b.use Destroy
end
end
def self.action_provision
Vagrant::Action::Builder.new.tap do |b|
#b.use CheckAccessible

27
lib/vagrant/lxd/action/destroy.rb

@ -0,0 +1,27 @@
module Vagrant
module Lxd
module Action
class Destroy
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::lxd::action::destroy")
end
def call(env)
driver = env[:machine].provider.driver
if driver.container?
if driver.state == :running
driver.stop
end
driver.destroy
end
@app.call(env)
end
end
end
end
end
# vim: set et ts=2 sw=2:

26
lib/vagrant/lxd/action/stop.rb

@ -0,0 +1,26 @@
module Vagrant
module Lxd
module Action
class Stop
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::lxd::action::stop")
end
def call(env)
driver = env[:machine].provider.driver
if driver.container?
if driver.state == :running
driver.stop
end
end
@app.call(env)
end
end
end
end
end
# vim: set et ts=2 sw=2:

8
lib/vagrant/lxd/driver.rb

@ -128,6 +128,14 @@ module Vagrant
container_data["state"]["status"].downcase.to_sym
end
def stop
execute "stop", @name
end
def destroy
execute "delete", @name
end
def get_image(remote)
return if image? # image already exists

Loading…
Cancel
Save