`vagrant provision`

This commit is contained in:
Mitchell Hashimoto 2012-08-14 21:21:31 -07:00
parent 7aa083d259
commit aaeb060f33
4 changed files with 67 additions and 19 deletions

View File

@ -4,10 +4,8 @@ module VagrantPlugins
module CommandProvision
class Command < Vagrant.plugin("1", :command)
def execute
options = {}
opts = OptionParser.new do |opts|
opts.banner = "Usage: vagrant provision [vm-name]"
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant provision [vm-name]"
end
# Parse the options
@ -16,25 +14,13 @@ module VagrantPlugins
# Go over each VM and provision!
@logger.debug("'provision' each target VM...")
with_target_vms(argv) do |vm|
if vm.created?
if vm.state == :running
@logger.info("Provisioning: #{vm.name}")
vm.provision
else
@logger.info("#{vm.name} not running. Not provisioning.")
vm.ui.info I18n.t("vagrant.commands.common.vm_not_running")
end
else
@logger.info("#{vm.name} not created. Not provisioning.")
vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
end
with_target_vms(argv) do |machine|
machine.action(:provision)
end
# Success, exit status 0
0
end
end
end
end
end

View File

@ -22,7 +22,9 @@ module VagrantPlugins
autoload :ForwardPorts, File.expand_path("../action/forward_ports", __FILE__)
autoload :Halt, File.expand_path("../action/halt", __FILE__)
autoload :HostName, File.expand_path("../action/host_name", __FILE__)
autoload :IsRunning, File.expand_path("../action/is_running", __FILE__)
autoload :MessageNotCreated, File.expand_path("../action/message_not_created", __FILE__)
autoload :MessageNotRunning, File.expand_path("../action/message_not_running", __FILE__)
autoload :MessageWillNotDestroy, File.expand_path("../action/message_will_not_destroy", __FILE__)
autoload :Network, File.expand_path("../action/network", __FILE__)
autoload :NFS, File.expand_path("../action/nfs", __FILE__)
@ -85,6 +87,30 @@ module VagrantPlugins
end
end
# This action just runs the provisioners on the machine.
def self.action_provision
Vagrant::Action::Builder.new.tap do |b|
b.use CheckVirtualbox
b.use Vagrant::Action::General::Validate
b.use Call, Created do |env1, b2|
if !env1[:result]
b2.use MessageNotCreated
next
end
b2.use Call, IsRunning do |env2, b3|
if !env2[:result]
b3.use MessageNotRunning
next
end
b3.use CheckAccessible
b3.use Provision
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.

View File

@ -0,0 +1,20 @@
module VagrantPlugins
module ProviderVirtualBox
module Action
class IsRunning
def initialize(app, env)
@app = app
end
def call(env)
# Set the result to be true if the machine is running.
env[:result] = env[:machine].state == :running
# 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

View File

@ -0,0 +1,16 @@
module VagrantPlugins
module ProviderVirtualBox
module Action
class MessageNotRunning
def initialize(app, env)
@app = app
end
def call(env)
env[:ui].info I18n.t("vagrant.commands.common.vm_not_running")
@app.call(env)
end
end
end
end
end