Class: Xen::ConfigFile
- Inherits:
-
Object
- Object
- Xen::ConfigFile
- Includes:
- Parentable
- Defined in:
- lib/xen/config_file.rb
Instance Attribute Summary collapse
-
#extra ⇒ Object
Returns the value of attribute extra.
-
#kernel ⇒ Object
Returns the value of attribute kernel.
-
#memory ⇒ Object
Returns the value of attribute memory.
-
#name ⇒ Object
Returns the value of attribute name.
-
#on_crash ⇒ Object
Returns the value of attribute on_crash.
-
#on_poweroff ⇒ Object
Returns the value of attribute on_poweroff.
-
#on_reboot ⇒ Object
Returns the value of attribute on_reboot.
-
#ramdisk ⇒ Object
Returns the value of attribute ramdisk.
-
#root ⇒ Object
Returns the value of attribute root.
-
#vbds ⇒ Object
Returns the value of attribute vbds.
-
#vifs ⇒ Object
Returns the value of attribute vifs.
Class Method Summary collapse
- .all ⇒ Object
- .create_from_config_file(config) ⇒ Object
- .find(*args) ⇒ Object
- .find_by_name(name) ⇒ Object
Instance Method Summary collapse
-
#auto ⇒ Object
(also: #auto?)
Returns true|false depending on whether slice is set to start automatically.
- #auto_file ⇒ Object
- #filename ⇒ Object
-
#initialize(*args) ⇒ ConfigFile
constructor
A new instance of ConfigFile.
- #save ⇒ Object
-
#set_auto(value) ⇒ Object
Set to true|false to enable|disable autostart of slice.
- #updated_at ⇒ Object
Methods included from Parentable
Constructor Details
#initialize(*args) ⇒ ConfigFile
Returns a new instance of ConfigFile.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/xen/config_file.rb', line 9 def initialize(*args) = args. @name = [:name] @kernel = [:kernel] @ramdisk = [:ramdisk] @memory = [:memory].to_i @root = [:root] @vbds = [:vbds] @vifs = [:vifs] @on_poweroff = [:on_poweroff] @on_reboot = [:on_reboot] @on_crash = [:on_crash] @extra = [:extra] end |
Instance Attribute Details
#extra ⇒ Object
Returns the value of attribute extra.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def extra @extra end |
#kernel ⇒ Object
Returns the value of attribute kernel.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def kernel @kernel end |
#memory ⇒ Object
Returns the value of attribute memory.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def memory @memory end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def name @name end |
#on_crash ⇒ Object
Returns the value of attribute on_crash.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def on_crash @on_crash end |
#on_poweroff ⇒ Object
Returns the value of attribute on_poweroff.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def on_poweroff @on_poweroff end |
#on_reboot ⇒ Object
Returns the value of attribute on_reboot.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def on_reboot @on_reboot end |
#ramdisk ⇒ Object
Returns the value of attribute ramdisk.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def ramdisk @ramdisk end |
#root ⇒ Object
Returns the value of attribute root.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def root @root end |
#vbds ⇒ Object
Returns the value of attribute vbds.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def vbds @vbds end |
#vifs ⇒ Object
Returns the value of attribute vifs.
7 8 9 |
# File 'lib/xen/config_file.rb', line 7 def vifs @vifs end |
Class Method Details
.all ⇒ Object
32 33 34 35 36 37 |
# File 'lib/xen/config_file.rb', line 32 def self.all config_files = Dir.glob("#{Xen::XEN_DOMU_CONFIG_DIR}/*#{Xen::CONFIG_FILE_EXTENSION}") config_files.collect do |filename| create_from_config_file(File.read(filename)) end end |
.create_from_config_file(config) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/xen/config_file.rb', line 74 def self.create_from_config_file(config) name, kernel, ramdisk, memory, root, disk, vif, on_poweroff, on_reboot, on_crash, extra = nil eval(config) vifs = Array(vif).collect { |v| Xen::Vif.from_str(v) } vbds = Array(disk).collect { |d| Xen::Vbd.from_str(d) } new(:name => name, :disk => disk, :kernel => kernel, :ramdisk => ramdisk, :memory => memory, :root => root, :vbds => vbds, :vifs => vifs, :on_poweroff => on_poweroff, :on_reboot => on_reboot, :on_crash => on_crash, :extra => extra) end |
.find(*args) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/xen/config_file.rb', line 24 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
39 40 41 42 43 |
# File 'lib/xen/config_file.rb', line 39 def self.find_by_name(name) return new(:name => 'Domain-0') if name == 'Domain-0' filename = "#{Xen::XEN_DOMU_CONFIG_DIR}/#{name}#{Xen::CONFIG_FILE_EXTENSION}" create_from_config_file(File.read(filename)) if File.exists?(filename) end |
Instance Method Details
#auto ⇒ Object Also known as: auto?
Returns true|false depending on whether slice is set to start automatically
68 69 70 |
# File 'lib/xen/config_file.rb', line 68 def auto File.symlink?(auto_file) && File.(File.readlink(auto_file), File.dirname(auto_file)) == filename end |
#auto_file ⇒ Object
49 50 51 |
# File 'lib/xen/config_file.rb', line 49 def auto_file "#{Xen::XEN_DOMU_CONFIG_DIR}/auto/#{name}#{Xen::CONFIG_FILE_EXTENSION}" end |
#filename ⇒ Object
45 46 47 |
# File 'lib/xen/config_file.rb', line 45 def filename "#{Xen::XEN_DOMU_CONFIG_DIR}/#{name}#{Xen::CONFIG_FILE_EXTENSION}" end |
#save ⇒ Object
82 83 84 85 |
# File 'lib/xen/config_file.rb', line 82 def save template = ERB.new IO.read(Xen::TEMPLATE_DIR + '/domu.cfg.erb') File.open(filename, 'w'){ |f| f.write template.result(binding) } end |
#set_auto(value) ⇒ Object
Set to true|false to enable|disable autostart of slice
58 59 60 61 62 63 64 65 |
# File 'lib/xen/config_file.rb', line 58 def set_auto(value) if value == true File.symlink("../#{File.basename(filename)}", auto_file) unless auto else File.unlink(auto_file) if auto end auto == value # return true if final state is as requested end |
#updated_at ⇒ Object
53 54 55 |
# File 'lib/xen/config_file.rb', line 53 def updated_at File.mtime(filename) end |