Class: Xen::ConfigFile

Inherits:
Object
  • Object
show all
Includes:
Parentable
Defined in:
lib/xen/config_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parentable

#slice

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)
  options = args.extract_options!
  @name = options[:name]
  @kernel = options[:kernel]
  @ramdisk = options[:ramdisk]
  @memory = options[:memory].to_i
  @root = options[:root]
  @vbds = options[:vbds]
  @vifs = options[:vifs]
  @on_poweroff = options[:on_poweroff]
  @on_reboot = options[:on_reboot]
  @on_crash = options[:on_crash]
  @extra = options[:extra]
end

Instance Attribute Details

#extraObject

Returns the value of attribute extra.



7
8
9
# File 'lib/xen/config_file.rb', line 7

def extra
  @extra
end

#kernelObject

Returns the value of attribute kernel.



7
8
9
# File 'lib/xen/config_file.rb', line 7

def kernel
  @kernel
end

#memoryObject

Returns the value of attribute memory.



7
8
9
# File 'lib/xen/config_file.rb', line 7

def memory
  @memory
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/xen/config_file.rb', line 7

def name
  @name
end

#on_crashObject

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_poweroffObject

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_rebootObject

Returns the value of attribute on_reboot.



7
8
9
# File 'lib/xen/config_file.rb', line 7

def on_reboot
  @on_reboot
end

#ramdiskObject

Returns the value of attribute ramdisk.



7
8
9
# File 'lib/xen/config_file.rb', line 7

def ramdisk
  @ramdisk
end

#rootObject

Returns the value of attribute root.



7
8
9
# File 'lib/xen/config_file.rb', line 7

def root
  @root
end

#vbdsObject

Returns the value of attribute vbds.



7
8
9
# File 'lib/xen/config_file.rb', line 7

def vbds
  @vbds
end

#vifsObject

Returns the value of attribute vifs.



7
8
9
# File 'lib/xen/config_file.rb', line 7

def vifs
  @vifs
end

Class Method Details

.allObject



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)
  options = args.extract_options!
  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

#autoObject 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.expand_path(File.readlink(auto_file), File.dirname(auto_file)) == filename
end

#auto_fileObject



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

#filenameObject



45
46
47
# File 'lib/xen/config_file.rb', line 45

def filename
  "#{Xen::XEN_DOMU_CONFIG_DIR}/#{name}#{Xen::CONFIG_FILE_EXTENSION}"
end

#saveObject



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_atObject



53
54
55
# File 'lib/xen/config_file.rb', line 53

def updated_at
  File.mtime(filename)
end