Class: VagrantPlugins::Openstack::Action::SnapshotDelete

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

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ SnapshotDelete

Returns a new instance of SnapshotDelete.



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

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

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-openstack-illuin-provider/action/snapshot_delete.rb', line 11

def call(env)
  nova = env[:openstack_client].nova
  machine_snapshots = nova.list_snapshots(env, env[:machine].id)

  snapshot = machine_snapshots.find { |s| s.name == env[:snapshot_name] }

  unless snapshot.nil?
    env[:ui].info(I18n.t('vagrant.actions.vm.snapshot.deleting',
                         name: snapshot.name))

    nova.delete_snapshot(env, snapshot.id)

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

  @app.call env
end