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(name, options = {}) ⇒ Instance
constructor
A new instance of Instance.
- #pause ⇒ Object
- #reboot ⇒ Object
- #uptime ⇒ Object
Methods included from Parentable
Constructor Details
#initialize(name, options = {}) ⇒ Instance
Returns a new instance of Instance.
5 6 7 8 9 10 11 12 13 |
# File 'lib/xen/instance.rb', line 5 def initialize(name, ={}) @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.
3 4 5 |
# File 'lib/xen/instance.rb', line 3 def cpu_time @cpu_time end |
#domid ⇒ Object (readonly)
Returns the value of attribute domid.
3 4 5 |
# File 'lib/xen/instance.rb', line 3 def domid @domid end |
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
3 4 5 |
# File 'lib/xen/instance.rb', line 3 def memory @memory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/xen/instance.rb', line 3 def name @name end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
3 4 5 |
# File 'lib/xen/instance.rb', line 3 def start_time @start_time end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
3 4 5 |
# File 'lib/xen/instance.rb', line 3 def state @state end |
#vcpus ⇒ Object (readonly)
Returns the value of attribute vcpus.
3 4 5 |
# File 'lib/xen/instance.rb', line 3 def vcpus @vcpus end |
Class Method Details
.all ⇒ Object
23 24 25 26 27 |
# File 'lib/xen/instance.rb', line 23 def self.all Xen::Command.detailed_instance_list.collect do |instance| new(name, instance) end end |
.create(name) ⇒ Object
36 37 38 39 |
# File 'lib/xen/instance.rb', line 36 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>.
47 48 49 |
# File 'lib/xen/instance.rb', line 47 def self.dom0(*args) find_by_name(:dom0) end |
.find(*args) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/xen/instance.rb', line 15 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
29 30 31 32 33 34 |
# File 'lib/xen/instance.rb', line 29 def self.find_by_name(name) Xen::Command.detailed_instance_list(name).each do |instance| return new(name, instance) end return false end |
.shutdown(name) ⇒ Object
41 42 43 44 |
# File 'lib/xen/instance.rb', line 41 def self.shutdown(name) output = Xen::Command.shutdown_instance(name) $? == 0 ? true : false end |
Instance Method Details
#destroy ⇒ Object
60 61 |
# File 'lib/xen/instance.rb', line 60 def destroy end |
#pause ⇒ Object
63 64 |
# File 'lib/xen/instance.rb', line 63 def pause end |
#reboot ⇒ Object
55 56 57 58 |
# File 'lib/xen/instance.rb', line 55 def reboot `xm reboot #{name}` $? == 0 ? true : false end |
#uptime ⇒ Object
51 52 53 |
# File 'lib/xen/instance.rb', line 51 def uptime start_time ? Time.now - start_time : nil end |