Class: Xen::VM
Class Method Summary collapse
-
.create(name, memory, host) ⇒ Object
Creates a new VM with a certain name set and a amount of memory (in bytes) on a host.
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.
-
#start!(paused = false) ⇒ Object
Starts a VM, and returns the current state.
-
#state(refresh = false) ⇒ Object
Gets the state of the VM.
-
#unpause! ⇒ Object
Unpauses the VM, and returns the current state.
- #vdbs ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(uid, host) ⇒ VM
Creates a new VM, Given the VM’s UID and the host it is running on.
54 55 56 57 |
# File 'lib/xen/vm.rb', line 54 def initialize(uid, host) @uid, @host = uid, host preload_record! end |
Class Method Details
.create(name, memory, host) ⇒ Object
Creates a new VM with a certain name set and a amount of memory (in bytes) on a host
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/xen/vm.rb', line 41 def self.create(name, memory, host) o = @initial_config.merge({ :name_label => name, :memory_static_max => memory, :memory_dynamic_max => memory, :memory_dynamic_min => memory, :memory_static_min => memory }) uid = host.get_value("VM.create", o) self.new(uid, host) end |
Instance Method Details
#clean_reboot! ⇒ Object
Reboots the VM in a clean way, and returns the current state
106 107 108 109 |
# File 'lib/xen/vm.rb', line 106 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
100 101 102 103 |
# File 'lib/xen/vm.rb', line 100 def clean_shutdown! @host.call("VM.clean_shutdown",@uid) state(true) end |
#hard_reboot! ⇒ Object
Hard reboots the VM, and returns the current state
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/xen/vm.rb', line 118 def hard_reboot! # Update 30/08/2007 # This function just returns an ENOTIMPLEMENTED in the Xen API, so we'll have to implement it ourselves # @host.call("VM.hard_reboot",@uid) # Should do: # hard_shutdown! # start! state(true) end |
#hard_shutdown! ⇒ Object
Shuts down the VM immediatly, hard, and returns the current state
112 113 114 115 |
# File 'lib/xen/vm.rb', line 112 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.
77 78 79 |
# File 'lib/xen/vm.rb', line 77 def is_dom0? @control_domain end |
#name ⇒ Object
Returns the VM’s name
72 73 74 |
# File 'lib/xen/vm.rb', line 72 def name @name ||= @host.get_value("VM.get_name_label",@uid) end |
#pause! ⇒ Object
Pauses the VM, and returns the current state
88 89 90 91 |
# File 'lib/xen/vm.rb', line 88 def pause! @host.call("VM.pause",@uid) state(true) end |
#start!(paused = false) ⇒ Object
Starts a VM, and returns the current state
82 83 84 85 |
# File 'lib/xen/vm.rb', line 82 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"
67 68 69 |
# File 'lib/xen/vm.rb', line 67 def state refresh = false @state = refresh || !@state ? @host.get_value("VM.get_power_state",@uid) : @state end |
#unpause! ⇒ Object
Unpauses the VM, and returns the current state
94 95 96 97 |
# File 'lib/xen/vm.rb', line 94 def unpause! @host.call("VM.unpause",@uid) state(true) end |