Class: Vixen::Model::VM

Inherits:
Base
  • Object
show all
Defined in:
lib/vixen/model/vm.rb

Instance Attribute Summary

Attributes inherited from Base

#handle

Instance Method Summary collapse

Methods inherited from Base

finalize, #get_string_property, #initialize

Constructor Details

This class inherits a constructor from Vixen::Model::Base

Instance Method Details

#create_snapshot(name, description = "", &block) ⇒ Object



10
11
12
# File 'lib/vixen/model/vm.rb', line 10

def create_snapshot(name, description="", &block)
  Vixen::Model::Snapshot.new(Vixen::Bridge.create_snapshot handle, name, description, &block)
end

#current_power_statesObject



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/vixen/model/vm.rb', line 95

def current_power_states
  states = []
  bitwise_state = Vixen::Bridge.current_power_state handle
  [ :powering_off, :powered_off, :powering_on, :powered_on, :suspending,
    :suspended, :tools_running, :resetting, :blocked_on_msg, :paused,
    :resuming
  ].each do |state|
    states << state if ((bitwise_state & Vixen::Constants::VixPowerState[state]) == Vixen::Constants::VixPowerState[state])
  end
  states
end

#current_snapshotObject



6
7
8
# File 'lib/vixen/model/vm.rb', line 6

def current_snapshot
  Vixen::Model::Snapshot.new(Vixen::Bridge.current_snapshot(handle))
end

#power_off(opts = {}, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vixen/model/vm.rb', line 37

def power_off(opts={}, &block)
  hard_power_off = opts[:hard] || :if_necessary
  case hard_power_off
  when :if_necessary
    Vixen::Bridge.power_off_using_guest(handle, &block) || Vixen::Bridge.power_off(handle, &block)
  when :always
    Vixen::Bridge.power_off(handle, &block)
  else
    Vixen::Bridge.power_off_using_guest(handle, &block)
  end
  self
end

#power_on(&block) ⇒ Object



22
23
24
25
26
# File 'lib/vixen/model/vm.rb', line 22

def power_on(&block)
  return self if powered_on? or powering_on? or resuming? or resetting?
  Vixen::Bridge.power_on handle, &block
  self
end

#powered_off?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/vixen/model/vm.rb', line 67

def powered_off?
  current_power_states.include? :powered_off
end

#powered_on?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/vixen/model/vm.rb', line 75

def powered_on?
  current_power_states.include? :powered_on
end

#powering_off?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/vixen/model/vm.rb', line 63

def powering_off?
  current_power_states.include? :powering_off
end

#powering_on?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/vixen/model/vm.rb', line 71

def powering_on?
  current_power_states.include? :powering_on
end

#remove_snapshot(snapshot, &block) ⇒ Object



18
19
20
# File 'lib/vixen/model/vm.rb', line 18

def remove_snapshot(snapshot, &block)
  Vixen::Bridge.remove_snaphost self, snapshot, &block
end

#reset(opts = {}, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vixen/model/vm.rb', line 50

def reset(opts={}, &block)
  hard_reset = opts[:hard] || :if_necessary
  case hard_reset
  when :if_necessary
    Vixen::Bridge.reset_using_guest(handle, &block) || Vixen::Bridge.reset(handle, &block)
  when :always
    Vixen::Bridge.reset(handle, &block)
  else
    Vixen::Bridge.reset_using_guest(handle, &block)
  end
  self
end

#resetting?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/vixen/model/vm.rb', line 91

def resetting?
  current_power_states.include? :resetting
end

#resume(&block) ⇒ Object



28
29
30
# File 'lib/vixen/model/vm.rb', line 28

def resume(&block)
  power_on &block
end

#resuming?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/vixen/model/vm.rb', line 79

def resuming?
  current_power_states.include? :resuming
end

#revert_to_snapshot(snapshot, &block) ⇒ Object



14
15
16
# File 'lib/vixen/model/vm.rb', line 14

def revert_to_snapshot(snapshot, &block)
  Vixen::Bridge.revert_to_snapshot self, snapshot, &block
end

#suspend(&block) ⇒ Object



32
33
34
35
# File 'lib/vixen/model/vm.rb', line 32

def suspend(&block)
  Vixen::Bridge.suspend handle, &block
  self
end

#suspended?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/vixen/model/vm.rb', line 87

def suspended?
  current_power_states.include? :suspended
end

#suspending?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/vixen/model/vm.rb', line 83

def suspending?
  current_power_states.include? :suspending
end