Class: Sahara::Session::Parallels

Inherits:
Object
  • Object
show all
Defined in:
lib/sahara/session/parallels.rb

Instance Method Summary collapse

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

#commitObject



54
55
56
57
# File 'lib/sahara/session/parallels.rb', line 54

def commit
  off
  on
end

#get_snapshot_idObject



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

Returns:

  • (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

Returns:

  • (Boolean)


64
65
66
# File 'lib/sahara/session/parallels.rb', line 64

def is_vm_created?
  return !@machine.id.nil?
end

#list_snapshotsObject



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

#offObject



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

#onObject



50
51
52
# File 'lib/sahara/session/parallels.rb', line 50

def on
  `#{@prlctl} snapshot "#{@instance_id}" --name "#{@sandboxname}"`
end

#rollbackObject



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