Class: Xen::Vm
- Inherits:
-
Object
- Object
- Xen::Vm
- Defined in:
- lib/xen/vm.rb
Instance Attribute Summary collapse
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
-
#clean_reboot! ⇒ Object
Reboots the VM in a clean way, and returns the current state.
-
#clean_shutdown! ⇒ Object
Shuts down the VM in a clean way, and returns the current state.
-
#hard_reboot! ⇒ Object
Hard reboots the VM, and returns the current state.
-
#hard_shutdown! ⇒ Object
Shuts down the VM immediatly, hard, and returns the current state.
-
#initialize(uid, host) ⇒ Vm
constructor
Creates a new VM, Given the VM’s UID and the host it is running on.
-
#is_dom0? ⇒ Boolean
Returns true if the current vm happens to be dom0.
-
#name ⇒ Object
Returns the VM’s name.
-
#pause! ⇒ Object
Pauses the VM, and returns the current state.
-
#record ⇒ Object
Record..
-
#start!(paused = false) ⇒ Object
Starts a VM, and returns the current state.
-
#state(refresh = false) ⇒ Object
Gets the state of the VM.
- #to_s ⇒ Object
-
#unpause! ⇒ Object
Unpauses the VM, and returns the current state.
-
#uuid ⇒ Object
Returns the VM’s uuid.
Constructor Details
#initialize(uid, host) ⇒ Vm
Creates a new VM, Given the VM’s UID and the host it is running on.
8 9 10 11 |
# File 'lib/xen/vm.rb', line 8 def initialize(uid, host) @uid, @host = uid, host # self.get_state # Too expensive! end |
Instance Attribute Details
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
5 6 7 |
# File 'lib/xen/vm.rb', line 5 def uid @uid end |
Instance Method Details
#clean_reboot! ⇒ Object
Reboots the VM in a clean way, and returns the current state
65 66 67 68 |
# File 'lib/xen/vm.rb', line 65 def clean_reboot! @host.call("VM.clean_reboot",@uid) state(true) end |
#clean_shutdown! ⇒ Object
Shuts down the VM in a clean way, and returns the current state
59 60 61 62 |
# File 'lib/xen/vm.rb', line 59 def clean_shutdown! @host.call("VM.clean_shutdown",@uid) state(true) end |
#hard_reboot! ⇒ Object
Hard reboots the VM, and returns the current state
77 78 79 80 |
# File 'lib/xen/vm.rb', line 77 def hard_reboot! @host.call("VM.hard_reboot",@uid) state(true) end |
#hard_shutdown! ⇒ Object
Shuts down the VM immediatly, hard, and returns the current state
71 72 73 74 |
# File 'lib/xen/vm.rb', line 71 def hard_shutdown! @host.call("VM.hard_shutdown",@uid) state(true) end |
#is_dom0? ⇒ Boolean
Returns true if the current vm happens to be dom0.
31 32 33 |
# File 'lib/xen/vm.rb', line 31 def is_dom0? name.to_s == "Domain-0" end |
#name ⇒ Object
Returns the VM’s name
26 27 28 |
# File 'lib/xen/vm.rb', line 26 def name @host.get_value("VM.get_name_label",@uid) end |
#pause! ⇒ Object
Pauses the VM, and returns the current state
47 48 49 50 |
# File 'lib/xen/vm.rb', line 47 def pause! @host.call("VM.pause",@uid) state(true) end |
#record ⇒ Object
Record..
83 84 85 |
# File 'lib/xen/vm.rb', line 83 def record @host.get_value("VM.get_record", @uid) end |
#start!(paused = false) ⇒ Object
Starts a VM, and returns the current state
41 42 43 44 |
# File 'lib/xen/vm.rb', line 41 def start!(paused = false) @host.call("VM.start",@uid, paused) state(true) end |
#state(refresh = false) ⇒ Object
Gets the state of the VM. The first time it is called it query’s the server, other times it is cached. There is an optional parameter ‘refresh’ which, when true, will re-query the server.
Example
# Having vm being a new initiated Vm
vm.state # => "Running"
vm.clean_shutdown! # => "Running"
# We wait a while
vm.state # => "Running" (cached)
vm.state(true) # => "Halted"
21 22 23 |
# File 'lib/xen/vm.rb', line 21 def state refresh = false @state = refresh || !@state ? @host.get_value("VM.get_power_state",@uid) : @state end |
#to_s ⇒ Object
87 88 89 |
# File 'lib/xen/vm.rb', line 87 def to_s @uid.to_s end |
#unpause! ⇒ Object
Unpauses the VM, and returns the current state
53 54 55 56 |
# File 'lib/xen/vm.rb', line 53 def unpause! @host.call("VM.unpause",@uid) state(true) end |
#uuid ⇒ Object
Returns the VM’s uuid
36 37 38 |
# File 'lib/xen/vm.rb', line 36 def uuid @host.get_value("VM.get_uuid",@uid) end |