Class: Xen::Slice
- Inherits:
-
Object
- Object
- Xen::Slice
- Defined in:
- lib/xen/slice.rb
Instance Attribute Summary collapse
-
#backups ⇒ Object
Returns the value of attribute backups.
-
#config ⇒ Object
XXX We’re assuming other processes aren’t going to edit configs This is reasonable in simple cases.
-
#image ⇒ Object
Returns the value of attribute image.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #config_newer_than_instance? ⇒ Boolean
- #create_image(args) ⇒ Object
-
#initialize(*args) ⇒ Slice
constructor
A new instance of Slice.
-
#instance ⇒ Object
Cache Xen instance info to reduce system calls to xm command.
- #running? ⇒ Boolean
- #save ⇒ Object
- #start ⇒ Object
- #state ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(*args) ⇒ Slice
Returns a new instance of Slice.
18 19 20 21 22 23 24 25 |
# File 'lib/xen/slice.rb', line 18 def initialize(*args) = args. # remove trailing hash (not used) @name = args.first @config = [:config] @instance = [:instance] @instance_cache_expires = Time.now @backups = Array([:backups]) end |
Instance Attribute Details
#backups ⇒ Object
Returns the value of attribute backups.
2 3 4 |
# File 'lib/xen/slice.rb', line 2 def backups @backups end |
#config ⇒ Object
XXX We’re assuming other processes aren’t going to edit configs This is reasonable in simple cases.
46 47 48 |
# File 'lib/xen/slice.rb', line 46 def config @config end |
#image ⇒ Object
Returns the value of attribute image.
2 3 4 |
# File 'lib/xen/slice.rb', line 2 def image @image end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/xen/slice.rb', line 2 def name @name end |
Class Method Details
.all(options = {}) ⇒ Object
14 15 16 |
# File 'lib/xen/slice.rb', line 14 def self.all(={}) self.find(:all, ) end |
.find(*args) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/xen/slice.rb', line 4 def self.find(*args) = args. case args.first when :all then Xen::Config.find(:all, ).collect { |config| config.slice } when :running then Xen::Instance.find(:all, ).collect { |instance| instance.slice } # Retrieve a Slice by name else Xen::Config.find_by_name(args.first) && self.new(args.first) end end |
Instance Method Details
#config_newer_than_instance? ⇒ Boolean
72 73 74 |
# File 'lib/xen/slice.rb', line 72 def config_newer_than_instance? instance && config.updated_at > instance.start_time end |
#create_image(args) ⇒ Object
27 28 29 30 |
# File 'lib/xen/slice.rb', line 27 def create_image(args) args = hash.collect{|k,v| "#{k}=#{v}"} Xen::Command.create_image end |
#instance ⇒ Object
Cache Xen instance info to reduce system calls to xm command. It still needs to be checked regularly as operations like shutdown and create can take a while.
35 36 37 38 39 40 41 42 |
# File 'lib/xen/slice.rb', line 35 def instance if @instance_cache_expires > Time.now @instance else @instance_cache_expires = Time.now + Xen::INSTANCE_OBJECT_LIFETIME @instance = Xen::Instance.find(@name) if @name end end |
#running? ⇒ Boolean
58 59 60 |
# File 'lib/xen/slice.rb', line 58 def running? self.instance ? true : false end |
#save ⇒ Object
76 77 78 |
# File 'lib/xen/slice.rb', line 76 def save @config.save end |
#start ⇒ Object
62 63 64 65 |
# File 'lib/xen/slice.rb', line 62 def start Xen::Instance.create(@name) @instance = Xen::Instance.find(@name) end |
#state ⇒ Object
54 55 56 |
# File 'lib/xen/slice.rb', line 54 def state self.instance ? :running : :stopped end |