Class: VagrantPlugins::Dustcloud::Action::StartInstance
- Inherits:
-
Object
- Object
- VagrantPlugins::Dustcloud::Action::StartInstance
- Defined in:
- lib/vagrant-dustcloud/action/start_instance.rb
Overview
This starts a stopped instance.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ StartInstance
constructor
A new instance of StartInstance.
Constructor Details
#initialize(app, env) ⇒ StartInstance
Returns a new instance of StartInstance.
12 13 14 15 |
# File 'lib/vagrant-dustcloud/action/start_instance.rb', line 12 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_dustcloud::action::start_instance") end |
Instance Method Details
#call(env) ⇒ Object
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 |
# File 'lib/vagrant-dustcloud/action/start_instance.rb', line 17 def call(env) # Initialize metrics if they haven't been env[:metrics] ||= {} env[:ui].info(I18n.t("vagrant_dustcloud.starting")) begin env[:dustcloud].start_vm(env[:machine].id) env[:metrics]["instance_ready_time"] = Util::Timer.time do env[:ui].info(I18n.t("vagrant_dustcloud.waiting_for_ready")) total_waited = 0 while true # If we're interrupted don't worry about waiting break if env[:interrupted] # Wait for the server to be ready vm = env[:dustcloud].get_vm(env[:machine].id) if vm["status"] == "ACTIVE" break end sleep(2) total_waited += 2 if total_waited > 180 raise Errors::InstanceReadyTimeout, timeout: 180 end end end env[:ui].info("Time to instance ready: #{env[:metrics]["instance_ready_time"]}") if !env[:interrupted] env[:metrics]["instance_ssh_time"] = Util::Timer.time do # Wait for SSH to be ready. env[:ui].info(I18n.t("vagrant_dustcloud.waiting_for_ssh")) network_ready_retries = 0 network_ready_retries_max = 10 while true # If we're interrupted then just back out break if env[:interrupted] # When an ec2 instance comes up, it's networking may not be ready # by the time we connect. begin break if env[:machine].communicate.ready? rescue Exception => e if network_ready_retries < network_ready_retries_max then network_ready_retries += 1 @logger.warn("SSH not yet up, retrying...") else raise e end end sleep 2 end end env[:ui].info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}") # Ready and booted! env[:ui].info(I18n.t("vagrant_dustcloud.ready")) end end @app.call(env) end |