providers/docker: Make use of Action::Builtin::IsState and remove provider specific actions
This commit is contained in:
parent
29f2d9b09d
commit
46cbeb38f0
|
@ -1,6 +1,7 @@
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module DockerProvider
|
module DockerProvider
|
||||||
module Action
|
module Action
|
||||||
|
# Include the built-in modules so we can use them as top-level things.
|
||||||
include Vagrant::Action::Builtin
|
include Vagrant::Action::Builtin
|
||||||
|
|
||||||
# This action brings the "machine" up from nothing, including creating the
|
# This action brings the "machine" up from nothing, including creating the
|
||||||
|
@ -8,8 +9,9 @@ module VagrantPlugins
|
||||||
def self.action_up
|
def self.action_up
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
b.use ConfigValidate
|
b.use ConfigValidate
|
||||||
b.use Call, Created do |env, b2|
|
b.use Call, IsState, :not_created do |env, b2|
|
||||||
if !env[:result]
|
# If the VM is NOT created yet, then do the setup steps
|
||||||
|
if env[:result]
|
||||||
b2.use HandleBox
|
b2.use HandleBox
|
||||||
# TODO: Find out where this fits into the process
|
# TODO: Find out where this fits into the process
|
||||||
# b2.use EnvSet, :port_collision_repair => true
|
# b2.use EnvSet, :port_collision_repair => true
|
||||||
|
@ -38,13 +40,13 @@ module VagrantPlugins
|
||||||
def self.action_provision
|
def self.action_provision
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
b.use ConfigValidate
|
b.use ConfigValidate
|
||||||
b.use Call, Created do |env1, b2|
|
b.use Call, IsState, :not_created do |env, b2|
|
||||||
if !env1[:result]
|
if env[:result]
|
||||||
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
b2.use Call, IsRunning do |env2, b3|
|
b2.use Call, IsState, :running do |env2, b3|
|
||||||
if !env2[:result]
|
if !env2[:result]
|
||||||
b3.use Message, I18n.t("docker_provider.messages.not_running")
|
b3.use Message, I18n.t("docker_provider.messages.not_running")
|
||||||
next
|
next
|
||||||
|
@ -60,15 +62,16 @@ module VagrantPlugins
|
||||||
# the virtual machine, gracefully or by force.
|
# the virtual machine, gracefully or by force.
|
||||||
def self.action_halt
|
def self.action_halt
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
b.use Call, Created do |env, b2|
|
b.use Call, IsState, :not_created do |env, b2|
|
||||||
if env[:result]
|
if env[:result]
|
||||||
b2.use Call, GracefulHalt, :stopped, :running do |env2, b3|
|
|
||||||
if !env2[:result]
|
|
||||||
b3.use Stop
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
b2.use Call, GracefulHalt, :stopped, :running do |env2, b3|
|
||||||
|
if !env2[:result]
|
||||||
|
b3.use Stop
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -79,8 +82,8 @@ module VagrantPlugins
|
||||||
# machine back up with the new configuration.
|
# machine back up with the new configuration.
|
||||||
def self.action_reload
|
def self.action_reload
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
b.use Call, Created do |env1, b2|
|
b.use Call, IsState, :not_created do |env, b2|
|
||||||
if !env1[:result]
|
if env[:result]
|
||||||
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
@ -96,8 +99,8 @@ module VagrantPlugins
|
||||||
# freeing the resources of the underlying virtual machine.
|
# freeing the resources of the underlying virtual machine.
|
||||||
def self.action_destroy
|
def self.action_destroy
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
b.use Call, Created do |env1, b2|
|
b.use Call, IsState, :not_created do |env, b2|
|
||||||
if !env1[:result]
|
if env[:result]
|
||||||
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
@ -120,23 +123,47 @@ module VagrantPlugins
|
||||||
# This is the action that will exec into an SSH shell.
|
# This is the action that will exec into an SSH shell.
|
||||||
def self.action_ssh
|
def self.action_ssh
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
b.use CheckRunning
|
b.use Call, IsState, :not_created do |env, b2|
|
||||||
b.use SSHExec
|
if env[:result]
|
||||||
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
b2.use Call, IsState, :running do |env2, b3|
|
||||||
|
if !env2[:result]
|
||||||
|
b3.use Message, I18n.t("docker_provider.messages.not_running")
|
||||||
|
next
|
||||||
|
end
|
||||||
|
b3.use SSHExec
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is the action that will run a single SSH command.
|
# This is the action that will run a single SSH command.
|
||||||
def self.action_ssh_run
|
def self.action_ssh_run
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
b.use CheckRunning
|
b.use Call, IsState, :not_created do |env, b2|
|
||||||
b.use SSHRun
|
if env[:result]
|
||||||
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
b2.use Call, IsState, :running do |env2, b3|
|
||||||
|
if !env2[:result]
|
||||||
|
raise Vagrant::Errors::VMNotRunningError
|
||||||
|
end
|
||||||
|
|
||||||
|
b3.use SSHRun
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.action_start
|
def self.action_start
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
b.use ConfigValidate
|
b.use ConfigValidate
|
||||||
b.use Call, IsRunning do |env, b2|
|
b.use Call, IsState, :running do |env, b2|
|
||||||
# If the container is running, then our work here is done, exit
|
# If the container is running, then our work here is done, exit
|
||||||
next if env[:result]
|
next if env[:result]
|
||||||
|
|
||||||
|
@ -157,15 +184,12 @@ module VagrantPlugins
|
||||||
|
|
||||||
# The autoload farm
|
# The autoload farm
|
||||||
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
||||||
autoload :CheckRunning, action_root.join("check_running")
|
|
||||||
autoload :Created, action_root.join("created")
|
|
||||||
autoload :Create, action_root.join("create")
|
autoload :Create, action_root.join("create")
|
||||||
autoload :Destroy, action_root.join("destroy")
|
autoload :Destroy, action_root.join("destroy")
|
||||||
autoload :ForwardPorts, action_root.join("forward_ports")
|
autoload :ForwardPorts, action_root.join("forward_ports")
|
||||||
autoload :Stop, action_root.join("stop")
|
autoload :Stop, action_root.join("stop")
|
||||||
autoload :PrepareNFSValidIds, action_root.join("prepare_nfs_valid_ids")
|
autoload :PrepareNFSValidIds, action_root.join("prepare_nfs_valid_ids")
|
||||||
autoload :PrepareNFSSettings, action_root.join("prepare_nfs_settings")
|
autoload :PrepareNFSSettings, action_root.join("prepare_nfs_settings")
|
||||||
autoload :IsRunning, action_root.join("is_running")
|
|
||||||
autoload :Start, action_root.join("start")
|
autoload :Start, action_root.join("start")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
module VagrantPlugins
|
|
||||||
module DockerProvider
|
|
||||||
module Action
|
|
||||||
class CheckRunning
|
|
||||||
def initialize(app, env)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
if env[:machine].state.id == :not_created
|
|
||||||
raise Vagrant::Errors::VMNotCreatedError
|
|
||||||
end
|
|
||||||
|
|
||||||
if env[:machine].state.id == :stopped
|
|
||||||
raise Vagrant::Errors::VMNotRunningError
|
|
||||||
end
|
|
||||||
|
|
||||||
# Call the next if we have one (but we shouldn't, since this
|
|
||||||
# middleware is built to run with the Call-type middlewares)
|
|
||||||
@app.call(env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,18 +0,0 @@
|
||||||
module VagrantPlugins
|
|
||||||
module DockerProvider
|
|
||||||
module Action
|
|
||||||
class Created
|
|
||||||
def initialize(app, env)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
machine = env[:machine]
|
|
||||||
driver = machine.provider.driver
|
|
||||||
env[:result] = machine.id && driver.created?(machine.id)
|
|
||||||
@app.call(env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,20 +0,0 @@
|
||||||
module VagrantPlugins
|
|
||||||
module DockerProvider
|
|
||||||
module Action
|
|
||||||
class IsRunning
|
|
||||||
def initialize(app, env)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
machine = env[:machine]
|
|
||||||
driver = machine.provider.driver
|
|
||||||
|
|
||||||
env[:result] = driver.running?(machine.id)
|
|
||||||
|
|
||||||
@app.call(env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue