Class: VagrantPlugins::Skytap::Command::Up

Inherits:
CommandUp::Command
  • Object
show all
Defined in:
lib/vagrant-skytap/command/up.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/vagrant-skytap/command/up.rb', line 13

def execute
  # This implementation of the "up" command overrides
  # the default implementation due to load order.
  if @env.default_provider == :skytap
    @logger.debug("Executing Skytap 'Up' implementation.")
  else
    @logger.debug("Calling default 'Up' implementation.")
    return super
  end

  options = {}
  options[:destroy_on_error] = true
  options[:parallel] = true
  options[:provision_ignore_sentinel] = false

  opts = OptionParser.new do |o|
    o.banner = "Usage: vagrant up [options] [name]"
    o.separator ""
    o.separator "Options:"
    o.separator ""

    build_start_options(o, options)

    o.on("--[no-]destroy-on-error",
         "Destroy machine if any fatal error happens (default to true)") do |destroy|
      options[:destroy_on_error] = destroy
    end

    o.on("--[no-]parallel",
         "Enable or disable parallelism if provider supports it") do |parallel|
      options[:parallel] = parallel
    end

    o.on("--provider PROVIDER", String,
         "Back the machine with a specific provider") do |provider|
      options[:provider] = provider
    end
  end

  # Parse the options
  argv = parse_options(opts)
  return if !argv

  # Validate the provisioners
  validate_provisioner_flags!(options)

  # Go over each VM and bring it up
  @logger.debug("'Up' each target VM...")

  machines = []
  names = argv
  if names.empty?
    autostart = false
    @env.vagrantfile.machine_names_and_options.each do |n, o|
      autostart = true if o.key?(:autostart)
      o[:autostart] = true if !o.key?(:autostart)
      names << n.to_s if o[:autostart]
    end

    # 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?
  end

  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))

      machines << machine
      machine.action(:create, options)
      machine.action(:update_hardware, options)
    end

    initial_states = machines.inject({}) {|acc, m| acc[m.id] = m.state.id ; acc }

    machines.each_with_index do |machine, i|
      machine.action(:run_vm, options.merge(
        first_machine:  i == 0,
        machines:       machines,
        initial_states: initial_states
      ))
    end
  end

  if machines.empty?
    @env.ui.info(I18n.t("vagrant.up_no_machines"))
    return 0
  end

  # 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

  # Success, exit status 0
  0
end