Class: VagrantPlugins::Azure::Action::StopInstance
- Inherits:
-
Object
- Object
- VagrantPlugins::Azure::Action::StopInstance
- Defined in:
- lib/vagrant-azure/action/stop_instance.rb
Constant Summary
Constants included from Util::VMStatusTranslator
Util::VMStatusTranslator::POWER_STATES, Util::VMStatusTranslator::PROVISIONING_STATES
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ StopInstance
constructor
A new instance of StopInstance.
Methods included from Util::VMStatusTranslator
#built?, #power_state, #running?, #stopped?, #stopping?, #tearing_down?, #vm_status_to_state
Methods included from Util::VMAwait
Methods included from Util::MachineIdHelper
#parse_machine_id, #serialize_machine_id
Constructor Details
#initialize(app, env) ⇒ StopInstance
Returns a new instance of StopInstance.
18 19 20 21 |
# File 'lib/vagrant-azure/action/stop_instance.rb', line 18 def initialize(app, env) @app = app @logger = Log4r::Logger.new('vagrant_azure::action::stop_instance') end |
Instance Method Details
#call(env) ⇒ Object
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 |
# File 'lib/vagrant-azure/action/stop_instance.rb', line 23 def call(env) env[:metrics] ||= {} parsed = parse_machine_id(env[:machine].id) if env[:machine].state.id == :stopped env[:ui].info(I18n.t('vagrant_azure.already_status', :status => 'stopped.')) else env[:ui].info(I18n.t('vagrant_azure.stopping', parsed)) env[:azure_arm_service].compute.virtual_machines.power_off(parsed[:group], parsed[:name]) # Wait for the instance to be ready first env[:metrics]['instance_stop_time'] = Util::Timer.time do env[:ui].info(I18n.t('vagrant_azure.waiting_for_stop')) task = await_true(env) do |vm| stopped?(vm.instance_view.statuses) end if task.value env[:ui].info(I18n.t('vagrant_azure.stopped', parsed)) else raise I18n.t('vagrant_azure.errors.failed_starting', parsed) unless env[:interrupted] end end env[:ui].info(I18n.t('vagrant_azure.stopped', parsed)) end @app.call(env) end |