2014-03-26 23:45:46 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module DockerProvider
|
|
|
|
module Action
|
2014-03-27 00:14:25 +00:00
|
|
|
include Vagrant::Action::Builtin
|
2014-03-26 23:45:46 +00:00
|
|
|
|
|
|
|
# This action brings the "machine" up from nothing, including creating the
|
|
|
|
# container, configuring metadata, and booting.
|
|
|
|
def self.action_up
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
|
|
|
b.use Call, Created do |env, b2|
|
2014-03-26 23:45:46 +00:00
|
|
|
if !env[:result]
|
2014-03-27 00:16:27 +00:00
|
|
|
b2.use HandleBox
|
2014-03-26 23:45:46 +00:00
|
|
|
# TODO: Find out where this fits into the process
|
2014-03-27 00:14:25 +00:00
|
|
|
# b2.use EnvSet, :port_collision_repair => true
|
|
|
|
# b2.use HandleForwardedPortCollisions
|
|
|
|
b2.use Provision
|
2014-03-26 23:45:46 +00:00
|
|
|
b2.use PrepareNFSValidIds
|
2014-03-27 00:14:25 +00:00
|
|
|
b2.use SyncedFolderCleanup
|
|
|
|
b2.use SyncedFolders
|
2014-03-26 23:45:46 +00:00
|
|
|
b2.use PrepareNFSSettings
|
|
|
|
b2.use ForwardPorts
|
|
|
|
# This will actually create and start, but that's fine
|
|
|
|
b2.use Create
|
|
|
|
b2.use action_boot
|
|
|
|
else
|
|
|
|
b2.use PrepareNFSValidIds
|
2014-03-27 00:14:25 +00:00
|
|
|
b2.use SyncedFolderCleanup
|
|
|
|
b2.use SyncedFolders
|
2014-03-26 23:45:46 +00:00
|
|
|
b2.use PrepareNFSSettings
|
|
|
|
b2.use action_start
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This action just runs the provisioners on the machine.
|
|
|
|
def self.action_provision
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
|
|
|
b.use Call, Created do |env1, b2|
|
2014-03-26 23:45:46 +00:00
|
|
|
if !env1[:result]
|
2014-03-27 00:21:40 +00:00
|
|
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
2014-03-26 23:45:46 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-03-27 00:14:25 +00:00
|
|
|
b2.use Call, IsRunning do |env2, b3|
|
2014-03-26 23:45:46 +00:00
|
|
|
if !env2[:result]
|
2014-03-27 00:21:40 +00:00
|
|
|
b3.use Message, I18n.t("docker_provider.messages.not_running")
|
2014-03-26 23:45:46 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-03-27 00:14:25 +00:00
|
|
|
b3.use Provision
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is the action that is primarily responsible for halting
|
|
|
|
# the virtual machine, gracefully or by force.
|
|
|
|
def self.action_halt
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use Call, Created do |env, b2|
|
2014-03-26 23:45:46 +00:00
|
|
|
if env[:result]
|
2014-03-27 00:14:25 +00:00
|
|
|
b2.use Call, GracefulHalt, :stopped, :running do |env2, b3|
|
2014-03-26 23:45:46 +00:00
|
|
|
if !env2[:result]
|
|
|
|
b3.use Stop
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2014-03-27 00:21:40 +00:00
|
|
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This action is responsible for reloading the machine, which
|
|
|
|
# brings it down, sucks in new configuration, and brings the
|
|
|
|
# machine back up with the new configuration.
|
|
|
|
def self.action_reload
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use Call, Created do |env1, b2|
|
2014-03-26 23:45:46 +00:00
|
|
|
if !env1[:result]
|
2014-03-27 00:21:40 +00:00
|
|
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
2014-03-26 23:45:46 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-03-27 00:14:25 +00:00
|
|
|
b2.use ConfigValidate
|
2014-03-26 23:45:46 +00:00
|
|
|
b2.use action_halt
|
|
|
|
b2.use action_start
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is the action that is primarily responsible for completely
|
|
|
|
# freeing the resources of the underlying virtual machine.
|
|
|
|
def self.action_destroy
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use Call, Created do |env1, b2|
|
2014-03-26 23:45:46 +00:00
|
|
|
if !env1[:result]
|
2014-03-27 00:21:40 +00:00
|
|
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
2014-03-26 23:45:46 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-03-27 00:14:25 +00:00
|
|
|
b2.use Call, DestroyConfirm do |env2, b3|
|
2014-03-26 23:45:46 +00:00
|
|
|
if env2[:result]
|
2014-03-27 00:14:25 +00:00
|
|
|
b3.use ConfigValidate
|
|
|
|
b3.use EnvSet, :force_halt => true
|
2014-03-26 23:45:46 +00:00
|
|
|
b3.use action_halt
|
|
|
|
b3.use Destroy
|
2014-03-27 00:14:25 +00:00
|
|
|
b3.use ProvisionerCleanup
|
2014-03-26 23:45:46 +00:00
|
|
|
else
|
2014-03-27 00:21:40 +00:00
|
|
|
b3.use Message, I18n.t("docker_provider.messages.will_not_destroy")
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is the action that will exec into an SSH shell.
|
|
|
|
def self.action_ssh
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-03-26 23:45:46 +00:00
|
|
|
b.use CheckRunning
|
2014-03-27 00:14:25 +00:00
|
|
|
b.use SSHExec
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is the action that will run a single SSH command.
|
|
|
|
def self.action_ssh_run
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-03-26 23:45:46 +00:00
|
|
|
b.use CheckRunning
|
2014-03-27 00:14:25 +00:00
|
|
|
b.use SSHRun
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.action_start
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
|
|
|
b.use Call, IsRunning do |env, b2|
|
2014-03-26 23:45:46 +00:00
|
|
|
# If the container is running, then our work here is done, exit
|
|
|
|
next if env[:result]
|
|
|
|
|
2014-03-27 00:14:25 +00:00
|
|
|
b2.use Provision
|
2014-03-27 00:21:40 +00:00
|
|
|
b2.use Message, I18n.t("docker_provider.messages.starting")
|
2014-03-26 23:45:46 +00:00
|
|
|
b2.use action_boot
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.action_boot
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
# TODO: b.use SetHostname
|
2014-03-26 23:45:46 +00:00
|
|
|
b.use Start
|
2014-03-27 00:14:25 +00:00
|
|
|
b.use WaitForCommunicator
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# The autoload farm
|
|
|
|
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 :Destroy, action_root.join("destroy")
|
|
|
|
autoload :ForwardPorts, action_root.join("forward_ports")
|
|
|
|
autoload :Stop, action_root.join("stop")
|
|
|
|
autoload :PrepareNFSValidIds, action_root.join("prepare_nfs_valid_ids")
|
|
|
|
autoload :PrepareNFSSettings, action_root.join("prepare_nfs_settings")
|
|
|
|
autoload :IsRunning, action_root.join("is_running")
|
|
|
|
autoload :Start, action_root.join("start")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|