Class: Sahara::Session::Parallels
- Inherits:
-
Object
- Object
- Sahara::Session::Parallels
- Defined in:
- lib/sahara/session/parallels.rb
Instance Method Summary collapse
- #commit ⇒ Object
- #get_snapshot_id ⇒ Object
-
#initialize(machine) ⇒ Parallels
constructor
A new instance of Parallels.
- #is_snapshot_mode_on? ⇒ Boolean
- #is_vm_created? ⇒ Boolean
- #list_snapshots ⇒ Object
- #off ⇒ Object
- #on ⇒ Object
- #rollback ⇒ Object
Constructor Details
#initialize(machine) ⇒ Parallels
Returns a new instance of Parallels.
5 6 7 8 9 10 11 |
# File 'lib/sahara/session/parallels.rb', line 5 def initialize(machine) @machine=machine @instance_id = @machine.id @prlctl="prlctl" @sandboxname="sahara-sandbox" @snapshots=list_snapshots end |
Instance Method Details
#commit ⇒ Object
54 55 56 57 |
# File 'lib/sahara/session/parallels.rb', line 54 def commit off on end |
#get_snapshot_id ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/sahara/session/parallels.rb', line 26 def get_snapshot_id # if we can get snapshot description without exception it exists begin snapshot_id = @snapshots.fetch(@sandboxname) rescue raise Sahara::Errors::SnapshotMissing end return snapshot_id end |
#is_snapshot_mode_on? ⇒ Boolean
36 37 38 39 40 41 42 43 |
# File 'lib/sahara/session/parallels.rb', line 36 def is_snapshot_mode_on? begin snapshot_id = get_snapshot_id rescue Sahara::Errors::SnapshotMissing return false end return true end |
#is_vm_created? ⇒ Boolean
64 65 66 |
# File 'lib/sahara/session/parallels.rb', line 64 def is_vm_created? return !@machine.id.nil? end |
#list_snapshots ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sahara/session/parallels.rb', line 13 def list_snapshots snapshotlist = Hash.new output = `#{@prlctl} snapshot-list "#{@instance_id}" --tree` snapshot_ids=output.scan(/\{([\w-]*)?\}/).flatten snapshot_ids.each do |id| res = `#{@prlctl} snapshot-list "#{@instance_id}" -i "#{id}"` if res =~ (/^Name:\s(.*)$/) snapshotlist[$1] = id end end snapshotlist end |
#off ⇒ Object
45 46 47 48 |
# File 'lib/sahara/session/parallels.rb', line 45 def off snapshot_id = get_snapshot_id `#{@prlctl} snapshot-delete "#{@instance_id}" --id "#{snapshot_id}" ` end |
#on ⇒ Object
50 51 52 |
# File 'lib/sahara/session/parallels.rb', line 50 def on `#{@prlctl} snapshot "#{@instance_id}" --name "#{@sandboxname}"` end |
#rollback ⇒ Object
59 60 61 62 |
# File 'lib/sahara/session/parallels.rb', line 59 def rollback snapshot_id = get_snapshot_id `#{@prlctl} snapshot-switch "#{@instance_id}" --id "#{snapshot_id}" ` end |