Class: Simp::BeakerHelpers::Snapshot
- Inherits:
-
Object
- Object
- Simp::BeakerHelpers::Snapshot
- Defined in:
- lib/simp/beaker_helpers/snapshot.rb
Overview
Helpers for managing Vagrant snapshots
Constant Summary collapse
- BASE_NAME =
The name of the base snapshot that is created if no snapshots currently exist
'_simp_beaker_base'
Class Method Summary collapse
-
.exist?(host, name) ⇒ Boolean
Whether or not a named snapshot exists.
-
.list(host) ⇒ Array[String]
List all snapshots for the given host.
-
.restore(host, snapshot_name) ⇒ Object
Restore a snapshot.
-
.restore_to_base(host) ⇒ Object
Restore all the way back to the base image.
-
.save(host, snapshot_name) ⇒ Object
Save a snapshot.
Class Method Details
.exist?(host, name) ⇒ Boolean
Whether or not a named snapshot exists
49 50 51 |
# File 'lib/simp/beaker_helpers/snapshot.rb', line 49 def self.exist?(host, name) list(host).include?(name) end |
.list(host) ⇒ Array[String]
List all snapshots for the given host
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/simp/beaker_helpers/snapshot.rb', line 60 def self.list(host) output = [] vdir = vagrant_dir(host) if vdir Dir.chdir(vdir) do output = %x(vagrant snapshot list #{host.name}).lines output.map! do |x| x.split(/^#{host.name}_/).last.split(':').first.delete('==>').strip end end end output end |
.restore(host, snapshot_name) ⇒ Object
Restore a snapshot
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/simp/beaker_helpers/snapshot.rb', line 84 def self.restore(host, snapshot_name) if enabled? vdir = vagrant_dir(host) if vdir Dir.chdir(vdir) do snap = "#{host.name}_#{snapshot_name}" output = %x(vagrant snapshot restore #{host.name} "#{snap}" 2>&1) if (output =~ /error/i) && (output =~ /child/) raise output end if (output =~ /snapshot.*not found/) raise output end logger.notify(output) retry_on( host, %(echo "restoring snapshot '#{snap}'" > /dev/null), :max_retries => 30, :retry_interval => 1 ) end end end end |
.restore_to_base(host) ⇒ Object
Restore all the way back to the base image
120 121 122 123 124 125 126 |
# File 'lib/simp/beaker_helpers/snapshot.rb', line 120 def self.restore_to_base(host) if exist?(host, BASE_NAME) restore(host, BASE_NAME) else save(host, BASE_NAME) end end |
.save(host, snapshot_name) ⇒ Object
Save a snapshot
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/simp/beaker_helpers/snapshot.rb', line 15 def self.save(host, snapshot_name) if enabled? vdir = vagrant_dir(host) if vdir Dir.chdir(vdir) do save(host, BASE_NAME) unless exist?(host, BASE_NAME) snap = "#{host.name}_#{snapshot_name}" output = %x(vagrant snapshot save --force #{host.name} "#{snap}") logger.notify(output) retry_on( host, %(echo "saving snapshot '#{snap}'" > /dev/null), :max_retries => 30, :retry_interval => 1 ) end end end end |