Class: VagrantPlugins::Skytap::Command::Up
- Defined in:
- lib/vagrant-skytap/command/up.rb
Instance Method Summary collapse
-
#bring_up_machines(machines, options = {}) ⇒ Array
Custom handling for Skytap environments.
- #execute ⇒ Object
Instance Method Details
#bring_up_machines(machines, options = {}) ⇒ Array
Custom handling for Skytap environments. Creating and running happens in multiple phases:
-
Compose Skytap environment from groups of VMs, or add groups of machines to an existing environment, using optimal number of API calls.
-
Customize the VMs.
-
Run the VMs. If parallelized this happens with a single API call.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/vagrant-skytap/command/up.rb', line 146 def bring_up_machines(machines, ={}) return [] unless machines.present? # Invoke once for the entire set of machines. result = machines.first.action(:create, .merge(machines: machines)) # Lets us eliminate some redundant API calls cached_objects = { api_client: result[:api_client], environment: result[:environment], machines: machines, initial_states: machines.inject({}) {|acc, m| acc[m.id] = m.state.id ; acc }, } machines.each do |machine| machine.action(:update_hardware, .merge(cached_objects)) end machines.each do |machine| @env.ui.info(I18n.t( "vagrant.commands.up.upping", name: machine.name, provider: machine.provider_name)) machine.action(:run_vm, .merge(cached_objects)) end end |
#execute ⇒ Object
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 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vagrant-skytap/command/up.rb', line 38 def execute = {} [:destroy_on_error] = true [:parallel] = true [:provision_ignore_sentinel] = false opts = OptionParser.new do |o| o. = "Usage: vagrant up [options] [name]" o.separator "" o.separator "Options:" o.separator "" (o, ) o.on("--[no-]destroy-on-error", "Destroy machine if any fatal error happens (default to true)") do |destroy| [:destroy_on_error] = destroy end o.on("--[no-]parallel", "Enable or disable parallelism if provider supports it") do |parallel| [:parallel] = parallel end o.on("--provider PROVIDER", String, "Back the machine with a specific provider") do |provider| [:provider] = provider end end # Parse the options argv = (opts) return if !argv # Validate the provisioners if method(:validate_provisioner_flags!).arity == 1 validate_provisioner_flags!() else # Second argument was added in Vagrant 1.8.0 # https://github.com/mitchellh/vagrant/pull/5981 validate_provisioner_flags!(, argv) end # Go over each VM and bring it up @logger.debug("'Up' each target VM...") machines = [] names = argv if names.empty? autostart = false @env.vagrantfile..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 # Collect the machines first so we know what their provider # is, and decide whether to call the Vagrant core implementation # of this command. with_target_vms(names, provider: [:provider]) {|machine| machines << machine} unless machines.first.provider_name == :skytap @logger.debug("Calling default 'Up' implementation.") return super end @logger.debug("Executing Skytap 'Up' implementation.") bring_up_machines(machines, ) 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. next if m.config.vm. == "" # 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.)) end # Success, exit status 0 0 end |