Sha256: a792b3d910b1d7098f2a069d42d5db4b070a1a214e24c3a97a58a8cfd1b71b05

Contents?: true

Size: 1.48 KB

Versions: 7

Compression:

Stored size: 1.48 KB

Contents

# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'log4r'
require 'vagrant/util/retryable'
require 'vagrant-google/util/timer'

module VagrantPlugins
  module Google
    module Action

      # This stops the running instance.
      class StopInstance

        include Vagrant::Util::Retryable

        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant_google::action::stop_instance")
        end

        def call(env)
          server = env[:google_compute].servers.get(env[:machine].id, env[:machine].provider_config.zone)

          if env[:machine].state.id == :TERMINATED
            env[:ui].info(I18n.t("vagrant_google.already_status", :status => env[:machine].state.id))
          else
            env[:ui].info(I18n.t("vagrant_google.stopping"))
            operation = server.stop
            operation.wait_for { ready? }
          end

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vagrant-google-1.0.0 lib/vagrant-google/action/stop_instance.rb
vagrant-google-1.0.0.rc0 lib/vagrant-google/action/stop_instance.rb
vagrant-google-0.2.5 lib/vagrant-google/action/stop_instance.rb
vagrant-google-0.2.5.rc0 lib/vagrant-google/action/stop_instance.rb
vagrant-google-0.2.4 lib/vagrant-google/action/stop_instance.rb
vagrant-google-0.2.3 lib/vagrant-google/action/stop_instance.rb
vagrant-google-0.2.2 lib/vagrant-google/action/stop_instance.rb