-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up Vagrant snapshots when VMs are destroyed
Add a step to the VM destroy action that cleans up any Vagrant snapshots.
- Loading branch information
Showing
4 changed files
with
54 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
source/lib/vagrant-openstack-provider/action/snapshot_cleanup.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'vagrant-openstack-provider/action/abstract_action' | ||
|
||
module VagrantPlugins | ||
module Openstack | ||
module Action | ||
class SnapshotCleanup < AbstractAction | ||
def initialize(app, _env) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
nova = env[:openstack_client].nova | ||
machine_snapshots = nova.list_snapshots(env, env[:machine].id) | ||
|
||
snapshots_to_clean = machine_snapshots.select do |s| | ||
s.metadata.key?('vagrant_snapshot') | ||
end | ||
|
||
@app.call env | ||
|
||
unless snapshots_to_clean.empty? | ||
env[:ui].info("Deleting Vagrant snapshots: #{snapshots_to_clean.map(&:name)}") | ||
end | ||
|
||
snapshots_to_clean.each do |s| | ||
nova.delete_snapshot(env, s.id) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters