Class: VagrantPlugins::OCI::Action::StopInstance
- Inherits:
-
Object
- Object
- VagrantPlugins::OCI::Action::StopInstance
- Defined in:
- lib/vagrant-oci/action/stop_instance.rb
Overview
This stops the running instance.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ StopInstance
constructor
A new instance of StopInstance.
Constructor Details
#initialize(app, env) ⇒ StopInstance
Returns a new instance of StopInstance.
8 9 10 11 |
# File 'lib/vagrant-oci/action/stop_instance.rb', line 8 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_oci::action::stop_instance") end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vagrant-oci/action/stop_instance.rb', line 13 def call(env) return :not_created if env[:machine].id.nil? begin server = env[:oci_compute].get_instance(env[:machine].id) rescue OCI::Errors::ServiceError return :not_created end lifecycle_state = server.data.lifecycle_state.upcase if %w[STOPPED STOPPING].include?(lifecycle_state) env[:ui].info(I18n.t("vagrant_oci.already_status", :status => lifecycle_state)) else env[:ui].info(I18n.t("vagrant_oci.stopping")) env[:oci_compute].instance_action(env[:machine].id, 'STOP') end @app.call(env) end |