Class: VagrantPlugins::Openstack::Action::SnapshotSave

Inherits:
AbstractAction
  • Object
show all
Defined in:
lib/vagrant-openstack-provider/action/snapshot_save.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, _env, retry_interval = 3) ⇒ SnapshotSave

Returns a new instance of SnapshotSave.



7
8
9
10
# File 'lib/vagrant-openstack-provider/action/snapshot_save.rb', line 7

def initialize(app, _env, retry_interval = 3)
  @app = app
  @retry_interval = retry_interval
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
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
# File 'lib/vagrant-openstack-provider/action/snapshot_save.rb', line 12

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