class Fission::Action::Snapshot::Reverter
def initialize(vm)
Fission::Action::SnapshotReverter.new @my_vm
Examples:
vm - An instance of VM
object.
Internal: Creates a new SnapshotReverter object. This accepts a VM
def initialize(vm) @vm = vm end
def revert_to_snapshot(name)
If successful, the Response's data attribute will be nil.
Returns a Response with the result.
@reverter.revert_to_snapshot('foo_snap_1')
Examples
name - The snapshot name to revert to.
revert to must exist and the Fusion GUI must not be running.
Public: Reverts the VM to the specified snapshot. The snapshot to
def revert_to_snapshot(name) unless @vm.exists? return Response.new :code => 1, :message => 'VM does not exist' end if Fusion.running? message = 'It looks like the Fusion GUI is currently running. ' message << 'A VM cannot be reverted to a snapshot when the Fusion GUI is running. ' message << 'Exit the Fusion GUI and try again.' return Response.new :code => 1, :message => 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 message = "Unable to find a snapshot named '#{name}'." return Response.new :code => 1, :message => 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
def vmrun_cmd
Returns a String for the configured value of
# => "/foo/bar/vmrun -T fusion"
@reverter.vmrun_cmd
Examples
Internal: Helper for getting the configured vmrun_cmd value.
def vmrun_cmd Fission.config['vmrun_cmd'] end