Sha256: b380c4289f47444d482654cf48f361f94482c14197eef61b3023bb423da04b1d

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

require 'vagrant-openstack-provider/action/abstract_action'

module VagrantPlugins
  module Openstack
    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

5 entries across 5 versions & 2 rubygems

Version Path
vagrant-openstack-provider-0.13.0 lib/vagrant-openstack-provider/action/snapshot_save.rb
vagrant-openstack-provider-0.12.0 lib/vagrant-openstack-provider/action/snapshot_save.rb
vagrant-openstack-provider-illuin-0.11.1 lib/vagrant-openstack-provider/action/snapshot_save.rb
vagrant-openstack-provider-0.11.0 lib/vagrant-openstack-provider/action/snapshot_save.rb
vagrant-openstack-provider-0.10.0 lib/vagrant-openstack-provider/action/snapshot_save.rb