Class: VagrantPlugins::ArubaCloud::Action::StartServer
- Inherits:
-
Object
- Object
- VagrantPlugins::ArubaCloud::Action::StartServer
- Includes:
- Vagrant::Util::Retryable
- Defined in:
- lib/vagrant-arubacloud/action/start_server.rb
Overview
This stop a server, if it exists
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ StartServer
constructor
A new instance of StartServer.
Constructor Details
#initialize(app, env) ⇒ StartServer
Returns a new instance of StartServer.
13 14 15 16 17 |
# File 'lib/vagrant-arubacloud/action/start_server.rb', line 13 def initialize(app, env) @app = app @env = env @logger = Log4r::Logger.new('vagrant_arubacloud::action::start_server') end |
Instance Method Details
#call(env) ⇒ Object
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 |
# File 'lib/vagrant-arubacloud/action/start_server.rb', line 19 def call(env) if env[:machine].id config = env[:machine].provider_config arubacloud_dc = config.endpoint env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.starting_server')) server = env[:arubacloud_compute].servers.get(env[:machine].id) # Check if the vm is already powered on @logger.debug("VM ready?: #{server.ready?}") if server.ready? # continue the middleware @app.call(env) else # Try to power-on the VM. begin server.power_on rescue Fog::ArubaCloud::Errors::VmStatus env[:ui].warn(I18n.t('vagrant_arubacloud.bad_state')) return rescue Fog::ArubaCloud::Errors::RequestError => e if e.response['ResultCode'].eql? 17 env[:ui].warn(I18n.t('vagrant_arubacloud.operation_already_in_queue')) return end end # Wait for the server to be proper started and up env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.waiting_server_powered_on')) retryable(:tries => 40, :sleep => 2) do server.wait_for(1) { ready? } end env[:ui].info(" [#{arubacloud_dc}] " + I18n.t('vagrant_arubacloud.server_powered_on')) end end @app.call(env) end |