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_file ⇒ Object
XXX We’re assuming other processes aren’t going to edit config_files 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_file_newer_than_instance? ⇒ Boolean
- #create_backup(options = {}) ⇒ Object
- #create_image(*args) ⇒ Object
- #first_ip ⇒ Object
-
#initialize(*args) ⇒ Slice
constructor
A new instance of Slice.
-
#instance ⇒ Object
Cache Xen instance info to reduce system calls to xm command.
-
#ip ⇒ Object
Primary IP.
- #root_disk ⇒ Object
- #running? ⇒ Boolean
- #save ⇒ Object
- #start ⇒ Object
- #state ⇒ Object
- #stop ⇒ Object
Constructor Details
Instance Attribute Details
#backups ⇒ Object
Returns the value of attribute backups.
3 4 5 |
# File 'lib/xen/slice.rb', line 3 def backups @backups end |
#config_file ⇒ Object
XXX We’re assuming other processes aren’t going to edit config_files This is reasonable in simple cases.
78 79 80 |
# File 'lib/xen/slice.rb', line 78 def config_file @config_file end |
#image ⇒ Object
Returns the value of attribute image.
3 4 5 |
# File 'lib/xen/slice.rb', line 3 def image @image end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/xen/slice.rb', line 3 def name @name end |
Class Method Details
.all(options = {}) ⇒ Object
15 16 17 |
# File 'lib/xen/slice.rb', line 15 def self.all(={}) self.find(:all, ) end |
.find(*args) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/xen/slice.rb', line 5 def self.find(*args) = args. case args.first when :all then Xen::ConfigFile.find(:all, ).collect { |config_file| new :name => config_file.name } when :running then Xen::Instance.find(:all, ).collect { |instance| new :name => instance.name } # Retrieve a Slice by name else Xen::ConfigFile.find_by_name(args.first) && new(:name => args.first) end end |
Instance Method Details
#config_file_newer_than_instance? ⇒ Boolean
112 113 114 |
# File 'lib/xen/slice.rb', line 112 def config_file_newer_than_instance? instance && config_file.updated_at > instance.start_time end |
#create_backup(options = {}) ⇒ Object
86 87 88 |
# File 'lib/xen/slice.rb', line 86 def create_backup( = {}) Xen::Backup.create(name, :options) end |
#create_image(*args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/xen/slice.rb', line 28 def create_image(*args) = args..stringify_keys # Load default values for options that have not been set .reverse_merge! Xen::XenToolsConf.find.to_hash # Set some derived options .reverse_merge! 'hostname' => name # Name host after this slice ['dhcp'] = true unless ['ip'] ['swap'] ||= ['memory'].to_i * 2 if ['root_pass'] ['role'] = 'passwd' ['role-args'] = ['root_pass'] end unless [nil,''].include?(['tarball']) ['install-method'] = 'tar' ['install-source'] = ['tarball'] .delete('dist') end args = %w(hostname dist memory size force boot role role-args roledir dir lvm mirror ip mac netmask broadcast gateway dhcp swap accounts admins cache config fs image image-dev initrd keep kernel modules output install hooks partitions passwd tar-cmd extension swap-dev noswap ide arch install-method install-source template evms) # Remove options that are not in allowed argument list .keys.each { |key| .delete(key) unless args.include?(key) } Xen::Command.create_image() end |
#first_ip ⇒ Object
94 95 96 |
# File 'lib/xen/slice.rb', line 94 def first_ip config_file.vifs.first.ip if config_file and config_file.vifs 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.
67 68 69 70 71 72 73 74 |
# File 'lib/xen/slice.rb', line 67 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 |
#ip ⇒ Object
Primary IP
125 126 127 |
# File 'lib/xen/slice.rb', line 125 def ip config_file.vifs[0].ip end |
#root_disk ⇒ Object
120 121 122 |
# File 'lib/xen/slice.rb', line 120 def root_disk config_file.vbds.detect { |vbd| vbd.name == "#{name}-disk" } unless config_file.nil? end |
#running? ⇒ Boolean
98 99 100 |
# File 'lib/xen/slice.rb', line 98 def running? self.instance ? true : false end |
#save ⇒ Object
116 117 118 |
# File 'lib/xen/slice.rb', line 116 def save @config_file.save end |
#start ⇒ Object
102 103 104 105 |
# File 'lib/xen/slice.rb', line 102 def start Xen::Instance.create(@name) @instance = Xen::Instance.find(@name) end |
#state ⇒ Object
90 91 92 |
# File 'lib/xen/slice.rb', line 90 def state self.instance ? :running : :stopped end |