Class: Xen::Instance
Instance Attribute Summary collapse
-
#cpu_time ⇒ Object
readonly
Returns the value of attribute cpu_time.
-
#domid ⇒ Object
readonly
Returns the value of attribute domid.
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#vcpus ⇒ Object
readonly
Returns the value of attribute vcpus.
Class Method Summary collapse
- .all ⇒ Object
- .create(name) ⇒ Object
-
.dom0(*args) ⇒ Object
A convenience wrapper for
find(:dom0)
.</tt>. - .find(*args) ⇒ Object
- .find_by_name(name) ⇒ Object
- .shutdown(name) ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(options = {}) ⇒ Instance
constructor
A new instance of Instance.
- #pause ⇒ Object
- #reboot ⇒ Object
- #uptime ⇒ Object
Methods included from Parentable
Constructor Details
#initialize(options = {}) ⇒ Instance
Returns a new instance of Instance.
6 7 8 9 10 11 12 13 14 |
# File 'lib/xen/instance.rb', line 6 def initialize(={}) @name = [:name] @domid = [:domid] @memory = [:memory] @cpu_time = [:cpu_time] @vcpus = [:vcpus] @state = [:state] @start_time = Time.at([:start_time].to_f) if [:start_time] end |
Instance Attribute Details
#cpu_time ⇒ Object (readonly)
Returns the value of attribute cpu_time.
4 5 6 |
# File 'lib/xen/instance.rb', line 4 def cpu_time @cpu_time end |
#domid ⇒ Object (readonly)
Returns the value of attribute domid.
4 5 6 |
# File 'lib/xen/instance.rb', line 4 def domid @domid end |
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
4 5 6 |
# File 'lib/xen/instance.rb', line 4 def memory @memory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/xen/instance.rb', line 4 def name @name end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
4 5 6 |
# File 'lib/xen/instance.rb', line 4 def start_time @start_time end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'lib/xen/instance.rb', line 4 def state @state end |
#vcpus ⇒ Object (readonly)
Returns the value of attribute vcpus.
4 5 6 |
# File 'lib/xen/instance.rb', line 4 def vcpus @vcpus end |
Class Method Details
.all ⇒ Object
24 25 26 27 28 |
# File 'lib/xen/instance.rb', line 24 def self.all Xen::Command.detailed_instance_list.collect do |instance| new(instance) end end |
.create(name) ⇒ Object
37 38 39 40 |
# File 'lib/xen/instance.rb', line 37 def self.create(name) output = Xen::Command.start_instance(name.to_s + Xen::CONFIG_FILE_EXTENSION) $? == 0 ? true : false end |
.dom0(*args) ⇒ Object
A convenience wrapper for find(:dom0)
.</tt>.
48 49 50 |
# File 'lib/xen/instance.rb', line 48 def self.dom0(*args) find_by_name(:dom0) end |
.find(*args) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/xen/instance.rb', line 16 def self.find(*args) = args. case args.first when :all then all else find_by_name(args.first) end end |
.find_by_name(name) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/xen/instance.rb', line 30 def self.find_by_name(name) Xen::Command.detailed_instance_list(name).each do |instance| return new(instance) end return false end |
.shutdown(name) ⇒ Object
42 43 44 45 |
# File 'lib/xen/instance.rb', line 42 def self.shutdown(name) output = Xen::Command.shutdown_instance(name) $? == 0 ? true : false end |
Instance Method Details
#destroy ⇒ Object
61 62 |
# File 'lib/xen/instance.rb', line 61 def destroy end |
#pause ⇒ Object
64 65 |
# File 'lib/xen/instance.rb', line 64 def pause end |
#reboot ⇒ Object
56 57 58 59 |
# File 'lib/xen/instance.rb', line 56 def reboot `xm reboot #{name}` $? == 0 ? true : false end |
#uptime ⇒ Object
52 53 54 |
# File 'lib/xen/instance.rb', line 52 def uptime start_time ? Time.now - start_time : nil end |