Sha256: 8082ce22459cc83ed6b732285b80cd6343cec3c14be0252b343e86551fe3a772

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

require 'vagrant-conoha/action/abstract_action'

module VagrantPlugins
  module ConoHa
    module Action
      class SnapshotSave < AbstractAction
        def initialize(app, _env, retry_interval = 3)
          @app = app
          @retry_interval = retry_interval
        end

        def call(env)
          nova = env[:openstack_client].nova
          config = env[:machine].provider_config

          env[:ui].info(I18n.t('vagrant.actions.vm.snapshot.saving',
                               name: env[:snapshot_name]))

          nova.create_snapshot(
            env,
            env[:machine].id, env[:snapshot_name])

          image = nova.list_snapshots(env, env[:machine].id).find { |i| i.name == env[:snapshot_name] }

          timeout(config.server_create_timeout, Errors::Timeout) do
            loop do
              image_status = nova.get_image_details(env, image.id)

              break if image_status['status'] == 'ACTIVE'

              unless image_status['progress'].nil?
                env[:ui].clear_line
                env[:ui].report_progress(image_status['progress'], 100, false)
              end

              sleep @retry_interval
            end
          end

          # Clear progress output.
          env[:ui].clear_line

          env[:ui].success(I18n.t('vagrant.actions.vm.snapshot.saved',
                                  name: env[:snapshot_name]))

          @app.call env
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-conoha-0.1.10 lib/vagrant-conoha/action/snapshot_save.rb
vagrant-conoha-0.1.9 lib/vagrant-conoha/action/snapshot_save.rb
vagrant-conoha-0.1.8 lib/vagrant-conoha/action/snapshot_save.rb