Class: Fission::Action::Snapshot::Reverter
- Defined in:
- lib/fission/action/snapshot/reverter.rb
Instance Method Summary collapse
-
#initialize(vm) ⇒ Reverter
constructor
Internal: Creates a new SnapshotReverter object.
-
#revert_to_snapshot(name) ⇒ Object
Public: Reverts the VM to the specified snapshot.
Constructor Details
#initialize(vm) ⇒ Reverter
Internal: Creates a new SnapshotReverter object. This accepts a VM object.
vm - An instance of VM
Examples:
Fission::Action::SnapshotReverter.new @my_vm
Returns a new SnapshotReverter object
17 18 19 |
# File 'lib/fission/action/snapshot/reverter.rb', line 17 def initialize(vm) @vm = vm end |
Instance Method Details
#revert_to_snapshot(name) ⇒ Object
Public: Reverts the VM to the specified snapshot. The snapshot to revert to must exist and the Fusion GUI must not be running.
name - The snapshot name to revert to.
Examples
@reverter.revert_to_snapshot('foo_snap_1')
Returns a Response with the result. If successful, the Response’s data attribute will be nil. If there is an error, an unsuccessful Response will be returned.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fission/action/snapshot/reverter.rb', line 33 def revert_to_snapshot(name) unless @vm.exists? return Response.new :code => 1, :message => 'VM does not exist' end if Fusion.running? = 'It looks like the Fusion GUI is currently running. ' << 'A VM cannot be reverted to a snapshot when the Fusion GUI is running. ' << 'Exit the Fusion GUI and try again.' return Response.new :code => 1, :message => end conf_file_response = @vm.conf_file return conf_file_response unless conf_file_response.successful? snapshots_response = @vm.snapshots return snapshots_response unless snapshots_response.successful? unless snapshots_response.data.include? name = "Unable to find a snapshot named '#{name}'." return Response.new :code => 1, :message => end command = "#{vmrun_cmd} revertToSnapshot " command << "'#{conf_file_response.data}' \"#{name}\" 2>&1" command_exec = Fission::Action::ShellExecutor.new command Response.from_shell_executor command_exec.execute end |