2012-04-19 20:59:48 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
2012-05-23 23:18:29 +00:00
|
|
|
require "vagrant"
|
|
|
|
|
|
|
|
require File.expand_path("../start_mixins", __FILE__)
|
|
|
|
|
2012-04-19 20:59:48 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module CommandUp
|
2012-11-07 05:05:14 +00:00
|
|
|
class Command < Vagrant.plugin("2", :command)
|
2012-04-20 04:33:26 +00:00
|
|
|
include StartMixins
|
2012-04-19 20:59:48 +00:00
|
|
|
|
2013-11-23 22:00:42 +00:00
|
|
|
def self.synopsis
|
|
|
|
"starts and provisions the vagrant environment"
|
|
|
|
end
|
|
|
|
|
2012-04-19 20:59:48 +00:00
|
|
|
def execute
|
|
|
|
options = {}
|
2013-08-29 19:12:53 +00:00
|
|
|
options[:destroy_on_error] = true
|
2013-04-16 22:22:14 +00:00
|
|
|
options[:parallel] = true
|
2013-09-02 16:03:46 +00:00
|
|
|
options[:provision_ignore_sentinel] = false
|
2013-04-16 22:22:14 +00:00
|
|
|
|
2012-08-15 05:38:41 +00:00
|
|
|
opts = OptionParser.new do |o|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.banner = "Usage: vagrant up [options] [name]"
|
|
|
|
o.separator ""
|
|
|
|
o.separator "Options:"
|
2012-08-15 05:38:41 +00:00
|
|
|
o.separator ""
|
2012-11-08 05:45:09 +00:00
|
|
|
|
2012-08-15 05:38:41 +00:00
|
|
|
build_start_options(o, options)
|
2012-11-08 05:45:09 +00:00
|
|
|
|
2013-08-29 19:12:53 +00:00
|
|
|
o.on("--[no-]destroy-on-error",
|
2014-02-08 08:20:50 +00:00
|
|
|
"Destroy machine if any fatal error happens (default to true)") do |destroy|
|
2013-08-29 19:12:53 +00:00
|
|
|
options[:destroy_on_error] = destroy
|
|
|
|
end
|
|
|
|
|
2013-04-16 22:22:14 +00:00
|
|
|
o.on("--[no-]parallel",
|
2014-02-08 08:20:50 +00:00
|
|
|
"Enable or disable parallelism if provider supports it") do |parallel|
|
2013-04-16 22:22:14 +00:00
|
|
|
options[:parallel] = parallel
|
|
|
|
end
|
|
|
|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.on("--provider PROVIDER", String,
|
|
|
|
"Back the machine with a specific provider") do |provider|
|
2012-12-24 05:23:08 +00:00
|
|
|
options[:provider] = provider
|
2012-11-08 05:45:09 +00:00
|
|
|
end
|
2012-04-19 20:59:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
|
|
|
|
2013-09-02 22:06:03 +00:00
|
|
|
# Validate the provisioners
|
|
|
|
validate_provisioner_flags!(options)
|
|
|
|
|
2012-04-19 20:59:48 +00:00
|
|
|
# Go over each VM and bring it up
|
|
|
|
@logger.debug("'Up' each target VM...")
|
2013-03-22 02:22:54 +00:00
|
|
|
|
|
|
|
# Build up the batch job of what we'll do
|
2014-04-09 21:57:16 +00:00
|
|
|
machines = []
|
2013-04-16 22:22:14 +00:00
|
|
|
@env.batch(options[:parallel]) do |batch|
|
2014-03-04 21:51:25 +00:00
|
|
|
names = argv
|
2014-04-10 17:43:46 +00:00
|
|
|
if names.empty?
|
2014-10-23 18:46:22 +00:00
|
|
|
autostart = false
|
2014-04-10 17:43:46 +00:00
|
|
|
@env.vagrantfile.machine_names_and_options.each do |n, o|
|
2015-01-05 23:29:01 +00:00
|
|
|
autostart = true if o.key?(:autostart)
|
|
|
|
o[:autostart] = true if !o.key?(:autostart)
|
2014-04-11 01:26:19 +00:00
|
|
|
names << n.to_s if o[:autostart]
|
2014-04-10 17:43:46 +00:00
|
|
|
end
|
2014-10-23 18:46:22 +00:00
|
|
|
|
|
|
|
# If we have an autostart key but no names, it means that
|
|
|
|
# all machines are autostart: false and we don't start anything.
|
|
|
|
names = nil if autostart && names.empty?
|
2014-04-10 17:43:46 +00:00
|
|
|
end
|
2014-04-10 17:33:21 +00:00
|
|
|
|
2014-10-23 18:46:22 +00:00
|
|
|
if names
|
|
|
|
with_target_vms(names, provider: options[:provider]) do |machine|
|
|
|
|
@env.ui.info(I18n.t(
|
|
|
|
"vagrant.commands.up.upping",
|
|
|
|
name: machine.name,
|
|
|
|
provider: machine.provider_name))
|
2013-03-22 02:22:54 +00:00
|
|
|
|
2014-10-23 18:46:22 +00:00
|
|
|
machines << machine
|
2014-04-09 21:57:16 +00:00
|
|
|
|
2014-10-23 18:46:22 +00:00
|
|
|
batch.action(machine, :up, options)
|
|
|
|
end
|
2013-03-22 02:22:54 +00:00
|
|
|
end
|
2012-04-19 20:59:48 +00:00
|
|
|
end
|
|
|
|
|
2014-10-23 18:46:22 +00:00
|
|
|
if machines.empty?
|
|
|
|
@env.ui.info(I18n.t("vagrant.up_no_machines"))
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2014-04-09 21:57:16 +00:00
|
|
|
# Output the post-up messages that we have, if any
|
|
|
|
machines.each do |m|
|
|
|
|
next if !m.config.vm.post_up_message
|
|
|
|
next if m.config.vm.post_up_message == ""
|
|
|
|
|
|
|
|
# Add a newline to separate things.
|
|
|
|
@env.ui.info("", prefix: false)
|
|
|
|
|
|
|
|
m.ui.success(I18n.t(
|
|
|
|
"vagrant.post_up_message",
|
|
|
|
name: m.name.to_s,
|
|
|
|
message: m.config.vm.post_up_message))
|
|
|
|
end
|
|
|
|
|
2012-04-19 20:59:48 +00:00
|
|
|
# Success, exit status 0
|
|
|
|
0
|
2012-08-15 05:38:41 +00:00
|
|
|
end
|
2012-04-19 20:59:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|