lib/vagrant-orchestrate/command/push.rb in vagrant-orchestrate-0.4.5 vs lib/vagrant-orchestrate/command/push.rb in vagrant-orchestrate-0.4.6

- old
+ new

@@ -1,7 +1,8 @@ require "optparse" require "vagrant" +require "vagrant-orchestrate/action/setcredentials" # Borrowed from http://stackoverflow.com/questions/12374645/splitting-an-array-into-equal-parts-in-ruby class Array def in_groups(num_groups) return [] if num_groups == 0 @@ -55,10 +56,12 @@ if machines.empty? @env.ui.info("No servers with :managed provider found. Skipping.") return 0 end + retrieve_creds(machines) if @env.vagrantfile.config.orchestrate.credentials + options[:parallel] = true strategy = options[:strategy] || @env.vagrantfile.config.orchestrate.strategy @env.ui.info("Pushing to managed servers using #{strategy} strategy.") # Handle a couple of them more tricky edges. @@ -128,11 +131,11 @@ end end # rubocop:enable Metrics/AbcSize, MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def prompt_for_continue - result = @env.ui.ask("Deployment paused for manual review. Would you like to continue? (y/n)") + result = @env.ui.ask("Deployment paused for manual review. Would you like to continue? (y/n) ") if result.upcase != "Y" @env.ui.info("Deployment push action cancelled by user") return false end true @@ -141,9 +144,26 @@ def batchify(machines, action, options) @env.batch(options[:parallel]) do |batch| machines.each do |machine| batch.action(machine, action, options) end + end + end + + def retrieve_creds(machines) + creds = VagrantPlugins::Orchestrate::Action::SetCredentials.new + (username, password) = creds.retrieve_creds(@env.vagrantfile.config.orchestrate.credentials, @env.ui) + + # Apply the credentials to the machine info, or back out if we were unable to procure them. + if username && password + machines.each do |machine| + creds.apply_creds(machine, username, password) + end + else + @env.ui.warn <<-WARNING +Vagrant-orchestrate could not gather credentials. \ +Continuing with default credentials." + WARNING end end end end end