Class: VagrantPlugins::ProfitBricks::Action::Start
- Inherits:
-
Object
- Object
- VagrantPlugins::ProfitBricks::Action::Start
- Defined in:
- lib/vagrant-profitbricks/action/start_server.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, _env) ⇒ Start
constructor
A new instance of Start.
Constructor Details
#initialize(app, _env) ⇒ Start
Returns a new instance of Start.
7 8 9 10 |
# File 'lib/vagrant-profitbricks/action/start_server.rb', line 7 def initialize(app, _env) @app = app @logger = Log4r::Logger.new('vagrant_profitbricks::action::starting_server') end |
Instance Method Details
#call(env) ⇒ Object
12 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 |
# File 'lib/vagrant-profitbricks/action/start_server.rb', line 12 def call(env) if env[:machine_state] == :not_created env[:ui].info(I18n.t('vagrant_profitbricks.not_created')) @app.call(env) end compute = env[:profitbricks_compute] server_id = env[:machine].id datacenter_id = env[:machine].provider_config.datacenter_id server = begin compute.servers.get(datacenter_id, server_id) rescue nil end if server.nil? @logger.warn "Unable to find server #{server_id}..." env[:ui].warn(I18n.t('vagrant_profitbricks.errors.server_not_found')) env[:machine].id = nil else @logger.info "Starting server #{server_id}..." env[:ui].info(I18n.t('vagrant_profitbricks.starting_server')) end if server.start 30.times do |_t| begin s = compute.servers.get(datacenter_id, server_id) break if s.vm_state == 'RUNNING' sleep 10 end end end @app.call(env) end |