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

#all_snapshotsObject



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

def all_snapshots
  roots = root_snapshots
  childs = roots.map {|s| s.all_children }
  (roots + childs).flatten
end

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



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

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

#current_power_statesObject



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/vixen/model/vm.rb', line 117

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



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

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

#guest_osObject



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

def guest_os
  get_string_property Vixen::Constants::VixPropertyId[:vm_guestos]
end

#nameObject



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

def name
  get_string_property Vixen::Constants::VixPropertyId[:vm_name]
end

#pathObject



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

def path
  get_string_property Vixen::Constants::VixPropertyId[:vmx_pathname]
end

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



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vixen/model/vm.rb', line 59

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



44
45
46
47
48
# File 'lib/vixen/model/vm.rb', line 44

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)


89
90
91
# File 'lib/vixen/model/vm.rb', line 89

def powered_off?
  current_power_states.include? :powered_off
end

#powered_on?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/vixen/model/vm.rb', line 97

def powered_on?
  current_power_states.include? :powered_on
end

#powering_off?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/vixen/model/vm.rb', line 85

def powering_off?
  current_power_states.include? :powering_off
end

#powering_on?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/vixen/model/vm.rb', line 93

def powering_on?
  current_power_states.include? :powering_on
end

#remove_snapshot(snapshot, &block) ⇒ Object



40
41
42
# File 'lib/vixen/model/vm.rb', line 40

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

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



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/vixen/model/vm.rb', line 72

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)


113
114
115
# File 'lib/vixen/model/vm.rb', line 113

def resetting?
  current_power_states.include? :resetting
end

#resume(&block) ⇒ Object



50
51
52
# File 'lib/vixen/model/vm.rb', line 50

def resume(&block)
  power_on &block
end

#resuming?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/vixen/model/vm.rb', line 101

def resuming?
  current_power_states.include? :resuming
end

#revert_to_snapshot(snapshot, &block) ⇒ Object



36
37
38
# File 'lib/vixen/model/vm.rb', line 36

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

#root_snapshotsObject



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

def root_snapshots
  Vixen::Bridge.get_root_snapshots handle
end

#suspend(&block) ⇒ Object



54
55
56
57
# File 'lib/vixen/model/vm.rb', line 54

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

#suspended?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/vixen/model/vm.rb', line 109

def suspended?
  current_power_states.include? :suspended
end

#suspending?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/vixen/model/vm.rb', line 105

def suspending?
  current_power_states.include? :suspending
end